Re: setting the location header
Thierry, Thanks once again. The supplied code snippet worked with a slight modification Reference reference = new Reference(http://localhost/exchange;); reference.setBaseRef(http://localhost;); Request request = new Request(Method.POST, reference); cheers /jima Thierry Boileau wrote: Hi Jim, The application must handle absolute URIs. You can update your code as follow : Reference reference = new Reference(/exchange); reference.setBaseRef(http://localhost;); Request request = new Request(Method.POST, reference); By doing so, the application still handles a reference with a relative part equals to /exchange. best regards, Thierry Boileau On Wed, Feb 27, 2008 at 8:49 PM, Jim Alateras [EMAIL PROTECTED] wrote: Thierry, Just some additional info. I am getting this error in a test case scenario so I may not be priming the 'request' with all the correct info Here is the code that I am using Request request = new Request(Method.POST, /exchange); Response response = application.handle(request); assertTrue(response.getStatus() == Status.SUCCESS_CREATED); assertTrue(response.getLocationRef().getPath() != null); Do i need to do anything extra to the request object before i pass it across to application.handle. cheers /jima Thierry Boileau wrote: Hello Jim, when passing a relative URI, the location reference is resolved against the base reference of the request's resource reference (getRequest().getResourceRef().getBaseRef()). Could you check the values of getRequest().getResourceRef() and getRequest().getResourceRef().getBaseRef()? best regards, Thierry Boileau On Wed, Feb 27, 2008 at 10:42 AM, Jim Alateras [EMAIL PROTECTED] wrote: Hi, I am trying to set the location header after a post to communicate the URL of the created resource. I basically use the following piece of code to set the location passing a relative uri getResponse().setLocationRef(sessionId); but i get the following error java.lang.IllegalArgumentException: Relative references are only usable when a base reference is set. Any ideas? cheers /jima
Re: setting the location header
great! regards, Thierry Boileau On Thu, Feb 28, 2008 at 7:53 PM, Jim Alateras [EMAIL PROTECTED] wrote: Thierry, Thanks once again. The supplied code snippet worked with a slight modification Reference reference = new Reference(http://localhost/exchange;); reference.setBaseRef(http://localhost;); Request request = new Request(Method.POST, reference); cheers /jima Thierry Boileau wrote: Hi Jim, The application must handle absolute URIs. You can update your code as follow : Reference reference = new Reference(/exchange); reference.setBaseRef(http://localhost;); Request request = new Request(Method.POST, reference); By doing so, the application still handles a reference with a relative part equals to /exchange. best regards, Thierry Boileau On Wed, Feb 27, 2008 at 8:49 PM, Jim Alateras [EMAIL PROTECTED] wrote: Thierry, Just some additional info. I am getting this error in a test case scenario so I may not be priming the 'request' with all the correct info Here is the code that I am using Request request = new Request(Method.POST, /exchange); Response response = application.handle(request); assertTrue(response.getStatus() == Status.SUCCESS_CREATED); assertTrue(response.getLocationRef().getPath() != null); Do i need to do anything extra to the request object before i pass it across to application.handle. cheers /jima Thierry Boileau wrote: Hello Jim, when passing a relative URI, the location reference is resolved against the base reference of the request's resource reference (getRequest().getResourceRef().getBaseRef()). Could you check the values of getRequest().getResourceRef() and getRequest().getResourceRef().getBaseRef()? best regards, Thierry Boileau On Wed, Feb 27, 2008 at 10:42 AM, Jim Alateras [EMAIL PROTECTED] wrote: Hi, I am trying to set the location header after a post to communicate the URL of the created resource. I basically use the following piece of code to set the location passing a relative uri getResponse().setLocationRef(sessionId); but i get the following error java.lang.IllegalArgumentException: Relative references are only usable when a base reference is set. Any ideas? cheers /jima
Re: setting the location header
Hi Jim, The application must handle absolute URIs. You can update your code as follow : Reference reference = new Reference(/exchange); reference.setBaseRef(http://localhost;); Request request = new Request(Method.POST, reference); By doing so, the application still handles a reference with a relative part equals to /exchange. best regards, Thierry Boileau On Wed, Feb 27, 2008 at 8:49 PM, Jim Alateras [EMAIL PROTECTED] wrote: Thierry, Just some additional info. I am getting this error in a test case scenario so I may not be priming the 'request' with all the correct info Here is the code that I am using Request request = new Request(Method.POST, /exchange); Response response = application.handle(request); assertTrue(response.getStatus() == Status.SUCCESS_CREATED); assertTrue(response.getLocationRef().getPath() != null); Do i need to do anything extra to the request object before i pass it across to application.handle. cheers /jima Thierry Boileau wrote: Hello Jim, when passing a relative URI, the location reference is resolved against the base reference of the request's resource reference (getRequest().getResourceRef().getBaseRef()). Could you check the values of getRequest().getResourceRef() and getRequest().getResourceRef().getBaseRef()? best regards, Thierry Boileau On Wed, Feb 27, 2008 at 10:42 AM, Jim Alateras [EMAIL PROTECTED] wrote: Hi, I am trying to set the location header after a post to communicate the URL of the created resource. I basically use the following piece of code to set the location passing a relative uri getResponse().setLocationRef(sessionId); but i get the following error java.lang.IllegalArgumentException: Relative references are only usable when a base reference is set. Any ideas? cheers /jima
Re: setting the location header
I gotta quit working in trunk all the time. setRedirectRef(...) does the same thing in 1.0.5, but is deprecated in trunk (1.1 and forward), I assume because Location: gets used for other things than redirects (e.g. creates). - Original Message - From: Jim Alateras [EMAIL PROTECTED] To: discuss@restlet.tigris.org Sent: Thursday, September 6, 2007 10:10:31 PM (GMT-0500) America/New_York Subject: Re: setting the location header response.setStatus(Status.SUCCESS_CREATED); response.setLocationRef(yourCreatedURIString); Is the setLocationRef method part of 1.0.5 release? cheers /jima
Re: setting the location header
Ooops. Not P/R/G. You want, then: response.setStatus(Status.SUCCESS_CREATED); response.setLocationRef(yourCreatedURIString); - R - Original Message - From: Jim Alateras [EMAIL PROTECTED] To: discuss@restlet.tigris.org Sent: Thursday, September 6, 2007 4:23:17 PM (GMT-0500) America/New_York Subject: Re: setting the location header Rob, Thanks for all the information. for the use case you describe. From the Javadoc (which is copied from RFC 2616, HTTP/1.1): Redirects the client to a different URI that SHOULD be retrieved using a GET method on that resource. This method exists primarily to allow the output of a POST-activated script to redirect the user agent to a selected resource. The new URI is not a substitute reference for the originally requested resource. So this sets the 303 status code and the target, which is probably what you want for a Post/Redirect/Get pattern. According to the Atom Publishing Protocol and i could be way wrong but on POST, which creates the new resource I want to return a 201 and set the Location header to newly created resource. - Rob
Re: setting the location header
response.setStatus(Status.SUCCESS_CREATED); response.setLocationRef(yourCreatedURIString); Is the setLocationRef method part of 1.0.5 release? cheers /jima
Re: setting the location header
Hi Jim, I was trying to find how to manipulate http headers (standard or extension) from a Resource class. I can't seem to get access to the headers through the Response class. http://www.restlet.org/documentation/1.0/faq#01 But the mechanism described here only allows you to set non-standard headers. Restlet attempts to have a means in the API for setting any standard headers like Location. You probably want Response.redirectOther(String targetUri) for the use case you describe. From the Javadoc (which is copied from RFC 2616, HTTP/1.1): Redirects the client to a different URI that SHOULD be retrieved using a GET method on that resource. This method exists primarily to allow the output of a POST-activated script to redirect the user agent to a selected resource. The new URI is not a substitute reference for the originally requested resource. So this sets the 303 status code and the target, which is probably what you want for a Post/Redirect/Get pattern. - Rob