Search code examples
integration-testinghttp-proxywiremock

WireMock To Use As Proxy For SOAP Service


Here is the scenario I'm trying to work on:

I'm writing Contract Driven Tests using Spring Cloud Contract. The tests for inter-communication between the microservices works fine.

Some microservices are calling SOAP-based services. As part of integration tests, I'm trying to use WireMock as a proxy for the SOAP-based services. Basically, the WireMock should intercept the call, then call the target live environment with the same request, return the same response to the test as a stub.

Unfortunately, I couldn't find any examples how to proceed with that. These services use the HTTP protocol. Any examples of how or any pointers to achieve this would be great. Thanks!


Solution

  • Firstly you need to point your SOAP client to the WireMock base URL, so e.g. if you're using a Spring properties file you might have something like this:

    soap.api.host=wiremock-host.internal
    soap.api.port=8888
    

    Then you need to configure the WireMock server with a low-priority, broad matching proxy stub. Here's an example of how that would look in JSON form:

    {
      "priority": 8,
      "response": {
        "proxyBaseUrl" : "http://target.soap.endpoint"
      }
    }
    

    Then finally, you would create additional stubs (at the default priority) for each request you want to intercept e.g.

    {
      "request": {
        "method": "POST",
        "urlPath": "/v1/some/thing",
        "headers": {
          "SOAPAction": {
            "contains": "MyAction"
          }
        }
      },
      "response": {
        "status": 200,
        "body": "<soap:Envelope ..."
      }
    }