JavaFX with JBoss Seam

This is an introductory post that shows how to use JavaFX with JBoss Seam. Communication between JavaFX and server (Seam) is done via Flamingo RIA framework. Flamingo, not only provides Flex to server communications like Granite DS and Blaze DS, but also provides JavaFX to server communications.

screenshot01.png

JavaFX:

package com.exadel.flamingo.javafx;


import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.TextOrigin;
import javafx.ext.swing.SwingButton;
import javafx.scene.layout.VBox;
import javafx.scene.control.TextBox;

import com.exadel.flamingo.javafx.samples.helloworld.javafx.HelloworldClient;

class Hello {
    public var name:String;
    public var str:String;
}
var helloModel = new Hello();

HelloworldClient.setServerUrl(FX.getArgument('uri') as java.lang.String);

var helloText: TextBox = TextBox {
    text: bind helloModel.name with inverse
    columns: 7
    selectOnFocus:true
}

var helloLabel = Text{
    y:8
    font: Font { name:"sansserif", size: 12 }
    fill: Color.BLACK
    content: bind "Server says: {helloModel.str}"
    textOrigin: TextOrigin.TOP
}

var helloButton = SwingButton  {
    text:"Say Hello!"
    action: function(){
        helloModel.str = HelloworldClient.CLIENT.hello(helloModel.name);
    }
}

Stage {
    title: "Helloworld Sample"
    width: 200
    height: 150
    scene: Scene {
        content: VBox {
            translateX: 5
            translateY: 5
            spacing: 10
            content: [
                HBox {
                    content: helloText
                    spacing: 10
                },
                HBox {
                    content: helloButton
                    spacing: 10
            	},
                HBox {
                    content: helloLabel
                    spacing: 10
            }]

        }
    }
}

HelloAction interface:

package com.exadel.flamingo.javafx.samples;

import org.jboss.seam.annotations.remoting.WebRemote;

public interface IHelloAction {

    @WebRemote
    public String hello(String name);
}

HelloAction (Seam component):

package com.exadel.flamingo.javafx.samples;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.remoting.WebRemote;

@Scope(ScopeType.STATELESS)
@Name("helloAction")
public class HelloAction implements IHelloAction {

    @WebRemote
    public String hello(String name) {
        return "Hello, " + name;
    }
}

Helloworld client:

package com.exadel.flamingo.javafx.samples.javafx;

import com.caucho.hessian.client.HessianProxyFactory;
import com.exadel.flamingo.javafx.samples.IHelloAction;
import java.net.MalformedURLException;

public class HelloworldClient {

    public static HelloworldClient CLIENT;
    private IHelloAction _service;
    private String _url;

    private HelloworldClient(String string) {
        _url = string;
    }
    public static void setServerUrl(String url) {
        CLIENT = new HelloworldClient(url);
    }
    private IHelloAction getService() {
        if (_service == null) {
            try {
                HessianProxyFactory factory = new HessianProxyFactory();
                _service = (IHelloAction) factory.create(IHelloAction.class, _url);
            } catch (MalformedURLException ex) {
                System.out.println(ex);
            }
        }
        return _service;
    }
    public String hello(String s) {
        return getService().hello(s);
    }
}

JSP file:






Helloworld


JavaFX with Seam!

javafx( { archive: "jnlp/helloworld-client-javafx.jar", draggable: true, width: 600, height: 560, code: "com.exadel.flamingo.javafx.MainFrame", name: "Helloworld", uri:'' } );

