mailcap: no object DCH for MIME type
guinotphil Jan 2, 2012 4:32 AMHello,
I've been running with an issue using java mail on JBoss AS 7.1.0.CR1b.
I can't give you sadly all the details, but here is the code used to call java mail:
Transport transport = null;
try {
javax.mail.Session session = MailSession.instance();
transport = session.getTransport();
transport.connect();
transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
} finally {
try { transport.close(); } catch (Exception e) { }
}
And with a specific mime type I get the following exception:
javax.mail.MessagingException: IOException while sending message;
nested exception is:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/related;
boundary="----=_Part_2_238935302.1325262220604"
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1141) [mail-1.4.4.jar:1.4.4]
at mypackage.MyClass.sendEmail(MyClass.java:361) [MyProject.jar:]
... 68 more
Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/related;
boundary="----=_Part_2_238935302.1325262220604"
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:905) [activation-1.1.1.jar:1.1.1]
at javax.activation.DataHandler.writeTo(DataHandler.java:330) [activation-1.1.1.jar:1.1.1]
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1476) [mail-1.4.4.jar:1.4.4]
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1772) [mail-1.4.4.jar:1.4.4]
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1099) [mail-1.4.4.jar:1.4.4]
... 69 more
After some investigations, I figured out that actually the module javax.activation resolves the mime type using the META-INF/mailcap file. But it actually looks for this file using the current thread's class loader (ie the application's class loader). Since, javax mail's mailcap is in mail.jar in the javax.mail.api module, it can't be found with the default configuration.
There is actually a workaround, is to add in the jboss-deployement-structure.xml the following dependency:
<module name="javax.mail.api"><imports><include path="META-INF"/><include path="META-INF/**"/></imports></module>
Then, the application's class loader will resolve the module's META-INF/mailcap.
I wonder then, shouldn't the default module dependency to javax.mail.api include META-INF for any J2EE project ?
Thank you very much.