简体   繁体   中英

Unmarshalling SOAP Envelope from file in Java

I want to unit-test the mapper objects that map/translate web service types generated by wsimport in to my own domain objects. I also want to test error-scenarios, such as SOAP faults and such, and I am thinking it would be best to test the mapper objects on authentic SOAP responses. I do not want to fire requests to the web service itself as this requires access to the web service, and poses round-trip time for each test.

Given this scenario, I am seeking to unmarshal SOAP messages from a particular XML-file containing a SOAP Envelope. I want to unmarshal the SOAP Envelope, and in turn the payload in the body to the corresponding Java types.

I've managed to unmarshal the payload itself by using JAXB unmarshalling, but I have not found a way to allow me to handle SOAP responses with SOAP faults an similar.

Is there an approach that given a SOAP Envelope XML-file would allow me to test my mappers in an easy manner?

Have you tried standard java SOAP API (javax.xml.soap)?

Something like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM