List of usage examples for org.apache.http.util EntityUtils toString
public static String toString(HttpEntity httpEntity) throws IOException, ParseException
From source file:com.coroptis.coidi.rp.services.impl.YadisServiceImpl.java
@Override public void readXrdsDocument(String url) { try {/*from ww w. j a va 2 s.c o m*/ HttpClient httpClient = httpService.getHttpClient(); HttpGet httpget = new HttpGet(url); httpget.setHeader("Accept", "application/xrds+xml"); HttpResponse response; response = httpClient.execute(httpget); HttpEntity entity = response.getEntity(); String string = EntityUtils.toString(entity); System.out.println(string); // extract "openid2.provider" } catch (ClientProtocolException e) { logger.error(e.getMessage(), e); throw new CoidiException(e.getMessage(), e); } catch (IOException e) { logger.error(e.getMessage(), e); throw new CoidiException(e.getMessage(), e); } }
From source file:org.opennms.poller.remote.MetadataUtils.java
public static Map<String, String> fetchGeodata() { final Map<String, String> ret = new HashMap<>(); final String url = "http://freegeoip.net/xml/"; final CloseableHttpClient httpclient = HttpClients.createDefault(); final HttpGet get = new HttpGet(url); CloseableHttpResponse response = null; try {/*w w w. j av a 2 s . c o m*/ response = httpclient.execute(get); final HttpEntity entity = response.getEntity(); final String xml = EntityUtils.toString(entity); System.err.println("xml = " + xml); final GeodataResponse geoResponse = JaxbUtils.unmarshal(GeodataResponse.class, xml); ret.put("external-ip-address", InetAddressUtils.str(geoResponse.getIp())); ret.put("country-code", geoResponse.getCountryCode()); ret.put("region-code", geoResponse.getRegionCode()); ret.put("city", geoResponse.getCity()); ret.put("zip-code", geoResponse.getZipCode()); ret.put("time-zone", geoResponse.getTimeZone()); ret.put("latitude", geoResponse.getLatitude() == null ? null : geoResponse.getLatitude().toString()); ret.put("longitude", geoResponse.getLongitude() == null ? null : geoResponse.getLongitude().toString()); EntityUtils.consumeQuietly(entity); } catch (final Exception e) { LOG.debug("Failed to get GeoIP data from " + url, e); } finally { IOUtils.closeQuietly(response); } return ret; }
From source file:org.jboss.test.capedwarf.blobstore.support.FileUploader.java
public String getUploadUrl(URL url) throws URISyntaxException, IOException { HttpClient httpClient = new DefaultHttpClient(); HttpGet get = new HttpGet(url.toURI()); HttpResponse response = httpClient.execute(get); return EntityUtils.toString(response.getEntity()).trim(); }
From source file:com.ascenttechnovation.geoecho.async.CheckLoginValidityAsyncTask.java
@Override protected Boolean doInBackground(String... url) { Log.d(Constants.LOG_TAG, Constants.CheckLoginValidityAsyncTask); Log.d(Constants.LOG_TAG, " The url to be fetched " + url[0]); try {/*from ww w . j av a2 s .c o m*/ httpPost = new HttpPost(url[0]); httpClient = new DefaultHttpClient(); httpResponse = httpClient.execute(httpPost); int status = httpResponse.getStatusLine().getStatusCode(); if (status == 200) { httpEntity = httpResponse.getEntity(); responseString = EntityUtils.toString(httpEntity); JSONObject jsonObject = new JSONObject(responseString); Log.d(Constants.LOG_TAG, " JSON OBJECT " + jsonObject); JSONArray jsonArray = jsonObject.getJSONArray("listing"); for (int i = 0; i < jsonArray.length(); i++) { JSONObject nestedJsonObject = jsonArray.getJSONObject(i); String licenseId = nestedJsonObject.getString("license_id"); } return true; } else { Log.d(Constants.LOG_TAG, " There was an error with status code" + status); return false; } } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:ecplugins.s3.TestUtils.java
/** * callRunProcedure/*from w w w. j a v a2 s .c o m*/ * * @param jo * @return the jobId of the job launched by runProcedure */ public static String callRunProcedure(JSONObject jo) throws Exception { HttpClient httpClient = new DefaultHttpClient(); JSONObject result = null; try { HttpPost httpPostRequest = new HttpPost("http://" + props.getProperty(StringConstants.COMMANDER_USER) + ":" + props.getProperty(StringConstants.COMMANDER_PASSWORD) + "@" + StringConstants.COMMANDER_SERVER + ":8000/rest/v1.0/jobs?request=runProcedure"); StringEntity input = new StringEntity(jo.toString()); input.setContentType("application/json"); httpPostRequest.setEntity(input); HttpResponse httpResponse = httpClient.execute(httpPostRequest); result = new JSONObject(EntityUtils.toString(httpResponse.getEntity())); return result.getString("jobId"); } finally { httpClient.getConnectionManager().shutdown(); } }
From source file:sendsms.WebService.java
public String post(String url, NameValuePair... parametros) { String source = null;/* ww w.j av a 2s . c o m*/ HttpClient httpClient = HttpClients.createDefault(); RequestBuilder requestBuilder = RequestBuilder.post().setUri(url); for (NameValuePair parametro : parametros) { requestBuilder.addParameter(parametro); } HttpUriRequest uriRequest = requestBuilder.build(); try { HttpResponse httpResponse = httpClient.execute(uriRequest); source = EntityUtils.toString(httpResponse.getEntity()); } catch (IOException e) { e.printStackTrace(); } return source; }
From source file:com.alibaba.openapi.client.util.URLEncodedUtils.java
/** * Returns a list of {@link NameValuePair NameValuePairs} as parsed from an * {@link HttpEntity}. The encoding is taken from the entity's * Content-Encoding header./* w w w . j a v a2 s.co m*/ * <p> * This is typically used while parsing an HTTP POST. * * @param entity * The entity to parse * @throws IOException * If there was an exception getting the entity's data. */ public static List<NameValuePair> parse(final HttpEntity entity) throws IOException { List<NameValuePair> result = Collections.emptyList(); if (isEncoded(entity)) { final String content = EntityUtils.toString(entity); final Header encoding = entity.getContentEncoding(); if (content != null && content.length() > 0) { result = new ArrayList<NameValuePair>(); parse(result, new Scanner(content), encoding != null ? encoding.getValue() : null); } } return result; }
From source file:com.jereksel.rommanager.XMLParser.java
/** * Getting XML from URL making HTTP request * * @param url string/*w ww.j a va 2 s .c o m*/ */ public String getXmlFromUrl(String url) { String xml = null; try { // defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); xml = EntityUtils.toString(httpEntity); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // return XML return xml; }
From source file:de.l3s.archivepig.enrich.StringContent.java
@Override public void enrich(Tuple data, Tuple enrichment, Object... params) throws Exception { byte[] payload = get(data, enrichField); HttpEntity entity = new ByteArrayEntity(payload); enrichment.append(EntityUtils.toString(entity).trim()); }