WebSocket Chat application using JEE 7 with Glassfish 4.0

I was interested in WebSocket technology since last year. I have a posting related to WebSocket using Grizzly implementation. Since then, WebSocket becomes a part of JEE 7 release and Glassfish 4.0 with JEE 7 has been released. There are tons of articles that explains what’s changed in JEE 7 and how to start using JEE 7.


In this posting, I’d like to briefly discuss my experience with WebSocket implementation in JEE 7.

  • Very simple : using @ annotation, I can declare POJO into WebSocket Server/Client Endpoint really easiy.
  • There is a way of creating a WebSocket Server Endpoint without using @ annotation.
  • It seems I can not use both in one project. Programmatic WebSocket implementation overwrites the annotation implementation.
  • WebSocket URI gave me a hard time. After I figure it out, it is obvious. However, when I was in it, I really didn’t see. It took me a while to realize those WebSocket sample codes does not specify the webcontext name. This is critical piece. I was struggled with “undefine” error.
  • ws://domain:port#/webcontext(project name)/serverendpoint

Even though my WebSocket chat application is very simple application, I found it much easier to implement – compare with Grizzly implementation.


Web is evolving so fast and new ideas are keep pouring out. I think WebSocket will be very useful technology in terms of replacing point to point messaging. Especially, the connection has to be maintained constantly. One application that I used to maintain uses applet to satisfy this requirement. I think replacing an applet with WebSocket will be beneficial.


I presented this topic to my colleagues in the company Lunch & Learn session. Here is my presentation using Prezi.

Original Prezi Link HERE.

Source Code at GitHub is HERE.


Configuring JEE7 with GlassFish (4.0-b87) on Eclipse

JEE7 release is just around the corner. Due to JRE security reason, my understanding is the release was postponed until next year. Short summary about Java EE 7 (JSR-342) can be found here and overview can be found here with very cool slide. My interest in WebSocket technology was high since last year. I’ve struggled to create my first WebSocket demo last year – there were many earlier implementation postings, but I had hard time finding newer GlassFish implementation. I learned that WebSocket 1.0 as a part of JEE7 supports method annotations around WebSocket lifecycle methods along with straight method implementations. If you want to know the detail, check this out.

In this posting, I’d like to explain how to set up GlassFish (latest build 4.0-b87) within Eclipse and explain some of troubles that I had. I didn’t want to install OEPE bundle. OEPE gives the whole package and makes it easier to configure, but I had some frustrating experience previously and decide not to go with OEPE.


First of all, I had to get rid of previously install GlassFish Plug in and GlassFish Tool in the Eclipse Juno. Click Help > About Eclipse > Install Details and remove any GlassFish related installation. I skipped this step and couldn’t deploy web application from the Eclipse. Symptom was the deployment hangs at 69% and no response from the server in Eclipse. There is a blog about how to clear old version of GlassFish tools in the Eclipse. For details, look at this blog.

Installation & Configuration

Once you are done,

  1. Time to download and install GlassFish 4.0.  Scroll to the bottom and download the latest GlassFish.
  2. Install GlassFish.
  3. Start up Eclipse and make sure you have the latest JDK. At least 7.
  4. Now, it is time to install GlassFish Tool. It seems there are two ways of doing it. In my case, first approach (Preeference > Install/Update > Add Available Software Site) didn’t work well. Site URL is  http://download.java.net/glassfish/eclipse/juno.
  5. Second approach is Help > New Software Install > past above URL.
  6. As soon as you do that, GlassFish Tool and Document will show up and you can install those in the Eclipse.

Coding & Testing

Now, time to code and test. I captured the code from Markus Eisele’s blog. The servlet is demonstrating by print out JSON object from JsonObjectBuilder.

Testing is simple, just start the GlassFish 4.0 and test localhost:8080/JEE7Test/JsonTester


Since I configured GlassFish 4.0 with JEE7, I’d like to modify my WebSocket chat demo using annotations and deploy to GlassFish 4.0. This will be a fun exercise and I will have a chance to read more JEE7 API documents.

MyFace implementation in Glassfish 3.1.1

Maybe I wasn’t searching enough, but I had agonizing experience by dealing with two JSF implementations in Dynamic Web Project in the Eclipse. Glassfish comes with Mojarra by default and it will conflict with other JSF implementation. By removing jsf-api.jar and jsf-impl.jar from Glassfish modules folder will break the project in the Eclipse. If I run the Glassfish outside of Eclipse, it may work, but I am using it within the Eclipse environment.

Solution to this problem was to modify the sun-web.xml file.

<sun-web-app error-url="">
<class-loader delegate="false"/>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class java code.</description>
<property name="useBundledJsf" value="true"/> 
 <property name="useMyFaces" value="true" />

* Make sure to change the quote when Copy & Paste into the Eclipse

Maybe useBundledJsf is newer property, but both works fine. By setting class-loader delegate false, it tells Glassfish that the project will use other implementation instead of Sun RI.

Also, I came across another solution – from MyFace wiki. By creating in your webapp a “fake” com.sun.faces.config.ConfigureListener that will be loaded BEFORE the sun RI one’s.

This class is here to prevent from using the real one from the sun reference implementation
public class ConfigureListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent servletContextEvent) {
//To change body of implemented methods use File | Settings | File Templates.
public void contextDestroyed(ServletContextEvent servletContextEvent) {
//To change body of implemented methods use File | Settings | File Templates.

I haven’t done above solution. Basically, modifying sun-web.xml will work just fine.