cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "iris ding (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CXF-6412) MessageBodyReader and MessageBodyWritter should follow different sorting rule
Date Tue, 19 May 2015 13:11:00 GMT

    [ https://issues.apache.org/jira/browse/CXF-6412?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14550396#comment-14550396
] 

iris ding commented on CXF-6412:
--------------------------------

The proposed change is as below:

private static class MessageBodyReaderComparator
                    implements Comparator<ProviderInfo<MessageBodyReader<?>>>
{

        @Override
        public int compare(ProviderInfo<MessageBodyReader<?>> p1,
                           ProviderInfo<MessageBodyReader<?>> p2) {
            MessageBodyReader<?> e1 = p1.getOldProvider();
            MessageBodyReader<?> e2 = p2.getOldProvider();

            List<MediaType> types1 = JAXRSUtils.getProviderConsumeTypes(e1);
            types1 = JAXRSUtils.sortMediaTypes(types1, null);
            List<MediaType> types2 = JAXRSUtils.getProviderConsumeTypes(e2);
            types2 = JAXRSUtils.sortMediaTypes(types2, null);
           //sort according to MediaType first
            int result = JAXRSUtils.compareSortedMediaTypes(types1, types2, null);
            if (result != 0) {
                return result;
            }
           //Sort according to JavaType secondly
            return compareClasses(e1, e2);
        }
    }


After this change, the issue in https://issues.apache.org/jira/browse/CXF-6380 is resolved.

> MessageBodyReader and MessageBodyWritter should follow different sorting rule
> -----------------------------------------------------------------------------
>
>                 Key: CXF-6412
>                 URL: https://issues.apache.org/jira/browse/CXF-6412
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 3.0.4, 2.7.15, 3.0.5
>            Reporter: iris ding
>
> According to JSR-339 spec, section 4.2.1 and 4.2.2, we need follow different sorting
rule for MessageBodyReader and MessageBodyWritter:
> For MessageBodyReader, it is:
>   <h3> 2. Identify the Java type of the parameter whose value will be mapped from
the entity body. Section 3.7</h3>
> describes how the Java method is chosen.
>    <h3>3. Select the set of MessageBodyReader classes that support the media type
of the request, see Section  4.2.3. </h3>
> For MessageBodyWritter, it is:
>   <h3>4. Sort the selected MessageBodyWriter providers with a primary key of generic
type where providers whose generic type is the nearest superclass of the object class are
sorted first and a secondary key of media type (see Section 4.2.3).</h3>
> But in our implementation, we use the same sorting rule:
>  1. compareClasses() ->compareSortedMediaTypes()
> This caused an issue in https://issues.apache.org/jira/browse/CXF-6380.
> Actually we need to adjust the MessageBodyReader sorting method.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message