I resolved my problem doing the below code:
Controller:
def bytes = SendHttpService.executeGetBinary("http://app.com",
"/pdf/", params)
response.setHeader("Expires", "0");
response.setHeader("Cache-Control","must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
response.setHeader("Content-Disposition", "inline; filename=\"relatorioGerencial.pdf\"");
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes,0,bytes.length);
ouputStream.flush();
ouputStream.close();
Here, send the request to return stream like the first example, note that the contentType is binary
def executePostBinary = { String httpUrl, String dataBody, String path, query = null, method = Method.POST->
def http = new HTTPBuilder()
try{
http.request( httpUrl , method , ContentType.BINARY ) { req ->
uri.path = path
uri.query = trataQuery(query)
headers.'User-Agent' = "Mozilla/5.0 Firefox/3.0.4"
headers.Accept = ContentType.BINARY
if(method==groovyx.net.http.Method.POST && dataBody!=null){
body = dataBody
}
response.success = { resp, inputStream ->
inputStream.bytes
}
response.'404' = {
'Not found'
}
}
}catch(HttpResponseException e){
println "Error "+e
println "Error Code "+e.statusCode
return false
}
}