Modify response with request data
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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")
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there a similar Sample for JSON/ REST vs SOAP/XML?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hiya
you could try the jsonslurper, see if that fits the bill for your needs
http://docs.groovy-lang.org/latest/html/gapi/groovy/json/JsonSlurper.html
regards
Mike
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
following on
if you're not bothered about any manipulation of the data and simply want to include input parameter values within the json response simply include the variable within the json response by using ${NonOptVarName} or ${#OptVarName}
i.e.
using /myreq/person/{name}/gumf?year={year}
putting in the values
/myreq/person/mike/gumf?year=2016
the reponse would use
{
"Name" = "${name}"
"Year" = ${#year}
}
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
following on
if you're not bothered about any manipulation of the data and simply want to include input parameter values within the json response simply include the variable within the json response by using ${NonOptVarName} or ${#OptVarName}
i.e.
using /myreq/person/{name}/gumf?year={year}
putting in the values
/myreq/person/mike/gumf?year=2016
the response would use
{
"Name" = "${name}"
"Year" = ${#year}
}
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
it seems that using the ${#year} from my previous example does not work now
as an alternative, within groovy script add something as follows in order to be able to reference the value within the response
context.year = mockRequest.getHttpRequest().getParameter("year")
then simply use ${year} within the response
