Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.5.9
-
None
-
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" />