Access the request XML in a SOAP UI mock response script

大兔子大兔子 提交于 2019-12-23 07:45:50

问题


I have a mock response, which needs to return a value that was in the request. For example, this request can come in:

<myReqest><myValue>123</myValue></myRequest>

I already have a mockResponse:

<myResponse><yourValue>${theValue}</yourValue></myResponse>

I know how to set the value of ${theValue} through the context variable, but I can't figure out how to access the request and parse it for the value.

Any help would be much appreciated.

Thanks, Jonny


回答1:


You can use the scripting feature to customize your response.

In the mockResponse window, you can click on the script menu.

In here you can put something like (using XPath to fully qualify the element you are looking for):

context.theValue = 
mockRequest.getRequestXmlObject().selectPath("//Message/text()")[0];

When you invoke the MockResponse, theValue variable should be automatically updated.




回答2:


The question/answer of SoapUI getting request parameters in mock service script is almost the same. To summarize:

def req = new XmlSlurper().parseText(mockRequest.requestContent)
context.theValue = req.myRequest.myValue



回答3:


Using Dispatch SEQUENCE the MokcResponse can be:

<myResponse><yourValue>${#MockResponse#Request#//myValue}</yourValue></myResponse>



回答4:


I'm not entirely sure of the context, which tool are you using?

We use Liquid XML Studio, which has a Web Services Test Client, which makes manually calling web services pretty straightforward, this kind of sounds like what your trying to do, but maybe you are trying to automate this process for testing?

Please provide a bit more info.

Simon




回答5:


If you're using SoapUI Pro just place the cursor where you want the value to be inserted, then right-click and select the parameter from the request via the "Get data..." submenu. This feature however is only available in the Pro version. Using the freeware edition you should follow khylo's answer.

Robert



来源:https://stackoverflow.com/questions/3415772/access-the-request-xml-in-a-soap-ui-mock-response-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!