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.


2 thoughts on “WebSocket Chat application using JEE 7 with Glassfish 4.0

  1. Hi Michael Jo,
    Now my requirement is to develop chat application(like facebook) with websocket+java ,
    please suggest me , if you have any sample application using websocket+java chat application please send me sample application to my mail id: narchintha@gmail.com
    Thanks in advance,

    1. Everything should be the same except the server side. The challenge is that you will need to group several users (start with only two users to make the requirement simple) and establish the connection between grouped users – I would name this a group session. In this case, it will be two users. Not like the sample code that I created, you will need a logic to hold all logged in users and a logic to put users into group session. Also, you will need a websocket logic to handle communication for a specific group session. I think your challenge is defining the group session logic. Actually, websocket part should be straight forward. Challenge is how dynamically you create an end point per group session. Hope this helps.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s