Re: how to redirect to another resource?

2008-12-22 Thread Thierry Boileau
Hello renfeng,

did you try to call the following methods on the request object?
 - request.getResourceRef().getBaseRef()
 - request.getHostRef()
 - request.getRootRef()

Otherwise, you can get the servletContext by casting the context:
ServletContextAdapter c = (ServletContextAdapter) context;
c.getServletContext();
But this method creates a strong coupling between your Restlet 
application and the Servlet container environment, and thus is not 
encouraged.

best regards,
Thierry Boileau


 I couldn't find a method to get the base url of ServerServlet. So it
 is hardcoded. Any clue how to retrieve it from the runtime
 environment? Thanks.

  String baseUrl = /context-root/restlet-root;
  router.attach(res1, new Redirector(
getContext(), baseUrl + res2,
Redirector.MODE_CLIENT_SEE_OTHER));




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


how to redirect to another resource?

2008-12-21 Thread renfeng
I couldn't find a method to get the base url of ServerServlet. So it
is hardcoded. Any clue how to retrieve it from the runtime
environment? Thanks.

 String baseUrl = /context-root/restlet-root;
 router.attach(res1, new Redirector(
   getContext(), baseUrl + res2,
   Redirector.MODE_CLIENT_SEE_OTHER));


-- 
View this message in context: 
http://n2.nabble.com/how-to-redirect-to-another-resource--tp1689188p1689188.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Re: how to Redirect...

2008-11-23 Thread Gan123

Yes, i used redirectPermanent(...) to redirect to a resource. i tried to
search for the difference between different redirect methods, can you please
tell me how those 3 (permament, seeother,Temporary) are different. any
resource URL also will be fine.

Thanks for your time.

