Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-8215

SSE breaks Pipeline Processing

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.3.5, 3.2.12
    • Fix Version/s: 3.3.6, 3.2.13, 3.4.0
    • Component/s: JAX-RS
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      Hi,

      I am using the Aries JAX-RS Whiteboard implementation that is using CXF internally.

      I realized a behavior that does not match my expectation, so I checked the JAX-RS specification and IMHO the current behavior is wrong.

      I opened an issue for Aires JAX-RS Whiteboard and have been told that it should be filled for CXF.

      I could copy the whole initial description of the other issue to this one or link it (https://issues.apache.org/jira/browse/ARIES-1968)... I assume that all information should be added to the issue for the specific project, so I copy it:

       
      The JAX-RS Specification 2.1 contains the chapter 9 for "Server-Sent Events".

      The chapter 9.5 "Pipeline Processing" declares:

      For compatibility purposes, implementations MUST initiate processing of an SSE response when either the first message is sent or when the resource method returns, whichever happens first. The initial SSE response, which may only include the HTTP headers, is processed using the standard JAX-RS pipeline as described in Appendix C. Each subsequent SSE event may include a different payload and thus require the use of a specific message body writer. Note that since this use case differs slightly from the normal JAX-RS pipeline, implementations SHOULD NOT call entity interceptors on each individual event (1).

      So, the initial SSE response is processes using the standard JAX-RS pipeline (Appendix C).

      Appendix C indicates that in front of the method invocation the "Container Request Chain" is handled and after the method invocation the "Container Response Chain" is handled.

      The container response chain is currently not handled for the first response!

      It is also not handled for the other reponses, but this is expected.

      I checked v1.0.5, v1.0.6 and v1.0.7 all seems to be broken for me.

      Test code:

      @Component(service = Application.class)
      @JaxrsName("rest")
      @JaxrsApplicationBase("rest")
      public class RESTApplicationImpl extends Application {
      }
      @Component(service = { RESTResource.class })
      @JaxrsResource
      @JaxrsName("foo")
      @JaxrsApplicationSelect("(" + JaxrsWhiteboardConstants.JAX_RS_NAME + "=rest)")
      @Path("/foo")
      public class RESTResource {
      @GET
       @Path("normal")
       public Response normal() {
       System.out.println("handle endpoint \"normal\"");
       return Response.ok().build();
       }
      @GET
       @Path("sse")
       @Produces(MediaType.SERVER_SENT_EVENTS)
       public void sse(@Context final SseEventSink eventSink, @Context final Sse sse) {
       System.out.println("handle endpoint \"sse\"");
       final ExecutorService executor = Executors.newSingleThreadExecutor();
       executor.execute(() -> {
       try (SseEventSink sink = eventSink) {
       eventSink.send(sse.newEvent("event1"));
       eventSink.send(sse.newEvent("event2"));
       }
       });
       executor.shutdown();
       }
      }
      
      @Component
      @JaxrsExtension
      @JaxrsApplicationSelect("(" + JaxrsWhiteboardConstants.JAX_RS_NAME + "=rest)")
      public class SimpleRequestFilter implements ContainerRequestFilter {
      @Override
       public void filter(final ContainerRequestContext context) {
       System.out.println("simple request filter");
       }
      }
      
      @Component
      @JaxrsExtension
      @JaxrsApplicationSelect("(" + JaxrsWhiteboardConstants.JAX_RS_NAME + "=rest)")
      public class SimpleResponseFilter implements ContainerResponseFilter {
      @Override
       public void filter(final ContainerRequestContext requestContext, final ContainerResponseContext responseContext)
       throws IOException {
       System.out.println("simple response filter");
       }
      }
      

      Test:

      On a GET request to "http://127.0.0.1:8080/rest/foo/normal" is see (on the server console):

      simple request filter
      handle endpoint "normal"
      simple response filter

      On a GET request to "http://127.0.0.1:8080/rest/foo/sse" is see (on the server console):

      simple request filter
      handle endpoint "sse"

      As the normal processing pipeline must be applied for the first SSE reponse I would expect "simple response filter" is shown once, too.

      In my application there is a ContainerResponseFilter to allow (configurable) CORS. If it is enabled, the headers that allow the cross-origin access are added.

      This needs to be added to the initial header (first response) of the SSE connection, too.
       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                reta Andriy Redko
                Reporter:
                maggu2810 Markus Rathgeb
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m