users@jersey.java.net

Re: [Jersey] Suites of Transactions

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 01 Oct 2008 10:57:30 +0100

Hi Greg,

On Sep 30, 2008, at 11:18 PM, Giacovelli, Greg wrote:

> Hi,
> After using Jersey for a few months, I have hit some stumbling
> blocks. Let’s say there is a web application with N resources. Each
> resource adheres to a common format. I.e. Each txn must have a
> version identifier. From what I can understand from the
> specification, the 2 ways to achieve this is to make sure you list
> out the required attributes in every method signature, or to create
> an abstract Resource that has a constructor that takes the required
> attributes that all the resources inherit from. This is essentially
> using inheritance to enforce a constraint (If I am missing
> something, please stop me now J ).

Yes, that is one way, with limitation you describe below.


>
> This gets tricky as you add more suites. If two or more suites have
> to cross, you are halted.
> I was wondering if there was a way to define a suite and annotate a
> resource as being part of a particular suite or suites. Then through
> use of a Context annotation, a bean can be made available with the
> data desired (some interface that the suite definition defines). I
> know this seems like more of a gripe with the jsr than Jersey but
> was wondering if it at least is a sound concern.

If i understand you correctly what you want is an IoC framework. Your
gripe is a valid one we hope to address in a standard way for Java EE
6 by using WebBeans.

There are two ways you can do this today using Jersey:

1) Register an InjectableProvider; or

2) Use Spring.

Jersey has good Spring integration, see the simple example here:

http://download.java.net/maven/2/com/sun/jersey/samples/spring-annotations/1.0-ea-SNAPSHOT/spring-annotations-1.0-ea-SNAPSHOT-project.zip
.

If you do not want to use Spring, want a lighter weight but simpler
approach, and you want to reuse say @Context, you can use
InjectableProvider. This is the framework by which all injection works
in Jersey. Let me know if you want more details on that.

Paul.

>
> Please let me know if I am unclear or just talking non-sense.
>
> Thanks,
> -Greg
>