soapui中根据请求头内容发送模拟响应

Send mock response based on request header content in soapui

我有两个模拟回答,例如:A,B

我想为像

这样的模拟响应编写条件

是的,很有可能使用 soapui 进行模拟。

让我们假设当调用 rest 服务时,可以根据用户的 请求 header Content-Type 值有不同的响应。

  • xmlResponse
  • jsonResponse
  • 故障响应

因此,将以上三个响应添加到模拟服务。并且用户 SCRIPT 作为调度员。

模拟服务脚本如下:

def responseType = mockRequest.request.getHeader('Content-Type')
if (!responseType) {
    return "faultResponse"
}
if ('application/json' == responseType.toLowerCase() || 'json' == responseType.toLowerCase()) {
    return "jsonResponse"   
} 
"xmlResponse"