Forum Discussion

maximojo's avatar
maximojo
Frequent Contributor
10 years ago

Modify response with request data

Hi all,

 

Newb question for you. 

 

All I want to do is grab data from the request and add it to the response. In this case a transactionId from the request I want to transfer to the response transactionId field.

 

I have put a variable in the response:

 

<int:TransactionId>${transId}</int:TransactionId>

 

and can get it to update from the script (I'm using a "Sequence" response). However I can't get the data from the request. 

 

Any pointers are appreciated.

 

m

  • Actuall I think I figured it out.

     

    def request = new XmlSlurper().parseText(mockRequest.requestContent)
    def a = request.Body.Transaction.TransactionId
    context.transId = a

     

    So now my response uses the same TransactionId as the request.

     

    However if anyone has any better way to do this please let me know.

     

    m

  • maximojo's avatar
    maximojo
    Frequent Contributor

    Actuall I think I figured it out.

     

    def request = new XmlSlurper().parseText(mockRequest.requestContent)
    def a = request.Body.Transaction.TransactionId
    context.transId = a

     

    So now my response uses the same TransactionId as the request.

     

    However if anyone has any better way to do this please let me know.

     

    m

    • LoundesM's avatar
      LoundesM
      Contributor

      Hiya couple of other methods

       

      //with xml based request

      def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )

      def holder = groovyUtils.getXmlHolder(mockRequest.requestContent)

      def transID = holder.getNodeValue("//TransactionId")

       

      //non xml based request

      def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )

      def queryContext = mockRequest.getRequestContext()

      def transID = queryContext.get("TransactionId")

       

       

       

      • samuel_perez's avatar
        samuel_perez
        Occasional Contributor

        Is there a similar Sample for JSON/ REST vs SOAP/XML?