【发布时间】:2019-08-09 19:20:41
【问题描述】:
我在 SoapUI 中创建了一个模拟服务。我在这个模拟服务中使用 Groovy,所以我可以模拟一些请求,以及将其他请求转发到我正在模拟的实际 Web 服务。 当 Web 服务返回三个可能的故障消息之一时,我无法从肥皂响应中检索到该实际故障。
模拟服务 Groovy 脚本仅使用以下响应进行回复(IOException,http 状态 500)。 但是当直接向实际的 Web 服务发送请求时,我得到了我真正想要得到的响应。
转发请求并检索响应的 Groovy 代码:
def soapUrl = new URL("[actual web service]");
def connection = soapUrl.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type" ,"text/html");
connection.setRequestProperty("SOAPAction", "");
connection.doOutput = true;
Writer writer = new OutputStreamWriter(connection.outputStream);
writer.write(soapRequest);
writer.flush();
writer.close();
connection.connect();
def soapResponse = connection.content.text;
// alert.showInfoMessage(soapResponse);
requestContext.responseMessage = soapResponse;
使用 Groovy 脚本模拟服务的响应:
<soapenv:Body>
<soapenv:Fault>
<faultcode>Server</faultcode>
<faultstring>Failed to dispatch using script; java.io.IOException: Server returned HTTP response code: 500 for URL: [the endpoint url]</faultstring>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
直接访问网络服务时的响应(使用相同的请求):
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server</faultcode>
<faultstring> [actual fault message] </faultstring>
<detail> [useful details about the fault] </detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
使用脚本时,为什么响应与直接检索不一样?
【问题讨论】:
标签: soap groovy mocking soapui fault