List of usage examples for org.apache.http.entity BufferedHttpEntity BufferedHttpEntity
public BufferedHttpEntity(HttpEntity httpEntity) throws IOException
From source file:com.http.ClientWithResponseHandler.java
public final static void main(String[] args) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); try {//from w ww.j a va 2 s.c o m HttpGet httpget = new HttpGet("http://www.google.com/"); System.out.println("executing request " + httpget.getURI()); // Create a custom response handler ResponseHandler<String> responseHandler = new ResponseHandler<String>() { public String handleResponse(final HttpResponse response) throws ClientProtocolException, IOException { int status = response.getStatusLine().getStatusCode(); System.out.println(response.getStatusLine()); if (status >= 200 && status < 300) { HttpEntity entity = response.getEntity(); entity = new BufferedHttpEntity(entity); System.out.println("---1-----:" + EntityUtils.toString(entity)); System.out.println("---2-----:" + EntityUtils.toString(entity)); return entity != null ? EntityUtils.toString(entity) : null; } else { throw new ClientProtocolException("Unexpected response status: " + status); } } }; String responseBody = httpclient.execute(httpget, responseHandler); System.out.println("----------------------------------------"); System.out.println(responseBody); System.out.println("----------------------------------------"); } finally { httpclient.close(); } }
From source file:Main.java
public static String getStringFromUrl(List<NameValuePair> nameValuePairs) throws ClientProtocolException, IOException { String url = "http://www.fsurugby.org/serve/request.php"; DefaultHttpClient client = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(httppost); HttpEntity entity = response.getEntity(); BufferedHttpEntity buffer = new BufferedHttpEntity(entity); InputStream is = buffer.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line;/*from ww w.ja va 2 s .co m*/ while ((line = reader.readLine()) != null) { sb.append(line); } return sb.toString(); }
From source file:guru.nidi.ramltester.httpcomponents.HttpComponentsUtils.java
static BufferedHttpEntity buffered(HttpEntity entity) { try {/* ww w .ja v a 2 s .c o m*/ return new BufferedHttpEntity(entity); } catch (IOException e) { throw new RuntimeException("Could not read content of entity", e); } }
From source file:org.elasticsearch.client.ResponseException.java
private static String buildMessage(Response response) throws IOException { String message = response.getRequestLine().getMethod() + " " + response.getHost() + response.getRequestLine().getUri() + ": " + response.getStatusLine().toString(); HttpEntity entity = response.getEntity(); if (entity != null) { if (entity.isRepeatable() == false) { entity = new BufferedHttpEntity(entity); response.getHttpResponse().setEntity(entity); }// w w w . jav a2 s . c o m message += "\n" + EntityUtils.toString(entity); } return message; }
From source file:fedroot.dacs.http.DacsResponse.java
public DacsResponse(HttpResponse httpResponse) throws DacsException { this.httpResponse = httpResponse; if (httpResponse.getEntity() != null) { try { // we use a BufferedHttpEntity so we can reset the input stream after a DacsCheckRequest this.inputStream = new BufferedHttpEntity(httpResponse.getEntity()).getContent(); } catch (IOException ex) { logger.log(Level.SEVERE, null, ex); throw new DacsException(ex.getLocalizedMessage()); }/*from www. jav a 2s .c o m*/ } }
From source file:cn.edu.szjm.support.http.IgnitedHttpResponseImpl.java
public IgnitedHttpResponseImpl(HttpResponse response) throws IOException { this.response = response; HttpEntity temp = response.getEntity(); if (temp != null) { entity = new BufferedHttpEntity(temp); }/*from w w w. ja v a 2s .c om*/ }
From source file:com.aspire.mandou.framework.http.BetterHttpResponseImpl.java
public BetterHttpResponseImpl(HttpResponse response) throws IOException { this.response = response; HttpEntity temp = response.getEntity(); if (temp != null) { entity = new BufferedHttpEntity(temp); }/* w w w . j av a 2 s .c o m*/ }
From source file:com.huguesjohnson.retroleague.util.HttpFetch.java
public static InputStream fetch(String address, int timeout) throws MalformedURLException, IOException { HttpGet httpRequest = new HttpGet(URI.create(address)); HttpClient httpclient = new DefaultHttpClient(); final HttpParams httpParameters = httpclient.getParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, timeout); HttpConnectionParams.setSoTimeout(httpParameters, timeout); HttpResponse response = (HttpResponse) httpclient.execute(httpRequest); HttpEntity entity = response.getEntity(); BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity); InputStream instream = bufHttpEntity.getContent(); return (instream); }
From source file:com.ksc.http.apache.utils.ApacheUtils.java
/** * Utility function for creating a new BufferedEntity and wrapping any errors * as an AmazonClientException.// w w w. j a v a2 s . c om * * @param entity The HTTP entity to wrap with a buffered HTTP entity. * @return A new BufferedHttpEntity wrapping the specified entity. * @throws FakeIOException only for test simulation */ public static HttpEntity newBufferedHttpEntity(HttpEntity entity) throws FakeIOException { try { return new BufferedHttpEntity(entity); } catch (FakeIOException e) { // Only for test simulation. throw e; } catch (IOException e) { throw new KscClientException("Unable to create HTTP entity: " + e.getMessage(), e); } }
From source file:com.example.android.navigationdrawerexample.LocationFileReader.java
public List<String[]> getFile() throws ClientProtocolException, IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httppost = new HttpGet(url); HttpResponse response = httpclient.execute(httppost); HttpEntity ht = response.getEntity(); BufferedHttpEntity buf = new BufferedHttpEntity(ht); InputStream is = buf.getContent(); BufferedReader r = new BufferedReader(new InputStreamReader(is)); StringBuilder total = new StringBuilder(); String line;// w ww .j a va 2 s .co m String[] location; while ((line = r.readLine()) != null) { total.append(line + "\n"); location = total.toString().split(" "); locationList.add(location); total.setLength(0); } return locationList; }