Hi On 01/08/13 10:17, ?????? wrote:
Hi, Thank you very much for your response!! I just want to also check if Interceptor supports Dynamic Binding (DynamicFeatures)? @Provider public class DynamicFeatureImpl implements DynamicFeature { @Override public void configure(ResourceInfo arg0, Configurable arg1) { if(Server.class.isAssignableFrom(arg0.getResourceClass()) && arg0.getResourceMethod().getName().contains("Dynamics")){ arg1.register(new DynamicFeatureInterceptor()); } } }
That actually has to work in CXF 2.7.5 - test is available, just as it happens I completely updated the initial rather messy code for supporting DynamicFeature during the last few days but that early code should be good enough to get you started with DynamicFeatures
Cheers, Sergey
Thank you very much! Di Ma 105634...@qq.com <mailto:105634...@qq.com> ------------------ ???????? ------------------ *??????:* "Sergey Beryozkin"<sberyoz...@gmail.com>; *????????:* 2013??8??1??(??????) ????5:10 *??????:* "users"<users@cxf.apache.org>; *????:* "??????"<105634...@qq.com>; *????:* Re: Question about Interceptor setup 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 > 105634...@qq.com > -- Sergey Beryozkin Talend Community Coders http://coders.talend.com/ Blog: http://sberyozkin.blogspot.com