I gave it a test with my setup and I get the same result. I have no custom providers in place right now either. No matter what headers I set on the request or which formats I place in @ProduceMime the response Content-Type header is always text/xml. However if I return a Response and set the header there it works like it should. See below.

@GET
@Path("/countries")
@ProduceMime("application/json")
public Response listCountries() {
        Countries countries = new Countries();
        List<CountryHolder> list = new ArrayList<CountryHolder>();
        for( Country c: countryDao.fetchAll())
                list.add(new CountryHolder(c));
        
        countries.setCountry(list);
return Response.ok(countries).header("Content-Type", "application/ json").build();
}

I personally like returning a Response object because it gives me the opportunity to gently massage the output but I agree that in concept the @ProduceMime("application/json") should be enough.

-Anthony

On Jul 10, 2008, at 2:30 PM, Brad wrote:

Hi,

I having a problem with content types which may be an issue with the
latest code off the trunk. What I'm seeing is the content-type isn't
being set to the desired value on the response from my service.

The service is annotated at class level:

@ProduceMime({"application/xml", "application/json", "text/html" })

My custom provider is annotaded like this:

@ProduceMime("application/json")

When I call the service I'm setting the "Accept" header to
"application/json". Everything looks fine inside the service and the
correct provider is called. Somehow though the client gets a response
that has the JSON from the provider but with the content-type set to
"text/xml".

I did some debugging and noticed that at JAXRSOutInterceptor line 158 :

  message.put(Message.CONTENT_TYPE, responseType.toString());

Which sets the content type on the message object which is good but it
doesn't seem to influence what is seen at the client.

What I did notice is  inside the message object there is also a
Response object (in my case an instance of Catalina's ResponseFacade)
that appears to hold the eventual content type and this is set to
"text/xml" which is (I'm assuming) the default set at
org.apache.cxf.binding.Binding.XMLBinding line 47. From this point on
nothing much seems to happen to the message/response other than the
output stream its carrying being closed. So I guess my problem is that
although the content-type is being set in the Message object as a
value in its local map table, the value is never transfered to the
eventual http response object.

When I set "Accept: text/html" I see the same problem, namely the
provider returns HTML but the response at the client has the header
"Conent-type: text/xml"

Does it sound like I'm on the right track?

Cheers,
Brad.

Reply via email to