users@jersey.java.net

[Jersey] Re: CloseableService and InjectableProvider

From: Franck <franck102_at_yahoo.com>
Date: Tue, 26 Mar 2013 11:52:48 +0100

Hi Marek,

I just filed http://java.net/jira/browse/JERSEY-1815

Thanks!
Franck

On Mar 20, 2013, at 2:19 PM, Marek Potociar <marek.potociar_at_oracle.com> wrote:

> Hello Franck,
> Please, feel free to file a RFE in our Jira. With Jersey 2.0 to be released soon, I'm not sure how much effort we'll be able to invest into implementing new features in Jersey 1.x codebase.
>
> Marek
>
> On Mar 18, 2013, at 2:24 PM, Franck Mangin <franck102_at_yahoo.com> wrote:
>
>> After trying everything I could think of I had to give up injecting those session and I switched back to a classical try/finally block.
>>
>> Really too bad Jersey doesn't provide a clean mechanism to clean up injected per request resources, I am not quite ready to switch to another IoC right now and this seems to be the accepted answer.
>>
>> Something really basic would do - e.g. if (injected instanceof JerseyCloseable( { injected.close() }, InjectableProvider.releaseValue()...
>>
>> Franck
>>
>>
>> From: Franck Mangin <franck102_at_yahoo.com>
>> To: "users_at_jersey.java.net" <users_at_jersey.java.net>
>> Sent: Friday, March 15, 2013 1:54 PM
>> Subject: [Jersey] CloseableService and InjectableProvider
>>
>> Hi all,
>>
>> I would like to use a CloseableService to properly release an injected session object when the request gets out of scope.
>>
>> It seems like the pattern below should work, however I would rather not depend on the resource classes to add the session to the closeable service, I would like that to be the responsibility of the InjectableProvider itself... However I don't know/understand whether injecting a CloseableService into the provider itself would work, and would have the proper scope?
>>
>> Suggestions welcome!
>> Thanks,
>> Franck Mangin
>>
>> class MyResource
>> {
>> @Context CloseableService _cs;
>>
>> public MyResource getIt(@Context Session session, ...)
>> {
>> _cs.add(session);
>> ...
>> }
>> }
>>
>> class SessionProvider implements InjectableProvider<Session>
>> {
>>
>> ...
>>
>> public ComponentScope getScope()
>> {
>> return ComponentScope.PerRequest;
>> }
>> }
>>
>>
>