Java Code Examples for org.apache.http.conn.scheme.Scheme
The following code examples are extracted from open source projects. You can click to
vote up the examples that are useful to you.
Example 1
From project androidannotations, under directory /AndroidAnnotations/functional-test-1-5-tests/src/test/java/com/googlecode/androidannotations/test15/.
Source file: SSLConnectionTest.java

@Test public void truststoreProvided(){ assertNotNull(activity.mHttpsClientTest1); ClientConnectionManager ccm=activity.mHttpsClientTest1.getConnectionManager(); assertNotNull(ccm); Scheme httpsScheme=ccm.getSchemeRegistry().getScheme("https"); assertNotNull(httpsScheme); assertEquals(443,httpsScheme.getDefaultPort()); SocketFactory socketFactHttps=httpsScheme.getSocketFactory(); if (!(socketFactHttps instanceof SSLSocketFactory)) { Assert.fail("wrong instance should be org.apache.http.conn.ssl.SSLSocketFactory, getting " + socketFactHttps); } assertEquals(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER,((SSLSocketFactory)socketFactHttps).getHostnameVerifier()); }
Example 2
From project httpClient, under directory /httpclient/src/test/java/org/apache/http/conn/.
Source file: TestScheme.java

@Test public void testHashCode(){ Scheme http=new Scheme("http",80,PlainSocketFactory.getSocketFactory()); Scheme myhttp=new Scheme("http",80,PlainSocketFactory.getSocketFactory()); Scheme https=new Scheme("https",443,SecureSocketFactoryMockup.INSTANCE); Assert.assertTrue(http.hashCode() != https.hashCode()); Assert.assertTrue(http.hashCode() == myhttp.hashCode()); }
Example 3
From project overthere, under directory /src/main/java/com/xebialabs/overthere/cifs/winrm/connector/.
Source file: ApacheHttpComponentsHttpClientHttpConnector.java

/** * Configure certificate trust strategy and hostname verifier strategy for the HttpClient */ private void configureTrust(final DefaultHttpClient httpclient) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { if (!"https".equalsIgnoreCase(getTargetURL().getProtocol())) { return; } final TrustStrategy trustStrategy=httpsCertTrustStrategy.getStrategy(); final X509HostnameVerifier hostnameVerifier=httpsHostnameVerifyStrategy.getVerifier(); final SSLSocketFactory socketFactory=new SSLSocketFactory(trustStrategy,hostnameVerifier); final Scheme sch=new Scheme("https",443,socketFactory); httpclient.getConnectionManager().getSchemeRegistry().register(sch); }
Example 4
From project qi4j-libraries, under directory /shiro-core/src/test/java/org/qi4j/library/shiro/.
Source file: StrictX509Test.java

@Test public void test() throws IOException { HttpGet get=new HttpGet(SECURED_SERVLET_PATH); ResponseHandler<String> responseHandler=new BasicResponseHandler(); DefaultHttpClient client=new DefaultHttpClient(); SSLSocketFactory sslsf=new SSLSocketFactory(X509FixturesData.clientSSLContext()); sslsf.setHostnameVerifier(new AllowAllHostnameVerifier()); Scheme https=new Scheme("https",sslsf,httpHost.getPort()); client.getConnectionManager().getSchemeRegistry().register(https); String response=client.execute(httpHost,get,responseHandler); assertEquals(ServletUsingSecuredService.OK,response); }
Example 5
From project Airports, under directory /src/com/nadmm/airports/utils/.
Source file: NetworkUtils.java

public static HttpClient getHttpClient(){ SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); HttpParams params=new BasicHttpParams(); ClientConnectionManager cm=new ThreadSafeClientConnManager(params,registry); HttpClient client=new DefaultHttpClient(cm,params); return client; }
Example 6
From project android-rackspacecloud, under directory /extensions/apachehc/src/main/java/org/jclouds/http/apachehc/config/.
Source file: ApacheHCHttpCommandExecutorServiceModule.java

@Singleton @Provides ClientConnectionManager newClientConnectionManager(HttpParams params,X509HostnameVerifier verifier,Closer closer) throws NoSuchAlgorithmException, KeyManagementException { SchemeRegistry schemeRegistry=new SchemeRegistry(); Scheme http=new Scheme("http",PlainSocketFactory.getSocketFactory(),80); SSLContext context=SSLContext.getInstance("TLS"); context.init(null,null,null); SSLSocketFactory sf=new SSLSocketFactory(context); sf.setHostnameVerifier(verifier); Scheme https=new Scheme("https",sf,443); SchemeRegistry sr=new SchemeRegistry(); sr.register(http); sr.register(https); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); final ClientConnectionManager cm=new ThreadSafeClientConnManager(params,schemeRegistry); closer.addToClose(new Closeable(){ @Override public void close() throws IOException { cm.shutdown(); } } ); return cm; }
Example 7
From project anode, under directory /src/net/haltcondition/anode/.
Source file: WebtoolsHttpClient.java

@Override protected ClientConnectionManager createClientConnectionManager(){ SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registry.register(new Scheme("https",newSslSocketFactory(),443)); return new SingleClientConnManager(getParams(),registry); }
Example 8
From project apps-for-android, under directory /Photostream/src/com/google/android/photostream/.
Source file: Flickr.java

private void Flickr(){ final HttpParams params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params,"UTF-8"); final SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); final ThreadSafeClientConnManager manager=new ThreadSafeClientConnManager(params,registry); mClient=new DefaultHttpClient(manager,params); }
Example 9
From project bbb-java, under directory /src/main/java/org/mconf/web/.
Source file: Authentication.java

@SuppressWarnings("deprecation") public Authentication(String server,String username,String password) throws HttpException, IOException { this.server=server; SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",new PlainSocketFactory(),80)); registry.register(new Scheme("https",new FakeSocketFactory(),443)); HttpParams params=new BasicHttpParams(); params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS,false); client=new DefaultHttpClient(new ThreadSafeClientConnManager(params,registry),params); authenticated=authenticate(username,password); }
Example 10
From project capedwarf-blue, under directory /urlfetch/src/main/java/org/jboss/capedwarf/urlfetch/.
Source file: JBossURLFetchService.java

protected HttpClient getClient(){ if (client == null) { SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",80,PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https",443,SSLSocketFactory.getSocketFactory())); HttpParams params=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params,30 * 1000); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params,"UTF-8"); ClientConnectionManager ccm=new ThreadSafeClientConnManager(schemeRegistry); client=new DefaultHttpClient(ccm,params); } return client; }
Example 11
From project capedwarf-green, under directory /connect/src/main/java/org/jboss/capedwarf/connect/server/.
Source file: ServerProxyHandler.java

/** * Create and initialize scheme registry. * @return the scheme registry */ protected SchemeRegistry createSchemeRegistry(){ SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",config.getPlainFactory(),config.getPort())); schemeRegistry.register(new Scheme("https",config.getSslFactory(),config.getSslPort())); return schemeRegistry; }
Example 12
From project crest, under directory /core/src/test/java/org/codegist/crest/io/http/.
Source file: HttpClientFactoryTest.java

@Test public void createWithMoreThanOneShouldCreateDefaultHttpClientWithConnectionManagerSetup() throws Exception { DefaultHttpClient expected=mock(DefaultHttpClient.class); ProxySelectorRoutePlanner planner=mock(ProxySelectorRoutePlanner.class); ClientConnectionManager clientConnectionManager=mock(ClientConnectionManager.class); SchemeRegistry schemeRegistry=new SchemeRegistry(); ProxySelector proxySelector=mock(ProxySelector.class); BasicHttpParams httpParams=mock(BasicHttpParams.class); ConnPerRouteBean routeBean=mock(ConnPerRouteBean.class); PlainSocketFactory plainSocketFactory=mock(PlainSocketFactory.class); SSLSocketFactory sslSocketFactory=mock(SSLSocketFactory.class); Scheme plainScheme=new Scheme("http",plainSocketFactory,80); Scheme sslScheme=new Scheme("https",sslSocketFactory,443); ThreadSafeClientConnManager threadSafeClientConnManager=mock(ThreadSafeClientConnManager.class); when(expected.getConnectionManager()).thenReturn(clientConnectionManager); when(clientConnectionManager.getSchemeRegistry()).thenReturn(schemeRegistry); mockStatic(ProxySelector.class); when(ProxySelector.getDefault()).thenReturn(proxySelector); mockStatic(PlainSocketFactory.class); when(PlainSocketFactory.getSocketFactory()).thenReturn(plainSocketFactory); mockStatic(SSLSocketFactory.class); when(SSLSocketFactory.getSocketFactory()).thenReturn(sslSocketFactory); whenNew(SchemeRegistry.class).withNoArguments().thenReturn(schemeRegistry); whenNew(Scheme.class).withArguments("http",plainSocketFactory,80).thenReturn(plainScheme); whenNew(Scheme.class).withArguments("https",sslSocketFactory,443).thenReturn(sslScheme); whenNew(ThreadSafeClientConnManager.class).withArguments(httpParams,schemeRegistry).thenReturn(threadSafeClientConnManager); whenNew(ConnPerRouteBean.class).withArguments(2).thenReturn(routeBean); whenNew(BasicHttpParams.class).withNoArguments().thenReturn(httpParams); whenNew(DefaultHttpClient.class).withArguments(threadSafeClientConnManager,httpParams).thenReturn(expected); whenNew(ProxySelectorRoutePlanner.class).withArguments(schemeRegistry,proxySelector).thenReturn(planner); when(crestConfig.getConcurrencyLevel()).thenReturn(2); HttpClient actual=HttpClientFactory.create(crestConfig,getClass()); assertSame(expected,actual); verify(expected).setRoutePlanner(planner); verify(httpParams).setParameter(CoreProtocolPNames.PROTOCOL_VERSION,HttpVersion.HTTP_1_1); verify(httpParams).setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE,routeBean); verify(httpParams).setIntParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS,2); assertSame(plainScheme,schemeRegistry.getScheme("http")); assertSame(sslScheme,schemeRegistry.getScheme("https")); }
Example 13
From project DeliciousDroid, under directory /src/com/deliciousdroid/client/.
Source file: HttpClientFactory.java

public static HttpClient getThreadSafeClient(){ HttpParams params=new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params,100); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpConnectionParams.setConnectionTimeout(params,REGISTRATION_TIMEOUT); HttpConnectionParams.setSoTimeout(params,REGISTRATION_TIMEOUT); ConnManagerParams.setTimeout(params,REGISTRATION_TIMEOUT); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager mgr=new ThreadSafeClientConnManager(params,schemeRegistry); HttpClient client=new DefaultHttpClient(mgr,params); return client; }
Example 14
From project dreamDroid, under directory /src/net/reichholf/dreamdroid/helpers/.
Source file: SimpleHttpClient.java

/** * @return ThreadSafeClientConnManager Instance */ public ThreadSafeClientConnManager getEasySSLClientConnectionManager(){ BasicHttpParams params=new BasicHttpParams(); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",new EasySSLSocketFactory(),443)); ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(params,schemeRegistry); return cm; }
Example 15
From project eve-api, under directory /cdi/src/main/java/org/onsteroids/eve/api/connector/http/.
Source file: PooledHttpApiConnection.java

/** * Initializses and configures the http client connection pool. */ private void initializeHttpClient(){ LOG.debug("Configuring the HttpClientPool with a maximum of {} connections",maxConnections); HttpParams params=new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params,maxConnections); ConnPerRouteBean connPerRoute=new ConnPerRouteBean(maxConnections); HttpHost serverHost=new HttpHost(serverUri.getHost(),serverUri.getPort()); connPerRoute.setMaxForRoute(new HttpRoute(serverHost),maxConnections); ConnManagerParams.setMaxConnectionsPerRoute(params,connPerRoute); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager cm=new ThreadSafeClientConnManager(params,schemeRegistry); httpClient=new DefaultHttpClient(cm,params); }
Example 16
From project exo.social.client, under directory /src/main/java/org/exoplatform/social/client/core/net/.
Source file: SocialHttpClientImpl.java

/** * Create a new HttpClient with reasonable defaults. * @return SocialHttpClient for you to use for all your requests. */ public static SocialHttpClient newInstance(){ HttpParams params=new BasicHttpParams(); HttpConnectionParams.setStaleCheckingEnabled(params,false); HttpConnectionParams.setConnectionTimeout(params,SOCKET_OPERATION_TIMEOUT); HttpConnectionParams.setSoTimeout(params,SOCKET_OPERATION_TIMEOUT); HttpConnectionParams.setSocketBufferSize(params,8192); HttpClientParams.setRedirecting(params,false); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); ClientConnectionManager manager=new ThreadSafeClientConnManager(params,schemeRegistry); return new SocialHttpClientImpl(manager,params); }
Example 17
From project fanfoudroid, under directory /src/com/ch_linghu/fanfoudroid/http/.
Source file: HttpClient.java

