-
-
Notifications
You must be signed in to change notification settings - Fork 751
Using Atmosphere with other Framework like RestEasy, Wink or Struts
jfarcand edited this page Nov 17, 2014
·
3 revisions
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);
}
}
- Understanding Atmosphere
- Understanding @ManagedService
- Using javax.inject.Inject and javax.inject.PostConstruct annotation
- Understanding Atmosphere's Annotation
- Understanding AtmosphereResource
- Understanding AtmosphereHandler
- Understanding WebSocketHandler
- Understanding Broadcaster
- Understanding BroadcasterCache
- Understanding Meteor
- Understanding BroadcastFilter
- Understanding Atmosphere's Events Listeners
- Understanding AtmosphereInterceptor
- Configuring Atmosphere for Performance
- Understanding JavaScript functions
- Understanding AtmosphereResourceSession
- Improving Performance by using the PoolableBroadcasterFactory
- Using Atmosphere Jersey API
- Using Meteor API
- Using AtmosphereHandler API
- Using Socket.IO
- Using GWT
- Writing HTML5 Server-Sent Events
- Using STOMP protocol
- Streaming WebSocket messages
- Configuring Atmosphere's Classes Creation and Injection
- Using AtmosphereInterceptor to customize Atmosphere Framework
- Writing WebSocket sub protocol
- Configuring Atmosphere for the Cloud
- Injecting Atmosphere's Components in Jersey
- Sharing connection between Browser's windows and tabs
- Understanding AtmosphereResourceSession
- Manage installed services
- Server Side: javadoc API
- Server Side: atmosphere.xml and web.xml configuration
- Client Side: atmosphere.js API