Hi,
We are building a custom distribution currently based on Karaf 4.2.2 (but
including some changes from Karaf 4.2.3) which is running on Java 8. We have
observed that once we are sending a SOAP message with attachments via CXF,
javamail will stop working.
The root cause for this was the following.
With the changes from [KARAF-5989] and [KARAF-6093] the javax.activation and
the javax.xml.soap are removed from the Java 8 section from jre.properties.
As a consequence the bundles
org.apache.servicemix.specs:org.apache.servicemix.specs.activation-api-1.1:2.9.0
and org.apache.servicemix.specs:
org.apache.servicemix.specs.saaj-api-1.3:2.9.0 are installed in the stack. In
order to make CXF work the bundle
org.apache.servicemix.bundles:org.apache.servicemix.bundles.saaj-impl:1.3.28_1
is also added to the stack.
The servicemix wrapped activation api bundle has an OSGi enabled registry for
MIME DataTypeHandlers, where javamail registers some data type handlers (among
others for text/plain via mailcap file). In addition javamail wires the
javax.activation package wth this bundle. So far everything works.
Unfortunately the constructor of
com.sun.xml.messaging.saaj.soap.AttachmentPartImpl contained in the saaj-impl
bundle (in version 1.3.28_1) registers
com.sun.xml.internal.messaging.saaj.soap.StringDataContentHandler as a data
content handler for text/plain. This class is coming from the JDK and
implements javax.activation.DataContentHandler from JDK. If after this
registration javamail tries to look up a DataContentHandler for text/plain, the
registry in the javax.activation api bundle will contain that handler but as
the bundles has its own version of javax.activationDataContentHandler, we will
get a ClassCastException:
java.lang.ClassCastException -
com.sun.xml.internal.messaging.saaj.soap.StringDataContentHandler cannot be
cast to javax.activation.DataContentHandler (loaded by
org.apache.felix.framework.BundleWiringImpl$BundleClassLoader@0x0000000100162fd8)
(found matching interface javax.activation.DataContentHandler loaded by , but
needed loader
org.apache.felix.framework.BundleWiringImpl$BundleClassLoader@0x0000000100162fd8)]java.lang.ClassCastException:
com.sun.xml.internal.messaging.saaj.soap.StringDataContentHandler cannot be
cast to javax.activation.DataContentHandler (loaded by
org.apache.felix.framework.BundleWiringImpl$BundleClassLoader@0x0000000100162fd8)
(found matching interface javax.activation.DataContentHandler loaded by , but
needed loader
org.apache.felix.framework.BundleWiringImpl$BundleClassLoader@0x0000000100162fd8)
at
com.sap.esb.activation.impl.OsgiMailcapCommandMap.createDataContentHandler(OsgiMailcapCommandMap.java:179)
at javax.activation.DataHandler.getDataContentHandler(DataHandler.java:249)
at javax.activation.DataHandler.getContent(DataHandler.java:142)
at javax.mail.internet.MimeMessage.getContent(MimeMessage.java:1454)
at
org.apache.camel.component.mail.MailBinding.extractHeadersFromMail(MailBinding.java:601)
The culprit seems to be the saaj-impl bundle. So I looked for newer version.
There is a version 1.4.0_1 that is actually registering DataContentHandlers like
com.sun.xml.messaging.saaj.soap.StringDataContentHandler (without the
internal), which is instead coming from the saaj-api bundle (which wires with
the javax.activation bundle in the stack), so this should work. Unfortunately
the version 1.4.0 imports package version 1.4 or later of package
javax.xml.soap, whereas the saaj-api-1.3 bundle is exporting version 1.3 of
that package.
Yesterday Jean Baptiste Onofré added version 1.5.1_1-SNAPSHOT to the servicemix
bundles repository, though I don't know why he did so and when he plans to
release that version.
Are you already aware of this or is this change not related to the Karaf 4.2.3
release at all?
Does anyone know any combination of saaj/saaj-impl OSGi bundles that work with
Java 8 on Karaf?
Best regards
Stephan