/** * Setup DefaultHttpClient Use ThreadSafeClientConnManager. */ private void prepareHttpClient(){ if (DEBUG) { enableDebug(); } HttpParams params=new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params,10); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(params,schemeRegistry); mClient=new DefaultHttpClient(cm,params); mClient.addResponseInterceptor(gzipResponseIntercepter); }
Example 18
From project FlipDroid, under directory /app/src/com/goal98/flipdroid2/client/.
Source file: HttpClientFactory.java

public static synchronized HttpClient getHttpClient(){ if (client == null) { HttpParams params=new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params,MAX_TOTAL_CONNECTIONS); ConnPerRouteBean connPerRoute=new ConnPerRouteBean(MAX_PER_ROUTE); ConnManagerParams.setMaxConnectionsPerRoute(params,connPerRoute); SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); ClientConnectionManager cm=new ThreadSafeClientConnManager(params,registry); client=new DefaultHttpClient(cm,params); } System.out.println("return cached client"); return client; }
Example 19
From project Fotolia-API, under directory /java/libs/httpcomponents-client-4.1.2/examples/org/apache/http/examples/client/.
Source file: ClientCustomSSL.java

public final static void main(String[] args) throws Exception { DefaultHttpClient httpclient=new DefaultHttpClient(); try { KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType()); FileInputStream instream=new FileInputStream(new File("my.keystore")); try { trustStore.load(instream,"nopassword".toCharArray()); } finally { try { instream.close(); } catch ( Exception ignore) { } } SSLSocketFactory socketFactory=new SSLSocketFactory(trustStore); Scheme sch=new Scheme("https",443,socketFactory); httpclient.getConnectionManager().getSchemeRegistry().register(sch); HttpGet httpget=new HttpGet("https://localhost/"); System.out.println("executing request" + httpget.getRequestLine()); HttpResponse response=httpclient.execute(httpget); HttpEntity entity=response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); } EntityUtils.consume(entity); } finally { httpclient.getConnectionManager().shutdown(); } }
Example 20
From project Game_3, under directory /android/src/playn/android/.
Source file: AndroidHttpClient.java

/** * Create a new HttpClient with reasonable defaults (which you can update). * @param userAgent to report in your HTTP requests. * @return AndroidHttpClient for you to use for all your requests. */ public static AndroidHttpClient newInstance(String userAgent){ HttpParams params=new BasicHttpParams(); HttpConnectionParams.setStaleCheckingEnabled(params,false); HttpConnectionParams.setConnectionTimeout(params,20 * 1000); HttpConnectionParams.setSoTimeout(params,20 * 1000); HttpConnectionParams.setSocketBufferSize(params,8192); HttpClientParams.setRedirecting(params,false); HttpProtocolParams.setUserAgent(params,userAgent); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager manager=new ThreadSafeClientConnManager(params,schemeRegistry); return new AndroidHttpClient(manager,params); }
Example 21
From project httpbuilder, under directory /src/main/java/groovyx/net/http/.
Source file: AsyncHTTPBuilder.java

/** * Initializes threading parameters for the HTTPClient's {@link ThreadSafeClientConnManager}, and this class' ThreadPoolExecutor. */ protected void initThreadPools(final int poolSize,final ExecutorService threadPool){ if (poolSize < 1) throw new IllegalArgumentException("poolSize may not be < 1"); HttpParams params=client != null ? client.getParams() : new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params,poolSize); ConnManagerParams.setMaxConnectionsPerRoute(params,new ConnPerRouteBean(poolSize)); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager cm=new ThreadSafeClientConnManager(params,schemeRegistry); super.client=new DefaultHttpClient(cm,params); this.threadPool=threadPool != null ? threadPool : new ThreadPoolExecutor(poolSize,poolSize,120,TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>()); }
Example 22
From project httpcache4j, under directory /resolvers/resolvers-httpcomponents-httpclient/src/main/java/org/codehaus/httpcache4j/resolver/.
Source file: HTTPClientResponseResolver.java

public static HTTPClientResponseResolver createMultithreadedInstance(){ SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(new BasicHttpParams(),schemeRegistry); return new HTTPClientResponseResolver(new DefaultHttpClient(cm,new BasicHttpParams())); }
Example 23
From project huiswerk, under directory /print/zxing-1.6/android/src/com/google/zxing/client/android/.
Source file: AndroidHttpClient.java

/** * Create a new HttpClient with reasonable defaults (which you can update). * @param userAgent to report in your HTTP requests. * @return AndroidHttpClient for you to use for all your requests. */ public static AndroidHttpClient newInstance(String userAgent){ HttpParams params=new BasicHttpParams(); HttpConnectionParams.setStaleCheckingEnabled(params,false); HttpConnectionParams.setConnectionTimeout(params,20 * 1000); HttpConnectionParams.setSoTimeout(params,20 * 1000); HttpConnectionParams.setSocketBufferSize(params,8192); HttpClientParams.setRedirecting(params,false); HttpProtocolParams.setUserAgent(params,userAgent); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager manager=new ThreadSafeClientConnManager(params,schemeRegistry); return new AndroidHttpClient(manager,params); }
Example 24
From project ihatovgram, under directory /src/client/android/ihatovgram/lib/httpcomponents-client-4.1.3/examples/org/apache/http/examples/client/.
Source file: ClientCustomSSL.java

public final static void main(String[] args) throws Exception { DefaultHttpClient httpclient=new DefaultHttpClient(); try { KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType()); FileInputStream instream=new FileInputStream(new File("my.keystore")); try { trustStore.load(instream,"nopassword".toCharArray()); } finally { try { instream.close(); } catch ( Exception ignore) { } } SSLSocketFactory socketFactory=new SSLSocketFactory(trustStore); Scheme sch=new Scheme("https",443,socketFactory); httpclient.getConnectionManager().getSchemeRegistry().register(sch); HttpGet httpget=new HttpGet("https://localhost/"); System.out.println("executing request" + httpget.getRequestLine()); HttpResponse response=httpclient.execute(httpget); HttpEntity entity=response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); } EntityUtils.consume(entity); } finally { httpclient.getConnectionManager().shutdown(); } }
Example 25
From project iSpace, under directory /base/httpcrawler/src/main/java/com/villemos/ispace/httpcrawler/.
Source file: HttpClientConfigurer.java

public static HttpClient setupClient(boolean ignoreAuthenticationFailure,String domain,Integer port,String proxyHost,Integer proxyPort,String authUser,String authPassword,CookieStore cookieStore) throws NoSuchAlgorithmException, KeyManagementException { DefaultHttpClient client=null; if (ignoreAuthenticationFailure) { SSLContext sslContext=SSLContext.getInstance("SSL"); sslContext.init(null,new TrustManager[]{new EasyX509TrustManager()},new SecureRandom()); SchemeRegistry schemeRegistry=new SchemeRegistry(); SSLSocketFactory sf=new SSLSocketFactory(sslContext); Scheme httpsScheme=new Scheme("https",sf,443); schemeRegistry.register(httpsScheme); SocketFactory sfa=new PlainSocketFactory(); Scheme httpScheme=new Scheme("http",sfa,80); schemeRegistry.register(httpScheme); HttpParams params=new BasicHttpParams(); ClientConnectionManager cm=new SingleClientConnManager(params,schemeRegistry); client=new DefaultHttpClient(cm,params); } else { client=new DefaultHttpClient(); } if (proxyHost != null && proxyPort != null) { HttpHost proxy=new HttpHost(proxyHost,proxyPort); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy); } else { ProxySelectorRoutePlanner routePlanner=new ProxySelectorRoutePlanner(client.getConnectionManager().getSchemeRegistry(),ProxySelector.getDefault()); client.setRoutePlanner(routePlanner); } if (authUser != null && authPassword != null) { client.getCredentialsProvider().setCredentials(new AuthScope(domain,port),new UsernamePasswordCredentials(authUser,authPassword)); } client.setCookieStore(cookieStore); client.getParams().setParameter(ClientPNames.COOKIE_POLICY,CookiePolicy.BEST_MATCH); return client; }
Example 26
From project jetty-project, under directory /jetty-reverse-http/reverse-http-client/src/test/java/org/mortbay/jetty/rhttp/client/.
Source file: ApacheClientTest.java

protected RHTTPClient createClient(int port,String targetId) throws Exception { SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),port)); connectionManager=new ThreadSafeClientConnManager(new BasicHttpParams(),schemeRegistry); HttpParams httpParams=new BasicHttpParams(); httpParams.setParameter("http.default-host",new HttpHost("localhost",port)); DefaultHttpClient httpClient=new DefaultHttpClient(connectionManager,httpParams); httpClient.setHttpRequestRetryHandler(new NoRetryHandler()); return new ApacheClient(httpClient,"",targetId); }
Example 27
From project JGlobus, under directory /container-test-utils/src/main/java/org/globus/gsi/testutils/container/.
Source file: ClientTest.java

/** * Test client with invalid credentials. * @throws Exception This should happen. */ @Test public void testInvalid() throws Exception { SSLConfigurator config=getConfig("classpath:/invalidkeystore.properties"); SSLSocketFactory fac=new SSLSocketFactory(config.getSSLContext()); fac.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); DefaultHttpClient httpclient=new DefaultHttpClient(); Scheme scheme=new Scheme("https",fac,getPort()); httpclient.getConnectionManager().getSchemeRegistry().register(scheme); HttpGet httpget=new HttpGet("https://localhost/"); System.out.println("executing request" + httpget.getRequestLine()); try { httpclient.execute(httpget); fail(); } catch ( SSLPeerUnverifiedException ex) { } }
Example 28
public WebDavHttpClient getHttpClient() throws MessagingException { if (mHttpClient == null) { mHttpClient=new WebDavHttpClient(); mHttpClient.getParams().setBooleanParameter("http.protocol.handle-redirects",false); mContext=new BasicHttpContext(); mAuthCookies=new BasicCookieStore(); mContext.setAttribute(ClientContext.COOKIE_STORE,mAuthCookies); SchemeRegistry reg=mHttpClient.getConnectionManager().getSchemeRegistry(); try { Scheme s=new Scheme("https",new TrustedSocketFactory(mHost,mSecure),443); reg.register(s); } catch ( NoSuchAlgorithmException nsa) { Log.e(K9.LOG_TAG,"NoSuchAlgorithmException in getHttpClient: " + nsa); throw new MessagingException("NoSuchAlgorithmException in getHttpClient: " + nsa); } catch ( KeyManagementException kme) { Log.e(K9.LOG_TAG,"KeyManagementException in getHttpClient: " + kme); throw new MessagingException("KeyManagementException in getHttpClient: " + kme); } } return mHttpClient; }
Example 29
From project leviathan, under directory /httpclient/src/main/java/ar/com/zauber/leviathan/impl/.
Source file: BulkURIFetchers.java

/** * create a safe {@link URIFetcher} */ public static URIFetcher createSafeHttpClientURIFetcher(){ final Map<String,Scheme> registries=new HashMap<String,Scheme>(); registries.put("http",new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registries.put("https",new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); final SchemeRegistry schemaRegistry=new SchemeRegistry(); schemaRegistry.setItems(registries); final HttpParams params=createHttpParams(); final ClientConnectionManager cm=new ThreadSafeClientConnManager(params,schemaRegistry); final HttpClient httpclient=new DefaultHttpClient(cm,params); final CharsetStrategy charsetStrategy=new ChainedCharsetStrategy(asList(new DefaultHttpCharsetStrategy(),new FixedCharsetStrategy("utf-8"))); return new HTTPClientURIFetcher(httpclient,charsetStrategy); }
Example 30
From project Locast-Android, under directory /src/edu/mit/mobile/android/locast/net/.
Source file: NetworkClient.java

@Override protected ClientConnectionManager createClientConnectionManager(){ final SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); return new ThreadSafeClientConnManager(getParams(),registry); }
Example 31
From project lyo.testsuite, under directory /org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/util/.
Source file: OSLCUtils.java

