Search in sources :

Example 81 with HostPreferences

use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.

the class HttpConnectionPoolBuilder method build.

/**
 * @param proxy    Proxy configuration
 * @param listener Log listener
 * @param prompt   Prompt for proxy credentials
 * @return Builder for HTTP client
 */
public HttpClientBuilder build(final Proxy proxy, final TranscriptListener listener, final LoginCallback prompt) {
    final HttpClientBuilder configuration = HttpClients.custom();
    // relying on internal proxy support in socket factory
    switch(proxy.getType()) {
        case HTTP:
        case HTTPS:
            final HttpHost h = new HttpHost(proxy.getHostname(), proxy.getPort(), Scheme.http.name());
            if (log.isInfoEnabled()) {
                log.info(String.format("Setup proxy %s", h));
            }
            configuration.setProxy(h);
            configuration.setProxyAuthenticationStrategy(new CallbackProxyAuthenticationStrategy(ProxyCredentialsStoreFactory.get(), host, prompt));
            break;
    }
    configuration.setUserAgent(new PreferencesUseragentProvider().get());
    final int timeout = new HostPreferences(host).getInteger("connection.timeout.seconds") * 1000;
    configuration.setDefaultSocketConfig(SocketConfig.custom().setTcpNoDelay(true).setSoTimeout(timeout).build());
    configuration.setDefaultRequestConfig(this.createRequestConfig(timeout));
    configuration.setDefaultConnectionConfig(ConnectionConfig.custom().setBufferSize(new HostPreferences(host).getInteger("http.socket.buffer")).setCharset(Charset.forName(host.getEncoding())).build());
    if (new HostPreferences(host).getBoolean("http.connections.reuse")) {
        configuration.setConnectionReuseStrategy(new DefaultClientConnectionReuseStrategy());
    } else {
        configuration.setConnectionReuseStrategy(new NoConnectionReuseStrategy());
    }
    configuration.setRetryHandler(new ExtendedHttpRequestRetryHandler(new HostPreferences(host).getInteger("http.connections.retry")));
    configuration.setServiceUnavailableRetryStrategy(new DisabledServiceUnavailableRetryStrategy());
    if (!new HostPreferences(host).getBoolean("http.compression.enable")) {
        configuration.disableContentCompression();
    }
    configuration.setRequestExecutor(new LoggingHttpRequestExecutor(listener));
    // Always register HTTP for possible use with proxy. Contains a number of protocol properties such as the
    // default port and the socket factory to be used to create the java.net.Socket instances for the given protocol
    configuration.setConnectionManager(this.createConnectionManager(this.createRegistry()));
    configuration.setDefaultAuthSchemeRegistry(RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.BASIC, new BasicSchemeFactory(Charset.forName(new HostPreferences(host).getProperty("http.credentials.charset")))).register(AuthSchemes.DIGEST, new DigestSchemeFactory(Charset.forName(new HostPreferences(host).getProperty("http.credentials.charset")))).register(AuthSchemes.NTLM, new HostPreferences(host).getBoolean("webdav.ntlm.windows.authentication.enable") && WinHttpClients.isWinAuthAvailable() ? new BackportWindowsNTLMSchemeFactory(null) : new NTLMSchemeFactory()).register(AuthSchemes.SPNEGO, new HostPreferences(host).getBoolean("webdav.ntlm.windows.authentication.enable") && WinHttpClients.isWinAuthAvailable() ? new BackportWindowsNegotiateSchemeFactory(null) : new SPNegoSchemeFactory()).register(AuthSchemes.KERBEROS, new KerberosSchemeFactory()).build());
    return configuration;
}
Also used : BasicSchemeFactory(org.apache.http.impl.auth.BasicSchemeFactory) KerberosSchemeFactory(org.apache.http.impl.auth.KerberosSchemeFactory) DefaultClientConnectionReuseStrategy(org.apache.http.impl.client.DefaultClientConnectionReuseStrategy) PreferencesUseragentProvider(ch.cyberduck.core.PreferencesUseragentProvider) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) SPNegoSchemeFactory(org.apache.http.impl.auth.SPNegoSchemeFactory) HostPreferences(ch.cyberduck.core.preferences.HostPreferences) NoConnectionReuseStrategy(org.apache.http.impl.NoConnectionReuseStrategy) HttpHost(org.apache.http.HttpHost) DigestSchemeFactory(org.apache.http.impl.auth.DigestSchemeFactory) NTLMSchemeFactory(org.apache.http.impl.auth.NTLMSchemeFactory)

Aggregations

HostPreferences (ch.cyberduck.core.preferences.HostPreferences)81 IOException (java.io.IOException)33 Path (ch.cyberduck.core.Path)29 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)18 BackgroundException (ch.cyberduck.core.exception.BackgroundException)12 DefaultIOExceptionMappingService (ch.cyberduck.core.DefaultIOExceptionMappingService)11 PathAttributes (ch.cyberduck.core.PathAttributes)11 NotfoundException (ch.cyberduck.core.exception.NotfoundException)11 File (com.google.api.services.drive.model.File)10 AttributedList (ch.cyberduck.core.AttributedList)8 URI (java.net.URI)8 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)7 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)6 SimplePathPredicate (ch.cyberduck.core.SimplePathPredicate)6 InteroperabilityException (ch.cyberduck.core.exception.InteroperabilityException)6 MemorySegementingOutputStream (ch.cyberduck.core.io.MemorySegementingOutputStream)6 NodesApi (ch.cyberduck.core.sds.io.swagger.client.api.NodesApi)5 Credentials (ch.cyberduck.core.Credentials)4 Partition (ch.cyberduck.core.collections.Partition)4 S3Protocol (ch.cyberduck.core.s3.S3Protocol)4