users@jax-rs-spec.java.net

[jax-rs-spec users] [jsr339-experts] Re: Error responses with entities and the media types

From: Sergey Beryozkin <sberyozkin_at_talend.com>
Date: Wed, 13 Mar 2013 21:34:34 +0000

On 13/03/13 21:29, Bill Burke wrote:
> Exactly....your example bypasses JAX-RS defaults.

Yes, indeed.
I was thinking more about the client expecting the 'positive' (XML)
response, in which case IMHO it is better if it gets
NotAcceptableException in case of the (server) user choosing manually to
return JSON, instead of the client getting a more obscure XML parser
exception. Of course the server does not know who the client is and how
it is written to consume the response, so my argument is probably more
theoretical...

Cheers, Sergey

>
> On 3/13/2013 5:16 PM, Sergey Beryozkin wrote:
>> On 13/03/13 20:20, Bill Burke wrote:
>>> Accept is a suggestion by the client. The server doesn't have to honor
>>> it.
>>
>> This is a bit theoretical :-). JAX-RS servers are supposed to honor it,
>> though users can bypass that
>>
>> Cheers, Sergey
>>
>>>
>>> On 3/13/2013 10:20 AM, Sergey Beryozkin wrote:
>>>> Hi
>>>>
>>>> We've talked about it before, in context of the exception mappers
>>>> mapping the exceptions to Responses with non empty entities,
>>>>
>>>> example, the client Accepts application/xml, the server throws an
>>>> exception, the mapper maps it to
>>>>
>>>> Response.status(400).type("text/plain").entity("Bad response").build().
>>>>
>>>> and this is exactly what the client should get back despite expecting
>>>> only XML.
>>>>
>>>> However, consider that either the application code or even the
>>>> exception
>>>> mapper does
>>>>
>>>> Response.status(200).type("application/json").entity(someEntityBean).build().
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> This is clearly an error that is better be detected by the server
>>>> runtime, before the client code like "client.get(StreamSource.class)"
>>>> reports something like "{" is not allowed in XML, etc.
>>>>
>>>> Should the spec say that if Response status is >=400 and the entity is
>>>> not null then this Response media type whatever it is, is used;
>>>> otherwise, if Response is 200, the entity is not null, then the runtime
>>>> should treat its media type the same way it treats @Produces ?
>>>>
>>>> Sergey
>>>
>>
>>
>


-- 
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com