static public void setupLazySSLSupport(HttpClient httpClient){ ClientConnectionManager connManager=httpClient.getConnectionManager(); SchemeRegistry schemeRegistry=connManager.getSchemeRegistry(); schemeRegistry.unregister("https"); TrustManager[] trustAllCerts=new TrustManager[]{new X509TrustManager(){ public void checkClientTrusted( java.security.cert.X509Certificate[] certs, String authType){ } public void checkServerTrusted( java.security.cert.X509Certificate[] certs, String authType){ } public java.security.cert.X509Certificate[] getAcceptedIssuers(){ return null; } } }; SSLContext sc=null; try { sc=SSLContext.getInstance("SSL"); sc.init(null,trustAllCerts,new java.security.SecureRandom()); } catch ( NoSuchAlgorithmException e) { } catch ( KeyManagementException e) { } SSLSocketFactory sf=new SSLSocketFactory(sc); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme https=new Scheme("https",sf,443); schemeRegistry.register(https); }
Example 32
From project MIT-Mobile-for-Android, under directory /src/com/google/zxing/client/android/.
Source file: AndroidHttpClient.java

/** * Create a new HttpClient with reasonable defaults (which you can update). * @param userAgent to report in your HTTP requests. * @return AndroidHttpClient for you to use for all your requests. */ public static AndroidHttpClient newInstance(String userAgent){ HttpParams params=new BasicHttpParams(); HttpConnectionParams.setStaleCheckingEnabled(params,false); HttpConnectionParams.setConnectionTimeout(params,20 * 1000); HttpConnectionParams.setSoTimeout(params,20 * 1000); HttpConnectionParams.setSocketBufferSize(params,8192); HttpClientParams.setRedirecting(params,false); HttpProtocolParams.setUserAgent(params,userAgent); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager manager=new ThreadSafeClientConnManager(params,schemeRegistry); return new AndroidHttpClient(manager,params); }
Example 33
From project Mobile-Tour-Guide, under directory /zxing-2.0/zxingorg/src/com/google/zxing/web/.
Source file: DecodeServlet.java

@Override public void init(ServletConfig servletConfig){ Logger logger=Logger.getLogger("com.google.zxing"); logger.addHandler(new ServletContextLogHandler(servletConfig.getServletContext())); params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); registry=new SchemeRegistry(); registry.register(new Scheme("http",80,PlainSocketFactory.getSocketFactory())); registry.register(new Scheme("https",443,SSLSocketFactory.getSocketFactory())); diskFileItemFactory=new DiskFileItemFactory(); log.info("DecodeServlet configured"); }
Example 34
From project onebusaway-java-api, under directory /src/test/java/fr/dudie/onebusaway/client/.
Source file: JsonOneBusAwayClientTest.java

/** * Instantiates the test. * @param name the test name * @throws IOException an error occurred during initialization */ public JsonOneBusAwayClientTest(final String name) throws IOException { super(name); LOGGER.info("Loading configuration file {}",PROPS_PATH); final InputStream in=JsonOneBusAwayClientTest.class.getResourceAsStream(PROPS_PATH); PROPS.load(in); LOGGER.info("Preparing http client"); final SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",new PlainSocketFactory(),80)); final ClientConnectionManager connexionManager=new SingleClientConnManager(null,registry); final HttpClient httpClient=new DefaultHttpClient(connexionManager,null); final String url=PROPS.getProperty("onebusaway.api.url"); final String key=PROPS.getProperty("onebusaway.api.key"); obaClient=new JsonOneBusAwayClient(httpClient,url,key); }
Example 35
From project Orweb, under directory /src/info/guardianproject/browser/.
Source file: AnonProxy.java

/** * Set the port for the HTTP proxy * @param port */ public AnonProxy(){ HttpHost proxy=new HttpHost(Browser.DEFAULT_PROXY_HOST,Integer.parseInt(Browser.DEFAULT_PROXY_PORT),"http"); SchemeRegistry supportedSchemes=new SchemeRegistry(); supportedSchemes.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); supportedSchemes.register(new Scheme("https",ModSSLSocketFactory.getSocketFactory(),443)); HttpParams hparams=new BasicHttpParams(); HttpProtocolParams.setVersion(hparams,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(hparams,"UTF-8"); HttpProtocolParams.setUseExpectContinue(hparams,true); ClientConnectionManager ccm=new ThreadSafeClientConnManager(hparams,supportedSchemes); mClient=new DefaultHttpClient(ccm,hparams); mClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy); }
Example 36
From project osgi-tests, under directory /test/glassfish-derby/src/test/java/org/ancoron/osgi/test/glassfish/.
Source file: GlassfishDerbyTest.java

protected DefaultHttpClient getHTTPClient() throws NoSuchAlgorithmException, KeyManagementException { SSLContext sslContext=SSLContext.getInstance("SSL"); sslContext.init(null,new TrustManager[]{new X509TrustManager(){ @Override public X509Certificate[] getAcceptedIssuers(){ System.out.println("getAcceptedIssuers ============="); return null; } @Override public void checkClientTrusted( X509Certificate[] certs, String authType){ System.out.println("checkClientTrusted ============="); } @Override public void checkServerTrusted( X509Certificate[] certs, String authType){ System.out.println("checkServerTrusted ============="); } } },new SecureRandom()); SSLSocketFactory sf=new SSLSocketFactory(sslContext,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme httpsScheme=new Scheme("https",8181,sf); PlainSocketFactory plain=new PlainSocketFactory(); Scheme httpScheme=new Scheme("http",8080,plain); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(httpsScheme); schemeRegistry.register(httpScheme); HttpParams params=new BasicHttpParams(); ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(schemeRegistry); cm.setMaxTotal(200); cm.setDefaultMaxPerRoute(20); DefaultHttpClient httpClient=new DefaultHttpClient(cm,params); httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,HttpVersion.HTTP_1_1); httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET,"UTF-8"); return httpClient; }
Example 37
From project PageTurner, under directory /src/main/java/net/nightwhistler/pageturner/sync/.
Source file: PageTurnerWebProgressService.java

@Override protected ClientConnectionManager createClientConnectionManager(){ SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registry.register(new Scheme("https",newSSlSocketFactory(),443)); return new SingleClientConnManager(getParams(),registry); }
Example 38
From project PartyWare, under directory /android/src/com/google/zxing/client/android/.
Source file: AndroidHttpClient.java

/** * Create a new HttpClient with reasonable defaults (which you can update). * @param userAgent to report in your HTTP requests. * @return AndroidHttpClient for you to use for all your requests. */ public static AndroidHttpClient newInstance(String userAgent){ HttpParams params=new BasicHttpParams(); HttpConnectionParams.setStaleCheckingEnabled(params,false); HttpConnectionParams.setConnectionTimeout(params,20 * 1000); HttpConnectionParams.setSoTimeout(params,20 * 1000); HttpConnectionParams.setSocketBufferSize(params,8192); HttpClientParams.setRedirecting(params,false); HttpProtocolParams.setUserAgent(params,userAgent); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager manager=new ThreadSafeClientConnManager(params,schemeRegistry); return new AndroidHttpClient(manager,params); }
Example 39
From project PinDroid, under directory /src/com/pindroid/client/.
Source file: HttpClientFactory.java

public static HttpClient getThreadSafeClient(){ HttpParams params=new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params,100); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpConnectionParams.setConnectionTimeout(params,REGISTRATION_TIMEOUT); HttpConnectionParams.setSoTimeout(params,REGISTRATION_TIMEOUT); ConnManagerParams.setTimeout(params,REGISTRATION_TIMEOUT); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager mgr=new ThreadSafeClientConnManager(params,schemeRegistry); HttpClient client=new DefaultHttpClient(mgr,params); return client; }
Example 40
From project Pitbull, under directory /pitbull-core/src/test/java/org/jboss/pitbull/test/.
Source file: SslEchoTest.java

private static DefaultHttpClient createHttpClient(int port){ try { java.lang.System.setProperty("sun.security.ssl.allowUnsafeRenegotiation","true"); X509TrustManager trustManager=new X509TrustManager(){ public void checkClientTrusted( X509Certificate[] chain, String authType) throws CertificateException { } public void checkServerTrusted( X509Certificate[] chain, String authType) throws CertificateException { } public X509Certificate[] getAcceptedIssuers(){ return null; } } ; SSLContext sslContext=SSLContext.getInstance("SSL"); sslContext.init(null,new TrustManager[]{trustManager},new SecureRandom()); SSLSocketFactory sf=new SSLSocketFactory(sslContext); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme httpsScheme=new Scheme("https",sf,port); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(httpsScheme); HttpParams params=new BasicHttpParams(); ClientConnectionManager cm=new SingleClientConnManager(params,schemeRegistry); return new DefaultHttpClient(cm,params); } catch ( Exception ex) { return null; } }
Example 41
From project platform_external_apache-http, under directory /src/org/apache/http/impl/client/.
Source file: DefaultRequestDirector.java

/** * Creates the CONNECT request for tunnelling. Called by {@link #createTunnelToTarget createTunnelToTarget}. * @param route the route to establish * @param context the context for request execution * @return the CONNECT request for tunnelling */ protected HttpRequest createConnectRequest(HttpRoute route,HttpContext context){ HttpHost target=route.getTargetHost(); String host=target.getHostName(); int port=target.getPort(); if (port < 0) { Scheme scheme=connManager.getSchemeRegistry().getScheme(target.getSchemeName()); port=scheme.getDefaultPort(); } StringBuilder buffer=new StringBuilder(host.length() + 6); buffer.append(host); buffer.append(':'); buffer.append(Integer.toString(port)); String authority=buffer.toString(); ProtocolVersion ver=HttpProtocolParams.getVersion(params); HttpRequest req=new BasicHttpRequest("CONNECT",authority,ver); return req; }
Example 42
From project Playlist, under directory /src/com/google/zxing/client/android/.
Source file: AndroidHttpClient.java

/** * Create a new HttpClient with reasonable defaults (which you can update). * @param userAgent to report in your HTTP requests. * @return AndroidHttpClient for you to use for all your requests. */ public static AndroidHttpClient newInstance(String userAgent){ HttpParams params=new BasicHttpParams(); HttpConnectionParams.setStaleCheckingEnabled(params,false); HttpConnectionParams.setConnectionTimeout(params,20 * 1000); HttpConnectionParams.setSoTimeout(params,20 * 1000); HttpConnectionParams.setSocketBufferSize(params,8192); HttpClientParams.setRedirecting(params,false); HttpProtocolParams.setUserAgent(params,userAgent); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager manager=new ThreadSafeClientConnManager(params,schemeRegistry); return new AndroidHttpClient(manager,params); }
Example 43
From project playn, under directory /android/src/playn/android/.
Source file: AndroidHttpClient.java

/** * Create a new HttpClient with reasonable defaults (which you can update). * @param userAgent to report in your HTTP requests. * @return AndroidHttpClient for you to use for all your requests. */ public static AndroidHttpClient newInstance(String userAgent){ HttpParams params=new BasicHttpParams(); HttpConnectionParams.setStaleCheckingEnabled(params,false); HttpConnectionParams.setConnectionTimeout(params,20 * 1000); HttpConnectionParams.setSoTimeout(params,20 * 1000); HttpConnectionParams.setSocketBufferSize(params,8192); HttpClientParams.setRedirecting(params,false); HttpProtocolParams.setUserAgent(params,userAgent); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager manager=new ThreadSafeClientConnManager(params,schemeRegistry); return new AndroidHttpClient(manager,params); }
Example 44
From project ptest-server, under directory /src/main/java/com/mnxfst/testing/client/.
Source file: TSClientPlanResultCollectCallable.java

public TSClientPlanResultCollectCallable(String hostname,int port,String uri){ this.httpHost=new HttpHost(hostname,port); this.getMethod=new HttpGet(uri.toString()); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",80,PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https",443,SSLSocketFactory.getSocketFactory())); ThreadSafeClientConnManager threadSafeClientConnectionManager=new ThreadSafeClientConnManager(schemeRegistry); threadSafeClientConnectionManager.setMaxTotal(20); threadSafeClientConnectionManager.setDefaultMaxPerRoute(20); this.httpClient=new DefaultHttpClient(threadSafeClientConnectionManager); }
Example 45
From project QuotaForAndroid, under directory /Quota/src/com/southfreo/quota/utils/.
Source file: GeoStore.java

@Override protected ClientConnectionManager createClientConnectionManager(){ SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registry.register(new Scheme("https",newSslSocketFactory(),443)); return new SingleClientConnManager(getParams(),registry); }
Example 46
From project rain-workload-toolkit, under directory /thirdparty/httpcomponents-client-4.0.1/examples/org/apache/http/examples/client/.
Source file: ClientCustomSSL.java

