Search code examples
javajakarta-mailapache-servicemix

ClassCastException when sending email under servicemix using JavaMail API


I'm sending email with attachments under servicemix using the JavaMail API. I'm using the same code that works stand-alone, and I get a strange exception:

Exception in thread "pool-6-thread-5" java.lang.ClassCastException: com.sun.mail.handlers.multipart_mixed at org.apache.servicemix.specs.activation.OsgiMailcapCommandMap.createDataContentHandler(Osg iMailcapCommandMap.java:60)

I've tried a lot of tricks, including importing package com.sun.mail.handlers in the bundle definition and those described in this thread.

The project is java 1.5 code run by JDK 1.5, FuseESB 4.2

-- edit --

The problem was caused by weblogic.jar loaded into servicemix, which provided own copies of mailcap and other files from java mail api and activation, exposed via META_INF.


Solution

  • It sounds like a conflicted Class case.

    ab.jar has Class AB

    cd.jar also has Class AB

    And then your application run with classpath including ab.jar and cd.jar. Java load Class AB from ab.jar, but actually the correct Class to be loaded is AB from cd.jar.

    Perhaps you can try searching the jar files for conflicted classes. Can be done easily by if you are using Eclipse. Include all jars to project's build path and then press: CTRL+SHIFT+T (shortcut for Open Type), key in: multipart_mixed and see how many jars have it.

    Could also conflict with activation.jar in java runtime library.