Forum Discussion

pandap's avatar
pandap
Contributor
13 years ago

[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

6 Replies

  • Hi,

    The Max value is set to 20 which I can increase and test, Can you tell me how to save raw request and response under request event into variable rather than writing to the file.

    Thanks,
    Prashanth
  • Hi

    In scenario 4 you could use a StringWriter instead of your FileOutputStream. After the call to testStepResult.writeTo you could then query the content of your StringWriter with either getBuffer() or toString().

    Regards,
    Joel Jonsson
    SmartBear Sweden
  • Hi,

    Thanks for the suggestion, it works to save the raw response to variable using StringWriter in Scenario 4. Can you tell me how to get raw request and response using request class, which will be executed under event "RequestFilter.afterRequest".

    Thanks,
    PRASHANTH
  • Here you go:

    log.info "REQUEST CONTENT"
    log.info context.requestContent

    log.info "RESPONSE CONTENT"
    log.info context.httpResponse.responseContent


    Thanks,
    Michael Giller
    SmartBear Software