users@jersey.java.net

Re: [Jersey] returning external URI

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 30 Nov 2009 09:48:59 +0100

On Nov 30, 2009, at 9:40 AM, Felipe Gaścho wrote:

> and what is the type for the @Produces annotation ? (if required at
> all)
>
> @GET
> @Produces( { MediaType.TEXT_HTML, MediaType.TEXT_PLAIN })
> @Path("{competition}/graph")
> public Response graph(@PathParam("competition") String login) {
> return Response
> .noContent()
> .header(
> "Location",
> "http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello
> |World")
> .build();
> }
>

It is not required because you are returning a 204 response i.e. the
accept request header makes no difference. Note that you can use a URI
instance instead of a String for the value of the Location header.

Use @Produces("text/plain") if you return the string of the URI as a
representation, as i do not know of any media type for URIs.

Paul.

>
> On Mon, Nov 30, 2009 at 9:25 AM, Paul Sandoz <Paul.Sandoz_at_sun.com>
> wrote:
>>
>> On Nov 28, 2009, at 1:36 PM, Felipe Gaścho wrote:
>>
>>> I want to create a Jersey resource that returns the URI of a
>>> google graph:
>>>
>>> like:
>>> http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello
>>> |World
>>>
>>> so, this resource will calculate the graph parameters and return the
>>> compelte URI a client can use to show a graph in an html page...
>>>
>>> what is the most correct HTTP Response type for that ?
>>>
>>> 1) Response.created(uri)
>>> 2) Response.seeOther(uri)
>>> 3) other ??
>>>
>>
>> The Location response header with a 204 response might be
>> appropriate,
>> because:
>>
>> "The Location response-header field is used to redirect the
>> recipient to a
>> location other than the Request-URI for completion of the
>> request..." [1]
>>
>> Otherwise send the string of the URI as a response entity.
>>
>> I do not think a 201 makes sense because i am not sure you are not
>> really
>> creating a new resource. A 303 response must not be cached. A 307
>> response
>> would be convenient for automatic redirection.
>>
>> Paul.
>>
>> [1] http://greenbytes.de/tech/webdav/rfc2616.html#header.location
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>
>
>
> --
> ------------------------------------------
> Felipe Gaścho
> 10+ Java Programmer
> CEJUG Senior Advisor
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>