title: SoapUI Groovy Scripts
body: <p>I'm trying to read the incoming request &amp; set the mock response depending on a value comming in the request in <code>soapUI 3.0</code>. I use the following groovy script for this. </p>
  
  <pre><code>def typeElement = mockRequest.getContentElement().execQuery("//ProductType");
  def records =  new XmlParser().parseText(typeElement[0].xmlText())
  if (records.text()=="15"){
      mockOperation.setDefaultResponse("Response 2");
  } else {
      mockOperation.setDefaultResponse("Response 1");
  }
  </code></pre>
  
  <p>But it does not work, complaining that <code>mockRequest</code> object is null:</p>
  
  <blockquote>
    <p>com.eviware.soapui.impl.wsdl.mock.DispatchException: Failed to dispatch using script; java.lang.NullPointerException: Cannot invoke method getContentElement() on null object</p>
  </blockquote>
  
  <p>but I've used similar kind of code with <code>soapUI 2.0</code> version and was successful. How can I fix this?</p>