users@jersey.java.net

[Jersey] Re: How to do Guice-based Grizzly-in-process-based deployment?

From: Robert Wierschke <wierob83_at_googlemail.com>
Date: Thu, 16 Dec 2010 15:38:29 +0100

Hi,

here is my MyGuiceListner class:

public class MyGuiceListner extends GuiceServletContextListener {

    @Override
    protected Injector getInjector() {
        return Guice.createInjector(new JerseyServletModule() {

            @Override
            protected void configureServlets() {

                DB dB = ...;
                bind(DB.class).toInstance(dB);

                Map<String, String> initParams = new HashMap<String,
String>();
                initParams.put(PackagesResourceConfig.PROPERTY_PACKAGES,
"my.package.MyGuiceListener");

                initParams.put("com.sun.jersey.api.json.POJOMappingFeature",
"true");


initParams.put("com.sun.jersey.config.property.WebPageContentRegex",
"(/(images|css|jsp|js)/.*|/.*.html|/observations.jsp)");

                filter("/*").through(GuiceContainer.class, initParams);
            }

        });
    }
}

This works when deployed in a Glassfish server.



On Thu, Dec 16, 2010 at 3:27 PM, Paul Sandoz <Paul.Sandoz_at_oracle.com> wrote:

> Hi,
>
> You need to set your initialization parameters in the Guice module that
> extends from ServletModule or JerseyServletModule and registered in your
> "MyGuiceListener".
>
> See:
>
>
> http://jersey.java.net/nonav/apidocs/latest/contribs/jersey-guice/com/sun/jersey/guice/spi/container/servlet/package-summary.html
>
> Paul.
>
>
> On Dec 16, 2010, at 3:13 PM, wierob wrote:
>
>
>> Hi,
>>
>> I'm trying to host my Jersey service using an embedded Grizzly server. The
>> service is configured via a GuiceFilter.
>>
>> After reading the source code of the GrizzlyWebTestContainerFactory class
>> I
>> found the following solution:
>>
>> GrizzlyWebServer webServer = new GrizzlyWebServer(9999);
>> ServletAdapter adapter = new ServletAdapter();
>>
>> adapter.addServletListener("my.package.MyGuiceListener");
>> adapter.addFilter(new GuiceFilter(), "jerseyfilter", null);
>> adapter.setServletPath("/");
>>
>> webServer.addGrizzlyAdapter(adapter, null);
>> webServer.start();
>> System.in.read();
>> webServer.stop();
>>
>> However, with this setup the the
>> "com.sun.jersey.config.property.WebPageContentRegex"-Feature does not
>> work.
>>
>> Since Jersey allows:
>>
>> SelectorThread st = RuntimeDelegate.createEndpoint(new
>> MyApplication(), SelectorThread.class);
>>
>> Is there something like a GuiceFilter-enabled version of
>> javax.?ws.?rs.?core.Application?
>>
>> thanks in advance
>> --
>> View this message in context:
>> http://jersey.576304.n2.nabble.com/How-to-do-Guice-based-Grizzly-in-process-based-deployment-tp5841767p5841767.html
>> Sent from the Jersey mailing list archive at Nabble.com.
>>
>
>