List of usage examples for org.apache.http.client HttpClient getConnectionManager
@Deprecated ClientConnectionManager getConnectionManager();
From source file:projekat.rest_client.Test.java
public static void main2(String[] args) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { String uri = "https://localhost:8443/secure/rest/places"; RestTemplateFactory factory = new RestTemplateFactory(); factory.afterPropertiesSet();// w w w . ja v a 2 s.c om RestTemplate restTemplate = factory.getObject(); // restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity<T>(createHeaders("marko", "marko")), List.class); HttpClient httpClient = factory.getAuth().getHttpClient(); TrustStrategy acceptingTrustStrategy = new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] certificate, String authType) { return true; } }; SSLSocketFactory sf = new SSLSocketFactory(acceptingTrustStrategy, ALLOW_ALL_HOSTNAME_VERIFIER); httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 8443, sf)); ResponseEntity<List> exchange = restTemplate.exchange(uri, HttpMethod.POST, new HttpEntity<>(createHeaders("marko", "marko")), List.class); List body = exchange.getBody(); for (Object object : body) { System.out.println("Mesto: " + object); } System.out.println("******************"); ResponseEntity<List> forEntity = restTemplate.getForEntity(uri, List.class); List body1 = forEntity.getBody(); for (Object object : body1) { System.out.println("Mesto: " + object); } }
From source file:com.lugia.timetable.SSLHttpClient.java
public static SSLHttpClient getHttpClient() throws KeyManagementException, KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException { HttpClient client = new DefaultHttpClient(); X509TrustManager tm = createX509TrustManager(); SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new MySSLSocketFactory(ctx); ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = client.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", ssf, 443)); return new SSLHttpClient(new ThreadSafeClientConnManager(client.getParams(), sr), client.getParams()); }
From source file:org.openremote.android.console.util.HTTPUtil.java
/** * Down load file and store it in local context. * //from ww w .java 2 s . co m * @param serverUrl the current server url * @param fileName the file name for downloading * * @return the int */ private static int downLoadFile(Context context, String serverUrl, String fileName) { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 5 * 1000); HttpConnectionParams.setSoTimeout(params, 5 * 1000); HttpClient client = new DefaultHttpClient(params); int statusCode = ControllerException.CONTROLLER_UNAVAILABLE; try { URL uri = new URL(serverUrl); if ("https".equals(uri.getProtocol())) { Scheme sch = new Scheme(uri.getProtocol(), new SelfCertificateSSLSocketFactory(context), uri.getPort()); client.getConnectionManager().getSchemeRegistry().register(sch); } HttpGet get = new HttpGet(serverUrl); SecurityUtil.addCredentialToHttpRequest(context, get); HttpResponse response = client.execute(get); statusCode = response.getStatusLine().getStatusCode(); if (statusCode == Constants.HTTP_SUCCESS) { FileOutputStream fOut = context.openFileOutput(fileName, Context.MODE_PRIVATE); InputStream is = response.getEntity().getContent(); byte buf[] = new byte[1024]; int len; while ((len = is.read(buf)) > 0) { fOut.write(buf, 0, len); } fOut.close(); is.close(); } } catch (MalformedURLException e) { Log.e("OpenRemote-HTTPUtil", "Create URL fail:" + serverUrl); } catch (IllegalArgumentException e) { Log.e("OpenRemote-IllegalArgumentException", "Download file " + fileName + " failed with URL: " + serverUrl, e); } catch (ClientProtocolException cpe) { Log.e("OpenRemote-ClientProtocolException", "Download file " + fileName + " failed with URL: " + serverUrl, cpe); } catch (IOException ioe) { Log.e("OpenRemote-IOException", "Download file " + fileName + " failed with URL: " + serverUrl, ioe); } return statusCode; }
From source file:com.mber.client.HTTParty.java
private static Call execute(final HttpUriRequest request) throws IOException { HttpClient client = new DefaultHttpClient(); try {/*from w w w. j a v a 2s .c o m*/ request.addHeader("REST-API-Version", MBER_VERSION); HttpResponse response = client.execute(request); String body = toString(response.getEntity().getContent()); return new Call(request.getMethod(), request.getURI(), response.getStatusLine().getStatusCode(), body); } finally { client.getConnectionManager().shutdown(); } }
From source file:org.zywx.wbpalmstar.platform.push.report.PushReportHttpClient.java
public static void close() { for (HttpClient httpClient : httpClients) { if (httpClient != null) { httpClient.getConnectionManager().shutdown(); httpClient = null;//from ww w. j ava 2 s . c om } } httpClients.clear(); }
From source file:com.appdynamics.openstack.nova.RestClient.java
static String getResponseString(HttpClient httpClient, HttpResponse response) throws Exception { try {/*from ww w.j av a 2 s . co m*/ HttpEntity reponseEntity = response.getEntity(); if (reponseEntity != null) { String responseString = EntityUtils.toString(reponseEntity); return responseString; } else { return ""; } } catch (Exception e) { throw e; } finally { httpClient.getConnectionManager().shutdown(); } }
From source file:csiro.pidsvc.helper.Http.java
public static String simpleGetRequest(String uri) { HttpClient httpClient = new DefaultHttpClient(); try {/* w w w .j a va 2s . c o m*/ HttpGet httpGet = new HttpGet(uri); // Get the data. HttpResponse response = httpClient.execute(httpGet); HttpEntity entity = response.getEntity(); // Return content. return EntityUtils.toString(entity); } catch (Exception e) { _logger.warn("Exception occurred while executing an HTTP request.", e); return null; } finally { httpClient.getConnectionManager().shutdown(); } }
From source file:com.upyun.sdk.utils.HttpClientUtils.java
@SuppressWarnings("deprecation") public static HttpClient getInstance() { HttpClient client = new DefaultHttpClient(); SSLContext ctx = null;/*from w w w.j a v a 2 s . c om*/ try { ctx = SSLContext.getInstance("TLS"); ctx.init(null, new TrustManager[] { tm }, null); } catch (Exception e) { LogUtil.exception(logger, e); } SSLSocketFactory ssf = new SSLSocketFactory(ctx); ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = client.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", ssf, 443)); client = new DefaultHttpClient(ccm, client.getParams()); return client; }
From source file:jp.co.conit.sss.sn.ex1.util.SNApiUtil.java
private static SNServerResult post(String url, List<NameValuePair> postData, SNServerResult result) { try {//from www. java 2 s. c om HttpClient httpCli = new DefaultHttpClient(); HttpPost post = new HttpPost(url); post.setEntity(new UrlEncodedFormEntity(postData, "utf-8")); HttpResponse response = httpCli.execute(post); int status = response.getStatusLine().getStatusCode(); result.mHttpStatus = status; HttpEntity entity = response.getEntity(); if (entity != null) { String responseBodyText = EntityUtils.toString(entity); entity.consumeContent(); httpCli.getConnectionManager().shutdown(); result.mResponseString = responseBodyText; } } catch (Exception e) { result.mCauseException = e; e.printStackTrace(); } return result; }
From source file:jp.co.conit.sss.sn.ex2.util.SNApiUtil.java
/** * GET????<br>/*from www .j ava 2s .c o m*/ * Exception????????<br> * HTTP?SUCCESS???????SNServerResult??????? * * @param url * @param result * @return */ private static SNServerResult get(String url, SNServerResult result) { try { Log.d("SN", "GET url:" + url); HttpClient httpCli = new DefaultHttpClient(); HttpGet get = new HttpGet(url); HttpResponse response = httpCli.execute(get); int status = response.getStatusLine().getStatusCode(); result.mHttpStatus = status; HttpEntity entity = response.getEntity(); if (entity != null) { String responseBodyText = EntityUtils.toString(entity); entity.consumeContent(); httpCli.getConnectionManager().shutdown(); result.mResponseString = responseBodyText; Log.d("SN", "GET response:" + responseBodyText); } } catch (Exception e) { result.mCauseException = e; e.printStackTrace(); } return result; }