pandap
13 years agoContributor
[Res]Best solution to save raw request and response to DB
Hi,
I am trying to save raw request and response using event handlers "LoadTestRunListener.afterTestStep", below are the scenarios which I tried and most of them works but can you tell if you have any other way which is always consistant.
Scenario 1. When used context.httpResponse.responseContent in event "LoadTestRunListener.afterTestStep" following error was reported:
Thu Oct 24 08:56:21 EDT 2013:ERROR:java.lang.NullPointerException: Cannot get property 'responseContent' on null object
Scenario 2. context.expand('${3.EIP_MeterReadWS#Request}') everytime the same request before replacing the actual value is saved to the database, and I can't get response with context.
Scenario 3. Below code is some times returning value as "discarded" but most of the time it is returing valid request and response. This is the most nearest to what I want.
for(result in testRunner.getResults()) {
def testStep = result.getTestStep();
def type = testStep.config.type
switch(type){ //determine what type of step it is and collect different info based on the step type
case 'request': //SOAP Request/Response test step
def xmlRequest = testStep.properties["Request"].value; //The Xml tab content of a Soap Request Test Step
rawRequest = result.getRequestContent(); //The raw request that is sent to the endpoint
rawResponse = result.getResponseContent(); //The raw response that is recieved from the service
break;
}
}
log.info rawRequest
log.info rawResponse
Do you know why some times it is showing the
Scenario 4. Below is always consitant when writing the Raw Request and Response to the file but I want to save the content to database
and I couldn't find a way to do that:
filePath = "C:/SOAPUI/LOGS/TestResults/"
fos = new FileOutputStream( filePath + testStepResult.testStep.label + ".txt", true )
pw = new PrintWriter( fos )
testStepResult.writeTo( pw )
pw.close()
fos.close()
Thanks,
Prashanth
I am trying to save raw request and response using event handlers "LoadTestRunListener.afterTestStep", below are the scenarios which I tried and most of them works but can you tell if you have any other way which is always consistant.
Scenario 1. When used context.httpResponse.responseContent in event "LoadTestRunListener.afterTestStep" following error was reported:
Thu Oct 24 08:56:21 EDT 2013:ERROR:java.lang.NullPointerException: Cannot get property 'responseContent' on null object
Scenario 2. context.expand('${3.EIP_MeterReadWS#Request}') everytime the same request before replacing the actual value is saved to the database, and I can't get response with context.
Scenario 3. Below code is some times returning value as "discarded" but most of the time it is returing valid request and response. This is the most nearest to what I want.
for(result in testRunner.getResults()) {
def testStep = result.getTestStep();
def type = testStep.config.type
switch(type){ //determine what type of step it is and collect different info based on the step type
case 'request': //SOAP Request/Response test step
def xmlRequest = testStep.properties["Request"].value; //The Xml tab content of a Soap Request Test Step
rawRequest = result.getRequestContent(); //The raw request that is sent to the endpoint
rawResponse = result.getResponseContent(); //The raw response that is recieved from the service
break;
}
}
log.info rawRequest
log.info rawResponse
Do you know why some times it is showing the
Scenario 4. Below is always consitant when writing the Raw Request and Response to the file but I want to save the content to database
and I couldn't find a way to do that:
filePath = "C:/SOAPUI/LOGS/TestResults/"
fos = new FileOutputStream( filePath + testStepResult.testStep.label + ".txt", true )
pw = new PrintWriter( fos )
testStepResult.writeTo( pw )
pw.close()
fos.close()
Thanks,
Prashanth