public final static void main(String[] args) throws Exception { DefaultHttpClient httpclient=new DefaultHttpClient(); KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType()); FileInputStream instream=new FileInputStream(new File("my.keystore")); try { trustStore.load(instream,"nopassword".toCharArray()); } finally { instream.close(); } SSLSocketFactory socketFactory=new SSLSocketFactory(trustStore); Scheme sch=new Scheme("https",socketFactory,443); httpclient.getConnectionManager().getSchemeRegistry().register(sch); HttpGet httpget=new HttpGet("https://localhost/"); System.out.println("executing request" + httpget.getRequestLine()); HttpResponse response=httpclient.execute(httpget); HttpEntity entity=response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); } if (entity != null) { entity.consumeContent(); } httpclient.getConnectionManager().shutdown(); }
Example 47
From project ratebeer-for-Android, under directory /RateBeerForAndroid/src/com/ratebeer/android/api/.
Source file: HttpHelper.java

private static void ensureClient(){ if (httpClient == null) { SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",new PlainSocketFactory(),80)); HttpParams httpparams=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpparams,TIMEOUT); HttpConnectionParams.setSoTimeout(httpparams,TIMEOUT); HttpProtocolParams.setUserAgent(httpparams,USER_AGENT); httpClient=new DefaultHttpClient(new ThreadSafeClientConnManager(httpparams,registry),httpparams); } }
Example 48
From project ratebeerforandroid, under directory /RateBeerForAndroid/src/com/ratebeer/android/api/.
Source file: HttpHelper.java

private static void ensureClient(){ if (httpClient == null) { SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",new PlainSocketFactory(),80)); HttpParams httpparams=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpparams,TIMEOUT); HttpConnectionParams.setSoTimeout(httpparams,TIMEOUT); HttpProtocolParams.setUserAgent(httpparams,USER_AGENT); httpClient=new DefaultHttpClient(new ThreadSafeClientConnManager(httpparams,registry),httpparams); } }
Example 49
From project ReGalAndroid, under directory /g2-java-client/src/main/java/net/dahanne/gallery/g2/java/client/business/.
Source file: G2Client.java

private DefaultHttpClient createHttpClient(){ SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",new FakeSocketFactory(),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); ClientConnectionManager cm=new ThreadSafeClientConnManager(params,schemeRegistry); return new DefaultHttpClient(cm,params); }
Example 50
From project repose, under directory /project-set/core/core-lib/src/main/java/com/rackspace/papi/service/proxy/httpcomponent/.
Source file: RequestProxyServiceImpl.java

private HttpClient getClient(){ synchronized (clientLock) { if (client == null) { LOG.info("Building Apache Components Http v4 Client"); manager=new PoolingClientConnectionManager(); manager.setMaxTotal(proxyThreadPool); manager.setDefaultMaxPerRoute(proxyThreadPool); SSLContext sslContext=ProxyUtilities.getTrustingSslContext(); SSLSocketFactory ssf=new SSLSocketFactory(sslContext,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); SchemeRegistry registry=manager.getSchemeRegistry(); Scheme scheme=new Scheme("https",DEFAULT_HTTPS_PORT,ssf); registry.register(scheme); client=new DefaultHttpClient(manager); client.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS,false); client.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT,readTimeout); client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,connectionTimeout); } return client; } }
Example 51
From project rest-assured, under directory /rest-assured/src/main/java/com/jayway/restassured/internal/http/.
Source file: AuthConfig.java

/** * Sets a certificate to be used for SSL authentication. See {@link Class#getResource(String)} for how to get a URL from a resource on the classpath. * @param certURL URL to a JKS keystore where the certificate is stored. * @param password password to decrypt the keystore */ public void certificate(String certURL,String password) throws GeneralSecurityException, IOException { KeyStore keyStore=KeyStore.getInstance(KeyStore.getDefaultType()); InputStream jksStream=new URL(certURL).openStream(); try { keyStore.load(jksStream,password.toCharArray()); } finally { jksStream.close(); } SSLSocketFactory ssl=new SSLSocketFactory(keyStore,password); ssl.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); builder.getClient().getConnectionManager().getSchemeRegistry().register(new Scheme("https",ssl,443)); }
Example 52
From project Rhybudd, under directory /src/net/networksaremadeofstring/rhybudd/.
Source file: ZenossAPIv2.java

private void PrepareSSLHTTPClient() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException { client=new DefaultHttpClient(); SchemeRegistry registry=new SchemeRegistry(); SocketFactory socketFactory=null; socketFactory=TrustAllSSLSocketFactory.getDefault(); registry.register(new Scheme("https",socketFactory,443)); mgr=new ThreadSafeClientConnManager(client.getParams(),registry); httpclient=new DefaultHttpClient(mgr,client.getParams()); }
Example 53
From project sched-assist, under directory /sched-assist-spi-caldav/src/main/java/org/jasig/schedassist/impl/caldav/.
Source file: SchemeRegistryProvider.java

/** * @see SchemeRegistryFactory#createDefault() * @param schemeName * @param port * @param useSsl * @return */ public static SchemeRegistry createSchemeRegistry(String schemeName,int port,boolean useSsl){ SchemeRegistry registry=SchemeRegistryFactory.createDefault(); if (useSsl) { registry.register(new Scheme(schemeName,port,SSLSocketFactory.getSocketFactory())); } else { registry.register(new Scheme(schemeName,port,PlainSocketFactory.getSocketFactory())); } return registry; }
Example 54
From project SchoolPlanner4Untis, under directory /src/edu/htl3r/schoolplanner/backend/network/.
Source file: Network.java

/** * Registriert eine {@link Scheme} fuer plain HTTP und falls uebergeben, eine fuer HTTPS. * @param scheme Scheme fuer HTTPS, die registriert werden soll */ private void registerSchemes(Scheme scheme){ client.getConnectionManager().getSchemeRegistry().register(new Scheme("http",PlainSocketFactory.getSocketFactory(),url != null && url.getPort() != -1 ? url.getPort() : 80)); if (scheme != null) { client.getConnectionManager().getSchemeRegistry().register(scheme); } }
Example 55
From project ShortcutLink, under directory /src/org/bibimbap/shortcutlink/.
Source file: AndroidHttpClient.java

/** * Create a new HttpClient with reasonable defaults (which you can update). * @param userAgent to report in your HTTP requests. * @return AndroidHttpClient for you to use for all your requests. */ public static AndroidHttpClient newInstance(String userAgent){ HttpParams params=new BasicHttpParams(); HttpConnectionParams.setStaleCheckingEnabled(params,false); HttpConnectionParams.setConnectionTimeout(params,20 * 1000); HttpConnectionParams.setSoTimeout(params,20 * 1000); HttpConnectionParams.setSocketBufferSize(params,8192); HttpClientParams.setRedirecting(params,false); HttpProtocolParams.setUserAgent(params,userAgent); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager manager=new ThreadSafeClientConnManager(params,schemeRegistry); return new AndroidHttpClient(manager,params); }
Example 56
From project spark, under directory /spark-http-client/src/main/java/spark/protocol/.
Source file: ProtocolDataSource.java

/** * Creates a new thread-safe HTTP connection pool for use with a data source. * @param poolSize The size of the connection pool. * @return A new connection pool with the given size. */ private HttpClient createPooledClient(){ HttpParams connMgrParams=new BasicHttpParams(); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme(HTTP_SCHEME,PlainSocketFactory.getSocketFactory(),HTTP_PORT)); schemeRegistry.register(new Scheme(HTTPS_SCHEME,SSLSocketFactory.getSocketFactory(),HTTPS_PORT)); ConnManagerParams.setMaxTotalConnections(connMgrParams,poolSize); ConnManagerParams.setMaxConnectionsPerRoute(connMgrParams,new ConnPerRouteBean(poolSize)); ClientConnectionManager ccm=new ThreadSafeClientConnManager(connMgrParams,schemeRegistry); HttpParams httpParams=new BasicHttpParams(); HttpProtocolParams.setUseExpectContinue(httpParams,false); ConnManagerParams.setTimeout(httpParams,acquireTimeout * 1000); return new DefaultHttpClient(ccm,httpParams); }
Example 57
From project spring-android, under directory /spring-android-rest-template/src/main/java/org/springframework/http/client/.
Source file: HttpComponentsClientHttpRequestFactory.java

/** * Create a new instance of the {@code HttpComponentsClientHttpRequestFactory} with a default {@link HttpClient}that uses a default {@link ThreadSafeClientConnManager}. */ public HttpComponentsClientHttpRequestFactory(){ SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); HttpParams params=new BasicHttpParams(); ThreadSafeClientConnManager connectionManager=new ThreadSafeClientConnManager(params,schemeRegistry); ConnManagerParams.setMaxTotalConnections(params,DEFAULT_MAX_TOTAL_CONNECTIONS); ConnManagerParams.setMaxConnectionsPerRoute(params,new ConnPerRouteBean(DEFAULT_MAX_CONNECTIONS_PER_ROUTE)); this.httpClient=new DefaultHttpClient(connectionManager,null); setReadTimeout(DEFAULT_READ_TIMEOUT_MILLISECONDS); }
Example 58
From project subsonic, under directory /subsonic-android/src/github/daneren2005/dsub/service/.
Source file: RESTMusicService.java

public RESTMusicService(){ HttpParams params=new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params,20); ConnManagerParams.setMaxConnectionsPerRoute(params,new ConnPerRouteBean(20)); HttpConnectionParams.setConnectionTimeout(params,SOCKET_CONNECT_TIMEOUT); HttpConnectionParams.setSoTimeout(params,SOCKET_READ_TIMEOUT_DEFAULT); HttpConnectionParams.setStaleCheckingEnabled(params,false); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",createSSLSocketFactory(),443)); connManager=new ThreadSafeClientConnManager(params,schemeRegistry); httpClient=new DefaultHttpClient(connManager,params); }
Example 59
From project Subsonic-Android, under directory /src/net/sourceforge/subsonic/androidapp/service/.
Source file: RESTMusicService.java

public RESTMusicService(){ HttpParams params=new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params,20); ConnManagerParams.setMaxConnectionsPerRoute(params,new ConnPerRouteBean(20)); HttpConnectionParams.setConnectionTimeout(params,SOCKET_CONNECT_TIMEOUT); HttpConnectionParams.setSoTimeout(params,SOCKET_READ_TIMEOUT_DEFAULT); HttpConnectionParams.setStaleCheckingEnabled(params,false); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",createSSLSocketFactory(),443)); connManager=new ThreadSafeClientConnManager(params,schemeRegistry); httpClient=new DefaultHttpClient(connManager,params); }
Example 60
From project subsonic_1, under directory /subsonic-android/src/net/sourceforge/subsonic/androidapp/service/.
Source file: RESTMusicService.java

public RESTMusicService(){ HttpParams params=new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params,20); ConnManagerParams.setMaxConnectionsPerRoute(params,new ConnPerRouteBean(20)); HttpConnectionParams.setConnectionTimeout(params,SOCKET_CONNECT_TIMEOUT); HttpConnectionParams.setSoTimeout(params,SOCKET_READ_TIMEOUT_DEFAULT); HttpConnectionParams.setStaleCheckingEnabled(params,false); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",createSSLSocketFactory(),443)); connManager=new ThreadSafeClientConnManager(params,schemeRegistry); httpClient=new DefaultHttpClient(connManager,params); }
Example 61
From project subsonic_2, under directory /subsonic-android/src/net/sourceforge/subsonic/androidapp/service/.
Source file: RESTMusicService.java

public RESTMusicService(){ HttpParams params=new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params,20); ConnManagerParams.setMaxConnectionsPerRoute(params,new ConnPerRouteBean(20)); HttpConnectionParams.setConnectionTimeout(params,SOCKET_CONNECT_TIMEOUT); HttpConnectionParams.setSoTimeout(params,SOCKET_READ_TIMEOUT_DEFAULT); HttpConnectionParams.setStaleCheckingEnabled(params,false); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",createSSLSocketFactory(),443)); connManager=new ThreadSafeClientConnManager(params,schemeRegistry); httpClient=new DefaultHttpClient(connManager,params); }
Example 62
From project Supersonic, under directory /subsonic-android/src/net/sourceforge/subsonic/androidapp/service/.
Source file: RESTMusicService.java

public RESTMusicService(){ HttpParams params=new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params,20); ConnManagerParams.setMaxConnectionsPerRoute(params,new ConnPerRouteBean(20)); HttpConnectionParams.setConnectionTimeout(params,SOCKET_CONNECT_TIMEOUT); HttpConnectionParams.setSoTimeout(params,SOCKET_READ_TIMEOUT_DEFAULT); HttpConnectionParams.setStaleCheckingEnabled(params,false); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",createSSLSocketFactory(),443)); connManager=new ThreadSafeClientConnManager(params,schemeRegistry); httpClient=new DefaultHttpClient(connManager,params); }
Example 63
From project tshirtslayer_android, under directory /src/org/xmlrpc/android/.
Source file: XMLRPCClient.java

