@RequestMapping(value="/obterWsnImprimirProtocolo",method = RequestMethod.GET )
public HttpEntity<byte[]> obterImprimirProtocolo(HttpServletRequest request) throws IOException, JSONException {
String [] uri = request.getRequestURL().toString().split("/");
String url = "http://"+ uri[2] + "/Reembolso/novo/ReembolsoServices/wsnImprimirProtocolo/";
String protocolo = request.getParameter("protocolo");
ObterImprimirProtocoloModel imprimirProtocoloModel = new ObterImprimirProtocoloModel();
imprimirProtocoloModel.setNumeroProtocolo(protocolo);
String jsonResult = "";
ConnectionHTTP connectionHTTP = new ConnectionHTTP();
JSONObject json = new JSONObject();
JSONArray jsonArray = new JSONArray();
byte[] arquivo = null;
json.put("numeroProtocolo", protocolo);
jsonArray.put(json);
//jsonResult = "wsnImprimirProtocolo\n\n"+connectionHTTP.connectionPOST(url, jsonArray);
jsonResult = connectionHTTP.connectionPOST(url, jsonArray);
/*int x = jsonResult.lastIndexOf("[");
String result = jsonResult.substring(x);*/
JSONArray array = new JSONArray("["+jsonResult+"]");
for (int i = 0; i < array.length(); i++) {
JSONObject jsonObject = new JSONObject(array.get(i).toString());
arquivo = jsonObject.get("imprimirProtocolo").toString().getBytes("utf-8");
}
HttpHeaders httpHeaders = new HttpHeaders();
String protocoloArquivo = "Protocolo-" + protocolo + ".pdf";
httpHeaders.add("Content-disposition", "attachment;filename=" + protocoloArquivo);
HttpEntity<byte[]> entity = new HttpEntity<byte[]>( arquivo, httpHeaders);
return entity;
}