List of usage examples for org.apache.http.impl.client HttpClientBuilder setServiceUnavailableRetryStrategy
public final HttpClientBuilder setServiceUnavailableRetryStrategy( final ServiceUnavailableRetryStrategy serviceUnavailStrategy)
From source file:com.github.aistomin.http.PostRequest.java
@Override public String execute() throws Exception { final Request request = Request.Post(this.resource); for (final Map.Entry<String, String> item : this.heads.entrySet()) { request.addHeader(item.getKey(), item.getValue()); }//w w w. j a v a2 s. co m final HttpClientBuilder builder = HttpClientBuilder.create(); builder.setRedirectStrategy(new LaxRedirectStrategy()); builder.setServiceUnavailableRetryStrategy(new ServiceUnavailableRetryStrategy() { public boolean retryRequest(final HttpResponse response, final int count, final HttpContext context) { return count <= PostRequest.RETRY_COUNT; } public long getRetryInterval() { return PostRequest.RETRY_INTERVAL; } }); return Executor.newInstance(builder.build()).execute(request).returnContent().asString(); }
From source file:ch.cyberduck.core.b2.B2Session.java
@Override public B2ApiClient connect(final HostKeyCallback key) throws BackgroundException { final HttpClientBuilder configuration = builder.build(this); configuration.setServiceUnavailableRetryStrategy(retryHandler); configuration.addInterceptorLast(retryHandler); return new B2ApiClient(configuration.build()); }
From source file:ch.cyberduck.core.hubic.HubicSession.java
@Override public Client connect(final HostKeyCallback key) throws BackgroundException { final HttpClientBuilder configuration = builder.build(this); configuration.addInterceptorLast(authorizationService); configuration.setServiceUnavailableRetryStrategy(retryHandler); return new Client(configuration.build()); }
From source file:ch.cyberduck.core.googledrive.DriveSession.java
@Override protected Drive connect(final HostKeyCallback callback) throws BackgroundException { final HttpClientBuilder configuration = builder.build(this); configuration.addInterceptorLast(authorizationService); configuration.setServiceUnavailableRetryStrategy(retryHandler); this.transport = new ApacheHttpTransport(configuration.build()); return new Drive.Builder(transport, json, new HttpRequestInitializer() { @Override/*from w w w . java 2s.c o m*/ public void initialize(HttpRequest request) throws IOException { request.setSuppressUserAgentSuffix(true); // OAuth Bearer added in interceptor } }).setApplicationName(useragent.get()).build(); }
From source file:ch.cyberduck.core.onedrive.OneDriveSession.java
@Override protected OneDriveAPI connect(final HostKeyCallback key) throws BackgroundException { final HttpClientBuilder configuration = builder.build(this); configuration.addInterceptorLast(authorizationService); configuration.setServiceUnavailableRetryStrategy(retryHandler); final RequestExecutor executor = new OneDriveCommonsHttpRequestExecutor(configuration.build()) { @Override/*from w ww .jav a 2s. c o m*/ 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() { return StringUtils.equals("graph.microsoft.com", host.getHostname()); } @Override public String getBaseURL() { return String.format("%s://%s%s", host.getProtocol().getScheme(), host.getHostname(), host.getProtocol().getContext()); } @Override public String getEmailURL() { return null; } }; }
From source file:ch.cyberduck.core.sds.SDSSession.java
@Override protected SDSApiClient connect(final HostKeyCallback key) throws BackgroundException { final HttpClientBuilder configuration = builder.build(this); switch (SDSProtocol.Authorization.valueOf(host.getProtocol().getAuthorization())) { case oauth:/*from ww w . j av a 2 s .co m*/ configuration .setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(authorizationService)); configuration.addInterceptorLast(authorizationService); configuration.addInterceptorLast(new HttpRequestInterceptor() { @Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { request.removeHeaders(SDSSession.SDS_AUTH_TOKEN_HEADER); } }); break; default: configuration.setServiceUnavailableRetryStrategy(retryHandler); configuration.addInterceptorLast(retryHandler); break; } final CloseableHttpClient apache = configuration.build(); final SDSApiClient client = new SDSApiClient(apache); client.setBasePath(new HostUrlProvider(false, 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; }