Reputation: 454
I have two requests, the first one is GET, second is PUT. I should receive the response data from GET request, modify it a little bit and send with PUT request. So far I managed to do all, except modifying the response data.
For GET request I use Regular Expression Extractor as Preprocessor:
And currently I send the PUT request without modifying the data:
JSON structure:
{
"property1" : 1,
"property2" : "2",
"innerPropery" : {
"innerProperty1" : "value1",
"innerProperty2" : "value2",
"innerProperty3" : "value3"
}
}
I should change the innerProperty2.
Thanks!
Upvotes: 1
Views: 1384
Reputation: 168157
You can do it without Regular Expression Extractor interim step.
getForm
requestgroovy
in the "Language" drop-downPut the following code into "Script" area:
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper
def response = prev.getResponseDataAsString()
def json = new JsonSlurper().parseText(response)
def builder = new JsonBuilder(json)
builder.content.property2 = '2.1'
vars.put("response", builder.toPrettyString())
saveForm
request use ${response}
as the request bodyReferences:
Upvotes: 6
Reputation: 454
I have managed to do this via BeanShell PostProcessor. First I have added a new BeanShell PostProcessor: click right button on getFrom, Add -> Post Processors -> BeanShell PostProcessor. After that I opened the reated BeanSChell and have written the following code in Script field:
responseString = vars.get("response");
log.info("Received response: " + responseString);
responseString = responseString.replace("\"prop1\" : \"value2\"", "\"prop1\" : \"value2.1\"");
log.info("Response to send: " + responseString);
vars.put("modifiedResponse", responseString);
In Parameters field I have written:
response
Finally, I changed for PUT request the body from
${response}
to
${modifiedResponse}
Upvotes: 0