There is a bug in Groovy version up to 2.3.7. HTTPBuilder is not able to automatically parse chunked response to JSON format. If external server returns response with header:
Transfer-Encoding : chunked
Usually applied code:
def http = new HTTPBuilder(url)
def result = http.request(POST, JSON) { req ->
body = inputData
response.success = { resp, json ->
...
}
response.failure = { resp ->
...
}
}
change to:
def http = new HTTPBuilder(url)
def result = http.request(POST, JSON) { req ->
body = inputData
response.success = { resp ->
String text = resp.entity.content.text
String contentType = resp.headers."Content-Type"
if (contentType?.startsWith("application/json")) {
def json = JsonSlurper().parseText(text)
...
}
else {
// return error
...
}
}
response.failure = { resp ->
...
}
}
The workaround gets whole data before JsonSlurper.