users@grizzly.java.net

Re: How does mapping work?

From: Oleksiy Stashok <Oleksiy.Stashok_at_Sun.COM>
Date: Thu, 27 May 2010 12:02:53 +0200

Andrea, probably you'd need to add one more adapter.
Here is how I did that:

         GrizzlyAdapter ga1 = new HelloAnotherAdapter();
         ws.addGrizzlyAdapter(ga1, new String[]{"/hello/*"});

     static class HelloAnotherAdapter extends GrizzlyAdapter {

         @Override
         public void service(GrizzlyRequest request, GrizzlyResponse
response) {
             try {
                 customizedErrorPage(request.getRequest(),
response.getResponse());
             } catch (Exception e) {
                 // log
             }
         }
     }

Hope this will help.

WBR,
Alexey.

On May 25, 2010, at 13:04 , Andrea Gualano wrote:

> Hello,
> I am confused by how the mapping of GrizzlyAdapters works.
>
> If I configure a web server like this:
>
> GrizzlyWebServer ws = new GrizzlyWebServer();
>
> ServletAdapter sa1 = new ServletAdapter();
> sa1.setServletInstance(new HelloWorldServlet());
> sa1.setContextPath("/hello");
> sa1.setServletPath("/world");
> ws.addGrizzlyAdapter(sa1, new String[]{"/hello/world/*"});
>
> ServletAdapter sa2 = new ServletAdapter();
> sa2.setServletInstance(new HelloMarsServlet());
> sa2.setContextPath("/hello");
> sa2.setServletPath("/mars");
> ws.addGrizzlyAdapter(sa2, new String[]{"/hello/mars/*"});
>
> ws.start();
>
> Requests to the URLs /hello/world, /hello/world/moon, and so on are
> served by HelloWorldServlet, as expected; requests to /hello/mars
> and /hello/mars/phobos are also served by HelloMarsServlet as
> expected.
> Request to / and /hi generate a 404 error, which is also expected.
>
> However, a request for /hello/mercury is served by HelloWorldServlet
> or HelloMarsServlet (randomly). Is this the expected behavior?
> What should I do to only serve /hello/world/* and /hello/mars/* ?
> Add an adapter for /? o for /hello/*?
>
> All tests done on version 1.9.18-k.
>
> Best regards,
> Andrea
>
> --
> Andrea Gualano
> ImaVis S.r.l.
> email: andrea.gualano_at_imavis.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>