Example usage for org.apache.http.conn.scheme PlainSocketFactory PlainSocketFactory

List of usage examples for org.apache.http.conn.scheme PlainSocketFactory PlainSocketFactory

Introduction

In this page you can find the example usage for org.apache.http.conn.scheme PlainSocketFactory PlainSocketFactory.

Prototype

public PlainSocketFactory() 

Source Link

Usage

From source file:Main.java

private static void ensureHttpClient() {
    if (httpClient != null)
        return;/*from w  w  w.j  a v a2s  .  c  o  m*/

    BasicHttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, 45000);
    HttpConnectionParams.setSoTimeout(params, 30000);

    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", new PlainSocketFactory(), 80));
    try {
        registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    } catch (Exception e) {
        Log.w(TAG, "Unable to register HTTPS socket factory: " + e.getLocalizedMessage());
    }

    ThreadSafeClientConnManager connManager = new ThreadSafeClientConnManager(params, registry);
    httpClient = new DefaultHttpClient(connManager, params);
}

From source file:Main.java

public static HttpClient getHttpClient() {

    if (httpClient != null) {
        return httpClient;
    }/*from   ww  w  .  j  a va 2 s .c om*/

    synchronized (HTTP_CLIENT) {
        HttpParams defaultParams = new BasicHttpParams();
        defaultParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 6000);
        defaultParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 6000);
        defaultParams.setLongParameter(ConnManagerPNames.TIMEOUT, 6000);

        SchemeRegistry scheme = new SchemeRegistry();
        scheme.register(new Scheme("http", new PlainSocketFactory(), 80));
        scheme.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

        ClientConnectionManager connMgr = new ThreadSafeClientConnManager(defaultParams, scheme);

        httpClient = new DefaultHttpClient(connMgr, defaultParams);
    }

    return httpClient;
}

From source file:org.transdroid.util.HttpHelper.java

public static HttpClient buildDefaultSearchHttpClient(boolean ignoreSslIssues) {

    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", new PlainSocketFactory(), 80));
    registry.register(new Scheme("https",
            ignoreSslIssues ? new IgnoreTlsSniSocketFactory() : new TlsSniSocketFactory(), 443));

    HttpParams httpparams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpparams, 8000);
    HttpConnectionParams.setSoTimeout(httpparams, 8000);
    DefaultHttpClient httpclient = new DefaultHttpClient(new ThreadSafeClientConnManager(httpparams, registry),
            httpparams);//from  w ww .j av  a 2  s  .c  o  m

    httpclient.addRequestInterceptor(HttpHelper.gzipRequestInterceptor);
    httpclient.addResponseInterceptor(HttpHelper.gzipResponseInterceptor);

    return httpclient;

}

From source file:org.ttrssreader.net.deprecated.HttpClientFactory.java

public HttpClientFactory() {

    boolean trustAllSslCerts = Controller.getInstance().trustAllSsl();
    boolean useCustomKeyStore = Controller.getInstance().useKeystore();

    registry = new SchemeRegistry();
    registry.register(new Scheme("http", new PlainSocketFactory(), 80));

    SocketFactory socketFactory;//from  w w  w  .  j av a  2s.c  o  m

    if (useCustomKeyStore && !trustAllSslCerts) {
        String keystorePassword = Controller.getInstance().getKeystorePassword();

        socketFactory = newSslSocketFactory(keystorePassword);
        if (socketFactory == null) {
            socketFactory = SSLSocketFactory.getSocketFactory();
            Log.w(TAG, "Custom key store could not be read, using default settings.");
        }

    } else if (trustAllSslCerts) {
        socketFactory = new FakeSocketFactory();
    } else {
        socketFactory = SSLSocketFactory.getSocketFactory();
    }

    registry.register(new Scheme("https", socketFactory, 443));

}

From source file:com.villemos.ispace.httpcrawler.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;/*w  w  w  .j  a va2s. c om*/

    /** Always ignore authentication protocol errors. */
    if (ignoreAuthenticationFailure) {
        SSLContext sslContext = SSLContext.getInstance("SSL");

        // set up a TrustManager that trusts everything
        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);
    }

    /** The target location may demand authentication. We setup preemptive authentication. */
    if (authUser != null && authPassword != null) {
        client.getCredentialsProvider().setCredentials(new AuthScope(domain, port),
                new UsernamePasswordCredentials(authUser, authPassword));
    }

    /** Set default cookie policy and store. Can be overridden for a specific method using for example;
     *    method.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY); 
     */
    client.setCookieStore(cookieStore);
    // client.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2965);      
    client.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);

    return client;
}

From source file:fr.itinerennes.api.client.TripDetailsTest.java

/**
 * Setup the ItineRennes client.//from   ww  w . ja  v a2 s  . c  om
 */
@Before
public void setupItineRennesClient() throws ParseException, IOException {

    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 JsonItineRennesApiClient obaClient = new JsonItineRennesApiClient(httpClient,
            SERVER.getUrl().toString());

    trip = obaClient.getTripDetails("2_12235");
}

From source file:fr.itinerennes.api.client.ScheduleForStopTest.java

/**
 * Setup the ItineRennes client./*from  w  w  w  . java  2  s .  c o  m*/
 */
@Before
public void setupItineRennesClient() throws ParseException, IOException {

    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 JsonItineRennesApiClient obaClient = new JsonItineRennesApiClient(httpClient,
            SERVER.getUrl().toString());

    final Calendar calendar = Calendar.getInstance();
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    calendar.setTime(sdf.parse("2013-11-04"));

    schedule = obaClient.getScheduleForStop("2_1017", calendar.getTime());
}

From source file:fr.dudie.keolis.client.AbstractJsonKeolisClientTest.java

/**
 * Instantiates the test./*from   w  ww  .ja  va  2  s  .c  o  m*/
 * 
 * @throws IOException
 *             an error occurred durign initialization
 */
public AbstractJsonKeolisClientTest() throws IOException {

    LOGGER.info("Loading configuration file {}", PROPS_PATH);
    final InputStream in = AbstractJsonKeolisClientTest.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("keolis.api.url");
    final String key = PROPS.getProperty("keolis.api.key");
    keolisClient = new JsonKeolisClient(httpClient, url, key);

}

From source file:neembuu.release1.httpclient.NHttpClient.java

public static DefaultHttpClient getNewInstance() {
    DefaultHttpClient new_httpClient = null;
    new_httpClient = new DefaultHttpClient();
    GlobalTestSettings.ProxySettings proxySettings = GlobalTestSettings.getGlobalProxySettings();
    HttpContext context = new BasicHttpContext();
    SchemeRegistry schemeRegistry = new SchemeRegistry();

    schemeRegistry.register(new Scheme("http", new PlainSocketFactory(), 80));

    try {/*from ww  w  .  j  a  v  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,
            new_httpClient.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));
    }

    new_httpClient = new DefaultHttpClient(
            new SingleClientConnManager(httpParams/*file.httpClient.getParams()*/, schemeRegistry),
            httpParams/*file.httpClient.getParams()*/);

    if (proxySettings != null) {
        new_httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials(proxySettings.userName, proxySettings.password));
    }

    return new_httpClient;
}

From source file:fr.itinerennes.api.client.JsonItineRennesApiClientTest.java

/**
 * Setup the ItineRennes client.// w ww  .  j  a  v a 2s .  c o  m
 */
@Before
public void setupItineRennesClient() {

    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);
    obaClient = new JsonItineRennesApiClient(httpClient, SERVER.getUrl().toString(), "test");
}