users@jersey.java.net

[Jersey] Re: Jersey-Guice chicken and egg problem

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Tue, 20 Dec 2011 10:36:48 +0100

IMHO the problem is more suitable for users_at_grizzly.java.net mailing
list as it seems to me that what you need is an integration between
Guice and Grizzly. Or am I missing it?

Marek

On Sat 17 Dec 2011 06:56:19 PM CET, Christopher Piggott wrote:
> Hi,
>
> This question seems to fall between jersey and guice, so I wasn't sure
> where to ask. Ultimately, though, the end goal is "Make
> GrizzlyWebServer instance available to resources" so I lean slightly
> toward asking jersey folks.
>
> My server startup looks like this (some class names changed to protect
> the guilty)
>
> ServletAdapter sa = new ServletAdapter();
> sa.addServletListener( MyContextListener.class.getName() );
> sa.addFilter( new GuiceFilter(), "guiceFilter", null );
> GrizzlyWebServer ws = new GrizzlyWebServer( port, ".", use_ssl );
> ws.addGrizzlyAdapter( sa, new String[] { "/" } );
> ws.start();
>
>
> start() causes grizzly to create the listener which calls my context
> listener which creates an injector (using my modules).
>
> The problem is, now I want to be able to get at certain things from
> that GrizzlyWebServer instance (for example, statistics) so that I can
> include them in a jersey resource. I would like to solve this by
> creating the GWS with guice, but that's a chicken and egg problem - in
> the above setup, it's the GWS that (indirectly, through the context
> listener) creates the injector.
>
> I can think of several awful ways to solve this, involving singletons
> and "Providers" that operate outside of guice - yuck.
>
> Is there a cleaner way? Like for example, is there some way to get at
> the ws instance through the ContextListener?
>
> --Chris