Quantcast
Channel: New board topics in SmartBear Community
Viewing all articles
Browse latest Browse all 20073

replace response with parameter from request

$
0
0

Hi All,

 

In the below case i need a script for both rest and soap services 

 

SOAP services

1.Request consists of a value UPRN which is the key driver 

2.I have external file where my UPRN file specific responses are placed , if specific file is found response should be specific to file --- I have implemented this already

3.if in the folder of responses the UPRN file is not found then I have a default xml where in , the UPRN field of the default xml should be changed to the one supplied in my request and I should get an amended response back with the UPRN field only changed to the value that came from request , rest all content be same as its from default file .

 

Is this possible ??

 

attaching request and response 

 

I would need thsi for both soap and rest services , in rest I have a parameter which needs to be replaced 

 

 

 

Adding files for my Rest request and response too  and also the code I implemented till now .

 

I would need code to be modified such that in case if post file doesn't exist the post code in the response should be changed to the post code from request and the response to be served back , only the post code to be changed rest all to be retained as is 

 

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
String URL = mockRequest.getRequest().getQueryString()
log.info "QueryString: " + URL

def postcode = URL.substring(URL.lastIndexOf("postcode")+9, URL.lastIndexOf("postcode")+15);
log.info "Postcode: " + postcode
/*def soNumber = holder.getNodeValue("//*:BillingOrderLoadRequest/*:salesOrderNumber")*/

def responseFileContent = new StringBuilder()
File testDataFile = new File(groovyUtils.projectPath+"/mockResponsesjson/${postcode}.json") //Load file containing test data response
if (testDataFile.exists()){
testDataFile.eachLine {content, lineNumber ->
responseFileContent.append(content) //Add each line of test data file to a String
}
}else{
responseFileContent="File not found!" //Or perhaps return a SOAP fault?
}
mockResponse.responseContent=responseFileContent //Populate response body
mockResponse.responseHttpStatus=200 //set status code (can also be done in UI)

def headers = mockResponse.responseHeaders
headers["Content-Type"]=["application/json"]
mockResponse.responseHeaders=headers //Headers can also be set in the UI


Viewing all articles
Browse latest Browse all 20073