users@jersey.java.net

[Jersey] Client multipart with custom headers in body

From: Victor Tatai <vtatai_at_gmail.com>
Date: Thu, 08 Nov 2012 08:49:20 -0300

I'm using Jersey Client (1.14, with Jersey Multipart), and I am trying
to do a multipart request with custom headers in the body parts. It is
not working though, and I'm getting the message below:

Caused by: javax.ws.rs.WebApplicationException:
java.lang.IllegalArgumentException: Invalid body part header
'Message-Id', only Content-* allowed
     at
com.sun.jersey.multipart.impl.MultiPartWriter.writeTo(MultiPartWriter.java:174)
     at
com.sun.jersey.multipart.impl.MultiPartWriter.writeTo(MultiPartWriter.java:71)
     at
com.sun.jersey.api.client.RequestWriter.writeRequestEntity(RequestWriter.java:300)
     at
com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:213)
     at
com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:149)
     ... 39 more

Which maps out to the code:

                 // Only headers that match "Content-*" are allowed on
body parts
                 if (!entry.getKey().toLowerCase().startsWith("content-")) {
                     throw new WebApplicationException(new
IllegalArgumentException("Invalid body part header '" + entry.getKey() +
"', only Content-* allowed"));
                 }

AFAICT RFC 1341 does not forbid having custom headers in the body parts,
it just states that "Such other fields are permitted to appear in body
parts but should not be depended on". Is this a bug in Jersey Multipart
or do you think this is correct?

Thanks,

Victor