cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Glen Mazza <glen.ma...@gmail.com>
Subject Re: REST sample works with CXF 2.6.2 but not CXF 2.7.4...
Date Fri, 10 May 2013 16:27:48 GMT
On 05/07/2013 05:46 PM, Sergey Beryozkin wrote:
>
>>
>>>>
>>>> -------------------
>>>> jsonp example
>>>> (http://people.apache.org/~gmazza/restexamples/jsonp.html):
>>>> After deploying via "mvn clean compile exec:java", the last cURL
>>>> statement in the above HTML:
>>>>
>>>> 2.7.5-SNAPSHOT returns this error:
>>>> gmazza@gmazza-work:/media/work1/jersey-samples-on-cxf/jsonp$ curl
>>>> -HAccept:application/x+javascript
>>>> http://localhost:9998/jsonp/changes?_jsonp=myCallback
>>>> myCallback(No message body writer has been found for response class
>>>> LinkedList.)
>>>
>>> In CXF 2.7.5 the refactoring has been made which exposed some issues
>>> with JSONP setups (I recall I had to do something similar in our
>>> system tests), looks like in this case you have
>>> https://github.com/gmazza/jersey-samples-on-cxf/blob/master/jsonp/src/main/java/com/sun/jersey/samples/jsonp/Main.java

>>>
>>>
>>>
>>> JSONP in interceptors 'accepting' application/json, but it needs to
>>> match "application/x+javascript", the actual value of HTTP Accept
>>>
>>
>> No luck. I checked in the change to the Main method given above and
>> tried with CXF 2.7.6-SNAPSHOT, but the same error occurs.
>>
>>
>>>> 2.6.7 works:
>>>> gmazza@gmazza-work:/media/work1/jersey-samples-on-cxf/jsonp$ curl
>>>> -HAccept:application/x+javascript
>>>> http://localhost:9998/jsonp/changes?_jsonp=myCallback
>>>> myCallback([{"madeByAdmin":false,"linesChanged":2,"logMessage":"title
>>>> \"User Guide\"
>>>> updated"},{"madeByAdmin":true,"linesChanged":1,"logMessage":"fixed
>>>> metadata"},{"madeByAdmin":false,"linesChanged":91,"logMessage":"added
>>>> index"},{"madeByAdmin":false,"linesChanged":650,"logMessage":"\"Troubleshoothing\"

>>>>
>>>>
>>>> chapter"},{"madeByAdmin":false,"linesChanged":1,"logMessage":"fixing
>>>> typo"}]);gmazza@gmazza-work:/media/work1/jersey-samples-on-cxf/jsonp$
>>>> -------------------
>
> Ok, I've looked into it closer. The reason it did not work with CXF 
> 2.7.6 was that Jackson provider is not typed to support 
> application/x+javascript. Setting "application/json" on JSONP in 
> interceptor is needed to get the runtime successfully selecting the 
> Jackson provider, however in CXF 2.7.6 the way the response type is 
> handled has changed (in the better way), so what happened was that 
> JSONP out pre-stream interceptor was actually setting
>
> "application/x+javascript" (so that a proper response type is 
> returned), but it does it too early actually though that worked in CXF 
> 2.6.7 as this type was not affecting the selection of MBW.
>
> Basically, if you update your example to set a mediaType property on 
> the out stream interceptor as "application/json" the example will 
> start working, but that will return "application/json" content type to 
> the browser.
>
> I've just added JAX-RS 2.0 out filter which should be used from now 
> on, it will set a response content type after Jackson has been 
> selected but before it is actually invoked, in the end resulting in a 
> proper content type returned too, so remove
>
> bean.getOutInterceptors().add(new JsonpPreStreamInterceptor());
>
> and add
>
> providerList.add(new 
> org.apache.cxf.jaxrs.provider.jsonp.JsonpJaxrsWriterInterceptor());
>
> It is a long story :-), but it has become better. And IMHO is still 
> cleaner than using JSONPadding objects within the application code
>
>

Hmm, I made the change:
https://github.com/gmazza/jersey-samples-on-cxf/commit/811d97be876286bfe62f2bc2e13667a25a0e5bfd

But still isn't working:
curl -HAccept:application/x+javascript 
http://localhost:9998/jsonp/changes?_jsonp=myCallback
No message body writer has been found for response class LinkedList.);



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message