|
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
|
|
From: Bill B. <bb...@re...> - 2008-07-11 22:17:05
|
I'm confused on what you're trying to do. You're creating a
ClientResponse on the serverside? Why? Why do you need a custom
ClientResponse object? ClientResponse should only be used with a client
interface.
Adam Jordens wrote:
> 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()).build());
> }
>
> 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
>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
> Studies have shown that voting for your favorite open source project,
> along with a healthy diet, reduces your potential for chronic lameness
> and boredom. Vote Now at http://www.sourceforge.net/community/cca08
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Resteasy-developers mailing list
> Res...@li...
> https://lists.sourceforge.net/lists/listinfo/resteasy-developers
--
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com
|
|
From: Adam J. <Ada...@ge...> - 2008-07-11 22:30:42
|
Heh. I was wondering if I was going to confuse anyone.
Essentially what I want to do is have the value of a Response (with a status
of 303) returned to the caller of the client framework.
>From what I had seen (and read?), if the client framework caller wanted
access to the actual response itself, it needed to be actually returned as a
ClientResponse. Am I mistaken?
The interaction is as follows:
Client A (via ClientFramework) POSTS to the '/searches/' resource and gets a
ClientResponse (or Response) back with a status code and ideally an entity.
Client B (via Web Browser) POSTS to '/searches/' and gets redirected to the
target of the Location header.
Does that make any more sense?
As for the CustomClientResponse, it's nothing more than a dummy
implementation of the ClientResponse interface to save me from doing a new
ClientResponse(response.getEntity(), response.getStatus(), etc.).
It's probably ignorable.
Regards,
Adam
On 11/07/08 3:16 PM, "Bill Burke" <bb...@re...> wrote:
> I'm confused on what you're trying to do. You're creating a
> ClientResponse on the serverside? Why? Why do you need a custom
> ClientResponse object? ClientResponse should only be used with a client
> interface.
>
> Adam Jordens wrote:
>> 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()).bu
>> ild());
>> }
>>
>> 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
>>
>>
>> ------------------------------------------------------------------------
>>
>> -------------------------------------------------------------------------
>> Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
>> Studies have shown that voting for your favorite open source project,
>> along with a healthy diet, reduces your potential for chronic lameness
>> and boredom. Vote Now at http://www.sourceforge.net/community/cca08
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Resteasy-developers mailing list
>> Res...@li...
>> https://lists.sourceforge.net/lists/listinfo/resteasy-developers
|
|
From: Bill B. <bb...@re...> - 2008-07-11 22:47:07
|
Adam Jordens wrote:
> Heh. I was wondering if I was going to confuse anyone.
>
> Essentially what I want to do is have the value of a Response (with a status
> of 303) returned to the caller of the client framework.
>
> From what I had seen (and read?), if the client framework caller wanted
> access to the actual response itself, it needed to be actually returned as a
> ClientResponse. Am I mistaken?
>
> The interaction is as follows:
>
> Client A (via ClientFramework) POSTS to the '/searches/' resource and gets a
> ClientResponse (or Response) back with a status code and ideally an entity.
>
The client and server would be seperate classes/interfaces:
client
@Path("/search")
public interface SearchEngineClient {
@POST
@ConsumeMime("application/xml")
@ProduceMime("*/*")
ClientResponse<Long> createSearch(ExtQuery);
}
server:
@Path("/search")
public class SearchEngine {
@POST
@ConsumeMime("application/xml")
@ProduceMime("*/*")
Response createSearch(ExtQuery) {
...
}
}
Is the problem that you can't get at a ClientResponse that has no entity
within it?
Bill
--
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com
|
|
From: Adam J. <Ada...@ge...> - 2008-07-12 04:03:14
|
Perfect, thanks for the timely responses.
I think I was getting hung up on wanting to keep the interface of the
resource the same as the client.
Once I separated the two, things look good.
Cheers,
Adam
On 11/07/08 3:47 PM, "Bill Burke" <bb...@re...> wrote:
>
>
> Adam Jordens wrote:
>> Heh. I was wondering if I was going to confuse anyone.
>>
>> Essentially what I want to do is have the value of a Response (with a status
>> of 303) returned to the caller of the client framework.
>>
>> From what I had seen (and read?), if the client framework caller wanted
>> access to the actual response itself, it needed to be actually returned as a
>> ClientResponse. Am I mistaken?
>>
>> The interaction is as follows:
>>
>> Client A (via ClientFramework) POSTS to the '/searches/' resource and gets a
>> ClientResponse (or Response) back with a status code and ideally an entity.
>>
>
> The client and server would be seperate classes/interfaces:
>
> client
>
> @Path("/search")
> public interface SearchEngineClient {
>
>
> @POST
> @ConsumeMime("application/xml")
> @ProduceMime("*/*")
> ClientResponse<Long> createSearch(ExtQuery);
> }
>
>
> server:
>
> @Path("/search")
> public class SearchEngine {
>
> @POST
> @ConsumeMime("application/xml")
> @ProduceMime("*/*")
> Response createSearch(ExtQuery) {
> ...
> }
> }
>
>
> Is the problem that you can't get at a ClientResponse that has no entity
> within it?
>
> Bill
|
|
From: Bill B. <bb...@re...> - 2008-07-12 20:47:07
|
Adam Jordens wrote: > Perfect, thanks for the timely responses. > > I think I was getting hung up on wanting to keep the interface of the > resource the same as the client. > I originally thought that this was possible (same interface for client and server), but it just can't be done all the time. Default and/or optional parameters screw things up. There's no need for Subresource locators on the client (I can't really support them either). Bill -- Bill Burke JBoss, a division of Red Hat http://bill.burkecentral.com |