org.apache.http.impl.client.HttpClientBuilder#setServiceUnavailableRetryStrategy()源码实例Demo

下面列出了org.apache.http.impl.client.HttpClientBuilder#setServiceUnavailableRetryStrategy() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: cyberduck   文件: DriveSession.java
@Override
protected Drive connect(final Proxy proxy, final HostKeyCallback callback, final LoginCallback prompt) {
    final HttpClientBuilder configuration = builder.build(proxy, this, prompt);
    authorizationService = new OAuth2RequestInterceptor(configuration.build(), host.getProtocol())
        .withRedirectUri(host.getProtocol().getOAuthRedirectUrl());
    configuration.addInterceptorLast(authorizationService);
    configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(host, authorizationService, prompt));
    configuration.addInterceptorLast(new RateLimitingHttpRequestInterceptor(new DefaultHttpRateLimiter(
        PreferencesFactory.get().getInteger("googledrive.limit.requests.second")
    )));
    this.transport = new ApacheHttpTransport(configuration.build());
    final UseragentProvider ua = new PreferencesUseragentProvider();
    return new Drive.Builder(transport, new JacksonFactory(), new UserAgentHttpRequestInitializer(ua))
        .setApplicationName(ua.get())
        .build();
}
 
源代码2 项目: cyberduck   文件: B2Session.java
@Override
public B2ApiClient connect(final Proxy proxy, final HostKeyCallback key, final LoginCallback prompt) {
    final HttpClientBuilder configuration = builder.build(proxy, this, prompt);
    configuration.setServiceUnavailableRetryStrategy(retryHandler = new B2ErrorResponseInterceptor(
        this));
    configuration.addInterceptorLast(retryHandler);
    return new B2ApiClient(configuration.build());
}
 
源代码3 项目: cyberduck   文件: StoregateSession.java
@Override
protected StoregateApiClient connect(final Proxy proxy, final HostKeyCallback key, final LoginCallback prompt) {
    final HttpClientBuilder configuration = builder.build(proxy, this, prompt);
    authorizationService = new OAuth2RequestInterceptor(builder.build(proxy, this, prompt).addInterceptorLast(new HttpRequestInterceptor() {
        @Override
        public void process(final HttpRequest request, final HttpContext context) {
            request.addHeader(HttpHeaders.AUTHORIZATION,
                String.format("Basic %s", Base64.encodeToString(String.format("%s:%s", host.getProtocol().getOAuthClientId(), host.getProtocol().getOAuthClientSecret()).getBytes(StandardCharsets.UTF_8), false)));
        }
    }).build(),
        host).withRedirectUri(CYBERDUCK_REDIRECT_URI.equals(host.getProtocol().getOAuthRedirectUrl()) ? host.getProtocol().getOAuthRedirectUrl() :
        Scheme.isURL(host.getProtocol().getOAuthRedirectUrl()) ? host.getProtocol().getOAuthRedirectUrl() : new HostUrlProvider().withUsername(false).withPath(true).get(
            host.getProtocol().getScheme(), host.getPort(), null, host.getHostname(), host.getProtocol().getOAuthRedirectUrl())
    );
    // Force login even if browser session already exists
    authorizationService.withParameter("prompt", "login");
    configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(host, authorizationService, prompt));
    configuration.addInterceptorLast(authorizationService);
    final CloseableHttpClient apache = configuration.build();
    final StoregateApiClient client = new StoregateApiClient(apache);
    final int timeout = PreferencesFactory.get().getInteger("connection.timeout.seconds") * 1000;
    client.setConnectTimeout(timeout);
    client.setBasePath(new HostUrlProvider().withUsername(false).withPath(true).get(host.getProtocol().getScheme(), host.getPort(),
        null, host.getHostname(), host.getProtocol().getContext()));
    client.setHttpClient(ClientBuilder.newClient(new ClientConfig()
        .register(new InputStreamProvider())
        .register(MultiPartFeature.class)
        .register(new JSON())
        .register(JacksonFeature.class)
        .connectorProvider(new HttpComponentsProvider(apache))));
    client.setUserAgent(new PreferencesUseragentProvider().get());
    return client;
}
 
源代码4 项目: cyberduck   文件: S3Session.java
@Override
public RequestEntityRestStorageService connect(final Proxy proxy, final HostKeyCallback hostkey, final LoginCallback prompt) {
    final HttpClientBuilder configuration = builder.build(proxy, this, prompt);
    // Only for AWS
    if(S3Session.isAwsHostname(host.getHostname())) {
        configuration.setServiceUnavailableRetryStrategy(new S3TokenExpiredResponseInterceptor(this,
            new ThreadLocalHostnameDelegatingTrustManager(trust, host.getHostname()), key, prompt));
    }
    return new RequestEntityRestStorageService(this, configuration);
}
 
源代码5 项目: cyberduck   文件: GoogleStorageSession.java
@Override
public Storage connect(final Proxy proxy, final HostKeyCallback key, final LoginCallback prompt) {
    final HttpClientBuilder configuration = builder.build(proxy, this, prompt);
    authorizationService = new OAuth2RequestInterceptor(configuration.build(), host.getProtocol())
        .withRedirectUri(host.getProtocol().getOAuthRedirectUrl());
    configuration.addInterceptorLast(authorizationService);
    configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(host, authorizationService, prompt));
    this.transport = new ApacheHttpTransport(configuration.build());
    final UseragentProvider ua = new PreferencesUseragentProvider();
    return new Storage.Builder(transport, new JacksonFactory(), new UserAgentHttpRequestInitializer(ua))
        .setApplicationName(ua.get())
        .build();
}
 
