It would nice to have the "known variables" feature of Resolver from 
the message below mentioned in tutorial section
   "10. URI rewriting and redirection"
at  http://www.restlet.org/documentation/2.0/tutorial#part10

and again in JavaDoc for org.restlet.routing.Redirector
   
http://www.restlet.org/documentation/2.0/jse/api/org/restlet/routing/Redirector.html

because there's no way to know from looking at the tutorial or the 
documentation for Redirector that this is possible, or required.
Resolver isn't mentioned at all in Redirector JavaDoc.

In Restlet 1.1, you could do this:

     component.getDefaultHost().attach("/",
                                       new 
Redirector(component.getContext().createChildContext(),
                                                      
"/path/to/startPage.html",
                                                      
Redirector.MODE_CLIENT_SEE_OTHER));

but in Restlet 2.0 you need to do this:
    component.getDefaultHost().attach("/",
                                       new 
Redirector(component.getContext().createChildContext(),
                                                      
"{rh}/path/to/startPage.html",
                                                      
Redirector.MODE_CLIENT_SEE_OTHER));

or else you get
java.lang.IllegalArgumentException: Relative references are only usable 
when a base reference is set.

Leigh.




-------- Original Message --------
Subject:        Re: How to write an Universal redirector
Date:   Wed, 24 Feb 2010 00:32:35 -0800
From:   Thierry Boileau <[email protected]>
Reply-To:       discuss <[email protected]>
To:     <[email protected]>



Hello,

actually, the second parameter in the Redirector constructor is a 
template using a set of known variables (see [0]).
You should be able to use the shipped Redirector, as follow (or 
something similar)
new Redirector(getContext(), 
"http://192.168.100.1:8080/RESTfulServices{rr}";, 
Redirector.MODE_CLIENT_DISPATCHER));

Don't forget to declare the client HTTP connector on the component (such 
redirection is seen as a new client call issued by the Component). This 
is done in the web.xml file see ([1])

          <servlet>
                  [...]
                  <init-param>
                          <param-name>org.restlet.clients</param-name>
                          <param-value>HTTP</param-value>
                  </init-param>
                  [...]
          </servlet>

[0] 
http://www.restlet.org/documentation/2.0/jse/api/org/restlet/util/Resolver.html
[1] 
http://www.restlet.org/documentation/2.0/jee/ext/org/restlet/ext/servlet/ServerServlet.html

Best regards,
Thierry Boileau

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

Reply via email to