protected MultiPart readMultiPart(Class<MultiPart> type, Type genericType,
Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, String> headers,
InputStream stream) throws IOException, MIMEParsingException {
mediaType = unquoteMediaTypeParameters(mediaType, "boundary");
MIMEMessage mm = new MIMEMessage(stream, mediaType.getParameters().get("boundary"), mimeConfig);
boolean formData = false;
MultiPart multiPart;
if (MediaTypes.typeEquals(mediaType, MediaType.MULTIPART_FORM_DATA_TYPE)) {
multiPart = new FormDataMultiPart();
formData = true;
} else {
multiPart = new MultiPart();
}
multiPart.setProviders(providers);
MultivaluedMap<String,String> mpHeaders = multiPart.getHeaders();
for (Map.Entry<String,List<String>> entry : headers.entrySet()) {
List<String> values = entry.getValue();
for (String value : values) {
mpHeaders.add(entry.getKey(), value);
}
}
boolean fileNameFix;
if (!formData) {
multiPart.setMediaType(mediaType);
fileNameFix = false;
} else {
// see if the User-Agent header corresponds to some version of MS Internet Explorer
// if so, need to set fileNameFix to true to handle issue http://java.net/jira/browse/JERSEY-759
String userAgent = headers.getFirst(HttpHeaders.USER_AGENT);
fileNameFix = userAgent != null && userAgent.contains(" MSIE ");
}
for (MIMEPart mp : mm.getAttachments()) {
BodyPart bodyPart = formData ? new FormDataBodyPart(fileNameFix) : new BodyPart();
// Configure providers
bodyPart.setProviders(providers);