Search code examples
javatomcatatmosphere

how to enable NIO / atmosphere on tomcat 6


I'm trying out atmosphere on tomcat 6 but only long polling works not websockets. The message i receive in the console output is

 Tomcat failed to detect this is a Comet application because context.xml is missing or the Http11NioProtocol Connector is not enabled.

Any info on this would be appreciated, thanks

Update: After modifying web.xml and server.xml the error message goes but the chat application always fallsback to long polling - I've tried several different .war deployments of websocket demos and they all behave the same.

I tried Tomcat 7 also, but it still uses long polling.

Some log info for startup

10:42:30.423 [main] INFO  o.atmosphere.cpr.AtmosphereFramework - Installed Default AtmosphereInterceptor [Android Interceptor Support, SSE Interceptor Support, JSONP Interceptor Support]. Set org.atmosphere.cpr.AtmosphereInterceptor.disableDefaults in your xml to disable them.
10:42:30.423 [main] WARN  o.atmosphere.cpr.AtmosphereFramework - No BroadcasterCache configured. Broadcasted message between client reconnection will be LOST. It is recommended to configure the HeaderBroadcasterCache.
10:42:30.423 [main] INFO  o.atmosphere.cpr.AtmosphereFramework - HttpSession supported: false
10:42:30.423 [main] INFO  o.atmosphere.cpr.AtmosphereFramework - Using BroadcasterFactory: org.atmosphere.cpr.DefaultBroadcasterFactory
10:42:30.423 [main] INFO  o.atmosphere.cpr.AtmosphereFramework - Using WebSocketProcessor: org.atmosphere.websocket.DefaultWebSocketProcessor
10:42:30.423 [main] INFO  o.atmosphere.cpr.AtmosphereFramework - Using Broadcaster: org.atmosphere.jersey.JerseyBroadcaster
10:42:30.428 [main] INFO  o.atmosphere.cpr.AtmosphereFramework - Atmosphere Framework 1.0.0.beta5 started.

27/08/2012 10:42:30 AM org.apache.coyote.http11.Http11NioProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
27/08/2012 10:42:30 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 11568 ms

When the chat client connects

27/08/2012 10:47:57 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector

INFO: Using a shared selector for servlet write/read

When a message is sent

10:48:09.256 [http-8080-exec-2] DEBUG o.a.cpr.AsynchronousProcessor - Cancelling the connection for request AtmosphereRequest{ contextPath=/atmosphere-rest-chat servletPath=/chat pathInfo=null requestURI=/atmosphere-rest-chat/chat requestURL=http://mogwai:8080/atmosphere-rest-chat/chat destroyable=true}

Solution

  • In context.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <Context>
        <Loader delegate="true"/>
    </Context>
    

    In server.xml:

    <Connector connectionTimeout="20000" port="8080" 
               protocol="org.apache.coyote.http11.Http11NioProtocol" 
               redirectPort="8443"/>
    

    Make sure you only have one implementation of CometProcessor defined in your classpath. You may want to remove catalina.jar from your webpass if it's bundled in. See this thread for more info:

    http://mail-archives.apache.org/mod_mbox/tomcat-users/200707.mbox/%3C11785700.post@talk.nabble.com%3E