List of usage examples for org.apache.http.impl.conn SingleClientConnManager SingleClientConnManager
@Deprecated public SingleClientConnManager(final HttpParams params, final SchemeRegistry schreg)
From source file:org.wso2.carbon.dynamic.client.web.app.registration.util.RemoteDCRClient.java
private static DefaultHttpClient getHTTPSClient() { DefaultHttpClient httpClient = new DefaultHttpClient(); // Setup the HTTPS settings to accept any certificate. HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; SchemeRegistry registry = new SchemeRegistry(); SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); registry.register(new Scheme( DynamicClientWebAppRegistrationConstants.RemoteServiceProperties.DYNAMIC_CLIENT_SERVICE_PROTOCOL, socketFactory, getServerHTTPSPort())); SingleClientConnManager mgr = new SingleClientConnManager(httpClient.getParams(), registry); httpClient = new DefaultHttpClient(mgr, httpClient.getParams()); // Set verifier HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); return httpClient; }
From source file:com.cooliris.mediayemaha.UriTexture.java
@Override protected Bitmap load(RenderView view) { Bitmap bitmap = null;/* ww w .j av a2 s .co m*/ if (mUri == null) return bitmap; try { if (mUri.startsWith("http://")) { if (!isCached(Utils.Crc64Long(mUri), MAX_RESOLUTION_A)) { mConnectionManager = new SingleClientConnManager(HTTP_PARAMS, SCHEME_REGISTRY); } } bitmap = createFromUri(view.getContext(), mUri, MAX_RESOLUTION_A, MAX_RESOLUTION_B, mCacheId, mConnectionManager); } catch (Exception e2) { Log.e(TAG, "Unable to load image from URI " + mUri); e2.printStackTrace(); } return bitmap; }
From source file:info.semanticsoftware.semassist.android.activity.AuthenticationActivity.java
private String authenicate(String username, String password) { String uri = serverURL + "/user"; Log.d(Constants.TAG, uri);//from www. j a va 2s . c o m String request = "<authenticate><username>" + username + "</username><password>" + password + "</password></authenticate>"; Representation representation = new StringRepresentation(request, MediaType.APPLICATION_XML); String serverResponse = null; if (serverURL.indexOf("https") < 0) { Log.i(TAG, "Sending authentication request to " + uri); Representation response = new ClientResource(uri).post(representation); try { StringWriter writer = new StringWriter(); response.write(writer); serverResponse = writer.toString(); Log.i(TAG, "Authentication response: " + serverResponse); } catch (Exception e) { e.printStackTrace(); } } else { try { Log.i(TAG, "Sending authentication request to " + uri); HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; DefaultHttpClient client = new DefaultHttpClient(); SchemeRegistry registry = new SchemeRegistry(); final KeyStore ks = KeyStore.getInstance("BKS"); // NOTE: the keystore must have been generated with BKS 146 and not later final InputStream in = getApplicationContext().getResources() .openRawResource(R.raw.clientkeystorenew); try { ks.load(in, getString(R.string.keystorePassword).toCharArray()); } finally { in.close(); } SSLSocketFactory socketFactory = new CustomSSLSocketFactory(ks); socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); registry.register(new Scheme("https", socketFactory, 443)); SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry); DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams()); // Set verifier HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); HttpPost post = new HttpPost(uri); post.setEntity(new StringEntity(representation.getText())); HttpResponse response = httpClient.execute(post); HttpEntity entity = response.getEntity(); InputStream inputstream = entity.getContent(); InputStreamReader inputstreamreader = new InputStreamReader(inputstream); BufferedReader bufferedreader = new BufferedReader(inputstreamreader); String string = null; while ((string = bufferedreader.readLine()) != null) { serverResponse += string; } } catch (Exception e) { e.printStackTrace(); } } return serverResponse; }
From source file:com.ocp.media.UriTexture.java
@Override protected Bitmap load(RenderView view) { Bitmap bitmap = null;//w w w . java 2 s . c o m if (mUri == null) return bitmap; try { if (mUri.startsWith("http://")) { if (!isCached(Utils.Crc64Long(mUri), MAX_RESOLUTION_A)) { mConnectionManager = new SingleClientConnManager(HTTP_PARAMS, SCHEME_REGISTRY); } } bitmap = createFromUri(view.getContext(), mUri, MAX_RESOLUTION_A, MAX_RESOLUTION_B, mCacheId, mConnectionManager); } catch (Exception e2) { Log.e(Gallery.TAG, TAG + ": " + "Unable to load image from URI " + mUri); e2.printStackTrace(); } return bitmap; }
From source file:com.cooliris.media.UriTexture.java
@Override protected Bitmap load(RenderView view) { Bitmap bitmap = null;/*ww w.j a va2s . co m*/ if (mUri == null) return bitmap; try { Context context = view.getContext(); int max_resolution = context.getResources().getInteger(R.integer.max_resolution); int max_resolution_screennail = context.getResources().getInteger(R.integer.max_resolution_screennail); if (mUri.startsWith("http://")) { if (!isCached(Utils.Crc64Long(mUri), max_resolution)) { mConnectionManager = new SingleClientConnManager(HTTP_PARAMS, SCHEME_REGISTRY); } } if (mIsScreennail) { bitmap = createFromUri(context, mUri, max_resolution_screennail, max_resolution_screennail, mCacheId, mConnectionManager); } if (mIsHiRes) { bitmap = createFromUri(context, mUri, max_resolution, max_resolution, mCacheId, mConnectionManager); } } catch (Exception e2) { Log.e(TAG, "Unable to load image from URI " + mUri); e2.printStackTrace(); } return bitmap; }
From source file:net.sourceforge.jwbf.mediawiki.live.LoginTest.java
private AbstractHttpClient getSSLFakeHttpClient() throws NoSuchAlgorithmException, KeyManagementException { SSLContext sslContext = SSLContext.getInstance("SSL"); sslContext.init(null, new TrustManager[] { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; }/*from w w w . ja va 2 s . co m*/ public void checkClientTrusted(X509Certificate[] certs, String authType) { } public void checkServerTrusted(X509Certificate[] certs, String authType) { } } }, new SecureRandom()); SSLSocketFactory sf = new SSLSocketFactory(sslContext); sf.setHostnameVerifier(new X509HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } public void verify(String host, String[] cns, String[] subjectAlts) throws SSLException { } public void verify(String host, X509Certificate cert) throws SSLException { } public void verify(String host, SSLSocket ssl) throws IOException { } }); Scheme httpsScheme = new Scheme("https", sf, 443); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(httpsScheme); HttpParams params = new BasicHttpParams(); ClientConnectionManager cm = new SingleClientConnManager(params, schemeRegistry); DefaultHttpClient httpClient = new DefaultHttpClient(cm, params); return httpClient; }
From source file:net.vexelon.mobileops.GLBClient.java
/** * Initialize Http Client//www. j a v a2 s .c o m */ private void initHttpClient() { HttpParams params = new BasicHttpParams(); params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); params.setParameter(CoreProtocolPNames.USER_AGENT, UserAgentHelper.getRandomUserAgent()); //params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, HTTP.UTF_8); // Bugfix #1: The target server failed to respond params.setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE); DefaultHttpClient client = new DefaultHttpClient(params); httpCookieStore = new BasicCookieStore(); client.setCookieStore(httpCookieStore); httpContext = new BasicHttpContext(); httpContext.setAttribute(ClientContext.COOKIE_STORE, httpCookieStore); // Bugfix #1: Adding retry handler to repeat failed requests HttpRequestRetryHandler retryHandler = new HttpRequestRetryHandler() { @Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { if (executionCount >= MAX_REQUEST_RETRIES) { return false; } if (exception instanceof NoHttpResponseException || exception instanceof ClientProtocolException) { return true; } return false; } }; client.setHttpRequestRetryHandler(retryHandler); // SSL HostnameVerifier verifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; try { SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", new PlainSocketFactory(), 80)); registry.register(new Scheme("https", new TrustAllSocketFactory(), 443)); SingleClientConnManager connMgr = new SingleClientConnManager(client.getParams(), registry); httpClient = new DefaultHttpClient(connMgr, client.getParams()); } catch (InvalidAlgorithmParameterException e) { // Log.e(Defs.LOG_TAG, "", e); // init without connection manager httpClient = new DefaultHttpClient(client.getParams()); } HttpsURLConnection.setDefaultHostnameVerifier(verifier); }
From source file:com.etime.ETimeActivity.java
private DefaultHttpClient setupHttpClient() { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); HttpParams params = new BasicHttpParams(); params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30); params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30)); params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpClientParams.setRedirecting(params, false); ClientConnectionManager cm = new SingleClientConnManager(params, schemeRegistry); return (new DefaultHttpClient(cm, params)); }
From source file:org.xdi.oxauth.BaseTest.java
public static DefaultHttpClient createHttpClient(HostnameVerifierType p_verifierType) { if (p_verifierType != null && p_verifierType != HostnameVerifierType.DEFAULT) { switch (p_verifierType) { case ALLOW_ALL: HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; DefaultHttpClient client = new DefaultHttpClient(); SchemeRegistry registry = new SchemeRegistry(); SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); registry.register(new Scheme("https", socketFactory, 443)); SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry); // Set verifier HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); return new DefaultHttpClient(mgr, client.getParams()); case DEFAULT: return new DefaultHttpClient(); }// w ww .j av a 2 s . c o m } return new DefaultHttpClient(); }