users@jersey.java.net

ServletContainer: Specify packages *and* application?

From: Chris Hubick <chris_at_hubick.com>
Date: Tue, 10 Nov 2009 02:11:54 -0700

Hi,

I have a package containing a generic JAX-RS Application subclass
MyApplication, which I am trying to not tie specifically to the Jersey
JAX-RS implementation. MyApplication does a lot of heavy lifting to
create and provide several singletons (root resources) which are tied to
it.

I also have a reusable utility package with a custom object MyObject.

MyApplication's constructor requires a MyObject.

So, I create a separate Jersey-specific utility package with an
InjectableProvider implementation for MyObject. Like MyObject, this
package is also reusable, and not tied to the MyApplication package.

Now, the problem comes when trying to instantiate all this inside
ServletContainer. What I would want to do is specify a 'packages'
init-param pointing to my InjectableProvider *and* specify an
'application' init-param for MyApplication. Sadly, it does not appear I
can do both?

It looks as though I can specify a 'resourceConfigClass', but does
ResourceConfig allow one to provide an Application whose singletons will
be retrieved?

In reality, I have many MyObject's, MyApplication's, and
InjectableProvider's, which would be combined in various ways as needed
depending on the environment. If ResourceConfig is the only answer, is
there a way to create and configure one at runtime, so that I don't need
to create a separate package for every component combination
ResourceConfig implementation? I guess I could write such a thing if it
doesn't exist.

Thanks for any advice!

-- 
Chris Hubick
mailto:chris_at_hubick.com
http://www.hubick.com/chris/