开发者

Access the request XML in a SOAP UI mock response script

开发者 https://www.devze.com 2023-01-10 04:04 出处:网络
I have a mock response, which needs to return a value that was in the request. For example, this request can come in:

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 th开发者_JAVA百科e value.

Any help would be much appreciated.

Thanks, Jonny


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.


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


Using Dispatch SEQUENCE the MokcResponse can be:

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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号