Search in sources :

Example 1 with SSLProtocolSocketFactory

use of org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory in project ecf by eclipse.

the class TestEquals method testProtocolSocketFactory.

public void testProtocolSocketFactory() {
    ProtocolSocketFactory p1 = new DefaultProtocolSocketFactory();
    ProtocolSocketFactory p2 = new DefaultProtocolSocketFactory();
    assertTrue(p1.equals(p2));
    assertTrue(p2.equals(p1));
    p1 = new SSLProtocolSocketFactory();
    p2 = new SSLProtocolSocketFactory();
    assertTrue(p1.equals(p2));
    assertTrue(p2.equals(p1));
}
Also used : ProtocolSocketFactory(org.apache.commons.httpclient.protocol.ProtocolSocketFactory) SSLProtocolSocketFactory(org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory) DefaultProtocolSocketFactory(org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory) DefaultProtocolSocketFactory(org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory) SSLProtocolSocketFactory(org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory)

Example 2 with SSLProtocolSocketFactory

use of org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory in project nutch by apache.

the class Http method configureClient.

/**
 * Configures the HTTP client
 */
private void configureClient() {
    // Set up an HTTPS socket factory that accepts self-signed certs.
    ProtocolSocketFactory factory;
    if (tlsCheckCertificate) {
        factory = new SSLProtocolSocketFactory();
    } else {
        factory = new DummySSLProtocolSocketFactory();
    }
    Protocol https = new Protocol("https", factory, 443);
    Protocol.registerProtocol("https", https);
    HttpConnectionManagerParams params = connectionManager.getParams();
    params.setConnectionTimeout(timeout);
    params.setSoTimeout(timeout);
    params.setSendBufferSize(BUFFER_SIZE);
    params.setReceiveBufferSize(BUFFER_SIZE);
    // --------------------------------------------------------------------------------
    // NUTCH-1836: Modification to increase the number of available connections
    // for multi-threaded crawls.
    // --------------------------------------------------------------------------------
    params.setMaxTotalConnections(conf.getInt("mapreduce.tasktracker.map.tasks.maximum", 5) * conf.getInt("fetcher.threads.fetch", maxThreadsTotal));
    // Also set max connections per host to maxThreadsTotal since all threads
    // might be used to fetch from the same host - otherwise timeout errors can
    // occur
    params.setDefaultMaxConnectionsPerHost(conf.getInt("fetcher.threads.fetch", maxThreadsTotal));
    // executeMethod(HttpMethod) seems to ignore the connection timeout on the
    // connection manager.
    // set it explicitly on the HttpClient.
    client.getParams().setConnectionManagerTimeout(timeout);
    HostConfiguration hostConf = client.getHostConfiguration();
    ArrayList<Header> headers = new ArrayList<Header>();
    // Note: some header fields (e.g., "User-Agent") are set per GET request
    if (!acceptLanguage.isEmpty()) {
        headers.add(new Header("Accept-Language", acceptLanguage));
    }
    if (!acceptCharset.isEmpty()) {
        headers.add(new Header("Accept-Charset", acceptCharset));
    }
    if (!accept.isEmpty()) {
        headers.add(new Header("Accept", accept));
    }
    // accept gzipped content
    headers.add(new Header("Accept-Encoding", "x-gzip, gzip, deflate"));
    hostConf.getParams().setParameter("http.default-headers", headers);
    // HTTP proxy server details
    if (useProxy) {
        hostConf.setProxy(proxyHost, proxyPort);
        if (proxyUsername.length() > 0) {
            AuthScope proxyAuthScope = getAuthScope(this.proxyHost, this.proxyPort, this.proxyRealm);
            NTCredentials proxyCredentials = new NTCredentials(this.proxyUsername, this.proxyPassword, Http.agentHost, this.proxyRealm);
            client.getState().setProxyCredentials(proxyAuthScope, proxyCredentials);
        }
    }
}
Also used : SSLProtocolSocketFactory(org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory) ProtocolSocketFactory(org.apache.commons.httpclient.protocol.ProtocolSocketFactory) SSLProtocolSocketFactory(org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory) Header(org.apache.commons.httpclient.Header) HttpConnectionManagerParams(org.apache.commons.httpclient.params.HttpConnectionManagerParams) HostConfiguration(org.apache.commons.httpclient.HostConfiguration) ArrayList(java.util.ArrayList) AuthScope(org.apache.commons.httpclient.auth.AuthScope) Protocol(org.apache.commons.httpclient.protocol.Protocol) NTCredentials(org.apache.commons.httpclient.NTCredentials)

Aggregations

ProtocolSocketFactory (org.apache.commons.httpclient.protocol.ProtocolSocketFactory)2 SSLProtocolSocketFactory (org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory)2 ArrayList (java.util.ArrayList)1 Header (org.apache.commons.httpclient.Header)1 HostConfiguration (org.apache.commons.httpclient.HostConfiguration)1 NTCredentials (org.apache.commons.httpclient.NTCredentials)1 AuthScope (org.apache.commons.httpclient.auth.AuthScope)1 HttpConnectionManagerParams (org.apache.commons.httpclient.params.HttpConnectionManagerParams)1 DefaultProtocolSocketFactory (org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory)1 Protocol (org.apache.commons.httpclient.protocol.Protocol)1