You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by 芷樱~ <10...@qq.com> on 2013/08/01 04:54:43 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