Description
The server side resource class and methods is:
@POST
@Consumes("text/xml;qs=0.7")
public String xml() {
return MediaType.TEXT_XML;
}
@POST
@Consumes("text/*")
public String postTextStar() {
return "text/*";
}
The http request and response:
Method POST
Content-Type: text/xml
-------
Response body: text/xml
According to Spec 3.7.2 Request Matching
3. Identify the method that will handle the request:
(b)A total ordering can be defined over combined media types as follows.
When we compareSortedConsumesMediaType, need combine(intersect) the contenttype and comuses first. So the response should be text/*.
Method xml->S(text/xml;qs=0.7, text/xml)=text/xml;qs=0.7
Method postTextStart->S(text/*,text/xml)=text/xml
n1/m1=n2/m2 and v1=v2 and v1'<v2, postTextStart should be selected.
Fix code for your refference:
int org.apache.cxf.jaxrs.utils.JAXRSUtils.compareSortedConsumesMediaTypes(List<MediaType> mts1, List<MediaType> mts2, MediaType ct)
public static int compareSortedConsumesMediaTypes(List<MediaType> mts1, List<MediaType> mts2, MediaType ct) {
List<MediaType> contentType = new ArrayList<MediaType>();
contentType.add(ct);
List<MediaType> actualMts1 = intersectSortMediaTypes(mts1, contentType, true);
List<MediaType> actualMts2 = intersectSortMediaTypes(mts2, contentType, true);
int size1 = actualMts1.size();
int size2 = actualMts2.size();
for (int i = 0; i < size1 && i < size2; i++) {
int result = compareMediaTypes(actualMts1.get, actualMts2.get, null);
if (result == 0)
if (result != 0)
{ return result; } }
return size1 == size2 ? 0 : size1 < size2 ? -1 : 1;
}