title: How Can i pass result from a method in groovy to the body of a request in SOAPUi
body: <p>Can i start by saying i am new to programming and SoapUI(more like a week old). i apologies in advance for asking the question(s) i am about to ask.</p>
  
  <h2>Problem</h2>
  
  <p>basically, i am trying to automate webservice.
  I need to create xml using Groovy in soapui and send it as part of a request body to a webservice(REST not SOAP) and do some assertion on the response received.  i will be sending quite a few request, hence the reason to automate.</p>
  
  <h2>My proposed solution (which i am not sure about)</h2>
  
  <pre><code>import groovyx.net.http.HTTPBuilder
  import groovyx.net.http.ContentType
  import groovyx.net.http.Method
  
  class XmlGenerator {
  
    // I created a class i.e. called XmlGenerator with a
    // static method called GetXML() which looks like this:
    public static def GetXML() 
    {
      def  writer = new StringWriter()
      def  xml = new MarkupBuilder(writer)
      xml.GetDMessage() //creating the xml message
      {
        PrescribedItems 
        {
          PrescribedMethod(xml,'Some Value','Some Value','Some Value')
          PrescribedItem
          {
            PrescribedMethod(xml,'Some Value','Some Value','Some Value')
          }
        }
      }
      return writer
    }
  
    // This method creates the XML needed but then i need to
    // pass the xml generated to a request boy; so i
    //create another method within the same class:  
    static def postXML(String baseUrl, String path)
    {
      def RequestBody = XmlGenerator.GetXML()  // i am not sure if this will work
      try 
      {
        def ret = null
        def http = new HTTPBuilder(baseUrl)
        http.request(Method.POST, ContentType.XML) 
        {
          uri.path = path
          body = RequestBody
        }
      }
      catch (groovyx.net.http.HttpResponseException ex) 
      {
        ex.printStackTrace()
        return null
      }
      catch (java.net.ConnectException ex) 
      {
        ex.printStackTrace()
        return null
      }
    }
  }
  </code></pre>
  
  <h2>Summary</h2>
  
  <p>A class called <code>XmlGenerator()</code> with 2 methods; <code>GetXML()</code> (used to generate XML ) and <code>postXML()</code> (Used to send XML generated by <code>GetXML()</code> to the Webservice.)</p>
  
  <h2>Questions</h2>
  
  <ol>
  <li><p>How can i make sure that this 2 methods ( <code>GetXML()</code> and <code>postXML()</code> ) are used by other request messages i.e. do i need to import the groovy scripte.g. do i do an import ... GroovyScriptName , if yes, please how?</p></li>
  <li><p>How can i create create the xml and run the request in subsequent request messages. For instance;
  do i do this; <code>XmlGenerator() gen = new XmlGenerator()</code>, then do <code>gen.GetXML()</code> and <code>gen.postXML()</code> to create and run the request. Also, what role can testRunner play in all this</p></li>
  <li><p>Running the code currently throws up <code>HTTPBuilder, ContentType , Method can not be resolved</code> even though i have imported them in the script (see above)</p></li>
  <li><p>Finally, what role can property play in building this framework? bearing in mind that the each request will be independent from the other request i.e. nothing is been passed around from one request to the other during test execution</p></li>
  </ol>