源代码6 项目: cyberduck   文件: DropboxSession.java
@Override
protected CustomDbxRawClientV2 connect(final Proxy proxy, final HostKeyCallback callback, final LoginCallback prompt) {
    final HttpClientBuilder configuration = builder.build(proxy, this, prompt);
    authorizationService = new OAuth2RequestInterceptor(configuration.build(), host.getProtocol())
        .withRedirectUri(host.getProtocol().getOAuthRedirectUrl());
    configuration.addInterceptorLast(authorizationService);
    configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(host, authorizationService, prompt));
    final CloseableHttpClient client = configuration.build();
    return new CustomDbxRawClientV2(DbxRequestConfig.newBuilder(useragent.get())
        .withAutoRetryDisabled()
        .withHttpRequestor(new DropboxCommonsHttpRequestExecutor(client)).build(),
        DbxHost.DEFAULT, null, null);
}
 
源代码7 项目: cyberduck   文件: HubicSession.java
@Override
public Client connect(final Proxy proxy, final HostKeyCallback key, final LoginCallback prompt) {
    final HttpClientBuilder configuration = builder.build(proxy, this, prompt);
    authorizationService = new OAuth2RequestInterceptor(configuration.build(), host.getProtocol())
        .withRedirectUri(host.getProtocol().getOAuthRedirectUrl());
    configuration.addInterceptorLast(authorizationService);
    configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(host, authorizationService, prompt));
    return new Client(configuration.build());
}
 
源代码8 项目: cyberduck   文件: GraphSession.java
@Override
protected OneDriveAPI connect(final Proxy proxy, final HostKeyCallback key, final LoginCallback prompt) {
    final HttpClientBuilder configuration = builder.build(proxy, this, prompt);
    authorizationService = new OAuth2RequestInterceptor(configuration.build(), host.getProtocol()) {
        @Override
        public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
            if(request.containsHeader(HttpHeaders.AUTHORIZATION)) {
                super.process(request, context);
            }
        }
    }.withRedirectUri(host.getProtocol().getOAuthRedirectUrl());
    configuration.addInterceptorLast(authorizationService);
    configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(host, authorizationService, prompt));
    final RequestExecutor executor = new GraphCommonsHttpRequestExecutor(configuration.build()) {
        @Override
        public void addAuthorizationHeader(final Set<RequestHeader> headers) {
            // Placeholder
            headers.add(new RequestHeader(HttpHeaders.AUTHORIZATION, "Bearer"));
        }
    };
    return new OneDriveAPI() {
        @Override
        public RequestExecutor getExecutor() {
            return executor;
        }

        @Override
        public boolean isBusinessConnection() {
            return false;
        }

        @Override
        public boolean isGraphConnection() {
            if(StringUtils.equals("graph.microsoft.com", host.getHostname())) {
                return true;
            }
            else if(StringUtils.equals("graph.microsoft.de", host.getHostname())) {
                return true;
            }
            return false;
        }

        @Override
        public String getBaseURL() {
            return String.format("%s://%s%s", host.getProtocol().getScheme(), host.getHostname(), host.getProtocol().getContext());
        }

        @Override
        public String getEmailURL() {
            return String.format("%s://%s%s", host.getProtocol().getScheme(), host.getHostname(), "/v1.0/me");
        }
    };
}
 
源代码9 项目: cyberduck   文件: HttpConnectionPoolBuilder.java
/**
 * @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();
    // Use HTTP Connect proxy implementation provided here instead of
    // 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 = preferences.getInteger("connection.timeout.seconds") * 1000;
    configuration.setDefaultSocketConfig(SocketConfig.custom()
        .setTcpNoDelay(true)
        .setSoTimeout(timeout)
        .build());
    configuration.setDefaultRequestConfig(this.createRequestConfig(timeout));
    configuration.setDefaultConnectionConfig(ConnectionConfig.custom()
        .setBufferSize(preferences.getInteger("http.socket.buffer"))
        .setCharset(Charset.forName(host.getEncoding()))
        .build());
    if(preferences.getBoolean("http.connections.reuse")) {
        configuration.setConnectionReuseStrategy(new DefaultClientConnectionReuseStrategy());
    }
    else {
        configuration.setConnectionReuseStrategy(new NoConnectionReuseStrategy());
    }
    configuration.setRetryHandler(new ExtendedHttpRequestRetryHandler(preferences.getInteger("http.connections.retry")));
    configuration.setServiceUnavailableRetryStrategy(new DisabledServiceUnavailableRetryStrategy());
    if(!preferences.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(preferences.getProperty("http.credentials.charset"))))
        .register(AuthSchemes.DIGEST, new DigestSchemeFactory(
            Charset.forName(preferences.getProperty("http.credentials.charset"))))
        .register(AuthSchemes.NTLM, preferences.getBoolean("webdav.ntlm.windows.authentication.enable") && WinHttpClients.isWinAuthAvailable() ?
            new BackportWindowsNTLMSchemeFactory(null) :
            new NTLMSchemeFactory())
        .register(AuthSchemes.SPNEGO, preferences.getBoolean("webdav.ntlm.windows.authentication.enable") && WinHttpClients.isWinAuthAvailable() ?
            new BackportWindowsNegotiateSchemeFactory(null) :
            new SPNegoSchemeFactory())
        .register(AuthSchemes.KERBEROS, new KerberosSchemeFactory()).build());
    return configuration;
}