Using Atmosphere with other Framework like RestEasy, Wink or Struts - Atmosphere/atmosphere GitHub Wiki

To use Atmosphere with other REST framework, all you need to do is to configure their servlet in atmosphere.xml

<atmosphere-handlers>
    <!-- CXF -->
    <atmosphere-handler support-session="false"
                        context-root="/*"
                        class-name="org.atmosphere.handler.ReflectorServletProcessor">
        <property name="servletClassName" 
                  value="org.apache.cxf.transport.servlet.CXFServlet"/>
    </atmosphere-handler>
</atmosphere-handlers>

<atmosphere-handlers>
    <!-- RestLet -->
    <atmosphere-handler support-session="false"
                        context-root="/*"
                        class-name="org.atmosphere.handler.ReflectorServletProcessor">
        <property name="servletClassName" 
                  value="org.restlet.ext.servlet.ServerServlet"/>
    </atmosphere-handler>
</atmosphere-handlers>

<atmosphere-handlers>
    <!-- Wink -->
    <atmosphere-handler support-session="false"
                        context-root="/*"
                        class-name="org.atmosphere.handler.ReflectorServletProcessor">
        <property name="servletClassName" 
                  value="org.apache.wink.server.internal.servlet.RestServlet"/>
    </atmosphere-handler>
</atmosphere-handlers>

<atmosphere-handlers>
    <!-- RESTEasy -->
    <atmosphere-handler support-session="false"
                        context-root="/*"
                        class-name="org.atmosphere.handler.ReflectorServletProcessor">
        <property name="servletClassName"  
              value="org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher"/>
    </atmosphere-handler>
</atmosphere-handlers>

And then in your resource you can retrieve the Atmosphere's object by doing:

@Path("/")
public class Foo {
   @Context HttpServletRequest req;
   @Path("/suspend")
   public void suspend() {
          AtmosphereResource r = (AtmosphereResource)
                req.getAttribute("org.atmosphere.cpr.AtmosphereResource");
          r.setBroadcaster(r.getAtmosphereConfig().getBroadcasterFactory().lookup("/myChannel"))
           .suspend();
   }

   @POST
   @Path("/broadcast")
   public String broadcast(String message) {
       AtmosphereResource r = (AtmosphereResource)
                req.getAttribute("org.atmosphere.cpr.AtmosphereResource");
       r.getAtmosphereConfig().getBroadcasterFactory().get("/myChannel").broadcast(messages);
       return "OK";
   }
}

You can also use the @AtmosphereService annotation directly, without any web/atmosphere.xml

@Path("/chat")
@AtmosphereService(
        dispatch = false,
        interceptors = {AtmosphereResourceLifecycleInterceptor.class, TrackMessageSizeInterceptor.class},
        path = "/chat",
        servlet = "org.glassfish.jersey.servlet.ServletContainer")
public class Jersey2Resource {

    /**
     * Echo the chat message. Jackson can clearly be used here, but for simplicity we just echo what we receive.
     * @param message
     */
    @POST
    public void broadcast(String message, @Context HttpServletRequest req) {
       AtmosphereResource r = (AtmosphereResource)
                req.getAttribute("org.atmosphere.cpr.AtmosphereResource");
       r.getAtmosphereConfig().getBroadcasterFactory().lookup("/chat").broadcast(message);
    }

}
⚠️ **GitHub.com Fallback** ⚠️