从 Java 文件中解组 SOAP 信封 [英] Unmarshalling SOAP Envelope from file in Java

查看:22
本文介绍了从 Java 文件中解组 SOAP 信封的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对映射器对象进行单元测试,这些映射器对象将 wsimport 生成的 Web 服务类型映射/转换为我自己的域对象.我还想测试错误场景,例如 SOAP 错误等,我认为最好在真实的 SOAP 响应上测试映射器对象.我不想向 Web 服务本身发出请求,因为这需要访问 Web 服务,并为每次测试带来往返时间.

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.

鉴于这种情况,我试图从包含 SOAP 信封的特定 XML 文件中解组 SOAP 消息.我想解组 SOAP Envelope,然后将正文中的有效负载转为相应的 Java 类型.

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.

我已经通过使用 JAXB 解组成功地解组了有效负载本身,但我还没有找到一种方法来允许我处理具有类似 SOAP 错误的 SOAP 响应.

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?

推荐答案

您是否尝试过标准的 Java SOAP API (javax.xml.soap)?

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

像这样:

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

这篇关于从 Java 文件中解组 SOAP 信封的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