cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Neal Hu (JIRA)" <>
Subject [jira] [Created] (CXF-6357) request matching on method matching issue with compareSortedConsumesMediaTypes
Date Mon, 20 Apr 2015 02:24:58 GMT
Neal Hu created CXF-6357:

             Summary: request matching on method matching issue with compareSortedConsumesMediaTypes
                 Key: CXF-6357
             Project: CXF
          Issue Type: Bug
          Components: JAX-RS
    Affects Versions: 3.0.3
         Environment: Windows
            Reporter: Neal Hu
             Fix For: 3.0.5

The server side resource class and methods is:
public String xml() {
return MediaType.TEXT_XML;

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>();
        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(i), actualMts2.get(i), null);
            if (result == 0) {
                result = compareQualityAndDistance(actualMts1.get(i), actualMts2.get(i), true);
            if (result != 0) {
                return result;
        return size1 == size2 ? 0 : size1 < size2 ? -1 : 1;

This message was sent by Atlassian JIRA

View raw message