Unmarshalling SOAP Envelope from file in Java

I want the unit-test mapper objects to display / translate the web service types generated by wsimport into my own domain objects. I also want to test error scenarios such as SOAP errors, etc., and I think it would be better to check mapper objects on authentic SOAP responses. I don’t want to launch requests to the web service itself, since this requires access to the web service, and for each test, round-trip time is created.

Given this scenario, I am trying to decouple the SOAP messages from a specific XML file containing the SOAP envelope. I want to untie the SOAP envelope and, in turn, the payload in the body of the corresponding Java types.

I managed to unleash the payload using JAXB unmarshalling, but I did not find a way to allow me to handle SOAP responses with SOAP errors.

Is there an approach that gives a SOAP Envelope XML file that will allow me to easily check my mappers?

+4
source share
1 answer

Have you tried the standard Java-SOAP API (javax.xml.soap)?

Something like that:

MessageFactory mf = MessageFactory.newInstance(); SOAPMessage message = mf.createMessage(); SOAPPart soapPart = message.getSOAPPart(); FileInputStream is = new FileInputStream(file); soapPart.setContent(new StreamSource(is)); 
+3
source

All Articles