Hi,
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 at a global level 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. Would appreciate some tips out here.
~ Barada
@baradasahu
On Jul 17, 2013, at 8:37 PM, Barada (Personal) wrote:
> Hi Michal,
>
> Thanks for the help.
> Tried this but the SecurityContext doesn't get injected into the custom ResourceMethodDispatchProvider.
>
> ~ Barada
> @baradasahu
>
>
>
>
> On Jul 17, 2013, at 5:31 PM, Michal Gajdos wrote:
>
>> Hi Barada,
>>
>> ResourceMethodDispatchProvider are invoked during JAX-RS application creation (i.e. deployment time) and you have no security context available at this time. You can, of course, inject the SecurityContext (it will be a proxy) into your ResourceMethodDispatchProvider implementation (via @Context) but you can't use it sooner than in a RequestDispatcher instance you're creating and returning from the ResourceMethodDispatchProvider#create method:
>>
>> public class MyDispatchProvider implements ResourceMethodDispatchProvider {
>>
>> @Context
>> private SecurityContext securityContext;
>>
>> @Override
>> public RequestDispatcher create(AbstractResourceMethod abstractResourceMethod) {
>> return new RequestDispatcher() {
>> @Override
>> public void dispatch(final Object resource, final HttpContext context) {
>> // Here you can use the SecurityContext.
>> // if (securityContext.isSecure()) {
>> // ...
>> // }
>> }
>> };
>> }
>> }
>>
>> Michal
>>
>> On 17.07.2013 08:56 , Barada (Personal) wrote:
>>> Hi,
>>>
>>> Am using Jersey 1.17.
>>> Am using a custom ResourceMethodDispatchProvider to decorate a resource method.
>>>
>>> Does Jersey provide any method of doing a class field injection (by using an InjectableProvider) into a custom ResourceMethodDispatchProvider?
>>>
>>> Am attempting to use the SecurityContext under which the request is executed.
>>>
>>> ~ Barada
>>> @baradasahu
>>>
>>>
>>>
>>>
>>
>