You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Benson Margulies <bi...@gmail.com> on 2011/11/22 15:40:21 UTC

Why is the default 'accept' for WebClient text/xml

Does the standard demand that the default setting of accept for
WebClient be text/xml? This seems completely arbitrary to me. Why not
*/*?

Re: Why is the default 'accept' for WebClient text/xml

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 29/11/11 10:13, Sergey Beryozkin wrote:
> Hi
> On 29/11/11 01:19, douglassparker wrote:
>> If a server method is annotated with @Produces(
>> {MediaType.APPLICATION_JSON,
>> MediaType.APPLICATION_XML} ) and the client does not provide an Accept
>> Header, my understanding is that the response MIME type should default to
>> the FIRST Mime type listed, JSON in this case. (I believe Jersey works
>> like
>> this.) But it doesn't. It defaults to XML. Isn't this a violation of the
>> spec?
>>
> Are you talking about the CXF server side choosing JSON in this case ? I
> don't think the spec says anything at all about what to offer in case of
> a missing Accept type, if a client does not mind then given that the
> server says it can serve either JSON or XML, then it means both formats
> are perfectly fine in case of a missing Accept
>

Forgot to mention, you can use server side qualifiers to affect this, 
CXF uses 'q', in 2.0 it will be 'qs'

{MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML;q=0.8}

That will always give you JSON in cases when Accept is not set

Cheers, Sergey

Re: Why is the default 'accept' for WebClient text/xml

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 29/11/11 01:19, douglassparker wrote:
> If a server method is annotated with  @Produces( {MediaType.APPLICATION_JSON,
> MediaType.APPLICATION_XML} ) and the client does not provide an Accept
> Header, my understanding is that the response MIME type should default to
> the FIRST Mime type listed, JSON in this case.  (I believe Jersey works like
> this.)  But it doesn't.  It defaults to XML.  Isn't this a violation of the
> spec?
>
Are you talking about the CXF server side choosing JSON in this case ? I 
don't think the spec says anything at all about what to offer in case of 
a missing Accept type, if a client does not mind then given that the 
server says it can serve either JSON or XML, then it means both formats 
are perfectly fine in case of a missing Accept

Sergey

> --
> View this message in context: http://cxf.547215.n5.nabble.com/Why-is-the-default-accept-for-WebClient-text-xml-tp5013707p5030783.html
> Sent from the cxf-user mailing list archive at Nabble.com.


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Re: Why is the default 'accept' for WebClient text/xml

Posted by douglassparker <do...@me.com>.
If a server method is annotated with  @Produces( {MediaType.APPLICATION_JSON,
MediaType.APPLICATION_XML} ) and the client does not provide an Accept
Header, my understanding is that the response MIME type should default to
the FIRST Mime type listed, JSON in this case.  (I believe Jersey works like
this.)  But it doesn't.  It defaults to XML.  Isn't this a violation of the
spec?    

--
View this message in context: http://cxf.547215.n5.nabble.com/Why-is-the-default-accept-for-WebClient-text-xml-tp5013707p5030783.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Why is the default 'accept' for WebClient text/xml

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi,

On 23/11/11 03:10, Benson Margulies wrote:
> On Tue, Nov 22, 2011 at 10:50 AM, Sergey Beryozkin<sb...@gmail.com>  wrote:
>> Hi Benson
>>
>> On 22/11/11 14:40, Benson Margulies wrote:
>>>
>>> Does the standard demand that the default setting of accept for
>>> WebClient be text/xml? This seems completely arbitrary to me. Why not
>>> */*?
>>
>> I though it would more likely lead to some unexpected responses, say
>> if you have the server code like this:
>>
>> public class Resource {
>>
>> @GET @Produces("application/xml", "application/json")
>> public Book getBook() {}
>>
>> @GET @Produces("text/plain")
>> public String getString() {}
>> }
>>
>> then I'm not sure what is going to happen with "Accept: */*", just
>> unpredictable.
>>
>> So I chose an xml format by default...
>
> I see what you mean about */*. FWIW, I'd pick 'throw an exception if
> no one called accept' instead if it were up to me.
>

Client API offered by JAX-RS 2.0 'enforces' that Accept is provided 
early; generally speaking I think that attempting to have API enforcing 
some kind of good practice creates a bit of 'tension' on the fluent API,
but I see better now why some users may actually like it :-)

Thanks, Sergey

Re: Why is the default 'accept' for WebClient text/xml

Posted by Benson Margulies <bi...@gmail.com>.
On Tue, Nov 22, 2011 at 10:50 AM, Sergey Beryozkin <sb...@gmail.com> wrote:
> Hi Benson
>
> On 22/11/11 14:40, Benson Margulies wrote:
>>
>> Does the standard demand that the default setting of accept for
>> WebClient be text/xml? This seems completely arbitrary to me. Why not
>> */*?
>
> I though it would more likely lead to some unexpected responses, say
> if you have the server code like this:
>
> public class Resource {
>
> @GET @Produces("application/xml", "application/json")
> public Book getBook() {}
>
> @GET @Produces("text/plain")
> public String getString() {}
> }
>
> then I'm not sure what is going to happen with "Accept: */*", just
> unpredictable.
>
> So I chose an xml format by default...

I see what you mean about */*. FWIW, I'd pick 'throw an exception if
no one called accept' instead if it were up to me.


>
> Sergey
>
>

Re: Why is the default 'accept' for WebClient text/xml

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Benson

On 22/11/11 14:40, Benson Margulies wrote:
> Does the standard demand that the default setting of accept for
> WebClient be text/xml? This seems completely arbitrary to me. Why not
> */*?

I though it would more likely lead to some unexpected responses, say
if you have the server code like this:

public class Resource {

@GET @Produces("application/xml", "application/json")
public Book getBook() {}

@GET @Produces("text/plain")
public String getString() {}
}

then I'm not sure what is going to happen with "Accept: */*", just 
unpredictable.

So I chose an xml format by default...

Sergey