WebSocket Support in Java Applications on Bluemix via the Liberty Runtime

Since Liberty profile you can use web sockets in your Java applications. This allows sending events from the server to web clients without having to poll the server.

The blog describes this core functionality pretty well and comes with a short video and a sample application. If you have a recent liberty profile installed in your IDE you can get this sample to work within minutes.

The Liberty buildpacks on IBM Bluemix support this functionality as well via the websocket-1.1 feature. However the default liberty configuration does not include this feature which is why you have to do two more steps when deploying your code as standalone application. Via the command line interface invoke the following commands.
1) cf set-env planningpoker JBP_CONFIG_LIBERTY “app_archive: {features: websocket-1.1, servlet-3.1}”
2) cf restage planningpoker

The sample application comes with a HTML page using plain old JavaScript. Since I needed this functionality in an application that uses AngularJS I used an AngularJS plugin angular-websocket. You can run this Angular sample easily together with the PlanningPoker sample above by just doing two changes.
1) In the JavaScript code change the websocket URL to “‘ws://’ + window.document.location.host + ‘/PlanningPoker/PokerEndpoint'” and in onMessage remove the JSON.parse
2) In PokerEndpoint.java remove the checks in sendMessage that prereq the room names

Then you can see messages from the PlanningPoker app also on the HTML page with the Angular code.