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:oracle.custom.ui.oauth.vo.OpenIdConfiguration.java

public static OpenIdConfiguration getInstance(String tenantName) throws Exception {
    if (configMap.containsKey(tenantName.toLowerCase())) {
        return configMap.get(tenantName.toLowerCase());
    }//  ww  w . j av  a 2s . c  om
    String url = ServerUtils.getIDCSBaseURL(tenantName) + endpoint;
    System.out.println("URL for tenant '" + tenantName + "' is '" + url + "'");
    HttpClient client = ServerUtils.getClient(tenantName);
    URI uri = new URI(url);
    HttpGet get = new HttpGet(uri);
    HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
    HttpResponse response = client.execute(host, get);
    try {
        HttpEntity entity2 = response.getEntity();
        String res = EntityUtils.toString(entity2);
        EntityUtils.consume(entity2);
        ObjectMapper mapper = new ObjectMapper();
        //res = res.replaceAll("secureoracle.idcs.internal.oracle.com:443", "oc-140-86-12-131.compute.oraclecloud.com");
        OpenIdConfiguration openIdConfigInstance = mapper.readValue(res, OpenIdConfiguration.class);

        configMap.put(tenantName.toLowerCase(), openIdConfigInstance);
        return openIdConfigInstance;
    } finally {
        if (response instanceof CloseableHttpResponse) {
            ((CloseableHttpResponse) response).close();
        }
    }
}

From source file:com.srotya.tau.alerts.media.HttpService.java

/**
 * @param alert/*w  ww . j a v  a2  s.  c  o  m*/
 * @throws AlertDeliveryException
 */
public void sendHttpCallback(Alert alert) throws AlertDeliveryException {
    try {
        CloseableHttpClient client = Utils.buildClient(alert.getTarget(), 3000, 3000);
        HttpPost request = new HttpPost(alert.getTarget());
        StringEntity body = new StringEntity(alert.getBody(), ContentType.APPLICATION_JSON);
        request.addHeader("content-type", "application/json");
        request.setEntity(body);
        HttpResponse response = client.execute(request);
        EntityUtils.consume(response.getEntity());
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode < 200 && statusCode >= 300) {
            throw exception;
        }
        client.close();
    } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException | IOException
            | AlertDeliveryException e) {
        throw exception;
    }
}

From source file:org.eclipse.dirigible.cli.apis.ImportProjectAPI.java

private static void executeRequest(CloseableHttpClient httpClient, HttpPost postRequest)
        throws IOException, ClientProtocolException {
    try {/* w  ww . j  a  v  a 2 s.c o  m*/
        CloseableHttpResponse response = httpClient.execute(postRequest);
        try {
            logger.log(Level.INFO, "----------------------------------------");
            logger.log(Level.INFO, response.getStatusLine().toString());
            HttpEntity resultEntity = response.getEntity();
            if (resultEntity != null) {
                logger.log(Level.INFO, "Response content length: " + resultEntity.getContentLength());
            }
            EntityUtils.consume(resultEntity);
        } finally {
            response.close();
        }
    } finally {
        httpClient.close();
    }
}

From source file:org.piraso.client.net.HttpPirasoTestHandler.java

@Override
public void execute() throws IOException, SAXException, ParserConfigurationException {
    try {/*from w  w w. j a  v  a 2s .c  om*/
        doExecute();
    } finally {
        EntityUtils.consume(responseEntity);
    }
}

From source file:at.ac.tuwien.big.testsuite.impl.util.DomResponseHandler.java

@Override
public Document handleResponse(final HttpResponse response) throws HttpResponseException, IOException {
    StatusLine statusLine = response.getStatusLine();
    HttpEntity entity = response.getEntity();
    Document doc = null;/*from   w  w w . j av a  2  s. c  om*/

    if (statusLine.getStatusCode() >= 300) {

        if (statusLine.getStatusCode() == 502 && retries < MAX_RETRIES) {
            // Proxy Error
            retries++;
            doc = httpClient.execute(request, this);
            retries = 0;
        } else {
            EntityUtils.consume(entity);
            throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
        }
    }

    if (doc == null) {
        doc = entity == null ? null : DomUtils.createDocument(entity.getContent());
    }

    request.releaseConnection();
    return doc;
}

From source file:org.callimachusproject.fluid.consumers.HttpEntityWriter.java

public Fluid consume(final HttpEntity result, final String base, final FluidType ftype,
        final FluidBuilder builder) {
    return new Vapor() {
        public String getSystemId() {
            return base;
        }/*  w  w  w  .j  av a  2  s. c o  m*/

        public FluidType getFluidType() {
            return ftype;
        }

        public void asVoid() throws IOException {
            if (result != null) {
                EntityUtils.consume(result);
            }
        }

        @Override
        protected String toHttpEntityMedia(FluidType media) {
            if (result == null)
                return ftype.as(media).preferred();
            Header hd = result.getContentType();
            if (hd == null)
                return ftype.as(media).preferred();
            return ftype.as(hd.getValue()).as(media).preferred();
        }

        @Override
        protected HttpEntity asHttpEntity(FluidType media) throws Exception {
            if (result == null)
                return null;
            return result;
        }

        @Override
        protected String toChannelMedia(FluidType media) {
            if (result == null)
                return ftype.as(media).preferred();
            Header hd = result.getContentType();
            if (hd == null)
                return ftype.as(media).preferred();
            return ftype.as(hd.getValue()).as(media).preferred();
        }

        @Override
        protected ReadableByteChannel asChannel(FluidType media) throws IOException, OpenRDFException,
                XMLStreamException, TransformerException, ParserConfigurationException {
            if (result == null)
                return null;
            return ChannelUtil.newChannel(result.getContent());
        }

        public String toString() {
            return String.valueOf(result);
        }
    };
}

From source file:org.sonatype.nexus.repository.view.payloads.HttpEntityPayload.java

@Override
public void close() throws IOException {
    EntityUtils.consume(entity);
}

From source file:org.apache.marmotta.platform.core.services.http.response.LastModifiedResponseHandler.java

@Override
public Date handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
    try {//from  w  w  w.j  av  a 2 s . c o m
        Header lastModH = response.getFirstHeader("Last-Modified");
        return lastModH != null ? parseDate(lastModH.getValue()) : null;
    } finally {
        EntityUtils.consume(response.getEntity());
    }
}

From source file:com.foundationdb.http.RestServiceITBase.java

@After
public final void tearDown() throws IOException {
    if (response != null) {
        EntityUtils.consume(response.getEntity());
    }//from  ww w  .j a v  a2  s. c  o m
    if (client != null) {
        client.close();
    }
}

From source file:fr.mael.microrss.xml.RSSFeedParser.java

@Override
public List<Article> readArticles(Feed feed) throws Exception {
    List<Article> articles = new ArrayList<Article>();
    JAXBContext jc = JAXBContext.newInstance("fr.mael.microrss.xml.rss");
    Unmarshaller unmarshaller = jc.createUnmarshaller();
    HttpGet get = new HttpGet(feed.getUrl());
    HttpResponse response = client.execute(get);
    try {//from   w ww  . j  a v a2s . c  om
        Rss rss = (Rss) unmarshaller.unmarshal(response.getEntity().getContent());
        for (RssItem item : rss.getChannel().getItem()) {
            Article article = readArticle(item);
            article.getFeeds().add(feed);
            articles.add(article);
        }
        return articles;
    } catch (Exception e) {
        EntityUtils.consume(response.getEntity());
        throw new Exception(e);
    }
}