title: HTTP 415 when calling Jersey multipart/mixed POST endpoint - fails with MultiPart as parameter
body: <p>I am implementing a REST endpoint in Jersey that should consume multipart/mixed requests in the format below:</p>
  
  <pre><code>content-type: multipart/mixed; boundary=--Boundary20171230945619789
  manifest: ["Type1","Type2","Type3"]
  content-length: 325
  
  ----Boundary20171230945619789
  Content-Type: application/json
  
  ["string1","string2","string3"]
  ----Boundary20171230945619789
  Content-Type: application/json
  
  ["string4","string5","string6"]
  ----Boundary20171230945619789
  Content-Type: application/json
  
  ["string7","string8","string9"]
  ----Boundary20171230945619789--
  </code></pre>
  
  <p>The "manifest" header field contains a JSON array of string keys to schemas used for processing of each body part.</p>
  
  <p>When I try to implement the request as follows:</p>
  
  <pre><code>@Path("request/test/post")
  @POST
  @Consumes("multipart/mixed")
  public Response tryPost(MultiPart multi) { ... }
  </code></pre>
  
  <p>I receive an HTTP 415 error:</p>
  
  <blockquote>
    <p>2017-09-19 17:34:32.006 [http-nio-9909-exec-1] ERROR
    com.sun.jersey.spi.container.ContainerRequest:460 - A message body
    reader for Java class org.glassfish.jersey.media.multipart.MultiPart,
    and Java type class org.glassfish.jersey.media.multipart.MultiPart,
    and MIME media type multipart/mixed;
    boundary=--Boundary20171230945619789 was not found. The registered
    message body readers compatible with the MIME media type are: */* ->
    com.sun.jersey.core.impl.provider.entity.FormProvider<br>
    com.sun.jersey.core.impl.provider.entity.StringProvider<br>
    com.sun.jersey.core.impl.provider.entity.ByteArrayProvider<br>
    com.sun.jersey.core.impl.provider.entity.FileProvider<br>
    com.sun.jersey.core.impl.provider.entity.InputStreamProvider<br>
    com.sun.jersey.core.impl.provider.entity.DataSourceProvider<br>
    com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
    com.sun.jersey.core.impl.provider.entity.ReaderProvider<br>
    com.sun.jersey.core.impl.provider.entity.DocumentProvider<br>
    com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader
    com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader
    com.sun.jersey.core.impl.provider.entity.SourceProvider$DOMSourceReader
    com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider<br>
    com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
    com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
    com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General
    com.sun.jersey.core.impl.provider.entity.EntityHolderReader</p>
  </blockquote>
  
  <p>Jersey/Jackson won't properly parse the request into a MultiPart object. If I change the signature to:</p>
  
  <pre><code>@Path("request/test/post")
  @POST
  @Consumes("multipart/mixed")
  public Response tryPost(@HeaderParam("Manifest") String manifest, String rqBody){
      //etc here...
  }
  </code></pre>
  
  <p>it works fine - <code>manifest</code> is populated with the JSON from the header field (which can be easily deserialized into an a List or Array of String), and <code>rqBody</code> is correctly populated with the request body. However, to use the request body this way I will have to do some ugly (and pitfall-laden) parsing and tokenizing.</p>
  
  <p>I have registered the <code>MultiPartFeature</code> class with <code>ResourceConfig</code>, and tried most of the other options that looked helpful. Almost all the examples I can see with Jersey are using multipart/form-data; even the Jersey documentation itself has basically no examples of endpoints consuming multipart/mixed requests beyond an extremely cursory section.</p>
  
  <p>Does anyone know what the issue here is? How do I properly implement the endpoint method to be able to read the request into a MultiPart object?</p>
  
  <p>Thanks in advance for any/all help.</p>