Refine search
@Override public void close() { // Release underlying connection back to the connection manager try { try { // Attempt to keep connection alive by consuming its remaining content EntityUtils.consume(this.httpResponse.getEntity()); } finally { if (this.httpResponse instanceof Closeable) { ((Closeable) this.httpResponse).close(); } } } catch (IOException ex) { // Ignore exception on close... } }
public String handleResponse(final HttpResponse response) throws HttpResponseException, IOException { final StatusLine statusLine = response.getStatusLine(); final HttpEntity entity = response.getEntity(); if (statusLine.getStatusCode() >= 300) { EntityUtils.consume(entity); throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); } return entity == null ? null : EntityUtils.toString(entity, Consts.UTF_8); }
int statusCode = response.getStatusLine().getStatusCode(); if (statusCode < 200 || statusCode >= 300) { throw new IOException( } finally { if (entity != null) { EntityUtils.consume(entity);
public InputStream handleResponse(final HttpResponse response) throws HttpResponseException, IOException { final StatusLine statusLine = response.getStatusLine(); final HttpEntity entity = response.getEntity(); if (statusLine.getStatusCode() >= 300) { EntityUtils.consume(entity); throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); } return entity == null ? null : entity.getContent(); }
response = HttpClientPool.getClient().execute(request); log.debug((httpVerb == null ? "GET" : httpVerb) + " execute (" + retryCount + ") on URL responded: " + response.getStatusLine().getStatusCode()); if (response != null && response.getEntity() != null) { try { EntityUtils.consume(response.getEntity()); // close out if (response != null && response.getStatusLine().getStatusCode() >= 200 && response.getStatusLine().getStatusCode() < 300) { if(theContent == null) theContent = "";
@Override public void close() { // Release underlying connection back to the connection manager try { try { // Attempt to keep connection alive by consuming its remaining content EntityUtils.consume(this.httpResponse.getEntity()); } finally { if (this.httpResponse instanceof Closeable) { ((Closeable) this.httpResponse).close(); } } } catch (IOException ex) { // Ignore exception on close... } }
private boolean setCache(boolean flag) throws IOException { String url = baseUrl + "/admin/config"; HttpPut put = newPut(url); HttpResponse response = null; try { HashMap<String, String> paraMap = new HashMap<String, String>(); paraMap.put("key", "kylin.query.cache-enabled"); paraMap.put("value", flag + ""); put.setEntity(new StringEntity(new ObjectMapper().writeValueAsString(paraMap), UTF_8)); response = client.execute(put); EntityUtils.consume(response.getEntity()); if (response.getStatusLine().getStatusCode() != 200) { return false; } else { return true; } } finally { cleanup(put, response); } }
final int responseCode = response.getStatusLine().getStatusCode(); logger.debug("responseCode={}", responseCode); case RESPONSE_CODE_OK: logger.debug("Server returned RESPONSE_CODE_OK, indicating there was no data."); EntityUtils.consume(response.getEntity()); return false;
/** * * @param response the httpresponse for processing * @param charset the charset used for getting HttpEntity * @param decode determines if the result should be decoded or not * @return HttpEntity in String representation using provided charset * @throws IOException */ public static String responseToString( HttpResponse response, Charset charset, boolean decode ) throws IOException { HttpEntity entity = response.getEntity(); String result = EntityUtils.toString( entity, charset ); EntityUtils.consume( entity ); if ( decode ) { result = URLDecoder.decode( result, StandardCharsets.UTF_8.name() ); } return result; }
/** * Send an encoded string to the Eventhub using post method */ private int request (String encoded) throws IOException { refreshSignature(); HttpPost httpPost = new HttpPost(targetURI); httpPost.setHeader("Content-type", "application/vnd.microsoft.servicebus.json"); httpPost.setHeader("Authorization", signature); httpPost.setHeader("Host", namespaceName + ".servicebus.windows.net "); StringEntity entity = new StringEntity(encoded); httpPost.setEntity(entity); HttpResponse response = httpclient.execute(httpPost); StatusLine status = response.getStatusLine(); HttpEntity entity2 = response.getEntity(); // do something useful with the response body // and ensure it is fully consumed EntityUtils.consume(entity2); int returnCode = status.getStatusCode(); if (returnCode != HttpStatus.SC_CREATED) { LOG.error (new IOException(status.getReasonPhrase()).toString()); throw new IOException(status.getReasonPhrase()); } return returnCode; }
response.setStatusCode(httpResponse.getStatusLine().getStatusCode()); response.setPostedParms(postParms); EntityUtils.consume(httpResponse.getEntity()); } catch (IOException e) {/*consume quietly*/}
/** * Convert a {@link HttpResponse} to a <string, string> map. * Put protected modifier here so it is visible to {@link AzkabanAjaxAPIClient}. * * @param response An http response returned by {@link org.apache.http.client.HttpClient} execution. * This should be JSON string. * @return A map composed by the first level of KV pair of json object */ protected static Map<String, String> handleResponse(HttpResponse response) throws IOException { int code = response.getStatusLine().getStatusCode(); if (code != HttpStatus.SC_CREATED && code != HttpStatus.SC_OK) { log.error("Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); throw new AzkabanClientException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); } // Get response in string HttpEntity entity = null; String jsonResponseString; try { entity = response.getEntity(); jsonResponseString = IOUtils.toString(entity.getContent(), "UTF-8"); log.info("Response string: " + jsonResponseString); } catch (Exception e) { throw new AzkabanClientException("Cannot convert response to a string", e); } finally { if (entity != null) { EntityUtils.consume(entity); } } return AzkabanClient.parseResponse(jsonResponseString); }
CloseableHttpResponse response = httpclient.execute(httpget); assertEquals(OK.value(), response.getStatusLine().getStatusCode()); EntityUtils.consume(response.getEntity()); response.close(); httpget.completed(); assertEquals(FOUND.value(), response.getStatusLine().getStatusCode()); location = response.getFirstHeader("Location").getValue(); response.close(); assertEquals(OK.value(), response.getStatusLine().getStatusCode());
+ "/" + key.getSchemaVersion()); HttpResponse httpResponse = httpClient.execute(restHost, getRequest, httpContext); HttpEntity entity = httpResponse.getEntity(); if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK && entity != null) { String content = EntityUtils.toString(entity); ObjectMapper mapper = new ObjectMapper(); + logSchemaDto.getCtlSchemaId()); HttpResponse httpCtlResponse = httpClient.execute(restHost, getCtlRequest, httpContext); HttpEntity ctlEntity = httpCtlResponse.getEntity(); if (httpCtlResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK && ctlEntity != null) { String ctlContent = EntityUtils.toString(entity); EntityUtils.consume(entity);
public String get(String url) { HttpGet httpGet = new HttpGet(url); httpGet.setConfig(requestConfig); try (CloseableHttpResponse response = httpClient.execute(httpGet)) { StatusLine statusLine = response.getStatusLine(); HttpEntity entity = response.getEntity(); if (statusLine.getStatusCode() >= 300) { EntityUtils.consume(entity); throw new WxRuntimeException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); } String responseContent = entity == null ? null : EntityUtils.toString(entity, Consts.UTF_8); return responseContent; } catch (IOException ex) { logger.error("http get: {} failed.", url, ex); throw new WxRuntimeException(999, ex.getMessage()); } }
private byte[] getResponseBody(HttpResponse response, boolean verifyResponse) throws IOException, GeneralSecurityException { HttpEntity resEntity = response.getEntity(); if (resEntity != null) { byte[] body = EntityUtils.toByteArray(resEntity); EntityUtils.consume(resEntity); if (verifyResponse) { Header signatureHeader = response .getFirstHeader(CommonEpConstans.SIGNATURE_HEADER_NAME); if (signatureHeader == null) { throw new IOException("can't verify message"); } byte[] signature; if (signatureHeader.getValue() != null) { signature = Base64.decodeBase64(signatureHeader.getValue() .getBytes(Charsets.UTF_8)); } else { signature = new byte[0]; } return verifyResponse(body, signature); } else { return body; } } else { throw new IOException("can't read message"); } }
@Override public DownloadbillResult handleResponse(HttpResponse response) throws ClientProtocolException, IOException { int status = response.getStatusLine().getStatusCode(); if (status >= 200 && status < 300) { HttpEntity entity = response.getEntity(); String str; str = EntityUtils.toString(entity, "utf-8"); EntityUtils.consume(entity); if(str.matches(".*<xml>(.*|\\n)+</xml>.*")){ return XMLConverUtil.convertToObject(DownloadbillResult.class,str);
/** * 发送body为输入流 * sample */ public static String postBodyAsStream(String url,InputStream inputStream, String encoding) throws Exception{ HttpPost httpPost = new HttpPost(url); HttpEntity body = new InputStreamEntity(inputStream); httpPost.setEntity(body); CloseableHttpResponse response = httpClient.execute(httpPost); try { HttpEntity entity = response.getEntity(); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != 200) { httpPost.abort(); throw new RuntimeException("HttpClient,error status code :" + statusCode); } String result = null; if (entity != null) { result = EntityUtils.toString(entity, encoding); } EntityUtils.consume(entity); return result; } finally { response.close(); } }