Esquire Theme by Matthew Buchanan
Social icons by Tim van Damme

12

Sep

Using Java for Web 3.0 (AjaxPush/Comet and WebSocket)

After playing with node.js for a few weekends I decided to see how Java accomplishes the new asynchronous low-latency nature of Web 3.0. In other words what does it take in Java to build the new “Hello World” of Web 3.0: an online chat server.

Traditionally it was a pain to do this because long open connections are not handled in the Servlet spec. So you had to rely on special container specific libraries. But now that is changing rapidly with Atomsphere. I was able to build a simple chat server for Apache Tomcat in short order. I actually I didn’t even have to build it as they had a chat server sample source code ready to go.

Atomsphere is pretty badass! It integrates rather nicely with JAX-RS and works with Apache Tomcat 6.0 and above so long as you set the protocol to NIO or APR. I’m hoping/predicting that Tomcat just makes NIO the default someday.

I only had couple of Gotcha’s:

  • Spring framework integration with the Atmosphere wrapped Jersey servlet
  • Maven Tomcat plugin protocol behavior.

To integrate with Spring and to fix Tomcat’s I did the following covered in this gist.

Unfortunately that still leaves the Maven Tomcat plugin which will only allow you to do HTTP/1.1 as the protocol. However there is a bug filed and its progressing nicely.

  1. agentgt posted this