Creating a saop message in java

2.3k Views Asked by At

I am trying to create a saop message in java and i am getting the error

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

My code is this

        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage soapMessage = messageFactory.createMessage();

        createSoapEnvelope(soapMessage);

        MimeHeaders headers = soapMessage.getMimeHeaders();
        headers.addHeader("SOAPAction", soapAction);

        soapMessage.saveChanges();

        /* Print the request message, just for debugging purposes */
        System.out.println("Request SOAP Message:");
        soapMessage.writeTo(System.out);
        System.out.println("\n");

        return soapMessage;
    }```

I am using jdk14, what could be the solution?


1

There are 1 best solutions below

1
Sagar Gangwal On

As error clearly suggesting com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found need to add dependency for that class.

Add below dependency in your pom.xml.

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