users@grizzly.java.net

Re: grizzly servlet webserver - multiple servlets in single context

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Tue, 13 Jan 2009 11:07:43 -0500

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();



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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>