/** * XMLRPCClient constructor. Creates new instance based on server URI (Code contributed by sgayda2 from issue #17, and by erickok from ticket #10) * @param XMLRPC server URI */ public XMLRPCClient(URI uri){ SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",new PlainSocketFactory(),80)); registry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); postMethod=new HttpPost(uri); postMethod.addHeader("Content-Type","text/xml"); httpParams=postMethod.getParams(); HttpProtocolParams.setUseExpectContinue(httpParams,false); this.client=new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams,registry),httpParams); }
Example 64
From project UDJ-Android-Client, under directory /src/org/klnusbaum/udj/network/.
Source file: ServerConnection.java

public static DefaultHttpClient getHttpClient() throws IOException { if (httpClient == null) { SchemeRegistry schemeReg=new SchemeRegistry(); schemeReg.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),SERVER_PORT)); BasicHttpParams params=new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params,100); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params,HTTP.UTF_8); HttpProtocolParams.setUseExpectContinue(params,true); ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(params,schemeReg); httpClient=new DefaultHttpClient(cm,params); } return httpClient; }
Example 65
From project Vega, under directory /platform/com.subgraph.vega.http.requests/src/com/subgraph/vega/internal/http/requests/connection/.
Source file: SocksModeClientConnectionOperator.java

@Override public void openConnection(OperatedClientConnection conn,HttpHost target,InetAddress local,HttpContext context,HttpParams params) throws IOException { if (!isSocksMode) { super.openConnection(conn,target,local,context,params); return; } final Scheme scheme=schemeRegistry.getScheme(target.getSchemeName()); final SchemeSocketFactory sf=scheme.getSchemeSocketFactory(); final int port=scheme.resolvePort(target.getPort()); Socket sock=sf.createSocket(params); conn.opening(sock,target); InetSocketAddress remoteAddress=InetSocketAddress.createUnresolved(target.getHostName(),port); InetSocketAddress localAddress=null; if (local != null) { localAddress=new InetSocketAddress(local,0); } try { Socket connsock=sf.connectSocket(sock,remoteAddress,localAddress,params); if (sock != connsock) { sock=connsock; conn.opening(sock,target); } prepareSocket(sock,context,params); conn.openCompleted(sf.isSecure(sock),params); return; } catch ( ConnectException ex) { throw new HttpHostConnectException(target,ex); } }
Example 66
From project wip, under directory /src/main/java/fr/ippon/wip/http/hc/.
Source file: HttpClientResourceManager.java

private HttpClientResourceManager(){ perUserClientMap=Collections.synchronizedMap(new HashMap<String,HttpClient>()); perUserCookieStoreMap=Collections.synchronizedMap(new HashMap<String,CookieStore>()); perUserWindowCredentialProviderMap=Collections.synchronizedMap(new HashMap<String,CredentialsProvider>()); currentPortletRequest=new ThreadLocal<PortletRequest>(); currentPortletResponse=new ThreadLocal<PortletResponse>(); currentRequest=new ThreadLocal<RequestBuilder>(); try { SSLSocketFactory ssf=new SSLSocketFactory(new TrustSelfSignedStrategy(),new AllowAllHostnameVerifier()); Scheme httpsScheme=new Scheme("https",443,ssf); PlainSocketFactory psf=new PlainSocketFactory(); Scheme httpScheme=new Scheme("http",80,psf); SchemeRegistry registry=new SchemeRegistry(); registry.register(httpsScheme); registry.register(httpScheme); connectionManager=new PoolingClientConnectionManager(registry); connectionManager.setDefaultMaxPerRoute(10); connectionManager.setMaxTotal(100); DefaultHttpClient defaultHttpClient=new DefaultHttpClient(connectionManager); defaultHttpClient.setRedirectStrategy(new LaxRedirectStrategy()); CacheConfig cacheConfig=createAndConfigureCache(); URL ehCacheConfig=getClass().getResource("/ehcache.xml"); cacheManager=CacheManager.create(ehCacheConfig); Ehcache ehcache=cacheManager.getEhcache("public"); EhcacheHttpCacheStorage httpCacheStorage=new EhcacheHttpCacheStorage(ehcache); CachingHttpClient sharedCacheClient=new CachingHttpClient(defaultHttpClient,httpCacheStorage,cacheConfig); HttpClientDecorator decoratedClient=new HttpClientDecorator(sharedCacheClient); decoratedClient.addPreProcessor(new LtpaRequestInterceptor()); decoratedClient.addPreProcessor(new StaleIfErrorRequestInterceptor(staleIfErrorTime)); decoratedClient.addFilter(new IgnoreHttpRequestFilter()); decoratedClient.addPostProcessor(new TransformerResponseInterceptor()); rootClient=decoratedClient; } catch ( Exception e) { throw new RuntimeException("Could not initialize connection manager",e); } }
Example 67
From project zeitgeist-api, under directory /deps/httpcomponents-client/examples/org/apache/http/examples/client/.
Source file: ClientCustomSSL.java

public final static void main(String[] args) throws Exception { DefaultHttpClient httpclient=new DefaultHttpClient(); try { KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType()); FileInputStream instream=new FileInputStream(new File("my.keystore")); try { trustStore.load(instream,"nopassword".toCharArray()); } finally { try { instream.close(); } catch ( Exception ignore) { } } SSLSocketFactory socketFactory=new SSLSocketFactory(trustStore); Scheme sch=new Scheme("https",443,socketFactory); httpclient.getConnectionManager().getSchemeRegistry().register(sch); HttpGet httpget=new HttpGet("https://localhost/"); System.out.println("executing request" + httpget.getRequestLine()); HttpResponse response=httpclient.execute(httpget); HttpEntity entity=response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); } EntityUtils.consume(entity); } finally { httpclient.getConnectionManager().shutdown(); } }
Example 68
From project zirco-browser, under directory /src/org/emergent/android/weave/client/.
Source file: WeaveTransport.java

private ClientConnectionManager createClientConnectionManager(boolean threadSafe){ SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),HTTP_PORT_DEFAULT)); schemeRegistry.register(new Scheme("https",m_sslSocketFactory,HTTPS_PORT_DEFAULT)); if (threadSafe) { return new ThreadSafeClientConnManager(sm_httpParams,schemeRegistry); } else { return new SingleClientConnManager(sm_httpParams,schemeRegistry); } }
Example 69
From project zxing-iphone, under directory /android/src/com/google/zxing/client/android/.
Source file: AndroidHttpClient.java

/** * Create a new HttpClient with reasonable defaults (which you can update). * @param userAgent to report in your HTTP requests. * @return AndroidHttpClient for you to use for all your requests. */ public static AndroidHttpClient newInstance(String userAgent){ HttpParams params=new BasicHttpParams(); HttpConnectionParams.setStaleCheckingEnabled(params,false); HttpConnectionParams.setConnectionTimeout(params,20 * 1000); HttpConnectionParams.setSoTimeout(params,20 * 1000); HttpConnectionParams.setSocketBufferSize(params,8192); HttpClientParams.setRedirecting(params,false); HttpProtocolParams.setUserAgent(params,userAgent); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager manager=new ThreadSafeClientConnManager(params,schemeRegistry); return new AndroidHttpClient(manager,params); }
Example 70
From project 4308Cirrus, under directory /tendril-android-lib/src/main/java/edu/colorado/cs/cirrus/android/.
Source file: HttpUtils.java

public static HttpClient getNewHttpClient(){ try { KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null,null); SSLSocketFactory sf=new EasySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params,HTTP.UTF_8); SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registry.register(new Scheme("https",sf,443)); ClientConnectionManager ccm=new ThreadSafeClientConnManager(params,registry); return new DefaultHttpClient(ccm,params); } catch ( Exception e) { return new DefaultHttpClient(); } }
Example 71
From project android-bankdroid, under directory /src/eu/nullbyte/android/urllib/.
Source file: Urllib.java

public Urllib(boolean acceptInvalidCertificates,boolean allowCircularRedirects){ this.acceptInvalidCertificates=acceptInvalidCertificates; this.headers=new HashMap<String,String>(); HttpParams params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params,this.charset); params.setBooleanParameter("http.protocol.expect-continue",false); if (allowCircularRedirects) params.setBooleanParameter("http.protocol.allow-circular-redirects",true); if (acceptInvalidCertificates) { SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registry.register(new Scheme("https",new EasySSLSocketFactory(),443)); ClientConnectionManager manager=new ThreadSafeClientConnManager(params,registry); httpclient=new DefaultHttpClient(manager,params); } else { SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager manager=new ThreadSafeClientConnManager(params,registry); httpclient=new DefaultHttpClient(manager,params); } context=new BasicHttpContext(); }
Example 72
From project androidquery, under directory /src/com/androidquery/callback/.
Source file: AbstractAjaxCallback.java

private static DefaultHttpClient getClient(){ if (client == null || !REUSE_CLIENT) { AQUtility.debug("creating http client"); HttpParams httpParams=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams,NET_TIMEOUT); HttpConnectionParams.setSoTimeout(httpParams,NET_TIMEOUT); ConnManagerParams.setMaxConnectionsPerRoute(httpParams,new ConnPerRouteBean(25)); HttpConnectionParams.setSocketBufferSize(httpParams,8192); SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registry.register(new Scheme("https",ssf == null ? SSLSocketFactory.getSocketFactory() : ssf,443)); ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(httpParams,registry); client=new DefaultHttpClient(cm,httpParams); } return client; }
Example 73
From project andstatus, under directory /src/org/andstatus/app/net/.
Source file: ConnectionOAuth.java

public ConnectionOAuth(MyAccount ma){ super(ma); mOauthBaseUrl=ma.getOauthBaseUrl(); HttpParams parameters=new BasicHttpParams(); HttpProtocolParams.setVersion(parameters,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(parameters,HTTP.DEFAULT_CONTENT_CHARSET); HttpProtocolParams.setUseExpectContinue(parameters,false); HttpConnectionParams.setTcpNoDelay(parameters,true); HttpConnectionParams.setSocketBufferSize(parameters,8192); SchemeRegistry schReg=new SchemeRegistry(); schReg.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); ClientConnectionManager tsccm=new ThreadSafeClientConnManager(parameters,schReg); mClient=new DefaultHttpClient(tsccm,parameters); OAuthKeys oak=new OAuthKeys(ma.getOriginId()); mConsumer=new CommonsHttpOAuthConsumer(oak.getConsumerKey(),oak.getConsumerSecret()); mProvider=new CommonsHttpOAuthProvider(getApiUrl(apiEnum.OAUTH_REQUEST_TOKEN),getApiUrl(apiEnum.OAUTH_ACCESS_TOKEN),getApiUrl(apiEnum.OAUTH_AUTHORIZE)); mProvider.setOAuth10a(true); if (ma.dataContains(ConnectionOAuth.USER_TOKEN) && ma.dataContains(ConnectionOAuth.USER_SECRET)) { setAuthInformation(ma.getDataString(ConnectionOAuth.USER_TOKEN,null),ma.getDataString(ConnectionOAuth.USER_SECRET,null)); } }
Example 74
From project andtweet, under directory /src/com/xorcode/andtweet/net/.
Source file: ConnectionOAuth.java

public ConnectionOAuth(SharedPreferences sp){ super(sp); HttpParams parameters=new BasicHttpParams(); HttpProtocolParams.setVersion(parameters,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(parameters,HTTP.DEFAULT_CONTENT_CHARSET); HttpProtocolParams.setUseExpectContinue(parameters,false); HttpConnectionParams.setTcpNoDelay(parameters,true); HttpConnectionParams.setSocketBufferSize(parameters,8192); SchemeRegistry schReg=new SchemeRegistry(); schReg.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); ClientConnectionManager tsccm=new ThreadSafeClientConnManager(parameters,schReg); mClient=new DefaultHttpClient(tsccm,parameters); mConsumer=new CommonsHttpOAuthConsumer(OAuthKeys.TWITTER_CONSUMER_KEY,OAuthKeys.TWITTER_CONSUMER_SECRET); loadSavedKeys(sp); }
Example 75
From project bitfluids, under directory /src/test/java/at/bitcoin_austria/bitfluids/.
Source file: NetTest.java

public static HttpClient wrapClient(HttpClient base){ try { SSLContext ctx=SSLContext.getInstance("TLS"); 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; } } ; 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) { throw new RuntimeException(ex); } }
Example 76
From project cloudify, under directory /rest-client/src/main/java/org/cloudifysource/restclient/.
Source file: GSRestClient.java

