A little bit of context :
My Java project used to write data in a local database, but now we are moving to a SAAS solution. Sadly, the API we are going to use can only be called via SOAP. That means I am changing all of my writers so they can create and send appropriate SOAP envelopes.
Since I had no knowledge of how SOAP worked, I made a little side project as a POC to test out how the libraries worked. I used Maven to import the dependencies, and started using javax.xml.soap, but then I read that this library is very deprecated, so instead I switched to jakarta
And it worked ! My POC send the right envelopes and got a response. So I started adapting my big project, and I added that to my pom.xml :
<dependency>
<groupId>jakarta.xml.ws</groupId>
<artifactId>jakarta.xml.ws-api</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>javax.xml.soap-api</artifactId>
<version>1.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.4.0</version>
<scope>compile</scope>
</dependency>
And I adapted the code from my POC to the main project :
try {
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
//Abstract method that needs to be overridden by each writer
createSoapEnvelope(soapMessage, itemProcessorResult);
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", soapAction);
soapMessage.saveChanges();
SOAPMessage soapResponse = soapConnection.call(
soapMessage,
ENDPOINT_URL
);
I don't post the whole createSoapEnvelope, because it's big, but it looks like this :
@Override
protected void createSoapEnveloppe(SOAPMessage soapMessage, ItemProcessorResult itemProcessorResult) throws SOAPException {
SOAPPart soapPart = soapMessage.getSOAPPart();
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration(namespaceShort, namespaceURI);
// SOAP Body
SOAPBody soapBody = envelope.getBody();
[A whole bunch of SOAPElements with addChildElement()]
After a mvn clean install, I could run my code, but I got errors at the execution
javax.xml.soap : Using deprecated META-INF/services mechanism with non-standard property: javax.xml.soap.MetaFactory. Property javax.xml.soap.SAAJMetaFactory should be used instead. com.sun.xml.messaging.saaj.soap.impl : SAAJ0101 : le parent dun élément SOAPBodyElement doit être un élément SOAPBody
It's strange that the error is in my system's language, and it means "The parent of a SOAPBodyElement must be a SOAPBody element"
I tried to fix that, but couldn't find anything. Then I noticed that the library used for the SOAPConnectionFactory was not the same in my POC and in the final project, by highlighting the class in IntelliJ
In my POC : POC library
In my project : Project library
So my POC is using jakarta, but my project is still using javax. I tried to delete javax from my project by removing the dependency from my pom.xml (both of them, the main one and the module's one), but somehow the library is still there and used, even after reloading the project dependencies and doing some mvn clean install several times.
I am assuming my problem comes from the fact that I'm using the wrong library, but maybe I'm wrong ? And if I'm not, how can I set the library right ? I'm using the latest version of IntelliJ and have been fiddling with the projet properties, but I don't know much about it.
Oh, and both the POC and the project have
import javax.xml.soap.*;
on top. I tried to replace it with jakarta.xml.soap.* but it's just not compiling
Thank you (and sorry if I made any errors, english is not my native language and my brain is fried)
UPDATE : I changed my pom.xml to exclude javax.xml.soap, and now my SOAPConnectionFactory uses jakarta ! I still got my french error though.