In a string of recent articles, I have discussed downloading, installing and running demos for a number of different tools, frameworks and libraries that support push-style (web) applications in one way or another. I have looked into ‘classic’ comet with Grizzly, Atmosphere and CometD as well as ADF Active Data Service and WebLogic Pub/Sub (Bayeux) Channels. I have also looked to WebSockets with jWebSocket, again Atmosphere and CometD and also with Kaazing. I am now working on a series of articles in which I use each of these frameworks and push infrastructures to implement the same simple push-style application – to see how that goes and to compare the various implementations. The functionality I will be implementing is simple:
- through the web client (HTML 5/javaScript), a user can select an image from a list of ’slides’
- the selection of the image is communicated to the server (background WebSocket based or alternatively regular AJAX)Comet (Bayeux)/Long Poll style)
- the server informs all connected clients about the selected image through a pushed message (background WebSocket based or alternatively Comet (Bayeux)/Long Poll style); these clients all synchronize that slide selection
- a Java (server side) component can also connect to the server and listen in to image selection events as well as publish image selection messages of its own
The first article discussed the implementation using WebSockets and Kaazing Gateway (https://technology.amis.nl/blog/14777/push-based-synchronized-slideshow-web-application-implemented-using-websockets-and-kaazing-websocket-gateway). In this article, I will present an implementation using the CometD framework.
I will use NetBeans as my IDE, Tomcat as the Servlet Container to run the application on and a combination of browsers (Chrome, Firefox and IE) to try it out.
Earlier articles described how to set up NetBeans (https://technology.amis.nl/blog/14661/first-experiences-and-getting-started-with-glassfish-3-1-and-netbeans-7-x-its-a-breeze) and Tomcat (https://technology.amis.nl/blog/14688/installing-tomcat-7-and-configuring-as-server-in-netbeans) – these may be helpful to get started. Another discusses getting the CometD demos running (https://technology.amis.nl/blog/14709/running-cometd-2-examples-locally-on-tomcat-using-maven-and-netbeans and https://technology.amis.nl/blog/14720/cometd-2-java-client-sample-open-project-in-netbeans-based-on-maven-pom-file-modify-sources-and-run-java-based-comet-client).
Create NetBeans project from Maven Archetype
Getting started with a new CometD project in NetBeans is very simple. From the Maven Archetype, NetBeans can create a project that not only has the dependencies set up correctly but also provides us with a simple starter application – including JavaScript library and JSP file – that is ready to run.
First, I needed to locate the proper archetype deatils for CometD with JQuery and Jetty 7 libraries:
http://mvnrepository.com/artifact/org.cometd.archetypes/cometd-archetype-jquery-jetty7/2.3.1