/** * Returns a HTTP client configured to use SSL. * @return HTTP client configured to use SSL * @throws RestException Reporting different failures while creating the HTTP client */ public final DefaultHttpClient getSSLHttpClient() throws RestException { try { final KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null,null); final SSLSocketFactory sf=new RestSSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); final HttpParams params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params,HTTP.UTF_8); final SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme(HTTPS,sf,url.getPort())); final ClientConnectionManager ccm=new ThreadSafeClientConnManager(params,registry); return new DefaultHttpClient(ccm,params); } catch ( final KeyStoreException e) { throw new RestException(e); } catch ( final NoSuchAlgorithmException e) { throw new RestException(e); } catch ( final CertificateException e) { throw new RestException(e); } catch ( final IOException e) { throw new RestException(e); } catch ( final KeyManagementException e) { throw new RestException(e); } catch ( final UnrecoverableKeyException e) { throw new RestException(e); } }
Example 77
From project components-ness-httpclient, under directory /client/src/main/java/com/nesscomputing/httpclient/factory/httpclient4/.
Source file: ApacheHttpClient4Factory.java

public ApacheHttpClient4Factory(final HttpClientDefaults clientDefaults,@Nullable final Set<? extends HttpClientObserver> httpClientObservers){ Preconditions.checkArgument(clientDefaults != null,"clientDefaults can not be null!"); this.httpClientObservers=httpClientObservers; initParams(); registry.register(HTTP_SCHEME); try { final TrustManager[] trustManagers=new TrustManager[]{getTrustManager(clientDefaults)}; final KeyManager[] keyManagers=getKeyManagers(clientDefaults); final SSLContext sslContext=SSLContext.getInstance("TLS"); sslContext.init(keyManagers,trustManagers,null); final SSLSocketFactory sslSocketFactory=new SSLSocketFactory(sslContext); registry.register(new Scheme("https",HTTPS_PORT,sslSocketFactory)); } catch ( GeneralSecurityException ce) { throw new IllegalStateException(ce); } catch ( IOException ioe) { throw new IllegalStateException(ioe); } connectionManager=new ThreadSafeClientConnManager(registry); }
Example 78
From project couchdb-lucene, under directory /src/main/java/com/github/rnewson/couchdb/lucene/.
Source file: HttpClientFactory.java

public static synchronized HttpClient getInstance() throws MalformedURLException { if (instance == null) { final HttpParams params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setUseExpectContinue(params,false); HttpConnectionParams.setTcpNoDelay(params,true); HttpConnectionParams.setStaleCheckingEnabled(params,false); ConnManagerParams.setMaxTotalConnections(params,1000); ConnManagerParams.setMaxConnectionsPerRoute(params,new ConnPerRouteBean(1000)); final SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),5984)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); final ClientConnectionManager cm=new ShieldedClientConnManager(new ThreadSafeClientConnManager(params,schemeRegistry)); instance=new DefaultHttpClient(cm,params); if (INI != null) { final CredentialsProvider credsProvider=new BasicCredentialsProvider(); final Iterator<?> it=INI.getKeys(); while (it.hasNext()) { final String key=(String)it.next(); if (!key.startsWith("lucene.") && key.endsWith(".url")) { final URL url=new URL(INI.getString(key)); if (url.getUserInfo() != null) { credsProvider.setCredentials(new AuthScope(url.getHost(),url.getPort()),new UsernamePasswordCredentials(url.getUserInfo())); } } } instance.setCredentialsProvider(credsProvider); instance.addRequestInterceptor(new PreemptiveAuthenticationRequestInterceptor(),0); } } return instance; }
Example 79
From project couchdb4j, under directory /src/java/com/fourspaces/couchdb/.
Source file: Session.java

/** * Constructor for obtaining a Session with an HTTP-AUTH username/password and (optionally) a secure connection This isn't supported by CouchDB - you need a proxy in front to use this * @param host - hostname * @param port - port to use * @param user - username * @param pass - password * @param secure - use an SSL connection? */ public Session(String host,int port,String user,String pass,boolean usesAuth,boolean secure){ this.host=host; this.port=port; this.user=user; this.pass=pass; this.usesAuth=usesAuth; this.secure=secure; httpParams=new BasicHttpParams(); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ThreadSafeClientConnManager connManager=new ThreadSafeClientConnManager(httpParams,schemeRegistry); DefaultHttpClient defaultClient=new DefaultHttpClient(connManager,httpParams); if (user != null) { defaultClient.getCredentialsProvider().setCredentials(AuthScope.ANY,new UsernamePasswordCredentials(user,pass)); } this.httpClient=defaultClient; setUserAgent("couchdb4j"); setSocketTimeout((30 * 1000)); setConnectionTimeout((15 * 1000)); }
Example 80
From project DiscogsForAndroid, under directory /src/com/discogs/services/.
Source file: NetworkHelper.java

private void initHTTPClient(){ SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); HttpParams params=new BasicHttpParams(); HttpProtocolParams.setContentCharset(params,"utf-8"); params.setBooleanParameter("http.protocol.expect-continue",false); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params,HTTP.DEFAULT_CONTENT_CHARSET); HttpProtocolParams.setUseExpectContinue(params,true); ThreadSafeClientConnManager connectionManager=new ThreadSafeClientConnManager(params,schemeRegistry); httpClient=new DefaultHttpClient(connectionManager,params); httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3,false)); httpClient.addRequestInterceptor(new HttpRequestInterceptor(){ public void process( final HttpRequest request, final HttpContext context) throws HttpException, IOException { if (!request.containsHeader("Accept-Encoding")) { request.addHeader("Accept-Encoding","gzip"); } } } ); httpClient.addResponseInterceptor(new HttpResponseInterceptor(){ public void process( final HttpResponse response, final HttpContext context) throws HttpException, IOException { HttpEntity entity=response.getEntity(); if (entity != null) { Header ceheader=entity.getContentEncoding(); if (ceheader != null) { HeaderElement[] codecs=ceheader.getElements(); for (int i=0; i < codecs.length; i++) { if (codecs[i].getName().equalsIgnoreCase("gzip")) { response.setEntity(new GzipDecompressingEntity(response.getEntity())); return; } } } } } } ); }
Example 81
From project droid-fu, under directory /src/main/java/com/github/droidfu/http/.
Source file: BetterHttp.java

public static void setupHttpClient(){ BasicHttpParams httpParams=new BasicHttpParams(); ConnManagerParams.setTimeout(httpParams,socketTimeout); ConnManagerParams.setMaxConnectionsPerRoute(httpParams,new ConnPerRouteBean(maxConnections)); ConnManagerParams.setMaxTotalConnections(httpParams,DEFAULT_MAX_CONNECTIONS); HttpConnectionParams.setSoTimeout(httpParams,socketTimeout); HttpConnectionParams.setTcpNoDelay(httpParams,true); HttpProtocolParams.setVersion(httpParams,HttpVersion.HTTP_1_1); HttpProtocolParams.setUserAgent(httpParams,httpUserAgent); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); if (DiagnosticSupport.ANDROID_API_LEVEL >= 7) { schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); } else { schemeRegistry.register(new Scheme("https",new EasySSLSocketFactory(),443)); } ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(httpParams,schemeRegistry); httpClient=new DefaultHttpClient(cm,httpParams); }
Example 82
From project friendica-for-android, under directory /mw-android-friendica-01/src/de/wikilab/android/friendica01/.
Source file: TwAjax.java

public DefaultHttpClient getNewHttpClient(){ if (ignoreSSLCerts) { try { KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null,null); SSLSocketFactory sf=new IgnoreCertsSSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params,HTTP.UTF_8); SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registry.register(new Scheme("https",sf,443)); ClientConnectionManager ccm=new ThreadSafeClientConnManager(params,registry); return new DefaultHttpClient(ccm,params); } catch ( Exception e) { return new DefaultHttpClient(); } } else { return new DefaultHttpClient(); } }
Example 83
From project ignition, under directory /ignition-support/ignition-support-lib/src/main/java/com/github/ignition/support/http/.
Source file: IgnitedHttp.java

protected void setupHttpClient(){ BasicHttpParams httpParams=new BasicHttpParams(); ConnManagerParams.setTimeout(httpParams,DEFAULT_WAIT_FOR_CONNECTION_TIMEOUT); ConnManagerParams.setMaxConnectionsPerRoute(httpParams,new ConnPerRouteBean(DEFAULT_MAX_CONNECTIONS)); ConnManagerParams.setMaxTotalConnections(httpParams,DEFAULT_MAX_CONNECTIONS); HttpConnectionParams.setSoTimeout(httpParams,DEFAULT_SOCKET_TIMEOUT); HttpConnectionParams.setTcpNoDelay(httpParams,true); HttpProtocolParams.setVersion(httpParams,HttpVersion.HTTP_1_1); HttpProtocolParams.setUserAgent(httpParams,DEFAULT_HTTP_USER_AGENT); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); if (IgnitedDiagnostics.ANDROID_API_LEVEL >= 7) { schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); } else { schemeRegistry.register(new Scheme("https",new EasySSLSocketFactory(),443)); } ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(httpParams,schemeRegistry); httpClient=new DefaultHttpClient(cm,httpParams); }
Example 84
From project janbanery, under directory /janbanery-android/src/main/java/pl/project13/janbanery/android/rest/.
Source file: AndroidCompatibleRestClient.java

public DefaultHttpClient getClient(){ DefaultHttpClient ret; HttpParams params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,new ProtocolVersion("HTTP",1,1)); HttpProtocolParams.setContentCharset(params,"UTF-8"); params.setBooleanParameter("http.protocol.expect-continue",false); SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); final SSLSocketFactory sslSocketFactory=SSLSocketFactory.getSocketFactory(); sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier()); registry.register(new Scheme("https",sslSocketFactory,443)); ThreadSafeClientConnManager manager=new ThreadSafeClientConnManager(params,registry); ret=new DefaultHttpClient(manager,params); return ret; }
Example 85
From project lightbox-android-webservices, under directory /LightboxAndroidWebServices/src/com/lightbox/android/network/.
Source file: HttpHelper.java

/** * Create an HttpClient. * @return a properly set HttpClient */ private static DefaultHttpClient createHttpClient(){ HttpParams params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme(STRING_HTTP,PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme(STRING_HTTPS,SSLSocketFactory.getSocketFactory(),443)); HttpConnectionParams.setConnectionTimeout(params,HTTP_TIMEOUT); HttpConnectionParams.setSoTimeout(params,HTTP_TIMEOUT); ConnManagerParams.setTimeout(params,HTTP_TIMEOUT); HttpConnectionParams.setSocketBufferSize(params,SOCKET_BUFFER_SIZE); HttpProtocolParams.setContentCharset(params,HTTP.UTF_8); HttpProtocolParams.setHttpElementCharset(params,HTTP.UTF_8); HttpProtocolParams.setUserAgent(params,String.format(USER_AGENT_FORMAT_STRING,AndroidUtils.getApplicationLabel(),AndroidUtils.getVersionCode(),android.os.Build.VERSION.RELEASE,android.os.Build.MODEL)); DefaultHttpClient client=new DefaultHttpClient(new ThreadSafeClientConnManager(params,schemeRegistry),params); enableGzipCompression(client); return client; }
Example 86
From project LRJavaLib, under directory /src/com/navnorth/learningregistry/.
Source file: LRClient.java

public static HttpClient getHttpClient(String scheme){ if (scheme.equals("https")) { try { KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null,null); SSLSocketFactory sf=new SelfSignSSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params,HTTP.UTF_8); SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registry.register(new Scheme("https",sf,443)); ClientConnectionManager ccm=new ThreadSafeClientConnManager(params,registry); return new DefaultHttpClient(ccm,params); } catch ( Exception e) { return new DefaultHttpClient(); } } else { return new DefaultHttpClient(); } }
Example 87
From project Maimonides, under directory /src/com/codeko/apps/maimonides/seneca/.
Source file: ClienteSeneca.java

public HttpClient getCliente(){ if (cliente == null) { try { SSLContext ctx=SSLContext.getInstance("TLS"); 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; } } ; ctx.init(null,new TrustManager[]{tm},null); SSLSocketFactory ssf=new SSLSocketFactory(ctx,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",80,PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https",443,ssf)); HttpParams params=new BasicHttpParams(); HttpProtocolParams.setUserAgent(params,"Mozilla/5.0 (X11; U; Linux i686; es-ES; rv:1.9.2.12) Gecko/20101027 Ubuntu/10.04 (lucid) Firefox/3.6.12"); ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(schemeRegistry); cm.setDefaultMaxPerRoute(10); cm.setMaxTotal(20); HttpConnectionParams.setConnectionTimeout(params,1000); cliente=new DefaultHttpClient(cm,params); } catch ( Exception ex) { Logger.getLogger(ClienteSeneca.class.getName()).log(Level.SEVERE,null,ex); setUltimoError("Error conectando con S?neca: " + ex.getLocalizedMessage()); setUltimaExcepcion(ex); } } ThreadSafeClientConnManager man=(ThreadSafeClientConnManager)cliente.getConnectionManager(); man.closeExpiredConnections(); man.closeIdleConnections(10,TimeUnit.SECONDS); Logger.getLogger(ClienteSeneca.class.getName()).log(Level.INFO,"Hay {0} conexiones abiertas.",man.getConnectionsInPool()); return cliente; }
Example 88
From project memcached-session-manager, under directory /core/src/test/java/de/javakaffee/web/msm/integration/.
Source file: NonStickySessionsIntegrationTest.java

