soaposgijava-11saajsoapexception

Unable to create message factory for SOAP: Unable to create SAAJ meta-factoryProvider com.sun.xml.messaging.saaj.soap.SAAJMetaFactoryImpl not found


Our product is built on eclipse RCP and OSGi frameworks. I have upgraded my code from JDK1.8 to JDK11. In the code I am creating a SOAP Message using MessageFactory.newInstance().createMessage() but I am getting below when running on JDK11.

javax.xml.soap.SOAPException: Unable to create message factory for SOAP: Unable to create SAAJ meta-factoryProvider com.sun.xml.messaging.saaj.soap.SAAJMetaFactoryImpl not found

I know that JDK11 does not have package com.sun.xml.messaging.saaj.soap which was there earlier in JDK1.8. So I have added a dependency for saaj-impl-1.5.1 and also its required transitive dependencies. I have also tried adding system properties to specify the implementations for MessageFactory but still getting the same error. Also tried with lower versions of saaj-impl but the error is still there.

I have tried the solutions mentioned in Unable to create SAAJ meta-factory after packaging as JAR and Unable to create SAAJ meta-factory: Provider com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found

Note: It works fine if I use jar based dependency but does not work when use plugin based dependency of the same versions. It seems something is going on with the class loader.


Solution

  • Was able to solve this by adding dependency https://mvnrepository.com/artifact/org.glassfish.hk2/osgi-resource-locator. Saaj-impl also has mechanism to load services in OSGi way and for that to work, we need this dependency. Add this dependency in the manifest.mf of the plugin where you are using saaj-api and saaj-impl