模拟 SOAP 服务在 SoapUI 中有效,但不适用于 Spring 集成

Mock SOAP service works in SoapUI but not with Spring Integration

我按照指南 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 集成 Web 服务出站网关对其进行测试。

我设置了一个 web 服务测试(下面的字符串 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

我做错了什么?

and body element [{http://www.w3.org/2003/05/soap-envelope}Envelope]

但是您发送了整个 SOAP Envelope,而不仅仅是 Body 它请求的。

所以,你的 requestXml 必须是这样的:

"<web:ConversionRate xmlns:web=\"http://www.webserviceX.NET/\">"
+ "<web:FromCurrency>?</web:FromCurrency>"
+ "<web:ToCurrency>?</web:ToCurrency>"
+ "</web:ConversionRate>"

并且不要忘记用适当的货币替换 ?:-)