@BeforeMethod public void setUp() throws Throwable { final InetSocketAddress address1=new InetSocketAddress("localhost",MEMCACHED_PORT_1); _daemon1=createDaemon(address1); _daemon1.start(); final InetSocketAddress address2=new InetSocketAddress("localhost",MEMCACHED_PORT_2); _daemon2=createDaemon(address2); _daemon2.start(); try { _tomcat1=startTomcat(TC_PORT_1); _tomcat2=startTomcat(TC_PORT_2); } catch ( final Throwable e) { LOG.error("could not start tomcat.",e); throw e; } final MemcachedNodesManager nodesManager=MemcachedNodesManager.createFor(MEMCACHED_NODES,null,_memcachedClientCallback); _client=new MemcachedClient(new SuffixLocatorConnectionFactory(nodesManager,nodesManager.getSessionIdFormat(),Statistics.create(),1000),Arrays.asList(address1,address2)); final SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); _httpClient=new DefaultHttpClient(new ThreadSafeClientConnManager(schemeRegistry)); _executor=Executors.newCachedThreadPool(); }
Example 89
From project miso-lims, under directory /core/src/main/java/uk/ac/bbsrc/tgac/miso/core/manager/.
Source file: ERASubmissionManager.java

/** * Builds a "trusting" trust manager. This is totally horrible and basically ignores everything that SSL stands for. This allows connection to self-signed certificate hosts, bypassing the normal validation exceptions that occur. <p/> Use at your own risk - again, this is horrible! */ public DefaultHttpClient getEvilTrustingTrustManager(DefaultHttpClient httpClient){ try { X509TrustManager trustManager=new X509TrustManager(){ public void checkClientTrusted( X509Certificate[] chain, String authType) throws CertificateException { log.warn("BYPASSING CLIENT TRUSTED CHECK!"); } public void checkServerTrusted( X509Certificate[] chain, String authType) throws CertificateException { log.warn("BYPASSING SERVER TRUSTED CHECK!"); } public X509Certificate[] getAcceptedIssuers(){ log.warn("BYPASSING CERTIFICATE ISSUER CHECKS!"); return null; } } ; SSLContext sslcontext=SSLContext.getInstance("TLS"); sslcontext.init(null,new TrustManager[]{trustManager},null); SSLSocketFactory sf=new SSLSocketFactory(sslcontext); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm=httpClient.getConnectionManager(); SchemeRegistry schemeRegistry=ccm.getSchemeRegistry(); schemeRegistry.register(new Scheme("https",sf,443)); return new DefaultHttpClient(ccm,httpClient.getParams()); } catch ( Throwable t) { log.warn("Something nasty happened with the EvilTrustingTrustManager. Warranty is null and void!"); t.printStackTrace(); return null; } }
Example 90
From project MobiPerf, under directory /android/src/com/mobiperf/speedometer/.
Source file: Checkin.java

/** * Return an appropriately-configured HTTP client. */ private HttpClient getNewHttpClient(){ DefaultHttpClient client; try { KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null,null); SSLSocketFactory sf=new MySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params,HTTP.UTF_8); HttpConnectionParams.setConnectionTimeout(params,POST_TIMEOUT_MILLISEC); HttpConnectionParams.setSoTimeout(params,POST_TIMEOUT_MILLISEC); SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registry.register(new Scheme("https",sf,443)); ClientConnectionManager ccm=new ThreadSafeClientConnManager(params,registry); client=new DefaultHttpClient(ccm,params); } catch ( Exception e) { Logger.w("Unable to create SSL HTTP client",e); client=new DefaultHttpClient(); } CookieStore store=new BasicCookieStore(); store.addCookie(authCookie); client.setCookieStore(store); return client; }
Example 91
From project moho, under directory /moho-impl/src/main/java/com/voxeo/moho/imified/.
Source file: IMifiedDriver.java

@Override public void init(SpiFramework framework){ _appEventSource=framework; HttpServlet servlet=framework.getHTTPController(); if (servlet.getServletConfig().getInitParameter("imifiedApiURL") != null) { _imifiedApiURL=servlet.getServletConfig().getInitParameter("imifiedApiURL"); } HttpParams params=new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params,20); ConnPerRouteBean connPerRoute=new ConnPerRouteBean(20); ConnManagerParams.setMaxConnectionsPerRoute(params,connPerRoute); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager cm=new ThreadSafeClientConnManager(params,schemeRegistry); _httpClient=new DefaultHttpClient(cm,params); _httpClient.setReuseStrategy(new DefaultConnectionReuseStrategy()); _httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy(){ public long getKeepAliveDuration( HttpResponse response, HttpContext context){ HeaderElementIterator it=new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE)); while (it.hasNext()) { HeaderElement he=it.nextElement(); String param=he.getName(); String value=he.getValue(); if (value != null && param.equalsIgnoreCase("timeout")) { try { return Long.parseLong(value) * 1000; } catch ( NumberFormatException ex) { } } } return -1; } } ); }
Example 92
From project npr-android-app, under directory /src/org/npr/android/news/.
Source file: StreamProxy.java

private HttpResponse download(String url){ DefaultHttpClient seed=new DefaultHttpClient(); SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); SingleClientConnManager mgr=new MyClientConnManager(seed.getParams(),registry); DefaultHttpClient http=new DefaultHttpClient(mgr,seed.getParams()); HttpGet method=new HttpGet(url); HttpResponse response=null; try { Log.d(LOG_TAG,"starting download"); response=http.execute(method); Log.d(LOG_TAG,"downloaded"); } catch ( ClientProtocolException e) { Log.e(LOG_TAG,"Error downloading",e); } catch ( IOException e) { Log.e(LOG_TAG,"Error downloading",e); } return response; }
Example 93
From project nuxeo-distribution, under directory /nuxeo-startup-wizard/src/main/java/org/nuxeo/wizard/download/.
Source file: PackageDownloader.java

protected PackageDownloader(){ SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); HttpParams httpParams=new BasicHttpParams(); HttpProtocolParams.setUseExpectContinue(httpParams,false); ConnManagerParams.setMaxTotalConnections(httpParams,NB_DOWNLOAD_THREADS); ConnManagerParams.setMaxConnectionsPerRoute(httpParams,new ConnPerRoute(){ @Override public int getMaxForRoute( HttpRoute arg0){ return NB_DOWNLOAD_THREADS; } } ); ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(httpParams,registry); httpClient=new DefaultHttpClient(cm,httpParams); }
Example 94
From project OAK, under directory /oak-library/src/main/java/oak/external/com/github/droidfu/http/.
Source file: BetterHttp.java

public static void setupHttpClient(){ BasicHttpParams httpParams=new BasicHttpParams(); ConnManagerParams.setTimeout(httpParams,socketTimeout); ConnManagerParams.setMaxConnectionsPerRoute(httpParams,new ConnPerRouteBean(maxConnections)); ConnManagerParams.setMaxTotalConnections(httpParams,DEFAULT_MAX_CONNECTIONS); HttpConnectionParams.setSoTimeout(httpParams,socketTimeout); HttpConnectionParams.setTcpNoDelay(httpParams,true); HttpProtocolParams.setVersion(httpParams,HttpVersion.HTTP_1_1); HttpProtocolParams.setUserAgent(httpParams,httpUserAgent); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); if (DiagnosticSupport.ANDROID_API_LEVEL >= 7) { schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); } else { schemeRegistry.register(new Scheme("https",new EasySSLSocketFactory(),443)); } ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(httpParams,schemeRegistry); httpClient=new DefaultHttpClient(cm,httpParams); }
Example 95
From project OpenMEAP, under directory /java-shared/openmeap-shared-jdk5/src/com/openmeap/util/.
Source file: SSLUtils.java

static public HttpClient getRelaxedSSLVerificationHttpClient(){ try { KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null,null); SSLSocketFactory sf=new MySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params,FormConstants.CHAR_ENC_DEFAULT); SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registry.register(new Scheme("https",sf,443)); ClientConnectionManager ccm=new ThreadSafeClientConnManager(params,registry); return new DefaultHttpClient(ccm,params); } catch ( Exception e) { return new DefaultHttpClient(); } }
Example 96
From project processFlowProvision, under directory /osProvision/src/main/java/org/jboss/processFlow/openshift/.
Source file: ShifterProvisioner.java

private void prepConnection() throws Exception { httpClient=new DefaultHttpClient(); SSLContext sslContext=SSLContext.getInstance("SSL"); sslContext.init(null,new TrustManager[]{new X509TrustManager(){ public X509Certificate[] getAcceptedIssuers(){ System.out.println("getAcceptedIssuers ============="); return null; } public void checkClientTrusted( X509Certificate[] certs, String authType){ System.out.println("checkClientTrusted ============="); } public void checkServerTrusted( X509Certificate[] certs, String authType){ System.out.println("checkServerTrusted ============="); } } },new SecureRandom()); SSLSocketFactory ssf=new SSLSocketFactory(sslContext,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm=httpClient.getConnectionManager(); SchemeRegistry sr=ccm.getSchemeRegistry(); sr.register(new Scheme("https",443,ssf)); UsernamePasswordCredentials credentials=new UsernamePasswordCredentials(accountId,password); URL urlObj=new URL(openshiftRestURI); AuthScope aScope=new AuthScope(urlObj.getHost(),urlObj.getPort()); httpClient.getCredentialsProvider().setCredentials(aScope,credentials); httpClient.addRequestInterceptor(new PreemptiveAuthInterceptor(),0); }
Example 97
From project proxy-servlet, under directory /src/main/java/com/woonoz/proxy/servlet/.
Source file: ProxyServlet.java

public void init(ProxyServletConfig config){ targetServer=config.getTargetUrl(); if (targetServer != null) { SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme(targetServer.getProtocol(),getPortOrDefault(targetServer.getPort()),PlainSocketFactory.getSocketFactory())); BasicHttpParams httpParams=new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams,config.getConnectionTimeout()); HttpConnectionParams.setSoTimeout(httpParams,config.getSocketTimeout()); ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(schemeRegistry); cm.setDefaultMaxPerRoute(config.getMaxConnections()); cm.setMaxTotal(config.getMaxConnections()); client=new DefaultHttpClient(cm,httpParams); client.removeResponseInterceptorByClass(ResponseProcessCookies.class); client.removeRequestInterceptorByClass(RequestAddCookies.class); final String remoteUserHeader=config.getRemoteUserHeader(); if (null != remoteUserHeader) { client.addRequestInterceptor(new HttpRequestInterceptor(){ @Override public void process( HttpRequest request, HttpContext context) throws HttpException, IOException { request.removeHeaders(remoteUserHeader); HttpRequestHandler handler; if (context != null && (handler=(HttpRequestHandler)context.getAttribute(HttpRequestHandler.class.getName())) != null) { String remoteUser=handler.getRequest().getRemoteUser(); if (remoteUser != null) { request.addHeader(remoteUserHeader,remoteUser); } } } } ); } } }
Example 98
From project proxydroid, under directory /src/com/github/droidfu/http/.
Source file: BetterHttp.java

public static void setupHttpClient(){ BasicHttpParams httpParams=new BasicHttpParams(); ConnManagerParams.setTimeout(httpParams,socketTimeout); ConnManagerParams.setMaxConnectionsPerRoute(httpParams,new ConnPerRouteBean(maxConnections)); ConnManagerParams.setMaxTotalConnections(httpParams,DEFAULT_MAX_CONNECTIONS); HttpConnectionParams.setSoTimeout(httpParams,socketTimeout); HttpConnectionParams.setTcpNoDelay(httpParams,true); HttpProtocolParams.setVersion(httpParams,HttpVersion.HTTP_1_1); HttpProtocolParams.setUserAgent(httpParams,httpUserAgent); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(httpParams,schemeRegistry); httpClient=new DefaultHttpClient(cm,httpParams); }
Example 99
From project rundeck-api-java-client, under directory /src/main/java/org/rundeck/api/.
Source file: ApiCall.java

