users@jax-rs-spec.java.net

[jax-rs-spec users] [jsr339-experts] Re: Re: INjecting ResourceContext into a filter.

From: Sergey Beryozkin <sberyozkin_at_talend.com>
Date: Mon, 12 Nov 2012 14:45:06 +0000

On 12/11/12 14:26, Santiago Pericas-Geertsen wrote:
>
> On Nov 12, 2012, at 7:40 AM, Sergey Beryozkin<sberyozkin_at_talend.com> wrote:
>
>> On 08/11/12 14:33, Santiago Pericas-Geertsen wrote:
>>> Jan,
>>>
>>> Good question. According to the spec this should work. Section 8.1 refers to the context types in Section 8.2 and ResourceContext is there. ResourceContext is in request scope and should be proxied when injected in a provider that is in application scope (the default for providers).
>>>
>> I wonder, should it actually work ? ResourceContext is there for helping with the initializing the sub resource implementations ?
>
> Yes, that's its primary use case. However, it's an injectable type, so other use cases are naturally possible. IMO, it falls into the same category of the other types listed in Section 8.2; all of which are required to be "properly" injected regardless of the injection point's scope.

I can see how it works but I wonder if some guidance should be provided.
When we have sub resources, the runtime may be able to build some
introspection info early at the startup and use ResourceContext effectively.

Letting ResourceContext be used in filters is just a recipe for getting
the performance bottlenecks created IMHO, but may be I'm wrong :-)

Sergey

>
> -- Santiago
>
>>> On Nov 8, 2012, at 2:50 AM, Jan Algermissen<jan.algermissen_at_nordsc.com> wrote:
>>>
>>>>
>>>> Using ResourceContext, it would then also be possible to do the following, or?
>>>>
>>>> (Enable full per-request DI on arbitrary instance inside a provider)
>>>>
>>>>
>>>> @Provider
>>>> class TestFilter implements ContainerRequestFilter {
>>>>
>>>> @Context
>>>> HttpHeaders headers;
>>>>
>>>> @Context
>>>> ResourceContext rc;
>>>>
>>>>
>>>> void filter(ContainerRequestContext requestContext) ... {
>>>>
>>>> SomeHelpingClass h = rc.initResource(new SomeHelpingClass(...))
>>>>
>>>> }
>>>>
>>>>
>>>> }
>>>>
>>>>
>>>> public class SomeHelpingClass {
>>>>
>>>> @PathParam("id") String id;
>>>>
>>>> public SomeHelpingClass() {
>>>> }
>>>>
>>>> }
>>>>
>>>>
>>>> Would that work?
>>>>
>>>> Jan
>>>>
>>>>
>>>
>>
>>
>