You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Jack Huang <hu...@gmail.com> on 2014/07/01 10:30:34 UTC

Re: JSONP is not works

When I register JsonpPreStreamInterceptor into <jaxrs:outInterceptors>, the
JSONP is not works, as below configuration:

    <jaxrs:server address="/rest">
        <jaxrs:serviceBeans>
            <ref bean="productServiceImpl"/>
        </jaxrs:serviceBeans>
        <jaxrs:providers>
            <bean
class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
        </jaxrs:providers>
        <jaxrs:inInterceptors>
            <bean
class="org.apache.cxf.jaxrs.provider.jsonp.JsonpInInterceptor"/>
        </jaxrs:inInterceptors>
        <jaxrs:outInterceptors>
            *<bean
class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor"/>*
            <bean
class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor"/>
        </jaxrs:outInterceptors>
    </jaxrs:server>

But, when I put JsonpPreStreamInterceptor into <jaxrs:providers>, the JSONP
is OK, as below configuration:

    <jaxrs:server address="/rest">
        <jaxrs:serviceBeans>
            <ref bean="productServiceImpl"/>
        </jaxrs:serviceBeans>
        <jaxrs:providers>
            <bean
class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
            *<bean
class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor"/>*
        </jaxrs:providers>
        <jaxrs:inInterceptors>
            <bean
class="org.apache.cxf.jaxrs.provider.jsonp.JsonpInInterceptor"/>
        </jaxrs:inInterceptors>
        <jaxrs:outInterceptors>
            <bean
class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor"/>
        </jaxrs:outInterceptors>
    </jaxrs:server>

I have not configured the mediaType property to "application/json" in
JsonpPreStreamInterceptor.

CXF Version is 3.0.0



--
View this message in context: http://cxf.547215.n5.nabble.com/JSONP-is-not-works-tp5739858p5745795.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: JSONP is not works

Posted by Sergey Beryozkin <sb...@gmail.com>.
Yes, have a look at
https://fisheye6.atlassian.com/browse/cxf/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml?r=b3288ed94bd6518780839a6b9716c64575c68073

a resource with "/jsonp" uses JSONProvider and the pre stream handler 
registered in outInterceptors, a resource with "/jsonp2" uses Jackson 
and indeed registers a handler in providers.

The reason behind is is that now the response content is determined 
early and as such, when a write of the response data is starting, in 
this case CT would application/javascript or similar which is not 
supported by Jackson. So using a handler as a WriterInterceptor lets us 
temporarily replace "application/javascript" with "application/json" and 
then restore "application/javascript".

Cheers, Sergey

On 02/07/14 23:24, Sergey Beryozkin wrote:
> Hi
>
> As far as I recall it should work with JSONProvider pre-configured to
> support application/x+javascript or similar which is not possible with
> Jackson which is where a writer interceptor comes in where it
> temporarily sets application/json for Jackson to write the data out
>
> I'll double check a bit later
> Sergey
>
>
> On 01/07/14 09:30, Jack Huang wrote:
>> When I register JsonpPreStreamInterceptor into
>> <jaxrs:outInterceptors>, the
>> JSONP is not works, as below configuration:
>>
>>      <jaxrs:server address="/rest">
>>          <jaxrs:serviceBeans>
>>              <ref bean="productServiceImpl"/>
>>          </jaxrs:serviceBeans>
>>          <jaxrs:providers>
>>              <bean
>> class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
>>          </jaxrs:providers>
>>          <jaxrs:inInterceptors>
>>              <bean
>> class="org.apache.cxf.jaxrs.provider.jsonp.JsonpInInterceptor"/>
>>          </jaxrs:inInterceptors>
>>          <jaxrs:outInterceptors>
>>              *<bean
>> class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor"/>*
>>              <bean
>> class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor"/>
>>          </jaxrs:outInterceptors>
>>      </jaxrs:server>
>>
>> But, when I put JsonpPreStreamInterceptor into <jaxrs:providers>, the
>> JSONP
>> is OK, as below configuration:
>>
>>      <jaxrs:server address="/rest">
>>          <jaxrs:serviceBeans>
>>              <ref bean="productServiceImpl"/>
>>          </jaxrs:serviceBeans>
>>          <jaxrs:providers>
>>              <bean
>> class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
>>              *<bean
>> class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor"/>*
>>          </jaxrs:providers>
>>          <jaxrs:inInterceptors>
>>              <bean
>> class="org.apache.cxf.jaxrs.provider.jsonp.JsonpInInterceptor"/>
>>          </jaxrs:inInterceptors>
>>          <jaxrs:outInterceptors>
>>              <bean
>> class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor"/>
>>          </jaxrs:outInterceptors>
>>      </jaxrs:server>
>>
>> I have not configured the mediaType property to "application/json" in
>> JsonpPreStreamInterceptor.
>>
>> CXF Version is 3.0.0
>>
>>
>>
>> --
>> View this message in context:
>> http://cxf.547215.n5.nabble.com/JSONP-is-not-works-tp5739858p5745795.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
>>
>
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Re: JSONP is not works

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

As far as I recall it should work with JSONProvider pre-configured to 
support application/x+javascript or similar which is not possible with 
Jackson which is where a writer interceptor comes in where it 
temporarily sets application/json for Jackson to write the data out

I'll double check a bit later
Sergey


On 01/07/14 09:30, Jack Huang wrote:
> When I register JsonpPreStreamInterceptor into <jaxrs:outInterceptors>, the
> JSONP is not works, as below configuration:
>
>      <jaxrs:server address="/rest">
>          <jaxrs:serviceBeans>
>              <ref bean="productServiceImpl"/>
>          </jaxrs:serviceBeans>
>          <jaxrs:providers>
>              <bean
> class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
>          </jaxrs:providers>
>          <jaxrs:inInterceptors>
>              <bean
> class="org.apache.cxf.jaxrs.provider.jsonp.JsonpInInterceptor"/>
>          </jaxrs:inInterceptors>
>          <jaxrs:outInterceptors>
>              *<bean
> class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor"/>*
>              <bean
> class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor"/>
>          </jaxrs:outInterceptors>
>      </jaxrs:server>
>
> But, when I put JsonpPreStreamInterceptor into <jaxrs:providers>, the JSONP
> is OK, as below configuration:
>
>      <jaxrs:server address="/rest">
>          <jaxrs:serviceBeans>
>              <ref bean="productServiceImpl"/>
>          </jaxrs:serviceBeans>
>          <jaxrs:providers>
>              <bean
> class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
>              *<bean
> class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor"/>*
>          </jaxrs:providers>
>          <jaxrs:inInterceptors>
>              <bean
> class="org.apache.cxf.jaxrs.provider.jsonp.JsonpInInterceptor"/>
>          </jaxrs:inInterceptors>
>          <jaxrs:outInterceptors>
>              <bean
> class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor"/>
>          </jaxrs:outInterceptors>
>      </jaxrs:server>
>
> I have not configured the mediaType property to "application/json" in
> JsonpPreStreamInterceptor.
>
> CXF Version is 3.0.0
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/JSONP-is-not-works-tp5739858p5745795.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com