/** * Instantiate a new {@link HttpClient} instance, configured to accept all SSL certificates * @return an {@link HttpClient} instance - won't be null */ private HttpClient instantiateHttpClient(){ DefaultHttpClient httpClient=new DefaultHttpClient(); HttpProtocolParams.setUserAgent(httpClient.getParams(),"RunDeck API Java Client " + RundeckClient.API_VERSION); SSLSocketFactory socketFactory=null; try { socketFactory=new SSLSocketFactory(new TrustStrategy(){ @Override public boolean isTrusted( X509Certificate[] chain, String authType) throws CertificateException { return true; } } ,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } catch ( KeyManagementException e) { throw new RuntimeException(e); } catch ( UnrecoverableKeyException e) { throw new RuntimeException(e); } catch ( NoSuchAlgorithmException e) { throw new RuntimeException(e); } catch ( KeyStoreException e) { throw new RuntimeException(e); } httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https",443,socketFactory)); System.setProperty("java.net.useSystemProxies","true"); httpClient.setRoutePlanner(new ProxySelectorRoutePlanner(httpClient.getConnectionManager().getSchemeRegistry(),ProxySelector.getDefault())); httpClient.addRequestInterceptor(new HttpRequestInterceptor(){ @Override public void process( HttpRequest request, HttpContext context) throws HttpException, IOException { if (client.getToken() != null) { request.addHeader(AUTH_TOKEN_HEADER,client.getToken()); } } } ); return httpClient; }
Example 100
From project sensei, under directory /sensei-core/src/main/java/com/senseidb/dataprovider/http/.
Source file: HttpsClientDecorator.java

public static DefaultHttpClient decorate(DefaultHttpClient 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) { logger.error(ex.getMessage(),ex); return null; } }
Example 101
From project skalli, under directory /org.eclipse.skalli.core/src/main/java/org/eclipse/skalli/core/internal/destination/.
Source file: DestinationServiceImpl.java

private void initializeConnectionManager(){ connectionManager=new ThreadSafeClientConnManager(); connectionManager.setMaxTotal(MAX_TOTAL_CONNECTIONS); connectionManager.setDefaultMaxPerRoute(MAX_CONNECTIONS_PER_ROUTE); SSLContext sslContext=getSSLContext(); try { sslContext.init(null,new TrustManager[]{new AlwaysTrustX509Manager()},null); } catch ( KeyManagementException e) { throw new IllegalStateException("Failed to initialize SSL context",e); } SSLSocketFactory socketFactory=new SSLSocketFactory(sslContext,new AllowAllHostnamesVerifier()); SchemeRegistry schemeRegistry=connectionManager.getSchemeRegistry(); schemeRegistry.register(new Scheme(HTTPS,443,socketFactory)); }
Example 102
From project SMSSync, under directory /smssync/src/org/addhen/smssync/net/.
Source file: MainHttpClient.java

public MainHttpClient(String url){ this.url=url; httpParameters=new BasicHttpParams(); httpParameters.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS,1); httpParameters.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE,new ConnPerRouteBean(1)); httpParameters.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE,false); HttpProtocolParams.setVersion(httpParameters,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(httpParameters,"utf8"); HttpConnectionParams.setConnectionTimeout(httpParameters,timeoutConnection); HttpConnectionParams.setSoTimeout(httpParameters,timeoutSocket); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); try { schemeRegistry.register(new Scheme("https",new TrustedSocketFactory(url,false),443)); } catch ( KeyManagementException e) { e.printStackTrace(); } catch ( NoSuchAlgorithmException e) { e.printStackTrace(); } ThreadSafeClientConnManager manager=new ThreadSafeClientConnManager(httpParameters,schemeRegistry); httpclient=new DefaultHttpClient(manager,httpParameters); }
Example 103
From project Speedometer, under directory /android/src/com/google/wireless/speed/speedometer/.
Source file: Checkin.java

/** * Return an appropriately-configured HTTP client. */ private HttpClient getNewHttpClient(){ DefaultHttpClient client; try { KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null,null); SSLSocketFactory sf=new MySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params,HTTP.UTF_8); HttpConnectionParams.setConnectionTimeout(params,POST_TIMEOUT_MILLISEC); HttpConnectionParams.setSoTimeout(params,POST_TIMEOUT_MILLISEC); SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registry.register(new Scheme("https",sf,443)); ClientConnectionManager ccm=new ThreadSafeClientConnManager(params,registry); client=new DefaultHttpClient(ccm,params); } catch ( Exception e) { Logger.w("Unable to create SSL HTTP client",e); client=new DefaultHttpClient(); } CookieStore store=new BasicCookieStore(); store.addCookie(authCookie); client.setCookieStore(store); return client; }
Example 104
From project SqueezeControl, under directory /src/com/squeezecontrol/image/.
Source file: HttpFetchingImageStore.java

public HttpFetchingImageStore(String baseUrl,String username,String password){ this.baseUrl=baseUrl; HttpParams params=new BasicHttpParams(); HttpConnectionParams.setStaleCheckingEnabled(params,false); HttpConnectionParams.setConnectionTimeout(params,20 * 1000); HttpConnectionParams.setSoTimeout(params,20 * 1000); HttpConnectionParams.setSocketBufferSize(params,8192); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager mgr=new ThreadSafeClientConnManager(params,schemeRegistry); mClient=new DefaultHttpClient(mgr,params); if (username != null && !"".equals(username)) { Credentials defaultcreds=new UsernamePasswordCredentials("dag","test"); mClient.getCredentialsProvider().setCredentials(AuthScope.ANY,defaultcreds); } }
Example 105
From project SVQCOM, under directory /Core/src/com/ushahidi/android/app/net/.
Source file: MainHttpClient.java

public MainHttpClient(Context context){ httpParameters=new BasicHttpParams(); httpParameters.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS,1); httpParameters.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE,new ConnPerRouteBean(1)); httpParameters.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE,false); HttpProtocolParams.setVersion(httpParameters,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(httpParameters,"utf8"); HttpConnectionParams.setConnectionTimeout(httpParameters,timeoutConnection); HttpConnectionParams.setSoTimeout(httpParameters,timeoutSocket); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); try { schemeRegistry.register(new Scheme("https",new TrustedSocketFactory(Preferences.domain,false),443)); } catch ( KeyManagementException e) { e.printStackTrace(); } catch ( NoSuchAlgorithmException e) { e.printStackTrace(); } httpClient=new DefaultHttpClient(new ThreadSafeClientConnManager(httpParameters,schemeRegistry),httpParameters); }
Example 106
From project TextSecure, under directory /src/org/thoughtcrime/securesms/mms/.
Source file: MmsCommunication.java

protected static HttpClient constructHttpClient(MmsConnectionParameters mmsConfig){ HttpParams params=new BasicHttpParams(); HttpConnectionParams.setStaleCheckingEnabled(params,false); HttpConnectionParams.setConnectionTimeout(params,20 * 1000); HttpConnectionParams.setSoTimeout(params,20 * 1000); HttpConnectionParams.setSocketBufferSize(params,8192); HttpClientParams.setRedirecting(params,false); HttpProtocolParams.setUserAgent(params,"TextSecure/0.1"); HttpProtocolParams.setContentCharset(params,"UTF-8"); if (mmsConfig.hasProxy()) { ConnRouteParams.setDefaultProxy(params,new HttpHost(mmsConfig.getProxy(),mmsConfig.getPort())); } SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager manager=new ThreadSafeClientConnManager(params,schemeRegistry); return new DefaultHttpClient(manager,params); }
Example 107
From project twitter4j_1, under directory /twitter4j-httpclient-support/src/main/java/twitter4j/internal/http/alternative/.
Source file: HttpClientImpl.java

public HttpClientImpl(HttpClientConfiguration conf){ this.conf=conf; SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",80,PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https",443,SSLSocketFactory.getSocketFactory())); ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(schemeRegistry); cm.setMaxTotal(conf.getHttpMaxTotalConnections()); cm.setDefaultMaxPerRoute(conf.getHttpDefaultMaxPerRoute()); DefaultHttpClient client=new DefaultHttpClient(cm); HttpParams params=client.getParams(); HttpConnectionParams.setConnectionTimeout(params,conf.getHttpConnectionTimeout()); HttpConnectionParams.setSoTimeout(params,conf.getHttpReadTimeout()); if (conf.getHttpProxyHost() != null && !conf.getHttpProxyHost().equals("")) { HttpHost proxy=new HttpHost(conf.getHttpProxyHost(),conf.getHttpProxyPort()); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy); if (conf.getHttpProxyUser() != null && !conf.getHttpProxyUser().equals("")) { if (logger.isDebugEnabled()) { logger.debug("Proxy AuthUser: " + conf.getHttpProxyUser()); logger.debug("Proxy AuthPassword: " + z_T4JInternalStringUtil.maskString(conf.getHttpProxyPassword())); } client.getCredentialsProvider().setCredentials(new AuthScope(conf.getHttpProxyHost(),conf.getHttpProxyPort()),new UsernamePasswordCredentials(conf.getHttpProxyUser(),conf.getHttpProxyPassword())); } } this.client=client; }
Example 108
From project Ushahidi_Android, under directory /Core/src/com/ushahidi/android/app/net/.
Source file: MainHttpClient.java

public MainHttpClient(Context context){ this.context=context; httpParameters=new BasicHttpParams(); httpParameters.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS,1); httpParameters.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE,new ConnPerRouteBean(1)); httpParameters.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE,false); HttpProtocolParams.setVersion(httpParameters,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(httpParameters,"utf8"); HttpConnectionParams.setConnectionTimeout(httpParameters,timeoutConnection); HttpConnectionParams.setSoTimeout(httpParameters,timeoutSocket); SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); try { schemeRegistry.register(new Scheme("https",new TrustedSocketFactory(Preferences.domain,false),443)); } catch ( KeyManagementException e) { e.printStackTrace(); } catch ( NoSuchAlgorithmException e) { e.printStackTrace(); } httpClient=new DefaultHttpClient(new ThreadSafeClientConnManager(httpParameters,schemeRegistry),httpParameters); httpClient.setParams(httpParameters); }
Example 109
From project YandexAPI, under directory /src/ru/elifantiev/yandex/.
Source file: SSLHttpClientFactory.java

public static HttpClient getNewHttpClient(){ try { KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null,null); SSLSocketFactory sf=new YandexSSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params=new BasicHttpParams(); HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params,HTTP.UTF_8); SchemeRegistry registry=new SchemeRegistry(); registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); registry.register(new Scheme("https",sf,443)); ClientConnectionManager ccm=new ThreadSafeClientConnManager(params,registry); return new DefaultHttpClient(ccm,params); } catch ( Exception e) { return new DefaultHttpClient(); } }
Example 110
From project zxing-android, under directory /src/com/laundrylocker/barcodescanner/.
Source file: AndroidHttpClient.java

/** * Create a new HttpClient with reasonable defaults (which you can update). * @param userAgent to report in your HTTP requests. * @return AndroidHttpClient for you to use for all your requests. */ public static AndroidHttpClient newInstance(String userAgent){ HttpParams params=new BasicHttpParams(); HttpConnectionParams.setStaleCheckingEnabled(params,false); HttpConnectionParams.setConnectionTimeout(params,20 * 1000); HttpConnectionParams.setSoTimeout(params,20 * 1000); HttpConnectionParams.setSocketBufferSize(params,8192); HttpClientParams.setRedirecting(params,false); if (userAgent != null) { HttpProtocolParams.setUserAgent(params,userAgent); } SchemeRegistry schemeRegistry=new SchemeRegistry(); schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80)); schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443)); ClientConnectionManager manager=new ThreadSafeClientConnManager(params,schemeRegistry); return new AndroidHttpClient(manager,params); }
Example 111
From project Zypr-API-Access-Library---Java, under directory /source/net/zypr/api/.
Source file: Protocol.java

private DefaultHttpClient getHTTPClient(){ DefaultHttpClient httpclient=new DefaultHttpClient(); httpclient.getConnectionManager().getSchemeRegistry().register(new Scheme("https",_socketFactory,443)); httpclient.addRequestInterceptor(new HttpRequestInterceptor(){ public void process( final HttpRequest request, final HttpContext context) throws HttpException, IOException { if (!request.containsHeader("Accept-Encoding")) { request.addHeader("Accept-Encoding","gzip"); } } } ); httpclient.addResponseInterceptor(new HttpResponseInterceptor(){ public void process( final HttpResponse response, final HttpContext context) throws HttpException, IOException { HttpEntity entity=response.getEntity(); Header ceheader=entity.getContentEncoding(); if (ceheader != null) { HeaderElement[] codecs=ceheader.getElements(); for (int index=0; index < codecs.length; index++) if (codecs[index].getName().equalsIgnoreCase("gzip")) { response.setEntity(new GzipDecompressingEntity(response.getEntity())); return; } } } } ); return (httpclient); }