users@jersey.java.net

[Jersey] Re: processing Response returned from Resource method

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Thu, 13 Oct 2011 14:23:11 +0200

On 10/12/2011 04:03 PM, Richard Levenberg wrote:
> The standard paradigm I generally use for resource methods looks like this:
>
> private Response fooMethod(String arg1, Object arg2, Foo arg3) {
> ResponseBuilder responseBuilder = Response.status(Response.Status.BAD_REQUEST);
> // do a bunch of stuff
>
> if (everythingOk)
> responseBuilder = Response.ok(someObject);
> }
> return responseBuilder.build();
> }
>
> The 'someObject' marshals as XML or JSON or whatever I need to the client just fine. In this one particular case in the
> same resource file, I am calling 'fooMethod' directly and getting the Response object. I need to figure out if the
> response was 200 or 400 (BAD_REQUEST) and if 200, see into the someObject. It looks to me as if ResponseImpl gives me
> some of that. I was wondering if there was another, better, way to do this?

Would Response.getStatus() to get th status code and Response.getEntity() to get your 'someObject' entity work for you?
If not why?

Marek

>
> r
>
> On 10/12/11 5:41 AM, Marek Potociar wrote:
>> Not sure I understand why you need to check whether the Response is an instance of ResponseImpl. Can you elaborate?
>>
>> Btw. in general it is certainly a bad idea to do that. You would be making your code dependent on an implementation
>> detail that can change at any time in future without any prior warning.
>>
>> Marek
>>
>>
>