JDK-8156928 : XmlDataContentHandler did not handle MimeType "application/XML", because of uppercase
  • Type: Bug
  • Component: xml
  • Sub-Component: jax-ws
  • Affected Version: 7,8,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2016-05-11
  • Updated: 2017-01-03
  • Resolved: 2017-01-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Fixed
Related Reports
Relates :  
Description
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


Comments
Fixed content type check in isXml to be case insensitive. Added junits to cover this for the future. Patch is in standalone JAXWS RI repository, JDK merge will be done later. Edit: Also raised javax.mail dependency in pom.xml to version 1.4.7 :)
08-09-2016

Added jUnit test using provided reproduction scenario. Test is failing as described with 8u102.
08-09-2016

Attached test case executed on: JDK 6u45 - Pass JDK 7 - Fail JDK 7u79 - Fail JDK 8 - Fail JDK 8u92 - Fail JDK 9ea - Fail
13-05-2016