|
From: Adam J. <Ada...@ge...> - 2008-07-11 16:56:57
|
Currently running beta5 and have run into a bit of an issue surrounding a
resource that returns a ClientResponse with a 303 See Other response code
and the appropriate Location: header.
Essentially I¹m trying to implement a POST then GET.
@POST
@ConsumeMime("application/xml")
@ProduceMime(³*/*²)
@Path("/search")
public ClientResponse<Long> createSearch(ExtQuery query)
{
...
return new
CustomClientResponse(Response.seeOther(uri).entity(specimenSearch.getId()).b
uild());
}
CustomClientResponse is just an implementation of a ClientResponse that
effectively wraps the status, entity and headers from a normal Response.
What I¹m hoping to be able to do is 2 things:
* Use the client-side framework to invoke this createSearch() and have
access to the returning ClientResource. I could either look at the headers
for the redirected location or just grab the entity and invoke a GET on
another resource.
* Use a web browser and POST to /search and have the browser automatically
redirect with a GET request to the 303 See Other resource.
Strangely enough, I¹ve been able to make get them both working (not having
the @ProduceMime(³*/*²) was causing some grief).
To get things working I had to do a minor patch to the MethodInjectorImpl.
Added (to MethodInjectorImpl.java.invoke()):
if (method.getReturnType().equals(ClientResponse.class))
{
ClientResponse clientResponse = (ClientResponse) rtn;
ResponseImpl response = new ResponseImpl();
response.setEntity(rtn);
response.setStatus(clientResponse.getStatus());
response.setMetadata(clientResponse.getHeaders());
return response;
}
Previously it looked like it was just creating a normal Response that
wrapped the ClientResponse but didn¹t inherit any of its status or headers.
At this stage, the client-side framework is able to POST to /search and get
back the appropriate ClientResponse, and the web browser was able to POST to
/search and get redirected to the appropriate resource. Success!
Now my biggest question is around whether or not these types of operations
should be supported?
Thanks,
Adam
|