web-services - SoapUI REST 模拟服务在模拟以根据请求值处理动态响应时给出错误(但相同的方法适用于 SOAP 模拟)

标签 web-services rest soap mocking soapui

我试图使用 soapUI 模拟以下 REST Web 服务

sample 请求:

   <Request>
            <HistoricTxn>
                <reference>E1</reference>
                <method>txn</method>
            </HistoricTxn>
    </Request>

样本响应1

<Response>
    <reason>ACCEPTED</reason>
    <status>1</status>
    <time>10:12</time>
</Response>

样本响应2

<Response>
    <information>Failure on invalid request details</information>
    <reason>fails Luhn check</reason>
    <status>3</status>
    <time>10:15</time>
</Response>

通常我使用这种 groovy 脚本来评估请求并输出动态响应。 (使用soapUI模拟SOAP网络服务时)

常规脚本:

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
def holder = groovyUtils.getXmlHolder(mockRequest.getRequestContent());

def reference = holder.getNodeValue("//reference");

if(reference == "Success"){
    return "SampleResponse1";
} else {
    return "SampleResponse2";
}

不幸的是,当我尝试向此 REST 模拟服务端点发送请求时,它会返回错误。 错误:

com.eviware.soapui.impl.wsdl.mock.DispatchException: Failed to dispatch using script; java.lang.NullPointerException: Cannot invoke method getRequestContent() on null object

我了解错误消息显示 getRequestContent() 已返回空值,因此我收到此异常。但同样适用于 SOAP 模拟服务,不会返回空值或导致异常。感谢任何解决此问题的解决方法。

最佳答案

我刚刚发现 mockRequest.getRequestContent() 对于发送到使用 soapUI(版本 5.2.1)模拟的 REST Web 服务的所有 POST、PUT、DELETE 请求返回 null

def holder = groovyUtils.getXmlHolder(mockRequest.getRequestContent());

由于上面的(RequestContent)返回null,soap UI无法计算下面标签的值。

def reference = holder.getNodeValue("//reference");

SoapUIOfficial References for this bug in soapUI(version 5.2.1):

https://community.smartbear.com/t5/SoapUI-NG/SoapUI-5-0-requestContent-is-null-for-Rest-Mock-service/td-p/40458

https://community.smartbear.com/t5/SoapUI-NG/Mock-Service-mockRequest-requestContent-is-NULL-HTTP-PUT/td-p/42138

关于web-services - SoapUI REST 模拟服务在模拟以根据请求值处理动态响应时给出错误(但相同的方法适用于 SOAP 模拟),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38313401/

相关文章:

security - 是否可以为不存在的资源返回 HTTP 401 而不是 404 以防止信息泄露?

java - HTTP Base64 编码 header

php - 糖皂 set_entry

linux - 如何从 Linux 中使用 wsHttpBinding 访问 WCF SOAP 服务?

java - 如何自定义soapUI库以从WSDL生成请求和响应?

java - tomcat - web 服务在 60 秒后超时,增加连接超时

iphone - 兴趣点 API/Web 服务

android - 使用 asp.net WebService 和 Android 将图像上传到 Azure Blob 存储?

java - 无法在 "The java web services tutorial"之后找到 taskdef 类 com.sun.tools.ws.ant.WsImport

java - org.apache.catalina.core.StandardContext.startInternal 一个或多个监听器启动失败