Forum Discussion

hofi's avatar
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:


<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

1 Reply

  • Hello,

    If you want this to be namespace-agnostic, then just change the line:

    def price = Double.valueOf(holder.getNodeValue("//moc:price"))


    to

    def price = Double.valueOf(holder.getNodeValue("//*:price"))


    As for why this isn't working when the Header isn't empty I can't really say. Could you please attach an example request where this does not work?

    Regards,
    Dain
    eviware support