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