Signup/Sign In

[SOLVED] Unable to create SAAJ meta-factory: Provider SAAJMetaFactoryImpl not found

Posted in Programming   LAST UPDATED: AUGUST 26, 2021

    While upgrading your Java web service application to newer versions of Java like Java 9 or Java 11, you can face this issue in your Java Web services. The stacktrace for the exception above should look like following:

    org.apache.cxf.binding.soap.SoapFault: Problems creating SAAJ object model
            at org.apache.cxf.binding.soap.saaj.SAAJInInterceptor.handleMessage(SAAJInInterceptor.java:257) ~[cxf-rt-bindings-soap-3.3.5.jar!/:3.3.5]
            at org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor.getSOAPMessage(WSS4JInInterceptor.java:179) ~[cxf-rt-ws-security-3.3.5.jar!/:3.3.5]
            at org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor.handleMessageInternal(WSS4JInInterceptor.java:246) ~[cxf-rt-ws-security-3.3.5.jar!/:3.3.5]
            at org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor.handleMessage(WSS4JInInterceptor.java:212) ~[cxf-rt-ws-security-3.3.5.jar!/:3.3.5]
            at com.emeter.security.authentication.ws.cxf.interceptors.WSSecurityInterceptor.handleMessage(WSSecurityInterceptor.java:63) ~[em-core.jar!/:1.0.0]
            at com.emeter.security.authentication.ws.cxf.interceptors.WSSecurityInterceptor.handleMessage(WSSecurityInterceptor.java:24) ~[em-core.jar!/:1.0.0]
    
    
    .........
    
    
    Caused by: javax.xml.soap.SOAPException: Unable to create message factory for SOAP: Unable to create SAAJ meta-factory: Provider com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found
            at javax.xml.soap.MessageFactory.newInstance(MessageFactory.java:120) ~[javax.xml.soap-api-1.4.0.jar!/:1.4.0]
            at org.apache.cxf.binding.soap.saaj.SAAJFactoryResolver.createMessageFactory(SAAJFactoryResolver.java:56) ~[cxf-rt-bindings-soap-3.3.5.jar!/:3.3.5]
            at org.apache.cxf.binding.soap.saaj.SAAJInInterceptor$SAAJPreInInterceptor.getFactory(SAAJInInterceptor.java:151) ~[cxf-rt-bindings-soap-3.3.5.jar!/:3.3.5]
            at org.apache.cxf.binding.soap.saaj.SAAJInInterceptor.handleMessage(SAAJInInterceptor.java:181) ~[cxf-rt-bindings-soap-3.3.5.jar!/:3.3.5]
    

    Well this is a consequence of the JAX-WS getting removed from Java 11 completely along with related technologies SAAJ and Web Services Metadata.

    So now we need to manually provide substitutes for these packages as separate JARs.

    The first choice for many developers have been the jaxws-ri or the jakarta.xml.ws-api.jar along with other jaxb JARs as the JAXB package has also been removed from Java 11.

    Include the saaj-impl.jar - Solution 1

    Also, you will find a few questions on Stackoverflow, with answers suggesting to include the saaj-impl jar in your project, which can work for you.

    <dependency>
        <groupId>com.sun.xml.messaging.saaj</groupId>
        <artifactId>saaj-impl</artifactId>
        <version>2.0.0-M1</version>
    </dependency>  

    Use Metro JAX-WS Implementation - Solution 2

    But there is a different bundle of Metro EE4J Initiative Jars which is best if you are facing troubles post Java 11 upgrade. In MVNRepository, you will find the JARs listed here: Glassfish Metro

    You need to add the webservices-api.jar and webservices-rt.jar as dependencies in your Java web service project.

    <dependency>
        <groupId>org.glassfish.metro</groupId>
        <artifactId>webservices-rt</artifactId>
        <version>2.4.4</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.metro</groupId>
        <artifactId>webservices-api</artifactId>
        <version>2.4.4</version>
    </dependency>

    The SAAJMetaFactoryImpl class is available in the webservices-rt.jar file and the above issue should get fixed by this.

    If none of the above solution works for you, please share your exception stacktrace in the comment section below and we can help you.

    You may also like:

    Published by: iamabhishek
    Tags:JavaJAX-WSWeb ServicesJava11
    IF YOU LIKE IT, THEN SHARE IT
     

    RELATED POSTS