users@jersey.java.net

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

From: Roytman, Alex <Roytmana_at_peacetech.com>
Date: Thu, 19 Feb 2009 12:39:23 -0500

Hello Paul,

Thank you, an excellent example!

Very helpful for my cleanup service as I was trying to use @Context to register my own @Context type where your example just use it for Injectable.

Currently, apart from request, there is only singleton scope. Any plans to have a session scope (and session concept and encapsulation) in JAX-RS and Jersey?

Also besides sharing a common injectables, do you see any other ways of communicating from request scope Resources to Singleton resources. For example by injecting @JaxRsResource("optional/resource/path") SingletoneResourceInterface. Session level resources could work as well.

Another thing I wanted to mention is Provider filtering. Let's say I use a third party library of providers and some of them conflict with my own. I would need a way of excluding some of them by either some sort of precedence or regular expressions

Thanks,

Alex
 



-----Original Message-----
From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
Sent: Wednesday, February 18, 2009 10:46 AM
To: users_at_jersey.dev.java.net
Subject: Re: [Jersey] Custom Context type is not injected?

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.