Hi Dustin,

You raise a good point. There is a trick to make it work which isn't
documented. See this example that I just tested:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
        xmlns="http://java.sun.com/xml/ns/javaee";
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
        id="WebApp_ID" version="2.5">

        <display-name>Restlet adapters</display-name>

        <servlet>
                <servlet-name>Restlet1</servlet-name>
        
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
                <init-param>
                        <param-name>org.restlet.application</param-name>
                        <param-value>test.MyApplication1</param-value>
                </init-param>
                <init-param>
        
<param-name>org.restlet.attribute.server</param-name>
                        <param-value>test.ServerServlet1</param-value>
                </init-param>
        </servlet>

        <servlet-mapping>
                <servlet-name>Restlet1</servlet-name>
                <url-pattern>/1/*</url-pattern>
        </servlet-mapping>

        <servlet>
                <servlet-name>Restlet2</servlet-name>
        
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
                <init-param>
                        <param-name>org.restlet.application</param-name>
                        <param-value>test.MyApplication2</param-value>
                </init-param>
                <init-param>
        
<param-name>org.restlet.attribute.server</param-name>
                        <param-value>test.ServerServlet2</param-value>
                </init-param>
        </servlet>

        <servlet-mapping>
                <servlet-name>Restlet2</servlet-name>
                <url-pattern>/2/*</url-pattern>
        </servlet-mapping>

</web-app>

BTW, I've just made a change in SVN trunk that makes the usage of the
"org.restlet.attribute.server" init parameter unecessary, resulting in this
simpler configuration:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
        xmlns="http://java.sun.com/xml/ns/javaee";
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
        id="WebApp_ID" version="2.5">

        <display-name>Restlet adapters</display-name>

        <servlet>
                <servlet-name>Restlet1</servlet-name>
        
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
                <init-param>
                        <param-name>org.restlet.application</param-name>
                        <param-value>test.MyApplication1</param-value>
                </init-param>
        </servlet>

        <servlet-mapping>
                <servlet-name>Restlet1</servlet-name>
                <url-pattern>/1/*</url-pattern>
        </servlet-mapping>

        <servlet>
                <servlet-name>Restlet2</servlet-name>
        
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
                <init-param>
                        <param-name>org.restlet.application</param-name>
                        <param-value>test.MyApplication2</param-value>
                </init-param>
        </servlet>

        <servlet-mapping>
                <servlet-name>Restlet2</servlet-name>
                <url-pattern>/2/*</url-pattern>
        </servlet-mapping>

</web-app>

I have also fully updated the Javadocs of this class with simpler and ready
to use example configuration, based on init-parameter rather than
context-parameter.

Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com


-----Message d'origine-----
De : Dustin Jenkins [mailto:[email protected]] 
Envoyé : jeudi 17 septembre 2009 18:01
À : [email protected]
Objet : Re: Servlet Container with multiple URL Mappings

Further to this...

     <servlet>
         <servlet-name>abcservlet</servlet-name>
         <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-
class>
         <init-param>
             <param-name>org.restlet.application</param-name>
             <param-value>ca.mysite.MyABCApplication</param-value>
         </init-param>
     </servlet>

     <servlet>
         <servlet-name>xyzservlet</servlet-name>
         <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-
class>
         <init-param>
             <param-name>org.restlet.application</param-name>
             <param-value>ca.mysite.MyXYZApplication</param-value>
         </init-param>
     </servlet>

     <servlet-mapping>
         <servlet-name>abcservlet</servlet-name>
         <url-pattern>/abc/*</url-pattern>
     </servlet-mapping>
     <servlet-mapping>
         <servlet-name>xyzservlet</servlet-name>
         <url-pattern>/xyz/*</url-pattern>
     </servlet-mapping>

Given this setup, the Applications are never being created, which  
means the createRoot() method is never creating the Routers  
necessary.  I then tried to supply a Component instead:

     <servlet>
         <servlet-name>abcservlet</servlet-name>
         <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-
class>
         <init-param>
             <param-name>org.restlet.component</param-name>
             <param-value>ca.mysite.MyABCComponent</param-value>
         </init-param>
     </servlet>

     <servlet>
         <servlet-name>xyzservlet</servlet-name>
         <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-
class>
         <init-param>
             <param-name>org.restlet.component</param-name>
             <param-value>ca.mysite.MyXYZComponent</param-value>
         </init-param>
     </servlet>

And in each constructor, all they do is attach their respecitve  
Applications to their default hosts via the getDefaultHost().attach()  
method.  I was using the getContext().createChildContext() method to  
pass to the Application's constructor:

...
public MyXYZComponent()
{
     super();
     getDefaultHost().attach(new  
MyXYZApplication(getContext().createChildContext());
}

But none of the parameters from the context-params are being copied  
over.  Even the getContext() method doesn't contain them anymore.

I know this is still a Milestone for Restlet 2.0, but is there a but  
in here anywhere?  How do I correctly do this?

Many thanks!
Dustin



On 16-Sep-09, at 2:03 PM, Dustin Jenkins wrote:

> I'm using JDK 1.6, Restlet 2.0M4 on FC8 running Tomcat 6.
>
> My current web.xml maps two different URLs like so:
>
> <web-app>
>     <context-param>
>         <param-name>org.restlet.application</param-name>
>         <param-value>ca.mysite.MyApplication</param-value>
>     </context-param>
>
>     <servlet>
>         <servlet-name>server</servlet-name>
>         <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-
> class>
>     </servlet>
>
>     <servlet-mapping>
>         <servlet-name>server</servlet-name>
>         <url-pattern>/abc/*</url-pattern>
>     </servlet-mapping
>     <servlet-mapping>
>         <servlet-name>server</servlet-name>
>         <url-pattern>/xyz/*</url-pattern>
>     </servlet-mapping>
> </web-app>
>
> Which means that there is only one Application with one Router to
> serve these two URLs.  So if I want to route just the /abc/ and /xyz/
> Resources, the Router will need to attach the "/" to two different
> Resources; one for abc, and the other for xyz, which can't be done.
>
> I think the documentation's suggestion was to use a Virtual Host
> instead, and have it map to different Applications.  Is that the best
> solution in this case?  Would it even work?  Is there something
> simpler?  If I did go that way, would I instead create my own
> Component, and attach separate Virtual Hosts, or one Virtual Host with
> separate Applications?
>
> Many thanks,
> Dustin
>
>
> Dustin Jenkins
> [email protected]
>
> ------------------------------------------------------
>
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=23957
36

Dustin Jenkins
[email protected]

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=23960
82

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2404429

Reply via email to