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

FormParam parsing fails when no content-type is provided

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Trivial
    • Resolution: Fixed
    • 2.3
    • 2.2.12, 2.3.1, 2.4
    • JAX-RS
    • None

    Description

      Ran into this writing unit tests - if no Content-Type is provided when doing a POST, some code handles a null media type and some doesn't:

      In org.apache.cxf.jaxrs.utils.JAXRSUtils.processFormParam(Message, String, Class<?>, Type, String, boolean) it treats a null media type as if it was the same as the form media type:

      if (mt == null || mt.isCompatible(MediaType.APPLICATION_FORM_URLENCODED_TYPE))

      However, when reading the body of the form fields, it calls getCharset(mt) to get the character set to use when decoding the form fields, which doesn't check for null and thus throws an error.

      Either the null media type should fall through and return an error (wrong content type) or it should be handled.

      Suggested fix: In org.apache.cxf.jaxrs.utils.FormUtils.getCharset(MediaType), add if(mt == null) return "UTF-8"; to the start of the method.

      Easy workaround: only use clients that provide a content type for form field POSTs

      Attachments

        Activity

          People

            sergey_beryozkin Sergey Beryozkin
            dobes_vandermeer Dobes Vandermeer
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: