List of usage examples for org.apache.http.client HttpClient getConnectionManager
@Deprecated ClientConnectionManager getConnectionManager();
From source file:eu.eexcess.partnerrecommender.test.PartnerRecommenderTestHelper.java
@SuppressWarnings({ "resource", "deprecation" }) static public ResultList getRecommendations(String deploymentContext, int port, StringEntity params) { HttpClient httpClient = new DefaultHttpClient(); ResultList resultList = null;//from w w w . j a va 2 s .c o m try { HttpPost request = new HttpPost( "http://localhost:" + port + "/" + deploymentContext + "/partner/recommend/"); request.addHeader("content-type", "application/xml"); request.setEntity(params); HttpResponse response = httpClient.execute(request); String responseString = EntityUtils.toString(response.getEntity()); resultList = PartnerRecommenderTestHelper.parseResponse(responseString); } catch (Exception ex) { System.out.println(ex); } finally { httpClient.getConnectionManager().shutdown(); } return resultList; }
From source file:com.jts.main.helper.Http.java
public static String sendPost(String url, URLParameter param) { String retval = ""; HttpClient httpClient = new DefaultHttpClient(); try {// w ww . java 2 s . c o m HttpPost request = new HttpPost(My.base_url + url); StringEntity params = new StringEntity(param.get()); request.addHeader("content-type", "application/x-www-form-urlencoded"); request.setEntity(params); HttpResponse response = httpClient.execute(request); // handle response here... retval = org.apache.http.util.EntityUtils.toString(response.getEntity()); org.apache.http.util.EntityUtils.consume(response.getEntity()); } catch (IOException | ParseException ex) { errMsg = ex.getMessage(); } finally { httpClient.getConnectionManager().shutdown(); } return retval; }
From source file:eu.eexcess.partnerdata.evaluation.enrichment.PartnerRecommenderEvaluationTestHelper.java
static public ResultList getRecommendations(String deploymentContext, int port, StringEntity params) { HttpClient httpClient = new DefaultHttpClient(); ResultList resultList = null;//from ww w .j av a2s . c om try { HttpPost request = new HttpPost( "http://localhost:" + port + "/" + deploymentContext + "/partner/recommend/"); request.addHeader("content-type", "application/xml"); request.setEntity(params); HttpResponse response = httpClient.execute(request); String responseString = EntityUtils.toString(response.getEntity()); resultList = PartnerRecommenderEvaluationTestHelper.parseResponse(responseString); } catch (Exception ex) { System.out.println(ex); } finally { httpClient.getConnectionManager().shutdown(); } return resultList; }
From source file:nl.coralic.beta.sms.utils.http.HttpHandler.java
private static Response doPost(String url, List<NameValuePair> postdata) { HttpClient httpclient = getHttpClient(); try {/* w w w. j a v a 2 s . c o m*/ HttpPost httpost = new HttpPost(url); httpost.setEntity(new UrlEncodedFormEntity(postdata, HTTP.UTF_8)); HttpResponse response = httpclient.execute(httpost); if (response.getStatusLine().getStatusCode() == 200) { ResponseHandler<String> responseHandler = new BasicResponseHandler(); return new Response(responseHandler.handleResponse(response)); } else { return new Response(R.string.ERR_PROV_NO_RESP); } } catch (Exception e) { return new Response(R.string.ERR_CONN_ERR); } finally { // Release the resources httpclient.getConnectionManager().shutdown(); } }
From source file:com.jts.main.helper.Http.java
public static String getPost(String url, URLParameter param) { String retval = ""; HttpClient httpClient = new DefaultHttpClient(); try {/*from w w w .j a va2 s. c om*/ String prm = param.toString(); HttpPost request = new HttpPost(My.base_url + url); StringEntity params = new StringEntity(prm); request.addHeader("content-type", "application/x-www-form-urlencoded"); request.setEntity(params); HttpResponse response = httpClient.execute(request); // handle response here... retval = org.apache.http.util.EntityUtils.toString(response.getEntity()); org.apache.http.util.EntityUtils.consume(response.getEntity()); } catch (IOException | ParseException ex) { errMsg = ex.getMessage(); } finally { httpClient.getConnectionManager().shutdown(); } return retval; }
From source file:es.tsb.ltba.nomhad.example.ClientWithResponseHandler.java
private static DefaultHttpClient wrapClient(HttpClient base) { try {// w w w .java 2s . c om SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = base.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", 443, ssf)); return new DefaultHttpClient(ccm, base.getParams()); } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:org.apache.stratos.cli.WebClientWrapper.java
public static HttpClient wrapClient(HttpClient base) { try {// w ww . j a v a 2 s. c o m SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx); ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = base.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", ssf, 443)); return new DefaultHttpClient(ccm, base.getParams()); } catch (Exception ex) { return null; } }
From source file:org.graylog2.systeminformation.Sender.java
public static void send(Map<String, Object> info, Core server) { HttpClient httpClient = new DefaultHttpClient(); try {//from w w w . j a va 2 s. co m HttpPost request = new HttpPost(getTarget(server)); List<NameValuePair> nameValuePairs = Lists.newArrayList(); nameValuePairs.add(new BasicNameValuePair("systeminfo", JSONValue.toJSONString(info))); request.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpClient.execute(request); if (response.getStatusLine().getStatusCode() != 201) { LOG.warn("Response code for system statistics was not 201, but " + response.getStatusLine().getStatusCode()); } } catch (Exception e) { LOG.warn("Could not send system statistics.", e); } finally { httpClient.getConnectionManager().shutdown(); } }
From source file:com.speakingcode.freemusicarchive.api.FMAConnector.java
/** * Makes the HTTP GET request to the provided REST url * @param requestUrl the URL to request/*www .j a v a 2s . c o m*/ * @return The string of the response from the HTTP request */ public static String callWebService(String requestUrl) { String deviceId = "xxxxx"; HttpClient httpclient = new DefaultHttpClient(); HttpGet request = new HttpGet(requestUrl); request.addHeader("deviceId", deviceId); ResponseHandler<String> handler = new BasicResponseHandler(); String result = ""; try { result = httpclient.execute(request, handler); } catch (ClientProtocolException e) { e.printStackTrace(); Log.e(TAG, "ClientProtocolException in callWebService(). " + e.getMessage()); } catch (IOException e) { e.printStackTrace(); Log.e(TAG, "IOException in callWebService(). " + e.getMessage()); } httpclient.getConnectionManager().shutdown(); Log.i(TAG, "**callWebService() successful. Result: **"); Log.i(TAG, result); Log.i(TAG, "*****************************************"); return result; }
From source file:ecplugins.s3.TestUtils.java
/** * Wrapper around a HTTP GET to a REST service * * @param url//from ww w . j a va 2s . c o m * @return JSONObject */ static JSONObject performHTTPGet(String url) throws IOException, JSONException { HttpClient httpClient = new DefaultHttpClient(); try { HttpGet httpGetRequest = new HttpGet(url); HttpResponse httpResponse = httpClient.execute(httpGetRequest); if (httpResponse.getStatusLine().getStatusCode() >= 400) { throw new RuntimeException("HTTP GET failed with " + httpResponse.getStatusLine().getStatusCode() + "-" + httpResponse.getStatusLine().getReasonPhrase()); } return new JSONObject(EntityUtils.toString(httpResponse.getEntity())); } finally { httpClient.getConnectionManager().shutdown(); } }