0

I have a JAX-RS resource, using Jersey, that provides a resource InstallOrder. When there is a POST Request for this resource it shall make a SOAP request and send it to yet another web service. I'm using the jakarta.xml.soap-api 1.4.2 library for the creation and sending of the SOAPMessage.

Before creating the SOAPMessage I'm getting a NullPointerException because SOAPConnectionFactory.newInstance() returns null. The code snippet looks like this:

SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance()
SOAPConnection connection = scf.createConnection();

The scf is unexpectedly null here. I'm using the exact same code in another SOAP web service with the same library and it works like a charm. I don't get where the problem is.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
lordzeu
  • 31
  • 5
  • When you say you are using *"the exact same code in another SOAP web service with the same library and it works like a charm"*, what does that mean? Is it a different environment? Is it the same? Are there differences, like maybe a different version of the library, different versions of Java, different system environment? – Bogdan Jun 25 '21 at 16:39
  • It is the same Tomcat in openshift environment / image. Therefore same java, same env, same version declared in POM ... I think I will bypass this problem by not using the SOAP libraries but simply send a http post which holds the SOAP body declared as text/xml. At least through Postman that works. Therefore it should work when send from a WebService too, right? – lordzeu Jun 30 '21 at 07:50

1 Answers1

0

I had the same problem and in my case I solved it by explicitly adding this to my POM file.

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

If you're not using Maven then this won't help directly, however it might help to know that behind the scenes the SOAPConnectionFactory uses com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnectionFactory to implement SOAP. At least this is true for javax.xml.soap-api 1.4.0.

DAB
  • 1,631
  • 19
  • 25