Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with the mail when 2 applications that has been deployed in tomcat

Before, I have deployed 1 application on Tomcat 6.0.24 and it was working fine. Now, I have deployed an AXIS webservice and the first applcaition is giving the error while sending the mail. I am using Java6 and for mailing with mail-1.4.2.jar.

 Error message:
     javax.mail.MessagingException: IOException while sending message;
       nested exception is:
   javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed; 
         boundary="----=_Part_8_85998487.1343293259308"
         at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:779)
             at javax.mail.Transport.send0(Transport.java:191)
         at javax.mail.Transport.send(Transport.java:120)

Also, if I remove the web service from the deploy and try to run the application, it works without any problem. Also, I'm able to receive the mail. Further, I would like to add is if I deploy the webservie on different tomcat then the applciation rums fine. The issue is only when both are on the same server at the same time.

like image 973
743 Avatar asked Dec 11 '25 12:12

743


1 Answers

Sorry for the late reply. I am able to trace the reason behind the issue. In the web service, i am using jaxws-rt-2.1.3.jar in which there is a class called com.sun.xml.ws.encoding.MimeCodec. In MimeCodec, there is a static block.

static { 
     // DataHandler.writeTo() may search for DCH. So adding some default ones.
     try {
         CommandMap map = CommandMap.getDefaultCommandMap();
         if (map instanceof MailcapCommandMap) {
             MailcapCommandMap mailMap = (MailcapCommandMap) map;
             String hndlrStr = ";;x-java-content-handler=";
             mailMap.addMailcap(
                 "text/xml" + hndlrStr + XmlDataContentHandler.class.getName());
             mailMap.addMailcap(
                 "application/xml" + hndlrStr + XmlDataContentHandler.class.getName());
             mailMap.addMailcap(
                 "image/*" + hndlrStr + ImageDataContentHandler.class.getName());
             mailMap.addMailcap(
                 "text/plain" + hndlrStr + StringDataContentHandler.class.getName());
         }
     } catch (Throwable t) {
         // ignore the exception.
     }
 }

The above static blocks provides some default MIME types for DCH and it was getting executed at WS startup. Now, before sending the mail, the code searches for MIME type using javax.activation,CommandMap(rt.jar/activation.jar). The expected mime type loading has been overridden in this case. The mail will work only if the MIME type is either of the above 4.

So, everytime before sending the mail, i just reset the CommandMAp to the expected functionality using the following code and the mail functionality has started working fine without any issue.

CommandMap.setDefaultCommandMap(new MailcapCommandMap());

Also, when i checked the older version of jaxws-rt.jar(2.1.1), the static block was not present there but the same functionality was provided by some other class(Sorry as i don't remember the name now).

Also, while debugging, i noticed that inside javax.activation.MailcapCommandMap, the MIME type was getting loaded from

System.getProperty("user.home") + File.separator + ".mailcap";

and

System.getProperty("java.home") + File.separator + "lib" + File.separator + "mailcap";

So, if we provide the MIME type at the above locations, then also, the mail should work(i have not tested this).

like image 83
743 Avatar answered Dec 14 '25 02:12

743



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!