Monday, November 25, 2013

Websockets !

Some interesting developments in JBoss EAP 6.x, with the introduction of an experimental implementation of the Websockets 1.0 JSR, a specification introduced in Java EE7. Developers will thus be able to enable websockets support in their existing EE 6 application, a key capability of modern web applications, without having to immediately migrate to brand new application server implementations and having to do without support. Since it uses the Websockets JSR standard, the web application will then be able to run on EE 7 application servers when the time comes for the big migration.

In addition to that, the implementation is based on the websockets implementation introduced in Apache Tomcat 7 and has compatibility with its Servlet 3.1 packaged renamed async IO.

Enabling websockets is not going to be automatic though, as Websockets 1.0 is not part of the previous JavaEE standard.

Using it involves the following checklist:
  • Use a build of the JBoss Web container from the 7.4 branch with JBoss EAP 6.2; the resultant jbossweb JAR can be placed in the org.jboss.as.web module of EAP in place of the existing web JAR, either by replacing it or after editing the module descriptor to have it use the updated JAR. The JAR contains the Websockets 1.0 API classes as well as the implementation as it is meant to be used in a Java EE6 environment, so no other JAR is necessary.
  • Required runtime is Java 7 for the Websockets 1.0 implementation
  • Use either the APR/native connector or the NIO2 connector (the latter should be used by default in the Web 7.4 builds)
  • Enable Websockets in the webapp, by loading the Servlet container initializer of the websockets implementation
The last step can be done easily using a dedicated "descriptor" JAR containing the services definition. One appropriate can be found in the web container svn repository: http://anonsvn.jboss.org/repos/jbossweb/branches/7.4.x/res/enable-websockets.jar