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.

Monday, January 27, 2014

Birthday Getaway!

I just turned 26 yesterday and guess what I did? I went to Baguio City for a day trip all by myself! Talk about making some from your bucket list come true, this is indeed an achievement. :)

Can't really tell all the specifics of my trip but one great thing I did, I went to the Cemetery of Negativism at Camp John Hay and buried all the ill feelings I have (I guess and hoped). I had fun indeed. SOOOO MUCH! :)

Anyway, here's a picture of me at one of the tomb where a negative feeling was buried. Had a long and steep walk before reaching the place so I got plenty of exercise on my birthday. Hah!