Consider the following code sending an HTTP 201 \"Created\" response to the client:
String url = \"/app/things?id=42\"; // example
response.setStatus(Htt
In case you are using JAX RS, there is a method in javax.ws.rs.core.Response
which automatically converts relative URLs:
public static Response.ResponseBuilder created(java.net.URI location)
Create a new ResponseBuilder for a created resource, set the location header using the supplied value.
Parameters:
location
- the URI of the new resource. If a relative URI is supplied it will be converted into an absolute URI by resolving it relative to the request URI.
Note however that there is a bug in the JAX RS implementation CXF which leads to incorrect absolute URLs.