Blog

Friday, 8 November 2013

Atmosphere WebSockets Exception on JBoss AS 7.1.1

Recently, we tried to integrate Atmosphere with our new application Agido to bring real time messaging and event broadcasting between users using our app. We encountered problems when we set "websocket" transport in atmosphere, and tried to use it with JBoss AS 7.1.1.


In maven repo, there is one more useful artifact for websocket support in 7.1:

    org.atmosphere.jboss.as
    jboss-as-websockets
    0.5

There is a wiki page about WebSocket support in JBoss (but unfortunately, websocket support is not possible on AS 7.1.1 version (last published version of AS7, however everything works on AS 7.1.2+). Using this artifact on AS 7.1.1 and trying to use Websocket protocol, causes this exception:
10:39:16,552 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/agido-server].[AtmosphereServlet]] (http-localhost-127.0.0.1-8080-2)   Servlet.service() for servlet AtmosphereServlet threw exception: java.lang.ClassNotFoundException: org.jboss.servlet.http.UpgradableHttpServletResponse from [Module "deployment.agido-server-1.0.0-SNAPSHOT.war:main" from Service Module Loader]
 at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
 at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
 at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
 at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
 at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
 at org.atmosphere.jboss.as.websockets.servlet.WebSocketServlet.event(WebSocketServlet.java:103) [jboss-as-websockets-0.5.jar:]
 at org.atmosphere.container.JBossWebSocketSupport.dispatch(JBossWebSocketSupport.java:87) [atmosphere-runtime-native-2.0.3.jar:2.0.3]
 at org.atmosphere.cpr.AtmosphereServlet.event(AtmosphereServlet.java:312) [atmosphere-runtime-native-2.0.3.jar:2.0.3]
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilterEvent(ApplicationFilterChain.java:494) [jbossweb-7.0.13.Final.jar:]
 at org.apache.catalina.core.ApplicationFilterChain.doFilterEvent(ApplicationFilterChain.java:399) [jbossweb-7.0.13.Final.jar:]
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:273) [jbossweb-7.0.13.Final.jar:]
 at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java) [jbossweb-7.0.13.Final.jar:]
 at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
 at pl.itcrowd.agido.server.web.TokenAuthenticator.invoke(TokenAuthenticator.java:66) [:]
 at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
 at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:897) [jbossweb-7.0.13.Final.jar:]
 at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:626) [jbossweb-7.0.13.Final.jar:]
 at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:2039) [jbossweb-7.0.13.Final.jar:]
 at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]

Also we encountered weird exception like this, using other transport protocols available in Atmosphere:
10:18:20,054 ERROR [org.apache.catalina.connector.CoyoteAdapter] (http-localhost-127.0.0.1-8080-1)   An exception or error occurred in the container during the request processing: java.lang.Illegal
StateException
        at org.jboss.msc.value.InjectedValue.getValue(InjectedValue.java:47)
        at org.jboss.as.connector.deployers.processors.CachedConnectionManagerSetupProcessor$CachedConnectionManagerSetupAction.setup(CachedConnectionManagerSetupProcessor.java:74)
        at org.jboss.as.web.ThreadSetupBindingListener.bind(ThreadSetupBindingListener.java:50) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
        at org.apache.catalina.core.StandardHostValve.event(StandardHostValve.java:231) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.valves.ValveBase.event(ValveBase.java:193) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.StandardEngineValve.event(StandardEngineValve.java:128) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.connector.CoyoteAdapter.event(CoyoteAdapter.java:265) [jbossweb-7.0.13.Final.jar:]
        at org.apache.coyote.http11.Http11AprProcessor.event(Http11AprProcessor.java:780) [jbossweb-7.0.13.Final.jar:]
        at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.event(Http11AprProtocol.java:579) [jbossweb-7.0.13.Final.jar:]
        at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:2033) [jbossweb-7.0.13.Final.jar:]
        at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]

Another mysterious side-effect of using this artifact on AS 7.1.1 is freezing connection, when we called atmosphere.unsubscribe(), using atmosphere.js libary on client side:

Request URL:http://localhost:8000/push/events/1?X-Atmosphere-Transport=close&X-Atmosphere-tracking-id=557a3034-7d5e-445f-9faf-47308c8a4962&_=1383913863051
Request Headersview source
Cache-Control:no-cache
Content-Type:text/plain
Pragma:no-cache
Referer: http://localhost:8000/projects
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.34 Safari/537.36
Query String Parametersview sourceview URL encoded
X-Atmosphere-Transport:close
X-Atmosphere-tracking-id:557a3034-7d5e-445f-9faf-47308c8a4962
_:1383913863051

This request hangs on "Pending" state, and never received response from server. Also browser tab gets frozen, so it was a serious problem.
So, class mentioned in first stack trace above: org.jboss.servlet.http.UpgradableHttpServletResponse is available only for JBoss AS 7.1.2+ versions. Thus we decided to use HTML5 Server Sent Events instead. Libary "jboss-as-websockets" shouldn't be used on AS 7.1.1 versions, all problems disappeared, when this libary has been removed from project :)