List of usage examples for org.apache.http.client HttpClient getConnectionManager
@Deprecated ClientConnectionManager getConnectionManager();
From source file:org.jboss.as.test.http.util.HttpClientUtils.java
/** * Returns https ready client./*from w w w . j a va2 s . c o m*/ * * @param base * @return */ public static HttpClient wrapHttpsClient(HttpClient base) { try { 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:net.paissad.waqtsalat.service.utils.HttpUtils.java
/** * <p>/*from w w w . j a v a 2 s . c o m*/ * <b>Example</b>: <i>getFilenameFromURL(http://domain.com/aaa/bbb.zip)</i> * would return '<i>bbb.zip</i>' * </p> * <p> * <b>Note</b>: * <ul> * <li>This method will follow the url redirections and will return the name * of the file of the last URL which is among all redirections.</li> * <li>If the URL has no filename (Ex: <i>http://domain.com)</i>, then an * empty string is returned.</li> * </ul> * </p> * * @param url * @return The name of the file from the URL. * @throws WSException */ public static String getFilenameFromURL(final String url) throws WSException { HttpHead request = null; HttpClient client = null; try { request = (HttpHead) getNewHttpRequest(url, RequestType.HEAD, null); client = getNewHttpClient(); client.execute(request); String resourcePath = request.getURI().getPath(); return resourcePath.substring(resourcePath.lastIndexOf("/") + 1); } catch (Exception e) { throw new WSException("Error while retrieving the ressource name of the URL.", e); } finally { if (client != null) { client.getConnectionManager().shutdown(); } } }
From source file:org.mahasen.ssl.SSLWrapper.java
/** * @param base//from ww w. ja v a 2 s .c o m * @return */ public static HttpClient wrapClient(HttpClient base) { try { 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) { ex.printStackTrace(); return null; } }
From source file:com.datatorrent.demos.mapreduce.Util.java
public static String getJsonForURL(String url) { HttpClient httpclient = new DefaultHttpClient(); logger.debug(url);/* w ww.j a v a 2 s .c o m*/ try { HttpGet httpget = new HttpGet(url); // Create a response handler ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody; try { responseBody = httpclient.execute(httpget, responseHandler); } catch (ClientProtocolException e) { logger.debug(e.getMessage()); return null; } catch (IOException e) { logger.debug(e.getMessage()); return null; } catch (Exception e) { logger.debug(e.getMessage()); return null; } return responseBody.trim(); } finally { httpclient.getConnectionManager().shutdown(); } }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.utils.HttpQueryUtils.java
public static String[] fileUpload(String uploadUrl, String name, byte[] byteArray) throws IOException { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(uploadUrl); String paramName = "vehicle"; String paramValue = name;//from w w w. ja v a 2 s. co m MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); entity.addPart(paramName, new InputStreamBody((new ByteArrayInputStream(byteArray)), "application/zip")); entity.addPart(paramName, new StringBody(paramValue, "text/plain", Charset.forName("UTF-8"))); httppost.setEntity(entity); HttpResponse httpResponse = httpclient.execute(httppost); StatusLine statusLine = httpResponse.getStatusLine(); String reason = statusLine.getReasonPhrase(); int rc = statusLine.getStatusCode(); String response = EntityUtils.toString(httpResponse.getEntity(), "UTF-8"); httpclient.getConnectionManager().shutdown(); return new String[] { String.valueOf(rc), reason, response }; }
From source file:eu.lod2.ConfigurationTab.java
public static List<String> request_graphs(LOD2DemoState state) throws Exception { List<String> result = null; HttpClient httpclient = new DefaultHttpClient(); try {/* w w w . java 2 s . c om*/ String prefixurl = state.getLod2WebApiService(); HttpGet httpget = new HttpGet(prefixurl + "/graphs"); httpget.addHeader("accept", "application/json"); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = httpclient.execute(httpget, responseHandler); result = parse_graph_api_result(responseBody); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } return result; }
From source file:org.mahasen.ssl.WebClientSSLWrapper.java
/** * @param base/* w w w . j a v a2 s . c om*/ * @return */ public static HttpClient wrapClient(HttpClient base) { try { 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) { System.out.println("Error while configuring security certificate for client"); return null; } }
From source file:es.tsb.ltba.nomhad.httpclient.NomhadHttpClient.java
/** * Authentication/*from w w w .ja v a 2 s. c o m*/ * * @param base * the client to be configured * @return the authentication-enabled client */ private static DefaultHttpClient wrapClient(HttpClient base) { try { 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.gw2InfoViewer.controllers.MainController.java
public static EventList getEventListWithoutNames(Options options) throws IOException { String eventsUrl = API_BASE_URL + API_VERSION + API_EVENTS; eventsUrl += "?world_id=" + options.getWorld(); eventsUrl += "&map_id=" + options.getMap(); eventsUrl += "&event_id=" + options.getEventId(); EventList eventList;//from w w w .ja v a 2 s .com HttpClient httpClient; HttpGet getEvents; getEvents = new HttpGet(eventsUrl); if (options.isProxyEnabled()) { httpClient = HttpsConnectionFactory.getHttpsClientWithProxy(StartComRootCertificate, options.getProxyAddress(), options.getProxyPort()); } else { httpClient = HttpsConnectionFactory.getHttpsClient(StartComRootCertificate); } eventList = JsonConversionService .parseEventListWithoutNames(httpClient.execute(getEvents).getEntity().getContent()); httpClient.getConnectionManager().shutdown(); return eventList; }
From source file:Main.java
public static String getRepsonseString(String url, Map<String, String> params) { HttpPost request = new HttpPost(url); List<NameValuePair> p = new ArrayList<NameValuePair>(); for (String key : params.keySet()) { p.add(new BasicNameValuePair(key, params.get(key))); }/* w ww . java 2s .c om*/ HttpClient httpClient = new DefaultHttpClient(); String result = null; try { request.setEntity(new UrlEncodedFormEntity(p, HTTP.UTF_8)); HttpResponse response = httpClient.execute(request); if (response.getStatusLine().getStatusCode() == 200) { result = new String(EntityUtils.toString(response.getEntity()).getBytes("ISO_8859_1"), "UTF-8"); } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (httpClient != null) httpClient.getConnectionManager().shutdown(); } return result; }