Let’s take the as a simple starting point. First we clone, build and run the default application with a JavaFX client and a basic Servlet 3 container :
git clone http://github.com/graniteds-tutorials/graniteds-tutorial-chat.git cd graniteds-tutorial-chat mvn clean install -Dclient=javafx -Dserver=servlet3 cd ../server-servlet3 mvn tomcat7:run-war
And start the JavaFX application in another window :
cd client-javafx mvn jfx:jar java -jar target/jfx/app/chat.jar
To configure websocket for this application, there are a few steps required :
In client-javafx/pom.xml, add the following dependency :
<dependencies> <dependency> <groupId>org.eclipse.jetty.websocket</groupId> <artifactId>websocket-client</artifactId> <version>9.1.5.v20140505</version> </dependency> <dependency> <groupId>org.eclipse.jetty.websocket</groupId> <artifactId>javax-websocket-client-impl</artifactId> <version>9.1.5.v20140505</version> </dependency> </dependencies>
This is the dependency for the Jetty 9 websocket client. You can alternatively use :
<dependency> <groupId>org.glassfish.tyrus.bundles</groupId> <artifactId>tyrus-standalone-client-jdk</artifactId> <version>1.8.2</version> </dependency>
In client-javafx/src/main/java/ChatClient.java, modify the configuration of the Consumer and Producer objects to use a websocket channel :
final Consumer chatConsumer = serverSession.getConsumer("chatTopic", "room", ChannelType.WEBSOCKET); final Producer chatProducer = serverSession.getProducer("chatTopic", "room", ChannelType.WEBSOCKET);
NOTE: if you are using a DataObserver in your application, it can be configured with:
new DataObserver(ChannelType.WEBSOCKET, serverSession)
That’s all if you are using the Servlet 3 configuration (with @ServerFilter).
You can rebuild and restart the server and client applications.
The Spring support does not (yet) detect and setup the JSR 356 support. You will also have to add the following listener to your web.xml :
<listener> <listener-class>org.granite.gravity.websocket.GravityWebSocketDeployer</listener-class> </listener>
Now you can rebuild everything and restart the server and client with a Spring backend.
cd graniteds-tutorial-chat cd server-spring mvn clean install -Dserver=spring mvn tomcat7:run-war]]>
Let’s take the as a simple starting point. First we clone, build and run the default application with a Flex client and a basic Servlet 3 container :
git clone http://github.com/graniteds-tutorials/graniteds-tutorial-chat.git cd graniteds-tutorial-chat mvn clean install -Dclient=flex -Dserver=servlet3 cd server-servlet3 mvn tomcat7:run-war
Now browse to check that everything works.
To configure websocket for this application, there are a few steps required :
In client-flex/pom.xml, add the following dependency :
<dependencies> <dependency> <groupId>org.graniteds</groupId> <artifactId>flex-websocket-client</artifactId> <version>1.0</version> <type>swc</type> </dependency> </dependencies>
In client-flex/src/main/flex/chat.mxml, modify the configuration of the Consumer and Producer objects to use a websocket channel :
chatConsumer = Spring.getInstance().mainServerSession.getConsumer("chatTopic", "room", ChannelType.WEBSOCKET); chatProducer = Spring.getInstance().mainServerSession.getProducer("chatTopic", "room", ChannelType.WEBSOCKET);
If you are using a DataObserver component, you can just change its channel before subscribing with :
myDataObserver.type = ChannelType.WEBSOCKET;
NOTE: if you are not using the Tide API (ServerSession) in your application, you will have to replace the GravityChannel by a WebSocketChannel :
channel = new WebSocketChannel("mychannel", "ws://localhost:8080/chat/websocketamf/amf"); channelSet = new ChannelSet(); channelSet.addChannel(channel); chatConsumer = new Consumer(); chatConsumer.destination = "chatTopic"; chatConsumer.topic = "room"; chatConsumer.channelSet = channelSet; chatProducer = new Producer(); chatProducer.destination = "chatTopic"; chatProducer.topic = "room"; chatProducer.channelSet = channelSet;
Flash requires a specific policy server for security reasons to allow the use of network sockets.
GraniteDS provides a very basic one that can be enabled with a simple listener in web.xml :
Add a web.xml in server-servlet3/src/main/webapp/WEB-INF/web.xml :
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <listener> <listener-class>org.granite.gravity.websocket.PolicyFileServerListener</listener-class> </listener> <context-param> <param-name>flashPolicyFileServer-allowDomains</param-name> <param-value>*:*</param-value> </context-param> </web-app>
NOTE: If you have multiple webapps in the same server, you need only one policy server (because it must run at the root context on the specific port 843). In this case, either configure it on one webapp, or better create a specific empty webapp that only hosts the policy server.
Now you can rebuild everything, restart the server and check that the application still works.
The Spring support does not (yet) detect and setup the JSR 356 support. You will also have to add the following listener to your web.xml :
<listener> <listener-class>org.granite.gravity.websocket.GravityWebSocketDeployer</listener-class> </listener>
Now you can rebuild everything and restart the server with a Spring backend.
cd graniteds-tutorial-chat mvn clean install -Dclient=flex -Dserver=spring cd server-spring mvn tomcat7:run-war]]>