cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jordan <>
Subject Why CXF Client default accept type is application/xml
Date Mon, 22 Sep 2014 14:23:15 GMT
Hi dear all.

We have using the CXF client. But we found the client default accept type is
application/xml and is not text/plain or */*. Could you please help take a
look? Appreciate it! :)

I think I get the root cause and I'm not sure if this can be treated as a
The reason is that if we don't explicitly set the accept header of the
client request, it will set it as "application/xml" instead of "*/*".
Therefore a request with accept header := application/xml comes to the
server. As the resource class is annotated by @Produce(TEXT_PLAIN), it will
refuse accept header with application/xml with 406 as expected. 

    public String getAll() {
        return strings.toString();

Client code is:

ClientBuilder cb = ClientBuilder.newBuilder();
				Client c =;
				WebTarget t1 = + "/string");
				String result = t1.request()..get(String.class);

				htmlPage = "\nClient string test: " + "\nReturn result: "
						+ result;

Then I will get the error message:

[ERROR   ] SRVE0777E: Exception thrown by application class
'sun.reflect.NativeConstructorAccessorImpl.newInstance0:-2' HTTP 406 Not Acceptable
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.lang.reflect.Constructor.newInstance(
	at [internal classes]

If I modify client code to:

The exception is disappear.

When I learn the CXF code, I found CXF really set the default accept type to

I'm not sure is there any reason to set application/xml as default? I always
think */* should be the default at least.

Or can we think this is a bug?

Thanks for your time and help! :)

View this message in context:
Sent from the cxf-dev mailing list archive at

View raw message