FULL PRODUCT VERSION :
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux com-prod 3.13.0-77-generic #121-Ubuntu SMP Wed Jan 20 10:50:42 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
EXTRA RELEVANT SYSTEM CONFIGURATION :
java-mail: mail-1.4.7.jar
A DESCRIPTION OF THE PROBLEM :
The RFC for AS2 requires the support for the mime-type "application/XML"
See https://www.ietf.org/rfc/rfc4130.txt Section 4.2 (Page 12)
The default XmlDataContentHandler (com.sun.xml.internal.ws.encoding.XmlDataContentHandler) however does refuse an mime-message with such an mime-type because the method isXml(ContentType ct) does not check case insensitiv.
But the Class javax.activation.ActivationDataFlavor does check by using "this.mimeType.equalsIgnoreCase(mimeType);" (see public boolean isMimeTypeEqual(String mimeType))
The check in XmlDataContentHandler.isXml should be case insensitiv.
REGRESSION. Last worked in version 6u45
ADDITIONAL REGRESSION INFORMATION:
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See source code
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Output:
application/xml processed
application/XML processed
ACTUAL -
Output:
application/xml processed
Exception in thread "main" java.io.IOException: Cannot convert DataSource with content type "application/XML" to object in XmlDataContentHandler
at com.sun.xml.internal.ws.encoding.XmlDataContentHandler.getContent(XmlDataContentHandler.java:85)
at javax.activation.DataSourceDataContentHandler.getContent(DataHandler.java:795)
at javax.activation.DataHandler.getContent(DataHandler.java:542)
at javax.mail.internet.MimeBodyPart.getContent(MimeBodyPart.java:637)
at Test.main(SignaturTest.java:63)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.io.IOException: Cannot convert DataSource with content type "application/XML" to object in XmlDataContentHandler
at com.sun.xml.internal.ws.encoding.XmlDataContentHandler.getContent(XmlDataContentHandler.java:85)
at javax.activation.DataSourceDataContentHandler.getContent(DataHandler.java:795)
at javax.activation.DataHandler.getContent(DataHandler.java:542)
at javax.mail.internet.MimeBodyPart.getContent(MimeBodyPart.java:637)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
MailcapCommandMap mailcapCommandMap = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
mailcapCommandMap.addMailcap("application/XML;; x-java-content-handler=com.sun.xml.internal.ws.encoding.XmlDataContentHandler");
mailcapCommandMap.addMailcap("application/xml;; x-java-content-handler=com.sun.xml.internal.ws.encoding.XmlDataContentHandler");
String contentType;
MimeMessage message;
MimeMultipart mimeMultipart;
final byte[] bodyConent = "<test/>".getBytes();
InternetHeaders headers = new InternetHeaders();
headers.setHeader("Content-Transfer-Encoding", "binary");
headers.setHeader("Content-Disposition", "attachment; filename=test.xml");
// this works
contentType = "application/xml";
message = new MimeMessage(Session.getDefaultInstance(new Properties()));
mimeMultipart = new MimeMultipart();
headers.setHeader("Content-Type", contentType);
mimeMultipart.addBodyPart(new MimeBodyPart(headers, bodyConent));
message.setContent(mimeMultipart);
message.saveChanges();
((MimeMultipart) message.getContent()).getBodyPart(0).getContent();
// will cause java.io.IOException
contentType = "application/XML";
message = new MimeMessage(Session.getDefaultInstance(new Properties()));
mimeMultipart = new MimeMultipart();
headers.setHeader("Content-Type", contentType);
mimeMultipart.addBodyPart(new MimeBodyPart(headers, bodyConent));
message.setContent(mimeMultipart);
message.saveChanges();
((MimeMultipart) message.getContent()).getBodyPart(0).getContent();
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Create an own XmlDataContentHandler and override JVM default-Settings