Hi
On 07/02/14 13:52, Jose María Zaragoza wrote:
Hi:

I'm using Apache CXF 2.7.3 and JAX-RS API to build a REST webservice

I've seen that the best response to return from a REST webservice when
an entity is created is a 201 HTTP code and set Location HTTP header
with the resource URI

My webservice is installed behind Apache HTTPD server as reverse proxy
Sometimes my webservice is invoked from internet as

http://www.mycompany.com/ws/myapp/process

and sometimes is invoked from a private network  as

http://internalname/myapp/process

How I can set Location header correctly ? I mean,
if requests come from intranet , to return Location:
http://internalname/myapp/get?id=xxxx
and request from private network , to return
Location:http://www.mycompany.com/ws/myapp/get?id=xxxx

How I can do this ?

Use @Context UtiInfo and get UriBuilder from it representing the current URI. Note, up until CXF 3.0.0, CXFServlet should have a disable-address-updates init parameter set to true in such cases


Other choice is to return a 200 HTTP code with some payload, but I
don't know if it's forbidden according REST rules

My view is that if it can help the application clients then I'm not worried about the rules, or rather about the purity of the way the application has been designed

I think AtomPub may even be recommending getting the created representation back, in addition to Location, in some cases.

If you have a browser then Location may be enough, if you have a code client, then it's not quite opaque, the code needs to extract Location and follow it. It really depends on the requirements

Cheers, Sergey

Thanks and regards



--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Reply via email to