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

Jsonp interceptors do not work with GZIPOutInterceptor

    XMLWordPrintableJSON

Details

    • Unknown

    Description

      Jsonp support via Jsonp(In,PreStream,PostStream)Interceptor (as described in http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-JSONWithPadding%28JSONP%29) conflicts with GZIPOutInterceptor.

      With a very simple test application request "http://localhost:7543/12?_jsonp=abc" without Gzip results in the following response

      abc(24);

      With Gzip:

      abc();24

      Apparent reason is that the method org.apache.cxf.jaxrs.provider.jsonp.AbstractJsonpOutInterceptor.writeValue(Message, String) writes directly to the response output stream. When the method is changed to write to message.getContent(OutputStream.class), responses with and without Gzip interceptor become the same "abc(24);", as expected.

      ------------------------

      Service code:

      package test.cxf.jsonp;
      import javax.ws.rs.*;
      @Path("/") @Produces("application/json")
      public class Service {
          @GET @Path("{id}") public int find(@PathParam("id") int id) {
              return id * 2;
          }
      }
      

      Configuration (with Gzip)

      <jaxrs:server id="jsonp" address="http://localhost:7543/">
          <jaxrs:serviceBeans>
            <ref bean="serviceBean" />
          </jaxrs:serviceBeans>       
          <jaxrs:inInterceptors>
             <bean class="org.apache.cxf.jaxrs.provider.jsonp.JsonpInInterceptor"/>
             <bean class="org.apache.cxf.transport.common.gzip.GZIPInInterceptor"/>
          </jaxrs:inInterceptors>
          <jaxrs:outInterceptors>
             <bean class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor"/>
             <bean class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor"/>
             <bean class="org.apache.cxf.transport.common.gzip.GZIPOutInterceptor"/>
          </jaxrs:outInterceptors> 
      </jaxrs:server>
      <bean id="serviceBean" class="test.cxf.jsonp.Service" />
      

      Attachments

        Activity

          People

            sergey_beryozkin Sergey Beryozkin
            vadimb Vadim Beilin
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: