List of usage examples for org.apache.http.util EntityUtils consume
public static void consume(HttpEntity httpEntity) throws IOException
From source file:com.foundationdb.http.HttpThreadedLoginIT.java
private static int openRestURL(String userInfo, int port, String path) throws Exception { HttpClient client = new DefaultHttpClient(); URI uri = new URI("http", userInfo, "localhost", port, path, null, null); HttpGet get = new HttpGet(uri); HttpResponse response = client.execute(get); int code = response.getStatusLine().getStatusCode(); EntityUtils.consume(response.getEntity()); client.getConnectionManager().shutdown(); return code;//from www. j av a 2 s.co m }
From source file:org.drftpd.util.HttpUtils.java
public static String retrieveHttpAsString(String url) throws HttpException, IOException { RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000) .setConnectionRequestTimeout(5000).setCookieSpec(CookieSpecs.IGNORE_COOKIES).build(); CloseableHttpClient httpclient = HttpClients.custom().setDefaultRequestConfig(requestConfig) .setUserAgent(_userAgent).build(); HttpGet httpGet = new HttpGet(url); httpGet.setConfig(requestConfig);/*from w w w. ja v a2s .c om*/ CloseableHttpResponse response = null; try { response = httpclient.execute(httpGet); final int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { throw new HttpException("Error " + statusCode + " for URL " + url); } HttpEntity entity = response.getEntity(); String data = EntityUtils.toString(entity); EntityUtils.consume(entity); return data; } catch (IOException e) { throw new IOException("Error for URL " + url, e); } finally { if (response != null) { response.close(); } httpclient.close(); } }
From source file:br.com.atmatech.sac.webService.WebServiceAtivacao.java
public Boolean login(String url, String user, String password, String cnpj) throws IOException { Boolean chave = false;/*from w w w . j a v a 2 s . c o m*/ HttpPost post = new HttpPost(url); boolean result = false; /* Configura os parmetros do POST */ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("login", user)); nameValuePairs.add(new BasicNameValuePair("senha", password)); post.setEntity(new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8)); HttpResponse response = client.execute(post); EntityUtils.consume(response.getEntity()); HttpGet get = new HttpGet("http://atma.serveftp.com/atma/view/nav/header_chave.php?cnpj=" + cnpj); response = client.execute(get); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line; FileWriter out = new FileWriter("./ativacao.html"); PrintWriter gravarArq = new PrintWriter(out); while ((line = rd.readLine()) != null) { gravarArq.print(line + "\n"); chave = true; } out.close(); return chave; }
From source file:org.apache.edgent.connectors.http.HttpResponders.java
/** * Return the input tuple on specified codes. * Function that returns null (no output) if the HTTP response * is not one of {@code codes}, otherwise it returns the input tuple. * The HTTP entity in the response is consumed and discarded. * @param <T> Type of input tuple. * @param codes HTTP status codes to result in output * @return Function that returns the input tuple on matching codes. *///from ww w . j a v a2 s . com public static <T> BiFunction<T, CloseableHttpResponse, T> inputOn(Integer... codes) { Set<Integer> uniqueCodes = new HashSet<>(Arrays.asList(codes)); return (t, resp) -> { int sc = resp.getStatusLine().getStatusCode(); try { EntityUtils.consume(resp.getEntity()); } catch (Exception e) { ; } return uniqueCodes.contains(sc) ? t : null; }; }
From source file:org.gradle.internal.resource.transport.http.HttpResourceUploader.java
public void upload(Factory<InputStream> source, Long contentLength, URI destination) throws IOException { HttpPut method = new HttpPut(destination); final RepeatableInputStreamEntity entity = new RepeatableInputStreamEntity(source, contentLength, ContentType.APPLICATION_OCTET_STREAM); method.setEntity(entity);//from w w w .j a v a 2 s.c o m HttpResponse response = http.performHttpRequest(method); EntityUtils.consume(response.getEntity()); if (!http.wasSuccessful(response)) { throw new IOException( String.format("Could not PUT '%s'. Received status code %s from server: %s", destination, response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase())); } }
From source file:com.noelportugal.amazonecho.SmartThings.java
public String setApp(String url, String body) { String output = ""; try {/* w ww . j ava2 s . co m*/ HttpPut httpPut = new HttpPut(url); httpPut.setHeader(HttpHeaders.CONTENT_TYPE, "application/json"); httpPut.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + bearer); StringEntity xmlEntity = new StringEntity(body); httpPut.setEntity(xmlEntity); HttpResponse httpResponse = httpclient.execute(httpPut); httpResponse.getEntity(); output = new BasicResponseHandler().handleResponse(httpResponse); if (xmlEntity != null) { EntityUtils.consume(xmlEntity); } } catch (Exception e) { System.err.println("setApp Error: " + e.getMessage()); } return output; }
From source file:net.oebs.jalos.Client.java
public String get(long id) throws IOException { HttpGet httpGet = new HttpGet(this.serviceUrl + "/a/" + id); CloseableHttpResponse response = httpClient.execute(httpGet); HttpEntity entity = response.getEntity(); String ret = response.getLastHeader("Location").toString(); EntityUtils.consume(entity); response.close();// w w w .j a v a2 s . c o m return ret; }
From source file:org.chaplib.HttpResource.java
public <T> T value(ContentParser<T> parser) { HttpResponse resp = execute(new HttpGet(uri)); HttpEntity entity = resp.getEntity(); if (entity == null) return null; try {// ww w.j av a 2 s. c o m return parser.parse(entity); } finally { try { EntityUtils.consume(entity); } catch (IOException e) { throw new RuntimeException(e); } } }
From source file:com.intel.cosbench.client.swift.SwiftResponse.java
public void consumeResposeBody() throws IOException { EntityUtils.consume(entity); }
From source file:org.jboss.aerogear.windows.mpns.internal.MpnsServiceImpl.java
@Override protected void push(HttpPost request, MpnsNotification message) { try {/*from w w w . j a v a2 s. c om*/ HttpResponse response = httpClient.execute(request); Utilities.fireDelegate(message, response, delegate); EntityUtils.consume(response.getEntity()); } catch (ClientProtocolException e) { throw new RuntimeException(e); } catch (IOException e) { throw new NetworkIOException(e); } }