users@jersey.java.net

Re: [Jersey] Custom Context type is not injected?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 18 Feb 2009 16:46:11 +0100

Hi Alex,

The attached maven project contains a very simple example of
supporting per-request injection on per-request resources and
singletons, where the latter uses a proxy.

The example shows the use of injecting an "Adder" service that is
capable of adding numbers and returning the sum. This service is
scoped per-request.

I think this example can be easily generalized such that one could
utilize a helper class as really the only unique thing from the
perspective of such services is the creation of a new instance of the
service when required.

Note that i have implemented two injectable providers, a per-request
and a singleton to do the same thing. The former is an optimization
for per-request resources. If the latter was only implemented it would
still work on per-request resources but not be as efficient (there is
no need to proxy in such cases).

Hope this helps,
Paul.






On Feb 18, 2009, at 10:44 AM, Paul Sandoz wrote:

>
> On Feb 17, 2009, at 6:26 PM, Roytman, Alex wrote:
>
>> Hello Paul,
>>
>> Thank you for the tip
>>
>> I do use InjectableProvider for JDO injection for per-request
>> lifecycle (it also subscribe its injections to cleanup service
>> automatically). I hoped to use @Context for cleanup service to
>> avoid an additional annotation for it. The cleanup service is the
>> service we talked about with regard of guaranteed "closeable"
>> closure at the end of lifecycle. I wanted it as transparent and non-
>> intrusive as possible so you could consider it for addition to
>> jersey and did not want extra annotations.
>>
>> I would appreciate your advise on how to proceed with
>> CleanupService integration with Jersey. If you would like me to use
>> InjectableProvider for CleanupService resolution, which annotation
>> would you like me to use?
>>
>
> You can reuse @Context, just make sure you check in your injectable
> provider for the type you want to support.
>
>
>> BTW Are there any samples on Resources with Session lifecycle and
>> on communication from request level resources to session level one?
>> I could not find any prescribed ways of doing it in the specs.
>>
>
> No, not currently. Session life-cycle is supported but it is
> currently not something i am keen to promote too much because it
> breaks one of the REST constraints (statelessness). However, the
> rules for injection of per-request stuff onto a per-session or per-
> singleton is the same.
>
> I think i need to write a simple example of how to do this. Let me
> try and do this within the next week or two.
>
> Paul.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>