Typo, @Path("/storage") needs to be used in both cases...
Cheers, Sergey

If you can't then the the workaround is to to split a method into with multiple ones which will cause the selection be driven by the annotations match :

@Path("/storage")
@ProduceMime("application/xml")
public Response getXml() {
    toXmlObj(privateGetStorage());
}

@Path("/json")
@ProduceMime("application/json")
public Response getJson() {
    toXmlObj(privateGetStorage());
}

// etc...


Cheers, SErgey

----- Original Message ----- From: "Sergey Beryozkin" <[EMAIL PROTECTED]>
To: <[email protected]>; <[EMAIL PROTECTED]>
Sent: Friday, July 04, 2008 2:00 PM
Subject: Re: JAXRS custom provider selection based on media type


Hi Brad

The trunk has been updated to take the Response.getMediaType() into 
consideration -
is there any chance you can try the latest source ?

Cheers, Sergey



Hi,

I have the following annotations on a method in my project:

   @GET
   @Path("/storage")
   @ProduceMime( {"application/xml", "application/json", "text/html",
"application/atom+xml"} )

the method in question returns a Response with an XMLBean object set
as the entity. Based on certain conditions I set the media type on the
Response to be "text/html". I have a custom provider which is supposed
to handle that combination of object and media types:

@ProduceMime({"text/html" })
@Provider

I also use the provider XMLBeansElementProvider which was added to
trunk. that provider has the following annotations:

@ProduceMime("application/xml")
@ConsumeMime("application/xml")
@Provider

My thinking is normally it will use XMLBeansElementProvider but when
certain conditions are met I can set the mime type on the response to
be "text/html" and the other provider will be invoked.

It looks like the provider is chosen by checking the mime types of a
list of candidates against the mime types in the annotation on my
business method. In
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(Message
message):

           Class targetType = responseObj.getClass();
           List<MediaType> availableContentTypes =
               computeAvailableContentTypes(message);

           MessageBodyWriter writer = null;
           for (MediaType type : availableContentTypes) {
               writer = ProviderFactory.getInstance()
                   .createMessageBodyWriter(targetType, type);

               if (writer != null) {
                   break;
               }
           }

So......after that extremely long winded explaination, doesn anyone
(Sergey?) know if its possible to make it pick the one matching the
mime type from the Response object? I did consider adding some code to
make it check against the media type from the message object first but
I'd like to stay with the standard CXF code.

Cheers,
Brad.


----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

Reply via email to