Wednesday 11 March 2009

Java mail MIME type errors

I've developed small job on local machine which sends email with PDF attachments. But when i ran it on test environment, an exception was thrown:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;

While searching the solution, found this question. Solution i found was adding MIME type handlers programmatically:
// add handlers for main MIME types
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");
CommandMap.setDefaultCommandMap(mc);
Others solutions didn't work for me - i had recent activation.jar and mail.jar in WEB-INF/lib folder already. Can someone explain me why META-INF/mailcap file wasn't read from mail.jar?

Monday 2 March 2009

Vendor branches

Little time ago had a little struggle with vendor branches. Red-book describes this concept pretty good, but command line interface is not my favourite (in this particular situation) when it comes to merging.
Preconditions: Eclipse, Subclipse, svn-load (or svn_load_dirs is equivalent, but i'm using Ubuntu and svn-load can be installed from default repositories)
Here's my example:
  1. update vendor version
    svn update /path/to/vendor
  2. copy updated version to another folder (we'll need to disconnect it from SVN)
    cp -r /path/to/vendor /path/to/vendor_copy
  3. disconnect folder from SVN
    rm -fr `find /path/to/vendor_copy -type d -name .svn`
  4. Send changes to SVN with svn-load:
    svn-load -t tags/vendor_version_2009-02-01 \
    http://svn.mydomain.com/projectX \
    branches/vendor \
    /path/to/vendor_copy
    * I prefer tagging each vendor import
  5. In Eclipse be sure that you've committed all changes and you're working in trunk
  6. Merge new tag and previous one:
  7. in Team Synchronizing perspective double check all changes (this perspective is really useful for merging)
  8. commit!
Hope this helps!