Reputation: 11327
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
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
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