17 years ago
MockService: Modify Request Elements
Hello everyone,
I'm currently starting to use SoapUI for generating MockServices, and I want to make a simple Service that receives a double, multiplies it with a certain factor and sends it back.
My request looks like this:
I used the following groovy script to multply the price by 1.3343:
That works, but only as long as the request doesn't have a different namespace than "moc" AND the soap header is empty. I.E. it only works as long as I send requests out of SoapUI.
Can anyone tell me how I must modify the groovy script to make it a) namespace-agnostic and more importantly b) work for request with a soap header
Many thanks in advance for your help!
Regards,
hofi
I'm currently starting to use SoapUI for generating MockServices, and I want to make a simple Service that receives a double, multiplies it with a certain factor and sends it back.
My request looks like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:moc="http://xml.netbeans.org/schema/MockCurrency01">
<soapenv:Header/>
<soapenv:Body>
<moc:MockCurrencyRequest>
<moc:price>1.00</moc:price>
</moc:MockCurrencyRequest>
</soapenv:Body>
</soapenv:Envelope>
I used the following groovy script to multply the price by 1.3343:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context)
def holder = groovyUtils.getXmlHolder(mockRequest.requestContent)
def price = Double.valueOf(holder.getNodeValue("//moc:price"))
price = price * 1.3343
context.setProperty("usd", price)
That works, but only as long as the request doesn't have a different namespace than "moc" AND the soap header is empty. I.E. it only works as long as I send requests out of SoapUI.
Can anyone tell me how I must modify the groovy script to make it a) namespace-agnostic and more importantly b) work for request with a soap header
Many thanks in advance for your help!
Regards,
hofi