Unmarshalling SOAP Envelope from file in Java

不羁岁月 提交于 2019-12-12 12:13:08

问题


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?


回答1:


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));


来源:https://stackoverflow.com/questions/3768898/unmarshalling-soap-envelope-from-file-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!