users@jersey.java.net

Re: [Jersey] Jersey as pure OSGi bundles

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 18 Jun 2009 21:16:14 +0200

On Jun 18, 2009, at 6:25 PM, Richard Wallace wrote:
>>
>> Thanks!
>> There is a lot going on behind the scenes here but i am guessing
>> that the
>> PAX framework is working out the bundle dependency from the maven
>> dependency.
>
> Yes it is. The documentation for that can be found at
> <http://wiki.ops4j.org/display/paxexam/Configuration+using+Maven+Plugin
> >.
> Basically, any bundles you want loaded you just add as dependencies
> with a provided scope in the pom and Pax Exam will take care of
> loading them into the framework.
>

OK.


>> I presume for your bundle application you are doing something like
>> that in
>> the test, namely overriding the ServletContainer.
>> Paul.
>>
>
> Yes, I need to override the ServletContainer to specify manually the
> resource classes.

OK.


> In my application I'm actually using Guice, so it's
> a bit easier thanks to the jersey-guice integration, although I still
> subclass the GuiceContainer so I can have Guice inject a
> WebApplication object and override the createWebApplication method to
> return it. But that's so I can have Guice inject the standard JSR311
> annotated fields, like @Param and friends. But, I'm not quite done
> with that and it's a subject for a different day. :)
>

Ah! that is on my TODO list and was thinking about how to tackle this
just the other day :-) but looks like you have more of a concrete idea
than I. Let me know when "that day" arrives...

Although Jersey can inject onto fields of Guice-managed classes i
really wanted something that would work with constructor parameters as
well, or in fact any Guice managed class even if it is not a resource
class. I was wondering if i could wrap the Jersey injection framework
so it would work for injection of anything configured in Jersey. There
should also be a way of making this reasonably efficient as well
(Jersey has optimizations to avoid re-doing lots of reflection work)


> I do have some ideas on how the resource classes can be found by
> scanning the bundle but I haven't had a chance to experiment with that
> quite yet, but it should be possible.
>

You can add fully qualified class names of resource classes to the
file "META-INF/services/jersey-server-components", i modified
ServiceFinder to support such files where the classes are not
constrained to implementing an interface.

Paul.