users@grizzly.java.net

Re: grizzly servlet webserver - multiple servlets in single context

From: Tom <808131_at_gmail.com>
Date: Wed, 14 Jan 2009 11:15:50 +0000

On Tue, Jan 13, 2009 at 4:07 PM, Jeanfrancois Arcand
<Jeanfrancois.Arcand_at_sun.com> wrote:
> Salut,
>
> Tom wrote:
>>
>> Hi,
>>
>> Is it possible to have more than one servlet running in a
>> ServletContext with the grizzly-servlet-webserver?
>
> Yes, it is. You need to use the GrizzlyAdapterChain (which is used by
> default by the GrizzlyWebServer class. Take a look at [1] for an example.
> Mainly, you can do:
>
>> GrizzlyWebServer ws = new GrizzlyWebServer(path);
>> ServletAdapter sa = new ServletAdapter();
>> sa.setRootFolder(".");
>> sa.setServletInstance(new ServletTest("Adapter-1"));
>> ws.addGrizzlyAdapter(sa, new String[]{"/Adapter-1"});
>>
>> ServletAdapter sa2 = new ServletAdapter();
>> sa2.setRootFolder("/tmp");
>> sa2.setServletInstance(new ServletTest("Adapter-2"));
>> ws.addGrizzlyAdapter(sa2, new String[]{"/Adapter-2"});
>>
>> System.out.println("Grizzly WebServer listening on port 8080");
>> ws.start();
>

Wouldn't this create two instances of a ServletContext? My 'webapp'
has a Listener that loads configuration and then the Servlets share
this resource (with ServletContext.getAttribute()).

I'm expecting multiple servlets to belong to one context. I appreciate
that this adds complexity (servlet mappings) and may be beyond the
scope of what the module is expected to support.

I was thinking I might be in the wrong place since some combination of
Grizzly and Glassfish must already be doing this for war-file
deployments. (I'm hoping to be free from war files and web.xml but
have everything else :-)

Thanks again!

Tom

>
>
> I've been using
>>
>> ServletAdapter to set up servlets but it creates its own context each
>> time.
>>
>> It doesn't look like too much work to extend the functionality of
>> ServletAdapter but I'm worried I am looking in the wrong place.
>> At the moment, my aim is to change one of our applications so that it
>> controls/manages the servlet engine, rather than the other way round.
>
> Try the above and let me know if you face any issues. I will fix them ASAP
> but my simple test:
>
> https://grizzly.dev.java.net/nonav/xref/com/sun/grizzly/samples/http/adapter/GrizzlyEmbedWebServer.html
> http://download.java.net/maven/2/com/sun/grizzly/samples/grizzly-multiple-adapter/1.9.4-SNAPSHOT/
>
> seems to works fine.
>
> A+
>
> -- Jeanfrancois
>
> [1]
> http://weblogs.java.net/blog/jfarcand/archive/2009/01/extending_the_g_5.html
>
>
>>
>> Regards,
>> Tom
>>