users@jersey.java.net

Location Header

From: Bruno Luiz Pereira da Silva <blpsilva_at_gmail.com>
Date: Mon, 12 May 2008 00:13:39 -0300

Hi guys, I'd like to ask you something related to the Location header set
when we create a new resource.

Resource.created(uri) does something that I think is kind of rigid. If I
pass an absolute URI, it respects it, just fine. I'd like to discuss what it
does when we send a relative URI.

When I use a relative URI, Jersey converts it to an absolute URI relative to
the resource's root URI. In some cases this is just fine, but sometimes I'd
like to set it differently.

For example, let's take an example of eBay services, where the collection of
products belonging to an user is located at /user/{id}/products. To add a
new product for this user, we could POST the product at /user/{id}/products.
However, I'd like to access this product at /products/{id}.

If I have an User resource mapped to /user, and a method mapped with
@Path("{userId}/products"), the only way I can return a Location header
pointing at /products/{id} is using an absolute URI.

I'd like to be able to set the Location header to /products/{id} using a
relative URI, even inside a different path (/user in this case). Do you
think it makes sense or am I willing to do something inadequate?

-- 
Regards,
Bruno Luiz Pereira da Silva
blpsilva_at_gmail.com
http://brunopereira.com.br