Here is the code I have for calling a SOAP service within the mock script.
the host can be override in the header as in
<header>
<host>142.234.345.67</host>
</header>
```
/**************************************/
/* get the override host value */
/**************************************/
def String host = holder.getNodeValue("//host");
//def host = context.expand('${#Project#host}');
//log.info("HOST => " + host);
/**************************************/
/* if no host override, use localhost */
/**************************************/
if (host == null || host.length() == 0)
host = "localhost";
/**************************************/
/* build the URL */
/**************************************/
service_url = "http://" + host + ":7001/my_downstream_service";
/**************************************/
/* setup the soap connection */
/**************************************/
def soapUrl = new URL(service_url);
def connection = soapUrl.openConnection();
def soapRequest = mockRequest.requestContent;
connection.setRequestMethod("POST");
connection.setRequestProperty("Accept-Encoding" ,"gzip,deflate");
connection.setRequestProperty("Content-Type" ,"text/xml;charset=UTF-8");
connection.setRequestProperty("SOAPAction", mockRequest.getSoapAction()); // mockRequest.getSoapAction());
connection.doOutput = true;
/**************************************/
/* remove host override from reqeust */
/**************************************/
def String requestStr = mockRequest.requestContent
def int pos1 = requestStr.indexOf("<host>");
if (pos1 > 0){
def String newReqeustStr
def int pos2 = requestStr.indexOf("</host>");
newReqeustStr = requestStr.substring(0, pos1) +
requestStr.substring(pos2 + 8, requestStr.length());
soapRequest = newReqeustStr;
}
/**************************************/
/* call service */
/**************************************/
Writer writer = new OutputStreamWriter(connection.outputStream);
writer.write(soapRequest);
writer.flush();
writer.close();
connection.connect();
def soapResponse = connection.content.text;
requestContext.responseMessage = soapResponse;
return "Response 1"
```