List of usage examples for org.apache.http.client HttpClient getConnectionManager
@Deprecated ClientConnectionManager getConnectionManager();
From source file:org.thialfihar.android.apg.keyimport.HkpKeyserver.java
@Override public String get(String keyIdHex) throws QueryFailedException { HttpClient client = new DefaultHttpClient(); try {//from w ww.j av a 2 s .c om String query = "http://" + mHost + ":" + mPort + "/pks/lookup?op=get&options=mr&search=" + keyIdHex; Log.d(Constants.TAG, "hkp keyserver get: " + query); HttpGet get = new HttpGet(query); HttpResponse response = client.execute(get); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new QueryFailedException("not found"); } HttpEntity entity = response.getEntity(); InputStream is = entity.getContent(); String data = readAll(is, EntityUtils.getContentCharSet(entity)); Matcher matcher = PgpHelper.PGP_PUBLIC_KEY.matcher(data); if (matcher.find()) { return matcher.group(1); } } catch (IOException e) { // nothing to do, better luck on the next keyserver } finally { client.getConnectionManager().shutdown(); } return null; }
From source file:fr.ortolang.discovery.keycloak.KeycloakSynchronizer.java
public void deleteIDP(AccessTokenResponse res, String alias) throws Failure, UnsupportedEncodingException { HttpClient client = new HttpClientBuilder().disableTrustManager().build(); try {// w ww .ja v a2 s . c o m HttpDelete delete = new HttpDelete(UriBuilder .fromUri(baseUrl + "/admin/realms/" + realm + "/identity-provider/instances/" + alias).build()); delete.addHeader("Authorization", "Bearer " + res.getToken()); delete.addHeader("Content-type", "application/json"); try { HttpResponse response = client.execute(delete); if (response.getStatusLine().getStatusCode() != 204) { throw new Failure(response.getStatusLine().getStatusCode()); } } catch (IOException e) { throw new RuntimeException(e); } } finally { client.getConnectionManager().shutdown(); } }
From source file:org.jboss.as.test.clustering.cluster.web.passivation.SessionPassivationAbstractCase.java
/** * Test that session is not passivated before minimum idle time (passivation-min-idle-time) is reached. * * @throws Exception/*from ww w. j a va 2 s.c o m*/ */ @Test public void testSessionPassivationWithMinIdleTime( @ArquillianResource @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1) throws Exception { // Create an instance of HttpClient HttpClient client = HttpClientUtils.relaxedCookieHttpClient(); try { // Setup the session HttpResponse response = ClusterHttpClientUtil.tryGet(client, baseURL1 + SimpleServlet.URL); Assert.assertFalse("Session should not be serialized", Boolean.valueOf(response.getFirstHeader(SimpleServlet.HEADER_SERIALIZED).getValue())); response.getEntity().getContent().close(); // Sleep for less than passivation-min-idle-time Thread.sleep(PASSIVATION_MIN_IDLE_TIME * 1000 - 100); // Make sure the session hasn't passivated already response = ClusterHttpClientUtil.tryGet(client, baseURL1 + SimpleServlet.URL); Assert.assertFalse("Session should not have been passivated", Boolean.valueOf(response.getFirstHeader(SimpleServlet.HEADER_SERIALIZED).getValue())); Assert.assertEquals(2, Integer.parseInt(response.getFirstHeader("value").getValue())); response.getEntity().getContent().close(); } finally { client.getConnectionManager().shutdown(); } }
From source file:no.kantega.kwashc.server.test.SSLProtocolTest.java
private HttpResponse checkClient(Site site, int httpsPort, HttpClient httpclient, String[] protocols, String[] ciphers) throws NoSuchAlgorithmException, KeyManagementException, IOException { SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, new TrustManager[] { allowAllTrustManager }, null); SSLSocketFactory sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 1000); params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 1000); SSLSocket socket = (SSLSocket) sf.createSocket(params); if (protocols != null) { socket.setEnabledProtocols(protocols); }/*from w ww . jav a 2 s . c o m*/ if (ciphers != null) { socket.setEnabledCipherSuites(ciphers); } URL url = new URL(site.getAddress()); InetSocketAddress address = new InetSocketAddress(url.getHost(), httpsPort); sf.connectSocket(socket, address, null, params); Scheme sch = new Scheme("https", httpsPort, sf); httpclient.getConnectionManager().getSchemeRegistry().register(sch); HttpGet request = new HttpGet( "https://" + url.getHost() + ":" + site.getSecureport() + url.getPath() + "blog"); return httpclient.execute(request); }
From source file:org.owasp.goatdroid.herdfinancial.requestresponse.RestClient.java
private void executeRequest(HttpUriRequest request, String url, Context context) { HttpClient client = CustomSSLSocketFactory.getNewHttpClient(); HashMap<String, String> proxyInfo = Utils.getProxyMap(context); String proxyHost = proxyInfo.get("proxyHost"); String proxyPort = proxyInfo.get("proxyPort"); if (!(proxyHost.equals("") || proxyPort.equals(""))) { HttpHost proxy = new HttpHost(proxyHost, Integer.parseInt(proxyPort)); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); }//from w ww .ja va 2 s . co m HttpResponse httpResponse; try { httpResponse = client.execute(request); responseCode = httpResponse.getStatusLine().getStatusCode(); message = httpResponse.getStatusLine().getReasonPhrase(); HttpEntity entity = httpResponse.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); response = convertStreamToString(instream); // Closing the input stream will trigger connection release instream.close(); } } catch (ClientProtocolException e) { client.getConnectionManager().shutdown(); } catch (IOException e) { client.getConnectionManager().shutdown(); } }
From source file:ilarkesto.net.ApacheHttpDownloader.java
private HttpClient wrapClientForDisabledServerChecking(HttpClient client) { try {/*from w w w .ja v a 2s .com*/ X509TrustManager tm = new X509TrustManager() { @Override public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } @Override public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } @Override public X509Certificate[] getAcceptedIssuers() { return null; } }; SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new UnsecureSSLSocketFactory(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 DefaultHttpClient(ccm, client.getParams()); } catch (Exception ex) { return null; } }
From source file:org.csware.ee.utils.Tools.java
public static String UpLoadListValue(String path, List<NameValuePair> formparams) { String json = null;// w ww . j a va2 s. co m InputStream is = null; HttpClient hc = new DefaultHttpClient(); HttpPost post = new HttpPost(path); UrlEncodedFormEntity entity; HttpResponse response = null; try { entity = new UrlEncodedFormEntity(formparams, "UTF-8"); post.addHeader("Accept", "text/javascript, text/html, application/xml, text/xml"); post.addHeader("Accept-Charset", "GBK,utf-8;q=0.7,*;q=0.3"); post.addHeader("Accept-Encoding", "gzip,deflate,sdch"); post.addHeader("Connection", "Keep-Alive"); post.addHeader("Cache-Control", "no-cache"); post.addHeader("Content-Type", "application/x-www-form-urlencoded"); post.setEntity(entity); response = hc.execute(post); System.out.println(response.getStatusLine().getStatusCode()); HttpEntity e = response.getEntity(); if (200 == response.getStatusLine().getStatusCode()) { if (!e.equals(null)) { json = EntityUtils.toString(e); //Log.i("Tools UpLoadListValue",json); // Log.i("Tools UpLoadListValue ucode", URLDecoder.decode(json, "utf-8")); } System.out.println("?"); } else { System.out.println(""); } hc.getConnectionManager().shutdown(); } catch (Exception e) { e.printStackTrace(); } return json; }
From source file:org.asqatasun.contentloader.DownloaderImpl.java
private String download(String url) { HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(url); httpclient.getParams().setParameter("http.socket.timeout", Integer.valueOf(10000)); httpclient.getParams().setParameter("http.connection.timeout", Integer.valueOf(10000)); // Create a response handler ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody;//from w w w. j a va 2 s . c o m try { responseBody = httpclient.execute(httpget, responseHandler); } catch (HttpResponseException ex) { LOGGER.warn(ex.getMessage() + " " + url); return ""; } catch (UnknownHostException ex) { LOGGER.warn(ex.getMessage() + " " + url); return ""; } catch (SSLPeerUnverifiedException ex) { LOGGER.warn(ex.getMessage() + " " + url); return ""; } catch (IOException ex) { LOGGER.warn(ex.getMessage() + " " + url); return ""; } // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); return responseBody; }
From source file:co.forsaken.api.json.JsonWebCall.java
public String executeGet() { if (_log)/*from w w w. j ava 2s.c om*/ System.out.println("Requested: [" + _url + "]"); try { canConnect(); } catch (Exception ex) { ex.printStackTrace(); return null; } HttpClient httpClient = new DefaultHttpClient(_connectionManager); InputStream in = null; String res = null; try { HttpGet request = new HttpGet(_url); request.setHeader("Content-Type", "application/json"); HttpResponse response = httpClient.execute(request); if (response != null) { in = response.getEntity().getContent(); res = convertStreamToString(in); } } catch (Exception ex) { System.out.println("JSONWebCall.execute() Error: \n" + ex.getMessage()); System.out.println("Result: \n" + res); StackTraceElement[] arrOfSTE; int max = (arrOfSTE = ex.getStackTrace()).length; for (int i = 0; i < max; i++) { StackTraceElement trace = arrOfSTE[i]; System.out.println(trace); } } finally { httpClient.getConnectionManager().shutdown(); if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } if (_log) System.out.println("Returned: [" + _url + "] [" + res + "]"); return res; }