users@jersey.java.net

Re: Returning response in JSON format in case of Exceptions

From: j2eeuser32 <nagmidde_at_gmail.com>
Date: Mon, 10 May 2010 07:52:15 -0700 (PDT)

Thanks for the quick reply.

I wrote the clients in Java (the ones I posted here) to test my service, but
the actual client utilizing the service would be non-java.

I like your idea of using ClientResponse always, but it only works in case
of Java clients.

Thanks.



Paul Sandoz wrote:
>
>
> On May 10, 2010, at 4:19 PM, j2eeuser32 wrote:
>
>>
>> Paul,
>>
>> Great, thank you. That helps a little bit.
>>
>> My client is not Java based, that makes it difficult to catch the
>> UniformInterfaceException.
>>
>
> But the program you are writing in Java presumably can?
>
>
>> My intention is this:
>> Client should never see any exceptions and should not deal with
>> getting the
>> entityText from the ClientResponse.
>> It should receive all types of responses (successful or errors/
>> exceptions)
>> only in the String type (JSON formatted).
>>
>> The client can have a logic to look for { "error" : { "messageKey" :
>> 123,
>> "errorMessage" : "Invalid parameter ..." } } to see if it is an error
>> message. Otherwise, it is successful message.
>>
>> I guess I have the following option:
>>
>> 1. To return a response status of less than 400 so that it wont
>> throw an
>> UniformInterfaceException
>>
>
> I would not recommending dong that, it is topsy turvy :-). The whole
> point of status codes is the client can react differently depending on
> the values.
>
> I can also pass the status code as one more parameter in the ErrorInfo
> message.
>
>
>> My only concern is whether I am handling all types of exceptions to
>> make
>> sure the response is always a String.
>>
>
> In this case if it is easier i recommend using ClientResponse and then
> using getEntity which will work independent of the status code.
>
> ClientResponse clientResponse =
> resource.path("/test/
> dummy
> ").accept(MediaType.APPLICATION_JSON_TYPE).get(ClientResponse.class);
> clientResponse.getEntity(String.class));
>
> Paul.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
>

-- 
View this message in context: http://jersey.576304.n2.nabble.com/Returning-response-in-JSON-format-in-case-of-Exceptions-tp4985840p5031000.html
Sent from the Jersey mailing list archive at Nabble.com.