List of usage examples for org.apache.http.auth.params AuthParams setCredentialCharset
public static void setCredentialCharset(final HttpParams params, final String charset)
From source file:ch.cyberduck.core.http.HTTP4Session.java
/** * Create new HTTP client with default configuration and custom trust manager. * * @return A new instance of a default HTTP client. *///from ww w . ja v a2 s .c o m protected AbstractHttpClient http() { if (null == http) { final HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, org.apache.http.HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, getEncoding()); HttpProtocolParams.setUserAgent(params, getUserAgent()); AuthParams.setCredentialCharset(params, "ISO-8859-1"); HttpConnectionParams.setTcpNoDelay(params, true); HttpConnectionParams.setSoTimeout(params, timeout()); HttpConnectionParams.setSocketBufferSize(params, 8192); HttpClientParams.setRedirecting(params, true); HttpClientParams.setAuthenticating(params, true); SchemeRegistry registry = new SchemeRegistry(); // Always register HTTP for possible use with proxy registry.register(new Scheme("http", host.getPort(), PlainSocketFactory.getSocketFactory())); if ("https".equals(this.getHost().getProtocol().getScheme())) { org.apache.http.conn.ssl.SSLSocketFactory factory = new SSLSocketFactory( new CustomTrustSSLProtocolSocketFactory(this.getTrustManager()).getSSLContext(), org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); registry.register(new Scheme(host.getProtocol().getScheme(), host.getPort(), factory)); } if (Preferences.instance().getBoolean("connection.proxy.enable")) { final Proxy proxy = ProxyFactory.instance(); if ("https".equals(this.getHost().getProtocol().getScheme())) { if (proxy.isHTTPSProxyEnabled(host)) { ConnRouteParams.setDefaultProxy(params, new HttpHost(proxy.getHTTPSProxyHost(host), proxy.getHTTPSProxyPort(host))); } } if ("http".equals(this.getHost().getProtocol().getScheme())) { if (proxy.isHTTPProxyEnabled(host)) { ConnRouteParams.setDefaultProxy(params, new HttpHost(proxy.getHTTPProxyHost(host), proxy.getHTTPProxyPort(host))); } } } ClientConnectionManager manager = new SingleClientConnManager(registry); http = new DefaultHttpClient(manager, params); this.configure(http); } return http; }
From source file:ch.cyberduck.core.http.HttpSession.java
protected AbstractHttpClient http(final String hostname) { if (!clients.containsKey(hostname)) { final HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, org.apache.http.HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, getEncoding()); HttpProtocolParams.setUserAgent(params, getUserAgent()); AuthParams.setCredentialCharset(params, Preferences.instance().getProperty("http.credentials.charset")); HttpConnectionParams.setTcpNoDelay(params, true); HttpConnectionParams.setSoTimeout(params, timeout()); HttpConnectionParams.setConnectionTimeout(params, timeout()); HttpConnectionParams.setSocketBufferSize(params, Preferences.instance().getInteger("http.socket.buffer")); HttpConnectionParams.setStaleCheckingEnabled(params, true); HttpClientParams.setRedirecting(params, true); HttpClientParams.setAuthenticating(params, true); HttpClientParams.setCookiePolicy(params, CookiePolicy.BEST_MATCH); // Sets the timeout in milliseconds used when retrieving a connection from the ClientConnectionManager HttpClientParams.setConnectionManagerTimeout(params, Preferences.instance().getLong("http.manager.timeout")); SchemeRegistry registry = new SchemeRegistry(); // Always register HTTP for possible use with proxy registry.register(new Scheme(ch.cyberduck.core.Scheme.http.toString(), host.getPort(), PlainSocketFactory.getSocketFactory())); registry.register(new Scheme(ch.cyberduck.core.Scheme.https.toString(), host.getPort(), new SSLSocketFactory( new CustomTrustSSLProtocolSocketFactory(this.getTrustManager()).getSSLContext(), new X509HostnameVerifier() { @Override public void verify(String host, SSLSocket ssl) throws IOException { log.warn("Hostname verification disabled for:" + host); }/* w w w . j a va 2s. co m*/ @Override public void verify(String host, X509Certificate cert) throws SSLException { log.warn("Hostname verification disabled for:" + host); } @Override public void verify(String host, String[] cns, String[] subjectAlts) throws SSLException { log.warn("Hostname verification disabled for:" + host); } @Override public boolean verify(String s, javax.net.ssl.SSLSession sslSession) { log.warn("Hostname verification disabled for:" + s); return true; } }))); if (Preferences.instance().getBoolean("connection.proxy.enable")) { final Proxy proxy = ProxyFactory.get(); if (ch.cyberduck.core.Scheme.https.equals(this.getHost().getProtocol().getScheme())) { if (proxy.isHTTPSProxyEnabled(host)) { ConnRouteParams.setDefaultProxy(params, new HttpHost(proxy.getHTTPSProxyHost(host), proxy.getHTTPSProxyPort(host))); } } if (ch.cyberduck.core.Scheme.http.equals(this.getHost().getProtocol().getScheme())) { if (proxy.isHTTPProxyEnabled(host)) { ConnRouteParams.setDefaultProxy(params, new HttpHost(proxy.getHTTPProxyHost(host), proxy.getHTTPProxyPort(host))); } } } PoolingClientConnectionManager manager = new PoolingClientConnectionManager(registry); manager.setMaxTotal(Preferences.instance().getInteger("http.connections.total")); manager.setDefaultMaxPerRoute(Preferences.instance().getInteger("http.connections.route")); AbstractHttpClient http = new DefaultHttpClient(manager, params); this.configure(http); clients.put(hostname, http); } return clients.get(hostname); }
From source file:org.eclipse.aether.transport.http.HttpTransporter.java
private static void configureClient(HttpParams params, RepositorySystemSession session, RemoteRepository repository, HttpHost proxy) { AuthParams.setCredentialCharset(params, ConfigUtils.getString(session, ConfigurationProperties.DEFAULT_HTTP_CREDENTIAL_ENCODING, ConfigurationProperties.HTTP_CREDENTIAL_ENCODING + "." + repository.getId(), ConfigurationProperties.HTTP_CREDENTIAL_ENCODING)); ConnRouteParams.setDefaultProxy(params, proxy); HttpConnectionParams.setConnectionTimeout(params, ConfigUtils.getInteger(session, ConfigurationProperties.DEFAULT_CONNECT_TIMEOUT, ConfigurationProperties.CONNECT_TIMEOUT + "." + repository.getId(), ConfigurationProperties.CONNECT_TIMEOUT)); HttpConnectionParams.setSoTimeout(params, ConfigUtils.getInteger(session, ConfigurationProperties.DEFAULT_REQUEST_TIMEOUT, ConfigurationProperties.REQUEST_TIMEOUT + "." + repository.getId(), ConfigurationProperties.REQUEST_TIMEOUT)); HttpProtocolParams.setUserAgent(params, ConfigUtils.getString(session, ConfigurationProperties.DEFAULT_USER_AGENT, ConfigurationProperties.USER_AGENT)); }