Example usage for org.apache.http.util EntityUtils consume

List of usage examples for org.apache.http.util EntityUtils consume

Introduction

In this page you can find the example usage for org.apache.http.util EntityUtils consume.

Prototype

public static void consume(HttpEntity httpEntity) throws IOException 

Source Link

Usage

From source file:org.jboss.aerogear.windows.mpns.internal.MpnsPooledService.java

@Override
protected void push(final HttpPost request, final MpnsNotification message) {
    executor.execute(new Runnable() {
        public void run() {
            try {
                HttpResponse response = httpClient.execute(request);
                Utilities.fireDelegate(message, response, delegate);
                EntityUtils.consume(response.getEntity());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }/*  w w w. java2 s. c o  m*/
        }
    });
}

From source file:com.soulgalore.web.pagesavings.impl.HTTPClientBodyFetcher.java

public String getBody(String url) throws IOException {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);

    try {//from  w  w w  .  j  av a 2  s .  c  o  m
        HttpResponse response = httpclient.execute(httpGet);
        HttpEntity entity = response.getEntity();

        final String encoding = entity.getContentEncoding() != null ? entity.getContentEncoding().getValue()
                : "UTF-8";

        final String body = (readBody(entity, encoding));

        EntityUtils.consume(entity);
        return body;
    } finally {
        httpGet.releaseConnection();
    }

}

From source file:org.robertburrelldonkin.template4couchdb.rest.DefaultResponseHandler.java

@Override
public T handleResponse(final HttpResponse response) throws ClientProtocolException, IOException {
    final HttpEntity entity = response.getEntity();
    final InputStream content = entity.getContent();
    final T result;
    try {//from w w  w. j  a  v  a 2 s.  c o m
        final StatusLine status = response.getStatusLine();
        if (isSupported(status.getStatusCode())) {
            result = mapper.from(content);
        } else {
            EntityUtils.consume(entity);
            throw new UnsupportedHttpResponseStatusException(status);
        }
    } finally {
        IOUtils.closeQuietly(content);
    }
    return result;
}

From source file:fr.mael.microrss.util.XMLUtil.java

public boolean isAtom(String URL) throws Exception {
    DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
    f.setNamespaceAware(true);//from   ww w  . j a va 2 s. c o  m
    DocumentBuilder builder = f.newDocumentBuilder();
    HttpGet get = new HttpGet(URL);
    HttpResponse response = client.execute(get);
    try {
        Document doc = builder.parse(response.getEntity().getContent());
        Element e = doc.getDocumentElement();
        return e.getLocalName().equals("feed") && e.getNamespaceURI().equals("http://www.w3.org/2005/Atom");
    } catch (Exception e) {
        EntityUtils.consume(response.getEntity());
        throw new Exception(e);
    }
}

From source file:net.gcolin.httpquery.AbstractElement.java

protected void close(HttpEntity entity) {
    try {/*from w  w w .j av a 2  s .  co  m*/
        EntityUtils.consume(entity);
    } catch (final IOException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, HttpHandlerImpl.ERROR_MESSAGE, e);
    }
}

From source file:eu.ebbitsproject.peoplemanager.utils.HttpUtils.java

public static void postData(String url, String action, String errorType, String objectId, String personId,
        String eventId) {/*from  www  .  ja  va 2 s.  c o  m*/
    CloseableHttpClient httpClient = HttpClients.createDefault();

    HttpPost httpPost = new HttpPost(url);
    List<NameValuePair> nvps = new ArrayList<>();
    nvps.add(new BasicNameValuePair("action", action));
    nvps.add(new BasicNameValuePair("personId", personId));
    nvps.add(new BasicNameValuePair("errorType", errorType));
    nvps.add(new BasicNameValuePair("objectId", objectId));
    nvps.add(new BasicNameValuePair("eventId", eventId));

    System.out.println("action = " + action);
    System.out.println("personId = " + personId);
    System.out.println("errorType = " + errorType);
    System.out.println("objectId = " + objectId);
    System.out.println("eventId = " + eventId);

    try {
        httpPost.setEntity(new UrlEncodedFormEntity(nvps));
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(HttpUtils.class.getName()).log(Level.SEVERE, null, ex);
    }

    CloseableHttpResponse response = null;
    try {
        response = httpClient.execute(httpPost);
        System.out.println(response.getStatusLine());
        HttpEntity entity = response.getEntity();
        EntityUtils.consume(entity);
    } catch (IOException e) {
        Logger.getLogger(HttpUtils.class.getName()).log(Level.SEVERE, null, e);
    } finally {
        try {
            response.close();
        } catch (IOException e) {
            Logger.getLogger(HttpUtils.class.getName()).log(Level.SEVERE, null, e);
        }
    }
}

From source file:at.ac.tuwien.infosys.jcloudscale.datastore.rest.Response.java

private void setContent(HttpResponse httpResponse) {
    HttpEntity httpEntity = httpResponse.getEntity();
    try {/* w w w  . j  a  v  a2  s .  c  o m*/
        if (httpEntity != null && httpEntity.getContent() != null) {
            content = IOUtils.toString(httpEntity.getContent()).trim();
        }
        EntityUtils.consume(httpEntity);
    } catch (Exception e) {
        throw new DatastoreException("Error reading Response: " + e.getMessage());
    }
}

From source file:com.networknt.light.server.handler.loader.MenuLoader.java

private static void loadMenuFile(File file) {
    Scanner scan = null;/*from w  ww. ja  va  2s .com*/
    try {
        scan = new Scanner(file, Loader.encoding);
        // the content is only the data portion. convert to map
        String content = scan.useDelimiter("\\Z").next();
        HttpPost httpPost = new HttpPost("http://injector:8080/api/rs");
        StringEntity input = new StringEntity(content);
        input.setContentType("application/json");
        httpPost.setEntity(input);
        CloseableHttpResponse response = httpclient.execute(httpPost);

        try {
            System.out.println(response.getStatusLine());
            HttpEntity entity = response.getEntity();
            BufferedReader rd = new BufferedReader(new InputStreamReader(entity.getContent()));
            String json = "";
            String line = "";
            while ((line = rd.readLine()) != null) {
                json = json + line;
            }
            System.out.println("json = " + json);
            EntityUtils.consume(entity);
        } finally {
            response.close();
        }
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } finally {
        if (scan != null)
            scan.close();
    }
}

From source file:org.hardisonbrewing.s3j.JaxbResponseHandler.java

@Override
public T handleResponse(HttpResponse httpResponse) throws HttpResponseException, IOException {

    System.out.println("  Response Headers");
    HttpUtil.printHeaders(httpResponse);

    HttpUtil.validateResponseCode(httpResponse);

    HttpEntity entity = null;/*from  w  w  w .  j  a v a 2  s .  c  om*/
    InputStream inputStream = null;

    try {

        entity = httpResponse.getEntity();
        inputStream = entity.getContent();
        return JAXB.unmarshal(inputStream, clazz);
    } catch (JAXBException e) {
        throw new IOException(e);
    } finally {
        IOUtil.close(inputStream);
        EntityUtils.consume(entity);
    }
}

From source file:org.workin.http.httpclient.v4.handler.response.AbstractResponseHandler.java

/**
 * @description ??/*from w ww  .ja v  a  2  s .c  o m*/
 * @author <a href="mailto:code727@gmail.com">?</a> 
 * @param response
 * @return
 * @throws IOException
 */
protected String doResponse(HttpResponse response) throws 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 ? EntityUtils.toString(entity, getEncoding()) : null;
}