【发布时间】:2016-06-09 15:56:10
【问题描述】:
我按照指南 here 在 SoapUI 中设置了一个模拟 SOAP 服务。在 SoapUI 中执行 CurrencyConvertorSoap12 请求 1 时,我得到了适当的响应:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://www.webserviceX.NET/">
<soap:Header/>
<soap:Body>
<web:ConversionRateResponse>
<web:ConversionRateResult>2.34</web:ConversionRateResult>
</web:ConversionRateResponse>
</soap:Body>
</soap:Envelope>
现在我想使用 Spring Integration Web 服务出站网关对其进行测试。
我设置了一个 Web 服务测试(下面的 String requestXML 是 SoapUI 中的同一个 XML 请求):
@Test
public void webServiceTest() {
AbstractApplicationContext context = new ClassPathXmlApplicationContext("Context.xml");
DestinationResolver<MessageChannel> channelResolver = new BeanFactoryChannelResolver(context);
String requestXml = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:web=\"http://www.webserviceX.NET/\">"
+ "<soap:Header/>"
+ "<soap:Body>"
+ "<web:ConversionRate>"
+ "<web:FromCurrency>?</web:FromCurrency>"
+ "<web:ToCurrency>?</web:ToCurrency>"
+ "</web:ConversionRate>"
+ "</soap:Body>"
+ "</soap:Envelope>";
Message<String> message = MessageBuilder.withPayload(requestXml).build();
MessageChannel channel = channelResolver.resolveDestination("wsInChannel");
channel.send(message);
}
Context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-stream="http://www.springframework.org/schema/integration/stream"
xmlns:int-ws="http://www.springframework.org/schema/integration/ws"
xmlns:int-ftp="http://www.springframework.org/schema/integration/ftp"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/stream
http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd
http://www.springframework.org/schema/integration/ws
http://www.springframework.org/schema/integration/ws/spring-integration-ws.xsd">
<int:channel id="wsInChannel"/>
<int:chain input-channel="wsInChannel" output-channel="stdoutChannel">
<int-ws:header-enricher>
<int-ws:soap-action value="http://www.webserviceX.NET/ConversionRate"/>
</int-ws:header-enricher>
<int-ws:outbound-gateway uri="http://localhost:8088/mockCurrencyConvertorSoap12"/>
</int:chain>
<int:channel id="stdoutChannel"/>
<int-stream:stdout-channel-adapter
id="consumer" channel="stdoutChannel" append-newline="true" />
</beans>
当我运行测试时,我在 SoapUI 中收到此错误:
Thu Jun 09 11:50:21 EDT 2016:ERROR:An error occurred [Missing operation for soapAction [http://www.webserviceX.NET/ConversionRate] and body element [{http://www.w3.org/2003/05/soap-envelope}Envelope] with SOAP Version [SOAP 1.1]], see error log for details
我做错了什么?
【问题讨论】:
-
恕我直言,不从文件中读取 XML 是您正在做的一件错误的事情
-
@ThomasRS 这只是一个概念证明。这通常不是我在 XML 中阅读的方式。
-
然后向我们展示您的 JAXB 实用程序;-) 我建议您也使用 CXF 进行评估并生成 Web 服务客户端;您还将获得服务器端点模拟。我已经举了一个例子here,它可以让你放弃SoapUI,至少在单元测试中是这样。
-
@ThomasRS 问题是关于如何使用 Spring Integration 正确发送 SOAP 请求,而不是用于读取 XML 的工具。
标签: spring soap spring-integration soapui