users@jersey.java.net

[Jersey] Decorate ResourceMethod based on incoming request params

From: Personal <Barada>
Date: Thu, 18 Jul 2013 07:37:26 +0530

I want to be able to decorate (selected) resource methods based on incoming request params.

Jersey primarily provides three hooks for manipulating incoming requests outside of the resource method.

1. ContainerRequestFilter/ContainerResponseFilter - Ideally I could place my code in here but this would be applied to all resource calls and not any
specific resources. I want some means to define as to which resource methods this filter should be applied to. Instead of adding the Filters to the ContainerRequest/ResponseFilters I can annotate my resource methods/classes with @ResourceFilters({}) and this could ideally do the trick of ensuring that this filter is only applied on the particular resource call and none other.

2. An alternative might be to use a ResourceFilterFactory. Here we have a create method available which allows us to filter the resources for which my filters should be applied to.

3. Using a ResourceMethodDispatchProvider and DispatchAdapter to decorate the function.
This is akin to what has been done in the metrics library by codahale. However, I do not seem to be able to inject any @Context Java types into this class.

1), 2) are instantiated during application startup which means that I cannot use the default IOC container to inject any values using `PerRequest` scoped
InjectableProviders.
3) additionally doesn't allow get injection of any types whether Singleton or Request scoped.

Is there a means to get `Request` scoped InjectableProviders to inject values into a ResourceFilter/ContainerRequest/ResponseFilter?

Using Jersey 1.17. Appreciate some pointers here.

~ Barada