1

I set up a mock SOAP service in SoapUI following the guide here. When executing the CurrencyConvertorSoap12 Request 1 within SoapUI, I get the appropriate response:

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

Now I want to test it using the Spring Integration web service outbound gateway.

I set up a web service test (the String requestXML below is the same XML request in SoapUI):

@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>

When I run the test, I get this error in 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

What am I doing wrong?

badjr
  • 2,166
  • 3
  • 20
  • 31
  • IMHO not reading XML from files is one wrong thing you're doing – ThomasRS Oct 29 '16 at 15:08
  • @ThomasRS This was only a proof of concept. This isn't normally how I would read in the XML. – badjr Oct 29 '16 at 15:16
  • Then show us your JAXB utility ;-) I suggest you also evaluate using CXF and generate a webservice client; you'll get the server endpoint mock too. I've put up an example [here](https://github.com/skjolber/mockito-soap-cxf) which will let you discard SoapUI, at least for unit testing. – ThomasRS Oct 29 '16 at 15:25
  • @ThomasRS The question was about how to properly send a SOAP request using Spring Integration, not the tools used to read in XML. – badjr Oct 29 '16 at 22:36

1 Answers1

2

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

But you send the whole SOAP Envelope, not just Body as it requests.

So, your requestXml must be like:

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

And don't forget to replace ? with an appropriate currencies :-)

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • When I made that change I get this error: `[Fatal Error] :1:21: The prefix "web" for element "web:ConversionRate" is not bound. ERROR: 'The prefix "web" for element "web:ConversionRate" is not bound.'` – badjr Jun 09 '16 at 16:34
  • I've just added `xmlns:web` to my answer. See updated XML. – Artem Bilan Jun 09 '16 at 16:38
  • Now getting this error: `Cannot create message: incorrect content-type for SOAP version. Got application/soap+xml; charset=UTF-8, but expected text/xml` – badjr Jun 09 '16 at 16:49
  • That is what Spring WS produces as a `content-type` header. Just change your SOAP-UI to accept that header instead of simple `text/xml` – Artem Bilan Jun 09 '16 at 16:57
  • I'm not seeing an option to change it from SoapUI. Is there a way to set the Spring WS header? – badjr Jun 09 '16 at 17:57
  • 1
    You have to configure `SaajSoapMessageFactory` with `SoapVersion.SOAP_11` and inject it into `` – Artem Bilan Jun 09 '16 at 18:48
  • I did this, and it actually worked when I used `SoapVersion.SOAP_12`. – badjr Jun 09 '16 at 19:50