List of usage examples for org.apache.http.client.methods CloseableHttpResponse getHeaders
Header[] getHeaders(String str);
From source file:org.flowable.admin.service.engine.FlowableClientService.java
public AttachmentResponseInfo executeDownloadRequest(HttpUriRequest request, String userName, String password, Integer... expectedStatusCodes) { FlowableServiceException exception = null; CloseableHttpClient client = getHttpClient(userName, password); try {/*from ww w . ja v a 2 s. co m*/ CloseableHttpResponse response = client.execute(request); try { int statusCode = -1; if (response.getStatusLine() != null) { statusCode = response.getStatusLine().getStatusCode(); } boolean success = Arrays.asList(expectedStatusCodes).contains(statusCode); if (success) { if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { String contentDispositionFileName[] = response.getHeaders("Content-Disposition")[0] .getValue().split("="); String fileName = contentDispositionFileName[contentDispositionFileName.length - 1]; return new AttachmentResponseInfo(fileName, IOUtils.toByteArray(response.getEntity().getContent())); } else { return new AttachmentResponseInfo(statusCode, readJsonContent(response.getEntity().getContent())); } } else { exception = new FlowableServiceException( extractError(readJsonContent(response.getEntity().getContent()), "An error occurred while calling Flowable: " + response.getStatusLine())); } } catch (Exception e) { log.warn("Error consuming response from uri " + request.getURI(), e); exception = wrapException(e, request); } finally { response.close(); } } catch (Exception e) { log.error("Error executing request to uri " + request.getURI(), e); exception = wrapException(e, request); } finally { try { client.close(); } catch (Exception e) { log.warn("Error closing http client instance", e); } } if (exception != null) { throw exception; } return null; }