@Override public HttpEntity getEntity() { return original.getEntity(); }
private void consumeBody(final HttpResponse response) throws IOException { final HttpEntity body = response.getEntity(); if (body != null) { IOUtils.consume(body); } }
public void close() throws IOException { IOUtils.consume(original.getEntity()); }
public void close() throws IOException { final HttpEntity entity = this.original.getEntity(); EntityUtils.consume(entity); }
public InputStream getContent() throws IOException { return response.getEntity().getContent(); }
static String readHttpResponseToString(HttpResponse httpResponse) throws IOException { HttpEntity httpEntity = httpResponse.getEntity(); if (httpEntity != null) { try { return HttpConnectionUtils.readStreamToString(httpEntity.getContent()); } catch (IllegalStateException e) { throw new IOException(e); } } return null; } }
@Override protected void closeConnection(HttpRequest request, oauth.signpost.http.HttpResponse response) throws Exception { if (response != null) { HttpEntity entity = ((HttpResponse) response.unwrap()).getEntity(); if (entity != null) { try { // free the connection entity.consumeContent(); } catch (IOException e) { // this means HTTP keep-alive is not possible e.printStackTrace(); } } } } }
final HttpEntity entity = response.getEntity(); if (entity != null) { try {
public static void enchance(final HttpResponse response, final ConnectionHolder connHolder) { final HttpEntity entity = response.getEntity(); if (entity != null && entity.isStreaming() && connHolder != null) { response.setEntity(new ResponseEntityProxy(entity, connHolder)); } }
@Override public void sendResponseEntity(final HttpResponse response) throws HttpException, IOException { Args.notNull(response, "HTTP response"); ensureOpen(); final HttpEntity entity = response.getEntity(); if (entity == null) { return; } final OutputStream outstream = prepareOutput(response); entity.writeTo(outstream); outstream.close(); }
public <T> T execute(final HttpHost target, final HttpRequest request, final ResponseHandler<? extends T> responseHandler, final HttpContext context) throws IOException, ClientProtocolException { final HttpResponse response = execute(target, request, context); try { return responseHandler.handleResponse(response); } finally { final HttpEntity entity = response.getEntity(); if (entity != null) { EntityUtils.consume(entity); } } }
protected String loadUrlBody(String address) { HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = null; String responseString = null; try { response = httpclient.execute(new HttpGet(address)); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpStatus.SC_OK){ ByteArrayOutputStream out = new ByteArrayOutputStream(); response.getEntity().writeTo(out); out.close(); responseString = out.toString(); } else{ response.getEntity().getContent().close(); throw new IOException(statusLine.getReasonPhrase()); } } catch (ClientProtocolException e) { } catch (IOException e) { } return responseString; }
public HttpResponse execute(final HttpHost target, final HttpRequest request, final HttpContext context) throws IOException { for (int c = 1;; c++) { final HttpResponse response = backend.execute(target, request, context); try { if (retryStrategy.retryRequest(response, c, context)) { EntityUtils.consume(response.getEntity()); final long nextInterval = retryStrategy.getRetryInterval(); try { log.trace("Wait for " + nextInterval); Thread.sleep(nextInterval); } catch (final InterruptedException e) { Thread.currentThread().interrupt(); throw new InterruptedIOException(); } } else { return response; } } catch (final RuntimeException ex) { try { EntityUtils.consume(response.getEntity()); } catch (final IOException ioex) { log.warn("I/O error consuming response content", ioex); } throw ex; } } }
/** * Updates an entity in a response by first consuming an existing entity, then setting the new one. * * @param response the response with an entity to update; must not be null. * @param entity the entity to set in the response. * @throws IOException if an error occurs while reading the input stream on the existing * entity. * @throws IllegalArgumentException if response is null. * * @since 4.3 */ public static void updateEntity( final HttpResponse response, final HttpEntity entity) throws IOException { Args.notNull(response, "Response"); consume(response.getEntity()); response.setEntity(entity); }
HttpEntity responseEntity = getResponse.getEntity(); BufferedHttpEntity httpEntity = null; try {
response.getEntity().consumeContent();
/** * Read the entity from the response body and pass it to the entity handler * method if the response was successful (a 2xx status code). If no response * body exists, this returns null. If the response was unsuccessful (>= 300 * status code), throws an {@link HttpResponseException}. */ @Override public T 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 : handleEntity(entity); }
@Override public void process( final HttpResponse response, final HttpContext context) throws HttpException, IOException { final HttpEntity entity = response.getEntity(); final HttpClientContext clientContext = HttpClientContext.adapt(context); final RequestConfig requestConfig = clientContext.getRequestConfig(); // entity can be null in case of 304 Not Modified, 204 No Content or similar // check for zero length entity. if (requestConfig.isDecompressionEnabled() && entity != null && entity.getContentLength() != 0) { final Header ceheader = entity.getContentEncoding(); if (ceheader != null) { final HeaderElement[] codecs = ceheader.getElements(); for (final HeaderElement codec : codecs) { final String codecname = codec.getName().toLowerCase(Locale.ROOT); final InputStreamFactory decoderFactory = decoderRegistry.lookup(codecname); if (decoderFactory != null) { response.setEntity(new DecompressingEntity(response.getEntity(), decoderFactory)); response.removeHeaders("Content-Length"); response.removeHeaders("Content-Encoding"); response.removeHeaders("Content-MD5"); } else { if (!"identity".equals(codecname)) { throw new HttpException("Unsupported Content-Coding: " + codec.getName()); } } } } } }