Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access the request XML in a SOAP UI mock response script

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

like image 333
Jonathan Avatar asked Aug 05 '10 14:08

Jonathan


People also ask

How do I open an XML file in SoapUI?

Select File > Import Project. Specify a path to the project XML file, or click Browse and navigate to the file manually. Click OK.

How do I check my SoapUI request and response?

To view the HTTP request, click RAW at SoapUI Request window (left side). The Request is posted to the web-server. Hence, the POST method of Http is used. The SOAP Request is transported in the body of the http message, which is shown as follows.


1 Answers

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.

like image 155
khylo Avatar answered Sep 19 '22 06:09

khylo