Forum Discussion

shapani's avatar
shapani
Occasional Contributor
13 years ago

Help needed to print Http request from grrovy script in soap

Hi All,

I got stuck for printing Http request in logfile using groovy script. The same code works for printing the http response.
------------------------------------------------------
import com.eviware.soapui.model.testsuite.TestCaseRunner
import com.eviware.soapui.model.testsuite.TestRunner.Status
import com.eviware.soapui.support.XmlHolder
import com.eviware.soapui.model.testsuite.TestStepResult
import com.eviware.soapui.impl.wsdl.teststeps.HttpTestRequest

import com.eviware.soapui.model.iface.MessageExchange

def useridEtn;
def targetStep;
def userId;
def objLog;
def stringRequest;

com.eviware.soapui.model.testsuite.TestStepResult targetStep1
com.eviware.soapui.impl.wsdl.teststeps.HttpTestRequest testRequest

com.eviware.soapui.model.iface.MessageExchange messageExchange

objLog = new library.LogResult(context.expand( '${#Project#logFilePath}' ))
objLog.logScriptStart("Release Checkout")

//-------------------Execute the API - get_p**s-----------//
targetStep1 = testRunner.runTestStepByName("get_p**s")
objLog.logHTTPTestRequestResult("get_p**s", targetStep1)


//Logging the Request/Response onto a file
log.info new String( messageExchange.getRawRequestData() );

request = context.expand('${get_plans#Request}')
log.info (request.toString());

response = context.expand('${get_plans#Response}')
objLog.logResponse("get_plans", response)


Note: I have also tried below code as it was suggested in forum. But it throws an error missing property getRawRequestData() for messageExchange.

log.info new String( messageExchange.getRawRequestData() );

Thanks in advance for your help.

Regards,
-Shital
  • shapani's avatar
    shapani
    Occasional Contributor
    I tried many below options to print http request, but couldnt print it.

    1) //def message = new String(com.eviware.soapui.model.iface.MessageExchange.getRawRequestData());
    //log.info message;

    2) def str = new com.eviware.soapui.model.iface.Request.getRequestContent()
    log.info str;

    3) /*def logArea = com.eviware.soapui.SoapUI.logMonitor.getLogArea( "http log" );
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    if( logArea != null )
    {
    def model = logArea.model
    // only continue of logArea not empty
    if( model.size > 0 )
    request = (model.getElementAt(0))
    //model.clear()
    } This option doesnt work when i have to print requests of more than one api as i am reading first line from http log tab.

    @Support team, is that a bug in soapui pro?
  • shapani's avatar
    shapani
    Occasional Contributor
    Hi,

    I could print http request message in log file using below code snippet as context also contains all properties which was passed in http reuest.

    if (context.containsKey("httpResponseProperties") = true)
    {
    ListValue = context.get("httpResponseProperties")
    log.info ListValue;
    }

    Thanks.
    -Shital