Name binding container filters are called for each call sent to a service in the application. JAX-RS 2.0 provides a new feature to restrict the container components only to a service or a method of the service. See how to do it. The first thing we need is an annotation marked with the new annotation @NameBinding:
@Target({ TYPE, METHOD })
@Retention(value = RUNTIME)
@NameBinding
public @interface Logged {
}
Now, add this annotation to the filter:
@Logged
public class RegisterResponse implements ContainerResponseFilter
Also, add it to a method of the service:
@Path("/receiver")
@Stateless
public class HttpReceiver {
@OPTIONS
@Path("/options")
@Produces(TEXT_PLAIN)
@Logged
public double options() {
return 88.99;
}
...
}
At this point, the annotated filter will be executed only when the client will call the option method of the service.