How to get the raw response and URL from HttpResponseDecorator

zoran119 picture zoran119 · Apr 19, 2013 · Viewed 9.4k times · Source

The REST Client of HTTP Builder returns a HttpResponseDecorator. How can I get the raw response out of it (for logging purposes)?

EDIT (some code might be handy):

    withRest(uri: domainName) {
        def response = post(path: 'wsPath', query: [q:'test'])
        if (!response.success) {
            log.error "API call failed. HTTP status: $response.status"
            // I want to log raw response and URL constructed here
        }

Answer

mekondelta picture mekondelta · Sep 30, 2013

I've been having a nightmare with the same problem. Here's my solution using HTTPBuilder:-

response.failure = {resp ->
    println "request failed with status ${resp.status}, response body was [${resp.entity.content.text}]"
    return null
}

Hope that helps!