List of usage examples for org.apache.http.util EntityUtils toString
public static String toString(HttpEntity httpEntity) throws IOException, ParseException
From source file:com.liferay.mobile.sdk.http.DiscoveryResponseHandler.java
public Discovery handleResponse(HttpResponse response) throws IOException { Discovery discovery;/*from w w w. j av a 2s. c o m*/ String json = EntityUtils.toString(response.getEntity()); try { discovery = new Discovery(json); } catch (JSONException je) { throw new IOException(je); } return discovery; }
From source file:org.mobile.mpos.util.HttpClientHelper.java
/** * get request//from ww w . j a v a 2s. c om * @param uri * @return */ public static String get(String uri) { CloseableHttpClient httpClient = HttpClients.createDefault(); try { HttpGet httpget = new HttpGet(uri); log.info("Executing request " + httpget.getRequestLine()); // 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(); if (status >= 200 && status < 300) { HttpEntity entity = response.getEntity(); return entity != null ? EntityUtils.toString(entity) : null; } else { throw new ClientProtocolException("Unexpected response status: " + status); } } }; String responseBody = httpClient.execute(httpget, responseHandler); log.info(" response " + responseBody); return responseBody; } catch (ClientProtocolException e) { log.error("ClientProtocolException " + e.getMessage()); } catch (IOException e) { log.error("IOException " + e.getMessage()); } finally { close(httpClient); } return null; }
From source file:pt.isel.mpd.monitrgw.webapi.MonitrApi.java
private static <T> T callMonitrAction(Class<T> destKlass, String action, Object... args) { final String uri = String.format(action, args); return HttpGw.getData(MONITR_URI + uri, ent -> jsonReader.fromJson(EntityUtils.toString(ent), destKlass)); }
From source file:com.ninehcom.userinfo.agent.ConnectAgent.java
public String sendRequestHttpsUTF8(String request, String path, Map<String, String> bodys) throws Exception { Map<String, String> header = new HashMap<>(); header.put("accept", "*/*"); header.put("connection", "Keep-Alive"); header.put("user-agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13"); header.put("Content-Type", "application/json"); HttpResponse response = HttpUtils.doGet(request, path, "", header, bodys); return EntityUtils.toString(response.getEntity()); }
From source file:com.touch6.sm.gateway.aliyun.AliyunSmsGateway.java
public static final boolean batchSend(String url, String path, String method, String auth, String vars, String phones, String signName, String smsTemplate) { Map<String, String> headers = new HashMap<>(); //?header?()Authorization:APPCODE 83359fd73fe94948385f570e3c139105 headers.put("Authorization", auth); Map<String, String> querys = new HashMap<>(); querys.put("ParamString", vars); querys.put("RecNum", phones); querys.put("SignName", signName); querys.put("TemplateCode", smsTemplate); String result = null;/*from w w w . ja v a 2 s.c o m*/ try { HttpResponse response = HttpUtils.doGet(url, path, method, headers, querys); result = EntityUtils.toString(response.getEntity()); //?responsebody logger.info("<<======?????:[{}]", result); JSONObject obj = JSONObject.parseObject(result); if ("true".equals(obj.getString("success"))) { return true; } else { return false; } } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:com.javaquery.aws.elasticsearch.GetExample.java
/** * Perform get request./* w w w . ja v a 2 s. com*/ * @param httpGet */ public static void httpGetRequest(HttpGet httpGet) { /* Create object of CloseableHttpClient */ CloseableHttpClient httpClient = HttpClients.createDefault(); /* Response handler for after request execution */ ResponseHandler<String> responseHandler = new ResponseHandler<String>() { @Override public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException { /* Get status code */ int status = response.getStatusLine().getStatusCode(); if (status >= 200 && status < 300) { /* Convert response to String */ HttpEntity entity = response.getEntity(); return entity != null ? EntityUtils.toString(entity) : null; } else { throw new ClientProtocolException("Unexpected response status: " + status); } } }; try { /* Execute URL and attach after execution response handler */ String strResponse = httpClient.execute(httpGet, responseHandler); /* Print the response */ System.out.println("Response: " + strResponse); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ppshein.sevendaynews.common.java
public static String getInputStreamFromUrl(String url) { String content = null;/*from w w w. j a v a 2s . c o m*/ try { HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(new HttpGet(url)); HttpEntity resEntity = response.getEntity(); content = EntityUtils.toString(resEntity); content = content.trim(); } catch (Exception e) { Log.e("log_tag", "Error in http connection " + e.toString()); } return content; }
From source file:eu.sisob.uma.NPL.Researchers.Freebase.Utils.java
public static JsonObject doRESTCall(String url) throws IOException { HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(new HttpGet(url)); JsonParser parser = new JsonParser(); JsonObject json_data = (JsonObject) parser.parse(EntityUtils.toString(response.getEntity())); return json_data; }
From source file:bad.robot.http.apache.ToStringConsumer.java
@Override public String toString(HttpEntity entity) throws IOException { return EntityUtils.toString(entity); }
From source file:com.uber.stream.kafka.mirrormaker.common.utils.HttpClientUtils.java
public static ResponseHandler<String> createResponseBodyExtractor() { return new ResponseHandler<String>() { @Override/* w ww .j a v a2 s. c om*/ public String handleResponse(final HttpResponse response) throws IOException { int status = response.getStatusLine().getStatusCode(); if (status >= 200 && status < 300) { HttpEntity entity = response.getEntity(); return entity != null ? EntityUtils.toString(entity) : null; } else { throw new ClientProtocolException( "Unexpected response status while getting /topics : " + status); } } }; }