Search in sources :

Example 1 with OutboundSseEventBodyWriter

use of org.apache.cxf.jaxrs.sse.OutboundSseEventBodyWriter in project cxf by apache.

the class SseAtmosphereEventSinkContextProvider method createContext.

@Override
public SseEventSink createContext(Message message) {
    final HttpServletRequest request = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
    if (request == null) {
        throw new IllegalStateException("Unable to retrieve HTTP request from the context");
    }
    final AtmosphereResource resource = (AtmosphereResource) request.getAttribute(AtmosphereResource.class.getName());
    if (resource == null) {
        throw new IllegalStateException("AtmosphereResource is not present, " + "is AtmosphereServlet configured properly?");
    }
    final Broadcaster broadcaster = resource.getAtmosphereConfig().getBroadcasterFactory().lookup(resource.uuid(), true);
    resource.removeFromAllBroadcasters();
    resource.setBroadcaster(broadcaster);
    final MessageBodyWriter<OutboundSseEvent> writer = new OutboundSseEventBodyWriter(ServerProviderFactory.getInstance(message), message.getExchange());
    return new SseAtmosphereEventSinkImpl(writer, resource);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) OutboundSseEvent(javax.ws.rs.sse.OutboundSseEvent) AtmosphereResource(org.atmosphere.cpr.AtmosphereResource) OutboundSseEventBodyWriter(org.apache.cxf.jaxrs.sse.OutboundSseEventBodyWriter) Broadcaster(org.atmosphere.cpr.Broadcaster)

Aggregations

HttpServletRequest (javax.servlet.http.HttpServletRequest)1 OutboundSseEvent (javax.ws.rs.sse.OutboundSseEvent)1 OutboundSseEventBodyWriter (org.apache.cxf.jaxrs.sse.OutboundSseEventBodyWriter)1 AtmosphereResource (org.atmosphere.cpr.AtmosphereResource)1 Broadcaster (org.atmosphere.cpr.Broadcaster)1