users@jersey.java.net

Re: [Jersey] Jersey as pure OSGi bundles

From: Richard Wallace <rwallace1979_at_gmail.com>
Date: Thu, 18 Jun 2009 09:25:07 -0700

On Thu, Jun 18, 2009 at 5:56 AM, Paul Sandoz<Paul.Sandoz_at_sun.com> wrote:
>
> On Jun 18, 2009, at 5:54 AM, Richard Wallace wrote:
>
> On Wed, Jun 17, 2009 at 8:59 AM, Richard Wallace <rwallace1979_at_gmail.com>
> wrote:
>>
>> On Wed, Jun 17, 2009 at 3:28 AM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
>> >
>> > Hi Richard,
>> >
>> > Thanks very much for persisting with this.
>> >
>> >
>> > On Jun 15, 2009, at 2:05 AM, Richard Wallace wrote:
>> >
>> >> Hey all,
>> >>
>> >> I've done some work on making the Jersey modules real OSGi bundles.
>> >> I've been doing this work on a branch I created on GitHub
>> >> <http://github.com/rwallace/jersey-osgi-ified/tree/master>.  I now
>> >> have the jersey-core, jersey-server and jersey-json loading and
>> >> working in an OSGi framework (tested on Felix 1.8.0), without having
>> >> to do any hacks or classloading tricks in application code.  Just
>> >> create the ServletContainer and go!
>> >>
>> >
>> > Great!
>> >
>> > Do you have a simple maven example of how you are deploying? that way i
>> > can easily do a full debug cycle :-)
>> >
>>
>> I don't currently.  But it should be pretty easy to put one together.
>> I can work on that a bit this evening.
>
> Here's a simple example of how you would do the OSGi tests
> <http://github.com/rwallace/jersey-osgi-ified/tree/4a142095e7dcd2dd5cd401c4ddae64c2a3518951/jersey/osgi-tests>
> It doesn't work yet because it needs a fixed jsr311-api 1.1 jar to be loaded
> into the OSGi framework.  But once we have that, we can add it the
> dependencies and should be on our way.
>
>
> 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.

> 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. 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. :)

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.

> Let me know if you have any further questions!
> Rich
>
>