reta commented on a change in pull request #398: [Draft] SSE implementation using AsyncContext URL: https://github.com/apache/cxf/pull/398#discussion_r183244517
########## File path: rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/SseEventSinkContextProvider.java ########## @@ -16,46 +16,85 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.cxf.jaxrs.sse.atmosphere; + +package org.apache.cxf.jaxrs.sse; + +import java.util.Collection; +import java.util.Collections; +import java.util.Set; + +import javax.servlet.AsyncContext; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.ext.MessageBodyWriter; import javax.ws.rs.sse.OutboundSseEvent; import javax.ws.rs.sse.SseEventSink; +import org.apache.cxf.interceptor.Fault; import org.apache.cxf.jaxrs.ext.ContextProvider; import org.apache.cxf.jaxrs.provider.ServerProviderFactory; -import org.apache.cxf.jaxrs.sse.OutboundSseEventBodyWriter; import org.apache.cxf.message.Message; +import org.apache.cxf.phase.Phase; +import org.apache.cxf.phase.PhaseInterceptor; import org.apache.cxf.transport.http.AbstractHTTPDestination; -import org.atmosphere.cpr.AtmosphereResource; -import org.atmosphere.cpr.Broadcaster; -public class SseAtmosphereEventSinkContextProvider implements ContextProvider<SseEventSink> { +public class SseEventSinkContextProvider implements ContextProvider<SseEventSink> { + @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 MessageBodyWriter<OutboundSseEvent> writer = new OutboundSseEventBodyWriter( + ServerProviderFactory.getInstance(message), message.getExchange()); + + AsyncContext ctx = request.startAsync(); Review comment: I think I found the alternative solution to the custom interceptor, which plays a bit more nicely with CXF / JAX-RS invocation lifecycle. Not sure if you tried it as well, but here is the idea: ``` final AsyncResponse async = new AsyncResponseImpl(message); return new SseEventSinkImpl(writer, async, request.getAsyncContext()); ``` The JAXRSInvoker will properly suspend the invocation (through the continuation provider) and as such, the interceptor chain as well. @csierra what do you think? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services