I tried to create filters and interceptors that would apply only to a specific method using an annotation derived from NameBinding.
I'm using JBoss 7.1.1.Final, where I did upgrade the modules by unzipping resteasy-jaxrs-3.0-beta-1 zip .
I have a couple of classes which define restful services, and I created (following examples as in http://docs.jboss.org/resteasy/docs/3.0-beta-1/javadocs/javax/ws/rs/NameBinding.html)
1) an annotation
@NameBinding
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(value = RetentionPolicy.RUNTIME)
public @interface FrontierResponse {
String value() default "";
}
2)
a Filter class , like
@FrontierResponse
public class FrontierResponseFilter implements ContainerResponseFilter {
@Inject
private Logger log;
/* (non-Javadoc)
* @see javax.ws.rs.container.ContainerResponseFilter#filter(javax.ws.rs.container.ContainerRequestContext, javax.ws.rs.container.ContainerResponseContext)
*/
@Override
public void filter(ContainerRequestContext ctx,
ContainerResponseContext respctx) throws IOException {
log.info("Frontier response filter :"+ctx.getMethod());
.....
3)
a restful service class, with a method annotated with the previous annotation
@FrontierResponse
@GET
@Produces("text/xml")
@Path("/{schema}/{db}/nodes")
public List<NodeType> listNodesInSchema(@PathParam("schema") String schema,
@PathParam("db") String db) {
log.info("Calling listNodesInSchema..."+schema+" "+db);
I noticed that :
1) if the filter class does not contain the @Provider annotation, then the filter is not applied at all...
BUT
2) if the filter class is annotated with @Provider...then ALL restful method do get filtered !
I do not know where I can have done something wrong, I suspect a bad installation, bad if somebody could enlight me I would
be grateful ;-)
Andrea