4 thoughts on “JavaFX with JBoss Seam

  1. very interesting,

    I am close from making it work either with Hessian 1 or 2

    but I seems I am missing something about the protocol handshake between the client and the server :

    On the client side :

    HessianProxyFactory factory = new HessianProxyFactory();
    // the following 3 lines are uncommented if we use Hessian2
    //factory.setHessian2Reply(true);
    //factory.setHessian2Request(true);
    //factory.setDebug(true);
    _service = (IHelloAction) factory.create(IHelloAction.class, _url);

    On the server side :

    public interface IHelloAction {

    @WebRemote
    public String hello(String name);
    }

    @Scope(ScopeType.STATELESS)
    @Name(“helloAction”)
    public class HelloAction implements IHelloAction {

    @WebRemote
    public String hello(String name) {
    return “Hello, ” name;
    }
    }

    If I use hessian-3.2.1.jar
    (in both client
    and server side) I get the following error on the server side :

    19:43:27,331 ERROR [ContextualHttpServletRequest] ended request due to
    exception
    com.caucho.hessian.io.HessianProtocolException: expected string at 0x6d
    at com.caucho.hessian.io.Hessian2Input.error(Hessian2Input.java:2714)
    at com.caucho.hessian.io.Hessian2Input.expect(Hessian2Input.java:2695)
    at
    com.caucho.hessian.io.Hessian2Input.readString(Hessian2Input.java:1322)
    at
    com.caucho.hessian.io.Hessian2Input.readMethod(Hessian2Input.java:267)
    at
    com.exadel.flamingo.service.seam.util.HessianSeamMethodInvoker.makeCall(HessianSeamMethodInvoker.java:64)
    at
    com.exadel.flamingo.service.seam.HessianToSeamRequestProcessor$HessianSeamContextualInvoker.invoke(HessianToSeamRequestProcessor.java:238)
    at
    com.exadel.flamingo.service.seam.HessianToSeamRequestProcessor$HessianSeamContextualInvoker.process(HessianToSeamRequestProcessor.java:214)
    at
    org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:53)
    at
    com.exadel.flamingo.service.seam.HessianToSeamRequestProcessor$HessianSeamContextualInvoker.runMethod(HessianToSeamRequestProcessor.java:251)
    at
    com.exadel.flamingo.service.seam.HessianToSeamRequestProcessor.process(HessianToSeamRequestProcessor.java:134)
    at
    com.exadel.flamingo.service.seam.HessianRemoteService.getResource(HessianRemoteService.java:74)
    at
    org.jboss.seam.servlet.SeamResourceServlet.doGet(SeamResourceServlet.java:75)
    at
    org.jboss.seam.servlet.SeamResourceServlet.doPost(SeamResourceServlet.java:92)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at
    org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
    at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
    at
    org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
    at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
    at
    org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
    at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
    at
    org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
    at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
    at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
    at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
    at
    org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
    at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
    at
    org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
    at
    org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
    at
    org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
    at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
    at
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at
    org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    at
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
    at
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:173)
    at
    org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
    at
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
    at
    org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
    at
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    at
    org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
    at
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
    at
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)

    If I use hessian-3.1.6.jar
    or
    hessian-3.1.3.jar
    (in both client and server side) there is no error on the server side
    BUT I get the following error on the client side :

    Exception in thread “AWT-EventQueue-0”
    com.caucho.hessian.client.HessianRuntimeException:
    com.caucho.hessian.io.HessianProtocolException: expected string at 0x48
    at
    com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:232)
    at $Proxy13.hello(Unknown Source)
    at
    com.exadel.flamingo.javafx.samples.javafx.HelloworldClient.hello(HelloworldClient.java:36)
    at com.exadel.flamingo.javafx.Hello$2.lambda(Hello.fx:41)
    at com.exadel.flamingo.javafx.Hello$2.lambda(Hello.fx:41)
    at com.exadel.flamingo.javafx.Hello$2.invoke(Hello.fx:40)
    at com.exadel.flamingo.javafx.Hello$2.invoke(Hello.fx:40)
    at com.exadel.flamingo.javafx.Hello$2.invoke(Hello.fx:40)
    at com.exadel.flamingo.javafx.Hello$2.invoke(Hello.fx:40)
    at
    javafx.ext.swing.SwingAbstractButton$1ActionListener$anon13.actionPerformed(SwingAbstractButton.fx:150)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown
    Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown
    Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at
    javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown
    Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
    Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: com.caucho.hessian.io.HessianProtocolException: expected
    string at 0x48
    at
    com.caucho.hessian.io.Hessian2Input.error(Hessian2Input.java:2705)
    at
    com.caucho.hessian.io.Hessian2Input.expect(Hessian2Input.java:2686)
    at
    com.caucho.hessian.io.Hessian2Input.readString(Hessian2Input.java:1403)
    at
    com.caucho.hessian.io.BasicDeserializer.readObject(BasicDeserializer.java:181)
    at
    com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:1753)
    at
    com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:220)
    … 31 more

    Have we forgotten something on the client side or the server side ?

    regards

    vincent

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s