Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-7310

org.apache.cxf.jaxrs.client.ClientProxyImpl#getAccept does not handle Accept header with multiple media types

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.1.10
    • 3.0.13, 3.1.11, 3.2.0
    • JAX-RS
    • None
    • Unknown

    Description

      The org.apache.cxf.jaxrs.client.ClientProxyImpl#getAccept method does not handle an accept header with multiple media types like so:

      Accept: application/json, text/plan, */*
      

      It throws an exception:

      Caused by: java.lang.IllegalArgumentException: Invalid media type string: application/json, text/plain, */*
      	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.utils.JAXRSUtils.toMediaType(JAXRSUtils.java:1723)
      	at org.apache.cxf.jaxrs.client.ClientProxyImpl.getAccept(ClientProxyImpl.java:396)
      	at org.apache.cxf.jaxrs.client.ClientProxyImpl.setRequestHeaders(ClientProxyImpl.java:367)
      

      I think the Accept header value needs to be split by ',' and each part passed to JAXRSUtils.toMediaType(...) to parse each correctly in this code:

      for (String s : headers) {
          types.add(JAXRSUtils.toMediaType(s));
      }
      

      Attachments

        Activity

          People

            sergey_beryozkin Sergey Beryozkin
            strelok1 Roman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: