List of usage examples for org.apache.http.conn.scheme PlainSocketFactory PlainSocketFactory
public PlainSocketFactory()
From source file:fr.dudie.nominatim.client.JsonNominatimClientTest.java
/** * Instantiates the test.//from w w w . j a v a 2s . co m * * @throws IOException * an error occurred during initialization */ public JsonNominatimClientTest() throws IOException { LOGGER.info("Loading configuration file {}", PROPS_PATH); final InputStream in = JsonNominatimClientTest.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 baseUrl = PROPS.getProperty("nominatim.server.url"); final String email = PROPS.getProperty("nominatim.headerEmail"); nominatimClient = new JsonNominatimClient(baseUrl, httpClient, email); }
From source file:com.google.appengine.tck.teamcity.ReportsFeature.java
public void start() { SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", 80, new PlainSocketFactory())); registry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); ClientConnectionManager ccm = new PoolingClientConnectionManager(registry); client = new DefaultHttpClient(ccm); }
From source file:neembuu.vfs.test.FileNameAndSizeFinderService.java
private DefaultHttpClient newClient() { DefaultHttpClient client = new DefaultHttpClient(); GlobalTestSettings.ProxySettings proxySettings = GlobalTestSettings.getGlobalProxySettings(); HttpContext context = new BasicHttpContext(); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", new PlainSocketFactory(), 80)); try {/* w ww .j av a 2 s . c o m*/ KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); schemeRegistry.register(new Scheme("https", new SSLSocketFactory(keyStore), 8080)); } catch (Exception a) { a.printStackTrace(System.err); } context.setAttribute(ClientContext.SCHEME_REGISTRY, schemeRegistry); context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, new BasicScheme()/*file.httpClient.getAuthSchemes()*/); context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, client.getCookieSpecs()/*file.httpClient.getCookieSpecs()*/ ); BasicCookieStore basicCookieStore = new BasicCookieStore(); context.setAttribute(ClientContext.COOKIE_STORE, basicCookieStore/*file.httpClient.getCookieStore()*/); context.setAttribute(ClientContext.CREDS_PROVIDER, new BasicCredentialsProvider()/*file.httpClient.getCredentialsProvider()*/); HttpConnection hc = new DefaultHttpClientConnection(); context.setAttribute(ExecutionContext.HTTP_CONNECTION, hc); //System.out.println(file.httpClient.getParams().getParameter("http.useragent")); HttpParams httpParams = new BasicHttpParams(); if (proxySettings != null) { AuthState as = new AuthState(); as.setCredentials(new UsernamePasswordCredentials(proxySettings.userName, proxySettings.password)); as.setAuthScope(AuthScope.ANY); as.setAuthScheme(new BasicScheme()); httpParams.setParameter(ClientContext.PROXY_AUTH_STATE, as); httpParams.setParameter("http.proxy_host", new HttpHost(proxySettings.host, proxySettings.port)); } client = new DefaultHttpClient( new SingleClientConnManager(httpParams/*file.httpClient.getParams()*/, schemeRegistry), httpParams/*file.httpClient.getParams()*/); if (proxySettings != null) { client.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxySettings.userName, proxySettings.password)); } return client; }
From source file:com.ntsync.android.sync.client.MyHttpClient.java
protected ClientConnectionManager createClientConnectionManager() { SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", new PlainSocketFactory(), 80)); registry.register(new Scheme("https", getSSLSocketFactory(), 443)); HttpParams params = getParams();// ww w . j av a 2 s. c o m HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, READ_TIMEOUT_MS); ConnManagerParams.setTimeout(params, GET_CONNECTION_MS); HttpProtocolParams.setUserAgent(params, getUserAgent(context, HttpProtocolParams.getUserAgent(params))); return new ThreadSafeClientConnManager(params, registry); }
From source file:org.transdroid.daemon.util.HttpHelper.java
/** * Creates a standard Apache HttpClient that is thread safe, supports different SSL auth methods and basic * authentication//from w w w .j av a2 s. co m * @param sslTrustAll Whether to trust all SSL certificates * @param sslTrustkey A specific SSL key to accept exclusively * @param timeout The connection timeout for all requests * @param authAddress The authentication domain address * @param authPort The authentication domain port number * @return An HttpClient that should be stored locally and reused for every new request * @throws DaemonException Thrown when information (such as username/password) is missing */ public static DefaultHttpClient createStandardHttpClient(boolean userBasicAuth, String username, String password, boolean sslTrustAll, String sslTrustkey, int timeout, String authAddress, int authPort) throws DaemonException { // Register http and https sockets SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", new PlainSocketFactory(), 80)); SocketFactory https_socket = sslTrustAll ? new FakeSocketFactory() : sslTrustkey != null ? new FakeSocketFactory(sslTrustkey) : SSLSocketFactory.getSocketFactory(); registry.register(new Scheme("https", https_socket, 443)); // Standard parameters HttpParams httpparams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpparams, timeout); HttpConnectionParams.setSoTimeout(httpparams, timeout); if (userAgent != null) { HttpProtocolParams.setUserAgent(httpparams, userAgent); } DefaultHttpClient httpclient = new DefaultHttpClient(new ThreadSafeClientConnManager(httpparams, registry), httpparams); // Authentication credentials if (userBasicAuth) { if (username == null || password == null) { throw new DaemonException(ExceptionType.AuthenticationFailure, "No username or password was provided while we hadauthentication enabled"); } httpclient.getCredentialsProvider().setCredentials( new AuthScope(authAddress, authPort, AuthScope.ANY_REALM), new UsernamePasswordCredentials(username, password)); } return httpclient; }
From source file:info.androidhive.volleyjson.util.SslHttpStack.java
@Override public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError { HttpUriRequest httpRequest = createHttpRequest(request, additionalHeaders); addHeaders(httpRequest, additionalHeaders); addHeaders(httpRequest, request.getHeaders()); onPrepareRequest(httpRequest);//w w w . ja va2 s. c om HttpParams httpParams = httpRequest.getParams(); int timeoutMs = request.getTimeoutMs(); // TODO: Reevaluate this connection timeout based on more wide-scale // data collection and possibly different for wifi vs. 3G. //HttpConnectionParams.setConnectionTimeout(httpParams, 5000); //HttpConnectionParams.setSoTimeout(httpParams, timeoutMs); /* Register schemes, HTTP and HTTPS */ SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", new PlainSocketFactory(), 80)); registry.register(new Scheme("https", new EasySSLSocketFactory(mIsConnectingToYourServer), 443)); /* Make a thread safe connection manager for the client */ ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(httpParams, registry); HttpClient httpClient = new DefaultHttpClient(manager, httpParams); return httpClient.execute(httpRequest); }
From source file:cn.dacas.emmclient.security.ssl.SslHttpStack.java
@Override public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError { HttpUriRequest httpRequest = createHttpRequest(request, additionalHeaders); addHeaders(httpRequest, additionalHeaders); addHeaders(httpRequest, request.getHeaders()); onPrepareRequest(httpRequest);/*from w ww .j a v a 2 s . co m*/ HttpParams httpParams = httpRequest.getParams(); int timeoutMs = request.getTimeoutMs(); // TODO: Reevaluate this connection timeout based on more wide-scale // data collection and possibly different for wifi vs. 3G. HttpConnectionParams.setConnectionTimeout(httpParams, 5000); HttpConnectionParams.setSoTimeout(httpParams, timeoutMs); /* Register schemes, HTTP and HTTPS */ SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", new PlainSocketFactory(), 80)); registry.register(new Scheme("https", new EasySSLSocketFactory(mIsConnectingToYourServer), 443)); /* Make a thread safe connection manager for the client */ ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(httpParams, registry); HttpClient httpClient = new DefaultHttpClient(manager, httpParams); return httpClient.execute(httpRequest); }
From source file:com.android.volley.ssl.SslHttpStack.java
@Override public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError { HttpUriRequest httpRequest = createHttpRequest(request, additionalHeaders); addHeaders(httpRequest, additionalHeaders); addHeaders(httpRequest, request.getHeaders()); onPrepareRequest(httpRequest);// w w w.j a v a 2 s .c o m HttpParams httpParams = httpRequest.getParams(); int timeoutMs = request.getTimeoutMs(); // TODO: Reevaluate this connection timeout based on more wide-scale // data collection and possibly different for wifi vs. 3G. HttpConnectionParams.setConnectionTimeout(httpParams, 5000); HttpConnectionParams.setSoTimeout(httpParams, timeoutMs); /* Register schemes, HTTP and HTTPS */ SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", new PlainSocketFactory(), 80)); //registry.register(new Scheme("https", new EasySSLSocketFactory(mIsConnectingToYourServer), 443)); /* Make a thread safe connection manager for the client */ ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(httpParams, registry); HttpClient httpClient = new DefaultHttpClient(manager, httpParams); return httpClient.execute(httpRequest); }
From source file:org.eclipse.aether.transport.http.GlobalState.java
public static ClientConnectionManager newConnectionManager(SslConfig sslConfig) { SchemeRegistry schemeReg = new SchemeRegistry(); schemeReg.register(new Scheme("http", 80, new PlainSocketFactory())); schemeReg.register(new Scheme("https", 443, new SslSocketFactory(sslConfig))); PoolingClientConnectionManager connMgr = new PoolingClientConnectionManager(schemeReg); connMgr.setMaxTotal(100);/* w ww. j a va 2 s . c om*/ connMgr.setDefaultMaxPerRoute(50); return connMgr; }
From source file:org.hfoss.posit.web.Communicator.java
public Communicator(Context _context) { mContext = _context;/*from w w w . ja va 2 s.c o m*/ mTotalTime = 0; mStart = 0; mHttpParams = new BasicHttpParams(); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", new PlainSocketFactory(), 80)); mConnectionManager = new ThreadSafeClientConnManager(mHttpParams, registry); mHttpClient = new DefaultHttpClient(mConnectionManager, mHttpParams); PreferenceManager.setDefaultValues(mContext, R.xml.posit_preferences, false); applicationPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); setApplicationAttributes(applicationPreferences.getString("AUTHKEY", ""), applicationPreferences.getString("SERVER_ADDRESS", server), applicationPreferences.getInt("PROJECT_ID", projectId)); TelephonyManager manager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); imei = manager.getDeviceId(); }