zoran119
zoran119

Reputation: 11327

How to get the raw response and URL from HttpResponseDecorator

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
        }

Upvotes: 10

Views: 11445

Answers (3)

Sanhaji Omar
Sanhaji Omar

Reputation: 332

I used XmlUtil, it returns the pretty printed xml:

    def data = respXml.data
    assert data instanceof groovy.util.slurpersupport.GPathResult

    println "${XmlUtil.serialize(data)}"

If your data is a parsed response from groovyx.net.http.HttpResponseDecorator

Hope it helps.

Upvotes: 0

devanon
devanon

Reputation: 161

Try this:

println response.data

Upvotes: -1

mekondelta
mekondelta

Reputation: 993

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!

Upvotes: 18

Related Questions