You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by 芷樱~ <10...@qq.com> on 2013/08/01 04:55:38 UTC
Question about Interceptor setup
Dear CXF Support,
I am trying to add a name-binding interceptor in JAX-RS 2.0, but the name binding does not work, the interceptor operates as a global interceptor. I have writen a name binding filter in the same way successfully. I am not sure what the problem is.
Could you please give me some advice? Thank you very much!!!
I use apache-cxf-2.7.5,apache-tomcat-6.0.37, and Java 6.
I setup namebinding in this way:
@NameBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD })
public @interface NamesBinding {
}
@Provider
@NamesBinding
public class NameInterceptor implements WriterInterceptor{
@Override
public void aroundWriteTo(WriterInterceptorContext arg0)
throws IOException, WebApplicationException {
arg0.getHeaders().add("MyInterceptorHeader", "From NameBinding Interceptor");
arg0.setEntity("This is from Name Binding Example.");
arg0.proceed();
}
}
@Path("/user")
public class Server {
@GET
@Path("/getString")
@Produces("text/plain")
@NamesBinding
public String getAString(){
return ".......";
}
}
And in the Spring file, Bean.xml, I write the Interceptor as Provider:
<jaxrs:server id="InterceptorServlet" address="/rest">
<jaxrs:serviceBeans>
<ref bean="InterceptorService" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="GlobalInterceptor" />
<ref bean="NameInterceptor" />
</jaxrs:providers>
<jaxrs:extensionMappings>
<entry key="json" value="application/json" />
<entry key="xml" value="application/xml" />
</jaxrs:extensionMappings>
<jaxrs:languageMappings>
<entry key="en" value="en-gb" />
</jaxrs:languageMappings>
</jaxrs:server>
Thank you very much!
Sincerely,
Di Ma
105634105@qq.com
Re: Question about Interceptor setup
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
I'm thinking of avoiding merging the code required to support binding
ReaderInterceptor and WriterInterceptor to specific methods only from
the trunk, the changes are quite sensitive, and I think it is a bit
risky at this stage, may be in time for 2.7.8 but I'm not really sure.
In CXF 2.7.x you can get the same by registering these interceptors from
DynamicFeature so given that a per-method specific registration is still
possible, I'm inclined to keep the code for the static name binding of
these interceptors on the trunk only
Also, in many case what you can do with these interceptors is also
possible with filters and MBR or MBW
Thanks, Sergey
On 01/08/13 10:10, Sergey Beryozkin wrote:
> Hi
>
> I believe in CXF 2.7.5 name binding are not working with
> ReaderInterceptor or WriterInterceptor, I did not even know it was
> required, so did it only for ContainerRequestFilter and
> ContainerResponseFilter (and client variants).
>
> This definitely has to work on the trunk (CXF 3.0.0-SNAPSHOT), I fixed
> it to get some early TCK tests passing. But I did not merge it to CXF
> 2.7.6 - there was a stream of changes to the trunk, some of them went
> into CXF 2.7.x, some not.
> I will investigate how realistic it is to merge the related changes to
> CXF 2.7.7-SNAPSHOT.
> I'll update this thread when I get a chance to look into it
>
> Thanks, Sergey
>
>
> On 01/08/13 03:55, 芷樱~ wrote:
>> Dear CXF Support,
>>
>> I am trying to add a name-binding interceptor in JAX-RS 2.0, but the
>> name binding does not work, the interceptor operates as a global
>> interceptor. I have writen a name binding filter in the same way
>> successfully. I am not sure what the problem is.
>>
>> Could you please give me some advice? Thank you very much!!!
>>
>> I use apache-cxf-2.7.5,apache-tomcat-6.0.37, and Java 6.
>>
>> I setup namebinding in this way:
>>
>> @NameBinding
>> @Retention(RetentionPolicy.RUNTIME)
>> @Target({ ElementType.TYPE, ElementType.METHOD })
>> public @interface NamesBinding {
>> }
>>
>> @Provider
>> @NamesBinding
>> public class NameInterceptor implements WriterInterceptor{
>> @Override
>> public void aroundWriteTo(WriterInterceptorContext arg0)
>> throws IOException, WebApplicationException {
>> arg0.getHeaders().add("MyInterceptorHeader", "From NameBinding
>> Interceptor");
>> arg0.setEntity("This is from Name Binding Example.");
>> arg0.proceed();
>> }
>> }
>>
>> @Path("/user")
>> public class Server {
>>
>> @GET
>> @Path("/getString")
>> @Produces("text/plain")
>> @NamesBinding
>> public String getAString(){
>> return ".......";
>> }
>> }
>> And in the Spring file, Bean.xml, I write the Interceptor as Provider:
>>
>> <jaxrs:server id="InterceptorServlet" address="/rest">
>> <jaxrs:serviceBeans>
>> <ref bean="InterceptorService" />
>> </jaxrs:serviceBeans>
>> <jaxrs:providers>
>> <ref bean="GlobalInterceptor" />
>> <ref bean="NameInterceptor" />
>> </jaxrs:providers>
>> <jaxrs:extensionMappings>
>> <entry key="json" value="application/json" />
>> <entry key="xml" value="application/xml" />
>> </jaxrs:extensionMappings>
>> <jaxrs:languageMappings>
>> <entry key="en" value="en-gb" />
>> </jaxrs:languageMappings>
>> </jaxrs:server>
>>
>> Thank you very much!
>>
>> Sincerely,
>>
>>
>> Di Ma
>> 105634105@qq.com
>>
>
>
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com
Re: Question about Interceptor setup
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
I believe in CXF 2.7.5 name binding are not working with
ReaderInterceptor or WriterInterceptor, I did not even know it was
required, so did it only for ContainerRequestFilter and
ContainerResponseFilter (and client variants).
This definitely has to work on the trunk (CXF 3.0.0-SNAPSHOT), I fixed
it to get some early TCK tests passing. But I did not merge it to CXF
2.7.6 - there was a stream of changes to the trunk, some of them went
into CXF 2.7.x, some not.
I will investigate how realistic it is to merge the related changes to
CXF 2.7.7-SNAPSHOT.
I'll update this thread when I get a chance to look into it
Thanks, Sergey
On 01/08/13 03:55, 芷樱~ wrote:
> Dear CXF Support,
>
> I am trying to add a name-binding interceptor in JAX-RS 2.0, but the name binding does not work, the interceptor operates as a global interceptor. I have writen a name binding filter in the same way successfully. I am not sure what the problem is.
>
> Could you please give me some advice? Thank you very much!!!
>
> I use apache-cxf-2.7.5,apache-tomcat-6.0.37, and Java 6.
>
> I setup namebinding in this way:
>
> @NameBinding
> @Retention(RetentionPolicy.RUNTIME)
> @Target({ ElementType.TYPE, ElementType.METHOD })
> public @interface NamesBinding {
> }
>
> @Provider
> @NamesBinding
> public class NameInterceptor implements WriterInterceptor{
> @Override
> public void aroundWriteTo(WriterInterceptorContext arg0)
> throws IOException, WebApplicationException {
> arg0.getHeaders().add("MyInterceptorHeader", "From NameBinding Interceptor");
> arg0.setEntity("This is from Name Binding Example.");
> arg0.proceed();
> }
> }
>
> @Path("/user")
> public class Server {
>
> @GET
> @Path("/getString")
> @Produces("text/plain")
> @NamesBinding
> public String getAString(){
> return ".......";
> }
> }
> And in the Spring file, Bean.xml, I write the Interceptor as Provider:
>
> <jaxrs:server id="InterceptorServlet" address="/rest">
> <jaxrs:serviceBeans>
> <ref bean="InterceptorService" />
> </jaxrs:serviceBeans>
> <jaxrs:providers>
> <ref bean="GlobalInterceptor" />
> <ref bean="NameInterceptor" />
> </jaxrs:providers>
> <jaxrs:extensionMappings>
> <entry key="json" value="application/json" />
> <entry key="xml" value="application/xml" />
> </jaxrs:extensionMappings>
> <jaxrs:languageMappings>
> <entry key="en" value="en-gb" />
> </jaxrs:languageMappings>
> </jaxrs:server>
>
> Thank you very much!
>
> Sincerely,
>
>
> Di Ma
> 105634105@qq.com
>
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com