Forum Discussion

alibaba82's avatar
alibaba82
Super Contributor
16 years ago

Checking for null reponse via groovy

I have a groovy scripts that looks like

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( "GetRecommendationItemsInList - Programs#Response" )

However, if the response is null, as in the case of a socket timeout, the above code fails with a null pointer exception.

How can I check for a null response so I can write something like

if (response != null)
{
do some stuff
}

else
do some other stuff

Thanks

Ali

1 Reply

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi,

    hmm.. easiest is just to wrap the code in a try-catch for NPE, but otherwise you could check for the response with

    def response = testRunner.testCase.testSteps["GetRecommendationItemsInList - Programs"].testRequest.response

    if( response == null || response.contentLength == 0 )
    {
    ...
    }
    else
    {
    ...
    }


    hope this helps!

    regards,

    /Ole
    eviware.com