Ted,

You do not want to duplicate the servlet mappings with Router URL
attachments, as that will only work with "double" URLs. So in your
example your URL would have to be:

http://localhost/testServlet/dog/testServlet/dog

This is assuming that you are installing your webapp under /ROOT (for
Tomcat) or /root (for jetty) 

There is a level of routing that happens in the servlet container
outside of the Restlet engine, and it is determined by either the name
of the WAR file or directory in the /webapps directory (again, assuming
Tomcat/Jetty). For instance, if your directory structure looks like
this:

/ServletContainer
    /webapps
        /testServlet
            ... Files for webapp

Then your url, with this given web.xml, should REALLY be:

http://localhost/testServlet/testServlet/dog/testServlet/dog

Because the first "/testServlet" tells the servlet container to route it
to the /testServlet webapp in the /webapps directory. The next
/testServlet/dog is your mapping within the web.xml file. The last
/testServlet/dog is the Router attachment.

A more appropriate mapping would be this:

    <!-- Catch all requests -->
    <servlet-mapping>
        <servlet-name>RestletServlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

Then you would be able to get to your page using:

http://localhost/testServlet/testServlet/dog

But, if you just want "dog", then you should attach the Router like
this:

router.attach("/dog",HelloWorldResource.class);

Then you could go to:

http://localhost/testServlet/dog


Again, this is because the servlet container will do an initial routing
of the context name based on the webapps you have installed. The Restlet
engine works within this context, so Router does not use the initial
context (which is "testServlet") to map its URLs.

As for worries about other servlets, because the Servlet container is
routing initially based on context, all other webapps will take
precedence. But, this is only a consideration if you install your
servlet into the ROOT context. However, the servlet container will still
look for installed contexts first before routing the request to the ROOT
context.

Hope that helps.

Also, you may want to check to see if you are getting into the Restlet
engine itself. Are you getting a 404 error from your servlet engine, or
from the Restlet engine. They will produce different looking pages
(unless you are using IE7, in which case the page will be hidden and you
will see a generic 404 error displayed by IE itself).

Mitch



> -----Original Message-----
> From: news [mailto:[EMAIL PROTECTED] On Behalf Of TA
> Sent: Friday, February 29, 2008 10:28 AM
> To: discuss@restlet.tigris.org
> Subject: Re: re servlet mapping question
> 
> Apologies for starting a new post on an existing thread but 
> everytime I try and follow up I get a top posting error.
> 
> Here is the thread on the issue
> 
> Rhett,
> 
> Thanks for the reply.
> 
> I tried mapping to something specific and it still does not 
> work, 404 error.
> 
> I set up a route like so
> 
> router.attach("/testServlet/dog",HelloWorldResource.class);
> 
> 
> and set up a mapping in the web.xml like so
> 
>    <servlet-mapping>
>       <servlet-name>RestletServlet</servlet-name>
>       <url-pattern>/testServlet/dog</url-pattern>
>    </servlet-mapping>
> 
> 
> I tried the URLs /testServlet/dog and also 
> /testServlet/testServlet/dog and no luck.
> 
> The only way it appears to work is if attachDefault is used 
> with a url-pattern of /*
> 
> Does anyone have an example of a route and url-pattern that 
> they know works on their setup?
> 
> Ted
> 
> Hi Ted,
> 
> 
> What Stephan was pointing out is that that _won't_ happen 
> because the container will continue to route requests to the 
> other servlets -- even if your restlet servlet wanted to 
> handle the other requests, it won't ever see them.
> 
> I'm not sure, but if I had to guess I'd suggest that your 
> problem is that your servlet was mapped to /testServlet/* and 
> you were trying to request /testServlet.  The containers I've 
> used (okay, just Tomcat) are very literal minded.  Try 
> requesting /testServlet/ or /testServlet/ somethingElse.
> 
> Rhett
> 
> Helo TA,
> 
> try to request /testServlet/testServlet/*, because you give 
> the "testServlet" double: one times in the web.xml and one 
> times while attaching to the router. I think, you should 
> remove the "testServlet" 
> from the attach method.
> 
> best regards
>    Stephan
> 
> New user and I'm playing around with the 
> firstStepsApplication using it in a tomcat web container.
> 
> I'm trying to play with the routing.
> 
> Instead of 
> 
>   Router router = new Router(getContext());
>   router.attachDefault(HelloWorldResource.class);
> 
> I'm trying to do
> 
> router.attach("/testServlet",HelloWorldResource.class);
> 
> and correspondingly, I've changed the entry in web.xml
> 
> from
> 
>    <servlet-mapping>
>       <servlet-name>RestletServlet</servlet-name>
>       <url-pattern>/*</url-pattern>
>    </servlet-mapping>
> 
> to 
> 
> <url-pattern>/testServlet/*</url-pattern>
> 
> and I can't get it to work, keep getting 404 error.
> 
> I don't want to default route to the app for all URIs in the 
> url mapping, just ones that start with /testServlet
> 
> Appreciate any help.
> 
> Ted
> 
> 
> 

Reply via email to