Reputation: 1
I am trying to parse the GET response through a common filter and send response to the client according the content received. But I am not able to execute the Filter class. I've added the code snippet below. Any help would be appreciated
@FrontierResponse
@Provider
public class PoweredbyResponseFilter implements ContainerResponseFilter {
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
if (requestContext.getMethod().equals("GET")) {
System.out.println("hellos");
}
//responseContext.getHeaders().add("X-Powered-By", "Jersey :-)");
}
}
My custom Annotation
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(value = RetentionPolicy.RUNTIME)
@NameBinding
public @interface FrontierResponse {
}
and this is my resource class
@GET
@FrontierResponse
@Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON})
public List<String> list() {...}
for additional information i am using
jersey jersey-bundle-1.17.jar javax.ws.rs-api-2.0.jar
Upvotes: 0
Views: 1255
Reputation: 1171
You need to decorate the method of the resource class by @FrontierResponse
, not the resource class. Or you may annotate extension of Application
class if you want to use your filter for all requests. Check spec for more details.
EDIT:
@NameBinding
is in JAX-RS since v2.0. You need to use implementation o that specification, that is Jersey 2.x. In the jersey 1.x this annotation will be ignored.
Upvotes: 1