Example usage for org.apache.http.impl.conn SingleClientConnManager SingleClientConnManager

List of usage examples for org.apache.http.impl.conn SingleClientConnManager SingleClientConnManager

Introduction

In this page you can find the example usage for org.apache.http.impl.conn SingleClientConnManager SingleClientConnManager.

Prototype

@Deprecated
public SingleClientConnManager(final HttpParams params, final SchemeRegistry schreg) 

Source Link

Document

Creates a new simple connection manager.

Usage

From source file:net.openwatch.acluaz.http.AZHttpClient.java

@Override
protected ClientConnectionManager createClientConnectionManager() {
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    // Register for port 443 our SSLSocketFactory with our keystore
    // to the ConnectionManager
    registry.register(new Scheme("https", newSslSocketFactory(), 443));
    return new SingleClientConnManager(getParams(), registry);
}

From source file:edu.syr.bytecast.githubcampfire.CampfirePost.java

public CampfirePostReply post(String message) {
    //see: http://stackoverflow.com/questions/2603691/android-httpclient-and-https
    try {//w  w  w . j  a  v a  2s . c o m
        String xml_message = "<message><type>TextMessage</type><body>" + message + "</body></message>";

        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

        BasicSchemeFactory factory = new BasicSchemeFactory();

        HttpParams params = new BasicHttpParams();
        params.setParameter("realm", "https://trifort.campfirenow.com/");

        SingleClientConnManager mgr = new SingleClientConnManager(params, schemeRegistry);
        DefaultHttpClient client = new DefaultHttpClient(mgr, params);
        String url = "https://trifort.campfirenow.com/room/" + m_room + "/speak.xml";
        HttpPost post = new HttpPost(url);
        post.setHeader("Content-type", "application/xml");

        AuthScheme scheme = factory.newInstance(params);
        Header header = scheme.authenticate(new UsernamePasswordCredentials(m_apiKey), post);

        HttpEntity entity = new StringEntity(xml_message);
        post.setEntity(entity);
        post.setHeader(header);
        HttpResponse response = client.execute(post);

        return new CampfirePostReply(response);
    } catch (Exception ex) {//post.setEntity;
        ex.printStackTrace();
        return null;
    }
}

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

/**
 * Setup the ItineRennes client./*w ww .  jav  a 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());

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

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

/**
 * Setup the ItineRennes client./*from  w ww  . j a v  a  2s  .co 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   ww w.j  a v  a 2 s.co  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: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;/*from ww w. ja v a  2  s.  c  o  m*/

    /** 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:org.pixmob.appengine.client.SSLEnabledHttpClient.java

public static SSLEnabledHttpClient newInstance(String userAgent) {
    // the following code comes from AndroidHttpClient (API level 10)

    final HttpParams params = new BasicHttpParams();

    // Turn off stale checking. Our connections break all the time anyway,
    // and it's not worth it to pay the penalty of checking every time.
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    final int timeout = 60 * 1000;
    HttpConnectionParams.setConnectionTimeout(params, timeout);
    HttpConnectionParams.setSoTimeout(params, timeout);
    HttpConnectionParams.setSocketBufferSize(params, 8192);

    // Don't handle redirects -- return them to the caller. Our code
    // often wants to re-POST after a redirect, which we must do ourselves.
    HttpClientParams.setRedirecting(params, false);

    // Set the specified user agent and register standard protocols.
    HttpProtocolParams.setUserAgent(params, userAgent);

    // Prevent UnknownHostException error with 3G connections:
    // http://stackoverflow.com/questions/2052299/httpclient-on-android-nohttpresponseexception-through-umts-3g
    HttpProtocolParams.setUseExpectContinue(params, false);

    final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

    final SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));

    final ClientConnectionManager manager = new SingleClientConnManager(params, schemeRegistry);
    final SSLEnabledHttpClient client = new SSLEnabledHttpClient(manager, params);
    client.addRequestInterceptor(new GzipRequestInterceptor());
    client.addResponseInterceptor(new GzipResponseInterceptor());

    return client;
}

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

/**
 * Setup the ItineRennes client.//from  www .ja  v  a2 s . com
 */
@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");
}

From source file:Main.java

public static DefaultHttpClient setHttpPostProxyParams(Context context) {

    Log.d(TAG, "ctx -- called ");

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    //schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));

    HttpParams params = new BasicHttpParams();

    /*Log.d(TAG, "----Add Proxy---");
    HttpHost proxy = new HttpHost(Constants.PROXY_HOST.trim(),
      Constants.PROXY_PORT);//w  ww. j a v a 2 s. com
    params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);*/

    /*if ((getWifiName(context).trim()).equalsIgnoreCase("secure-impact")) {
       Log.d(TAG, "----Add Proxy---");
       HttpHost proxy = new HttpHost(Constants.PROXY_HOST.trim(),
         Constants.PROXY_PORT);
       params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }*/

    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 SingleClientConnManager(params, schemeRegistry);

    DefaultHttpClient mHttpClient = new DefaultHttpClient(cm, params);

    return mHttpClient;
}

From source file:com.dajodi.scandic.Singleton.java

private DefaultHttpClient creatHttpClient() {
    HttpParams parms = new BasicHttpParams();
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    SingleClientConnManager manager = new SingleClientConnManager(parms, registry);
    DefaultHttpClient client = new DefaultHttpClient(manager, parms);
    return client;
}