cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Moroski (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (CXF-6997) Accept header doesn't correctly support multiple media ranges
Date Mon, 08 Aug 2016 13:12:20 GMT

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

Jeff Moroski edited comment on CXF-6997 at 8/8/16 1:11 PM:
-----------------------------------------------------------

Gah, you're right. I was getting my delimiters mixed up.

The custom filtering apparently is calling MediaType.valueOf directly.
{code:java}
        List<MediaType> mediaList = operationInfo.getProduceTypes();
        List<MediaType> exchangeContentTypes = (List<MediaType>)m.getExchange().get(Message.ACCEPT_CONTENT_TYPE);
        assert exchangeContentTypes.size() > 0;

        String mediaListValue = appendAllMediaTypes(exchangeContentTypes);
        AcceptHeader accHeader = new AcceptHeader(mediaListValue);
        List<MediaType> updatedMediaList = replaceAnyTypeWithResponseMediaType(responseContext,
mediaList);

        MediaType assignableMedia = getAssignableMedia(updatedMediaList, MediaType.valueOf(accHeader.toString()));
        if (assignableMedia != null && !StringUtils.isEmpty(accHeader.getVersionAttribute()))
{
            responseContext.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, assignableMedia);
        }
{code}

Let me look into that more and see about working around the multi types there.

That value in the Accept header is actually built by multiple calls to org.apache.cxf.jaxrs.client.AbstractClient.accept(String...).
 Is there a recommended way to handle the multiple types?


was (Author: jmoroski@vmware.com):
Gah, you're right. I was getting my delimiters mixed up.

That value in the Accept header is actually built by multiple calls to org.apache.cxf.jaxrs.client.AbstractClient.accept(String...)

The custom filtering apparently is calling MediaType.valueOf directly.
{code:java}
        List<MediaType> mediaList = operationInfo.getProduceTypes();
        List<MediaType> exchangeContentTypes = (List<MediaType>)m.getExchange().get(Message.ACCEPT_CONTENT_TYPE);
        assert exchangeContentTypes.size() > 0;

        String mediaListValue = appendAllMediaTypes(exchangeContentTypes);
        AcceptHeader accHeader = new AcceptHeader(mediaListValue);
        List<MediaType> updatedMediaList = replaceAnyTypeWithResponseMediaType(responseContext,
mediaList);

        MediaType assignableMedia = getAssignableMedia(updatedMediaList, MediaType.valueOf(accHeader.toString()));
        if (assignableMedia != null && !StringUtils.isEmpty(accHeader.getVersionAttribute()))
{
            responseContext.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, assignableMedia);
        }
{code}

Let me look into that more and see about working around the multi types there.

> Accept header doesn't correctly support multiple media ranges
> -------------------------------------------------------------
>
>                 Key: CXF-6997
>                 URL: https://issues.apache.org/jira/browse/CXF-6997
>             Project: CXF
>          Issue Type: Bug
>    Affects Versions: 3.1.6
>            Reporter: Jeff Moroski
>
> An Accept value of {{application/*+xml,application/*+xml;version=25.0,application/*+xml;version=1.5}}
is valid according to [Section 5.3.2 of RFC 7231|https://tools.ietf.org/html/rfc7231#section-5.3.2],
but when a media range and no corresponding accept params exists anywhere but the end of the
value, the MediaTypeHeaderProvider fails to process the value correctly:
> {noformat}
> Server stack trace: java.lang.IllegalArgumentException: Invalid media type string: application/*+xml,application/*+xml;version=25.0,application/*+xml;version=1.5
> at org.apache.cxf.jaxrs.impl.MediaTypeHeaderProvider.internalValueOf(MediaTypeHeaderProvider.java:90)
> at org.apache.cxf.jaxrs.impl.MediaTypeHeaderProvider.valueOf(MediaTypeHeaderProvider.java:65)
> at org.apache.cxf.jaxrs.impl.MediaTypeHeaderProvider.fromString(MediaTypeHeaderProvider.java:55)
> at org.apache.cxf.jaxrs.impl.MediaTypeHeaderProvider.fromString(MediaTypeHeaderProvider.java:42)
> at javax.ws.rs.core.MediaType.valueOf(MediaType.java:179)
> {noformat}



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

Mime
View raw message