Pages

Tuesday, January 28, 2014

javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed in Tomcat

Last week, I encountered a very weird error in my Email service application. The error was like this:
javax.mail.MessagingException: IOException while sending message;
  nested exception is:
 javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed; 
 boundary="----=_Part_0_29947292.1390460403892"
 at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:625)

The issue is being encountered when the application is deployed in a separate Tomcat instance (not in the main server). What's weird is when I deploy it in the main instance's webapps or via Eclipse. There's no problem.

So, seems like activation.jar (it is a shared lib folder named endorsed) wasn’t able to locate the mail.jar file because they’re not in the same level when they were loaded by Tomcat (you know instance issues and stuff).

1) activiation.jar (exists in the endorsed folder)
2) mail.jar (exists in the applications’ lib folder)

So the easiest way to resolve this is put the mail.jar in the endorsed folder too.

However, we are just sharing an environment from the main instance (which is being used by other applications). Hence, for our case we can't just put it there. :( So I really got annoyed with the issue because I can't see any workaround anymore but luckily, after hours of checking and debugging, I finally found a way to resolve it. :)

So to fix the issue programmatically, you can configure your application's mailcap registry through MailcapCommandMap. I put this few lines before sending the message and it worked!
MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
        mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
        mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
        mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
        mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
        mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");

You can check more about MailcapCommandMap here.

No comments:

Post a Comment