Signup/Sign In
LAST UPDATED: JUNE 5, 2023

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

Technology #oracle

    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 stack trace for the exception above should look like the 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 deleted from Java 11 along with related technologies SAAJ and Web Services Metadata.

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

    The first choice for many developers has 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.

    How to Solve "Unable to create SAAJ meta-factory: Provider SAAJMetaFactoryImpl not found"

    Solution 1 - Include the saaj-impl.jar as a Dependency

    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>  

    Solution 2 - Use Metro JAX-WS Implementation

    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 must 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 solutions works for you, please share your exception stack trace in the comment section below and we can help you.

    Conclusion

    Encountering the error message "Unable to create SAAJ meta-factory: Provider SAAJMetaFactoryImpl not found" can be frustrating, especially when working with SOAP-based web services or Java applications. However, by following the steps outlined in this article, you can successfully resolve this issue and ensure the smooth execution of your code.

    From checking dependencies and classpath configurations to validating the Java version and adjusting the application server settings, each solution discussed provides a potential fix for the problem. Remember to carefully analyze the error message and its context to identify the root cause before applying the appropriate solution. W

    ith the troubleshooting techniques and guidelines provided, you can overcome the "Provider SAAJMetaFactoryImpl not found" error and continue developing and deploying your SOAP-based applications with confidence. Don't let this error hinder your progress; instead, use it as an opportunity to deepen your understanding of Java development and strengthen your problem-solving skills.

    You may also like:

    I like writing content about C/C++, DBMS, Java, Docker, general How-tos, Linux, PHP, Java, Go lang, Cloud, and Web development. I have 10 years of diverse experience in software development. Founder @ Studytonight
    IF YOU LIKE IT, THEN SHARE IT
    Advertisement

    RELATED POSTS