cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "芷樱~" <105634...@qq.com>
Subject Question about Interceptor setup
Date Thu, 01 Aug 2013 02:55:38 GMT
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
Mime
  • Unnamed multipart/alternative (inline, 8-Bit, 0 bytes)
View raw message