users@jersey.java.net

Enhanced Guice-Jersey integration

From: Richard Wallace <rwallace_at_thewallacepack.net>
Date: Mon, 22 Jun 2009 22:17:17 -0700

Hey all,

I'm working on improving the Guice-Jersey integration. To do that I'm
making use of the Guice 2.0 ability to do custom injections
<http://code.google.com/docreader/#p=google-guice&s=google-guice&t=CustomInjections>.
 I've got most of the @Context annotations working, so you can do

@Path("resource")
class MyResource {
    @Inject
    public MyResource(HttpHeaders headers, Request request,
SecurityContext securityContext, UriInfo uriInfo) {
        // ... assign them locally
    }
}

or

@Path("resource")
class MyResource {
    @Context HttpHeaders headers;
    @Context Request request
    @Context SecurityContext securityContext;
    @Context UriInfo uriInfo;
}

The biggest problem I'm having is trying to figure out how to do the
injection for the Providers type. I do the implementation of the
getMessageBodyReader and getMessageBodyWriter, but am unsure what to
do for getExceptionMapper and getContextResolver as they seem to only
be available internally to the WebApplicationImpl.

Here's the code so far. <http://pastie.org/521175>

I also haven't tackled how to inject the @HeaderParam, @CookieParam,
@MatrixParam, @QueryParam or @PathParam values. But from what I've
seen so far it seems those values are all only available internally in
WebApplicationImpl as well. So I'm not quite sure how I'm going to
get at them.

Another unfortunate limitation is that only injectables that have
actual hard types like HttpHeaders, Request, etc. will be able to be
injected via the constructor. The others will have to be injected
into the fields themselves. This is something that James Strachan has
talked about patching so it may be possible in the future.

Any ideas how I can access the fields that I need?

Thanks,
Rich