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));
}
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);
}
}
}
Aggregations