On Sat, Nov 22, 2008 at 4:55 PM, jlouvel (via Nabble) 
[EMAIL PROTECTED][EMAIL PROTECTED]
 wrote:


 Hi Gan123,

 You want to use one of the Response#redirect*(uri) methods.

 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 : Gan123 [mailto:[EMAIL 
 PROTECTED]http://n2.nabble.com/user/SendEmail.jtp?type=nodenode=1565297i=0]

 Envoye : vendredi 21 novembre 2008 16:01
 A : [EMAIL 
 PROTECTED]http://n2.nabble.com/user/SendEmail.jtp?type=nodenode=1565297i=1
 Objet : how to Redirect...


 Hi,

   Just started exploring restlet and trying to implement a simple
 employee details info management app. it have two pages, one to create a
 new
 employee. second that lists all employees. once the employee is created the

 resource should be redirected to other resource which will list all the
 employees. how i could do this either by giving URI or by giving second
 resource ref in 1st resource?

 Thanks in advance.
 --
 View this message in context:
 http://n2.nabble.com/how-to-Redirect...-tp1562040p1562040.html
 Sent from the Restlet Discuss mailing list archive at Nabble.com.



 --
  View message @
 http://n2.nabble.com/how-to-Redirect...-tp1562040p1565297.html
 To start a new topic under Restlet Discuss, email
 [EMAIL PROTECTED][EMAIL PROTECTED]
 To unsubscribe from Restlet Discuss, click here (link removed) ==.




-- 
View this message in context: 
http://n2.nabble.com/how-to-Redirect...-tp1562040p1570948.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.


RE: how to Redirect...

2008-11-22 Thread Jerome Louvel

Hi Gan123,

You want to use one of the Response#redirect*(uri) methods.

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 : Gan123 [mailto:[EMAIL PROTECTED] 
Envoye : vendredi 21 novembre 2008 16:01
A : discuss@restlet.tigris.org
Objet : how to Redirect...


Hi,

  Just started exploring restlet and trying to implement a simple
employee details info management app. it have two pages, one to create a new
employee. second that lists all employees. once the employee is created the
resource should be redirected to other resource which will list all the
employees. how i could do this either by giving URI or by giving second
resource ref in 1st resource?

Thanks in advance. 
-- 
View this message in context:
http://n2.nabble.com/how-to-Redirect...-tp1562040p1562040.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.



how to Redirect...

2008-11-21 Thread Gan123

Hi,

  Just started exploring restlet and trying to implement a simple
employee details info management app. it have two pages, one to create a new
employee. second that lists all employees. once the employee is created the
resource should be redirected to other resource which will list all the
employees. how i could do this either by giving URI or by giving second
resource ref in 1st resource?

Thanks in advance. 
-- 
View this message in context: 
http://n2.nabble.com/how-to-Redirect...-tp1562040p1562040.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.



RE: How to redirect to a resource?

2007-12-22 Thread Jerome Louvel

Hi Rob,

I've added the Reference constructor taking two refs as parameter (the
baseRef and the uriRef).

Concerning the redirection to relative URIs, we already have some logic in
place. See the current code:

public void setLocationRef(String locationUri) {
Reference baseRef = (getRequest().getResourceRef() != null) ?
getRequest()
.getResourceRef().getBaseRef()
: null;
setLocationRef(new Reference(baseRef, locationUri).getTargetRef());
}

I've made sure that this logic is invoked by the redirect*() methods taking
a String-based URI parameter. 

Changes in SVN trunk. Thanks for the suggestions!

Best regards,
Jerome  

 -Message d'origine-
 De : Rob Heittman [mailto:[EMAIL PROTECTED] 
 Envoyé : dimanche 16 décembre 2007 22:37
 À : discuss@restlet.tigris.org
 Objet : Re: How to redirect to a resource?
 
 I left out a step in the first example I typed.  You have to 
 explicitly getTargetRef() ... I did this in the second block 
 of code but omitted it in the first.  So, that example, corrected is:
 
 response.redirectTemporary (
   new Reference(
 request.getResourceRef ().getParentRef().getParentRef(),
 
 group/ + groupId
   ).getTargetRef()
 );
 
 your test case code would then be:
 
final String baseHref =  http://localhost:8080/app/api;;
final String path = group/1;
final Reference ref = new Reference(new 
 Reference(baseHref), path) .getTargetRef();
System.out.println(ref);
 
 ... and that would yield the information you want.
 
 For what you are doing, getRootRef() may be much easier than 
 trying to process relative references, which would require 
 you to know where you are in the hierarchy. 
 
 I still think it would be helpful if the Response redirect* 
 methods handled relative references more transparently ... it 
 is an extremely common use case to need to do this inside a 
 Resource, and I feel it shouldn't be necessary to master the 
 Reference API to do it correctly. 
 
 Cheers,
 
 - Rob
 
 
 
 On 12/16/07, Pavel Kolesnikov [EMAIL PROTECTED] wrote: 
 
   Thank Rob, but the constructor Reference(Reference, 
 String) does not
   seem to work, it actually produces a Reference instance 
 that seem to 
   completely ignore the first argument.
   
 
 
 


How to redirect to a resource?

2007-12-16 Thread Pavel Kolesnikov
Hi all,

I have a problem redirecting to a resource in my app if the app is
mapped to non-root URL. The setup is as follows:

I have a restlet application deployed in Tomcat under the /app
context. The restlet ServerServlet is mapped to /api/*, so to root
restlet of my application is actually mapped to
http://localhost:8080/app/api.

The restlets and resources are mapped as follows:

   /item/{item} - ItemResource
   /group/{group} - GroupResource (group is actually a collection of items)
   /item{item}/group - ItemInGroupRedirectingRestlet

As the names may suggest, I want the ItemInGroupRedirectingRestlet to
redirect to the URI of a group where the item {item} belongs to.

However, if I call

   response.redirectTemporary(/group/ + groupId);

it redirects to http://localhost:8080/group/groupId while I want it to
redirect to http://localhost:8080/app/api/group/groupId (as I have
written, http://localhost:8080/app/api is the root URL of my REST
application).

Can you please someone tell me what's the most appropriate way get it
redirected to the proper URL? Do I have to construct the target URL
manually by digging the necessary information from some Context
object, or is there a more elegant way?

thanks,

Pavel


Re: How to redirect to a resource?

2007-12-16 Thread Rob Heittman
Hi Pavel,

I'd start with the resource reference exposed by Request, and use the
methods of the Reference object to do what you want, e.g.

response.redirectTemporary(
  new Reference(
request.getResourceRef().getParentRef().getParentRef(),
group/ + groupId
  )
);

But Jerome and friends,

Now that I say it out loud, though, I can't think of a good reason why the
response.redirect* methods couldn't attempt this internally if they are
passed a relative URI string or reference, e.g. in o.r.d.Response:

public void setRedirectRef(Reference redirectRef){
  if(redirectRef.isRelative()){ // relative redirects not legal in HTTP/1.1,
resolve
newRedirectRef = new Reference(
  getRequest().getResourceRef(),
  redirectRef.getFragment()
).getTargetRef();
// how come there isn't a Reference(Reference, Reference) constructor
anyway?
this.redirectRef = newRedirectRef;
  } else {
this.redirectRef = redirectRef;
  }
}

I would have to imagine this is *always* what the user would want when
passing a relative Reference or String into one of these redirects.
Thoughts, anybody?

- Rob


On 12/16/07, Pavel Kolesnikov [EMAIL PROTECTED] wrote:

 However, if I call

response.redirectTemporary(group/ + groupId);

 it redirects to http://localhost:8080/group/groupId while I want it to
 redirect to http://localhost:8080/app/api/group/groupId (as I have
 written, http://localhost:8080/app/api is the root URL of my REST
 application).




Re: How to redirect to a resource?

2007-12-16 Thread Pavel Kolesnikov
Thank Rob, but the constructor Reference(Reference, String) does not
seem to work, it actually produces a Reference instance that seem to
completely ignore the first argument.

More exactly, the following code:

   final String baseHref = http://localhost:8080/app/api;;
   final String path = group/1;
   final Reference ref = new Reference(new Reference(baseHref), path);
   System.out.println(ref);

prints group/1 instead of  http://localhost:8080/app/api/group/1;.

However, I've realized I can get the URL of the root restlet by
request.getRootRef(), so I'm able to construct the URL I need by
simply calling

   request.getRootRef() + /group/1

thanks

Pavel

On 16/12/2007, Rob Heittman [EMAIL PROTECTED] wrote:

 Hi Pavel,

 I'd start with the resource reference exposed by Request, and use the
 methods of the Reference object to do what you want, e.g.

 response.redirectTemporary(
   new Reference(
 request.getResourceRef().getParentRef().getParentRef(),
 group/ + groupId
   )


Re: How to redirect to a resource?

2007-12-16 Thread Rob Heittman
I left out a step in the first example I typed.  You have to explicitly
getTargetRef() ... I did this in the second block of code but omitted it in
the first.  So, that example, corrected is:

response.redirectTemporary(
  new Reference(
request.getResourceRef ().getParentRef().getParentRef(),
group/ + groupId
  ).getTargetRef()
);

your test case code would then be:

   final String baseHref = http://localhost:8080/app/api;;
   final String path = group/1;
   final Reference ref = new Reference(new Reference(baseHref), path)
.getTargetRef();
   System.out.println(ref);

... and that would yield the information you want.

For what you are doing, getRootRef() may be much easier than trying to
process relative references, which would require you to know where you are
in the hierarchy.

I still think it would be helpful if the Response redirect* methods handled
relative references more transparently ... it is an extremely common use
case to need to do this inside a Resource, and I feel it shouldn't be
necessary to master the Reference API to do it correctly.

Cheers,

- Rob


On 12/16/07, Pavel Kolesnikov [EMAIL PROTECTED] wrote:

 Thank Rob, but the constructor Reference(Reference, String) does not
 seem to work, it actually produces a Reference instance that seem to
 completely ignore the first argument.