/** * Returns a feign {@link Client} wrapping a {@link okhttp3.OkHttpClient} client with optionally * specified {@link SSLSocketFactory}. */ public static Client newOkHttpClient( Optional<TrustContext> trustContext, Optional<ProxySelector> proxySelector, String userAgent) { return new OkHttpClient(newRawOkHttpClient(trustContext, proxySelector, userAgent)); }
public static <T> T createProxy( Optional<TrustContext> trustContext, String uri, boolean refreshingHttpClient, Class<T> type, String userAgent) { return Feign.builder() .contract(contract) .encoder(encoder) .decoder(decoder) .errorDecoder(errorDecoder) .retryer(new InterruptHonoringRetryer()) .client(refreshingHttpClient ? FeignOkHttpClients.newRefreshingOkHttpClient(trustContext, Optional.empty(), userAgent) : FeignOkHttpClients.newOkHttpClient(trustContext, Optional.empty(), userAgent)) .target(type, uri); }
/** * Returns a Feign {@link Client} wrapping an {@link okhttp3.OkHttpClient}. This {@link Client} recreates * itself in the event that either {@link CounterBackedRefreshingClient#DEFAULT_REQUEST_COUNT_BEFORE_REFRESH} * requests have been made, or if {@link ExceptionCountingRefreshingClient#DEFAULT_EXCEPTION_COUNT_BEFORE_REFRESH} * consecutive exceptions have been thrown by the underlying client. */ public static Client newRefreshingOkHttpClient( Optional<TrustContext> trustContext, Optional<ProxySelector> proxySelector, String userAgent) { Supplier<Client> clientSupplier = () -> CounterBackedRefreshingClient.createRefreshingClient( () -> newOkHttpClient(trustContext, proxySelector, userAgent)); return ExceptionCountingRefreshingClient.createRefreshingClient(clientSupplier); }
private static <T> T createProxyWithFailover( Optional<TrustContext> trustContext, Optional<ProxySelector> proxySelector, Collection<String> endpointUris, Request.Options feignOptions, int maxBackoffMillis, Class<T> type, String userAgent) { FailoverFeignTarget<T> failoverFeignTarget = new FailoverFeignTarget<>(endpointUris, maxBackoffMillis, type); Client client = failoverFeignTarget.wrapClient( FeignOkHttpClients.newRefreshingOkHttpClient(trustContext, proxySelector, userAgent)); return Feign.builder() .contract(contract) .encoder(encoder) .decoder(decoder) .errorDecoder(errorDecoder) .client(client) .retryer(failoverFeignTarget) .options(feignOptions) .target(failoverFeignTarget); }
public static <T> T createRsProxy( Optional<TrustContext> trustContext, String uri, Class<T> type, String userAgent) { return Feign.builder() .contract(contract) .encoder(encoder) .decoder(decoder) .errorDecoder(new RsErrorDecoder()) .client(FeignOkHttpClients.newOkHttpClient(trustContext, Optional.empty(), userAgent)) .target(type, uri); }
private static <T> T createProxyWithFailover( Optional<TrustContext> trustContext, Optional<ProxySelector> proxySelector, Collection<String> endpointUris, Request.Options feignOptions, int maxBackoffMillis, Class<T> type, String userAgent) { FailoverFeignTarget<T> failoverFeignTarget = new FailoverFeignTarget<>(endpointUris, maxBackoffMillis, type); Client client = failoverFeignTarget.wrapClient( FeignOkHttpClients.newRefreshingOkHttpClient(trustContext, proxySelector, userAgent)); return Feign.builder() .contract(contract) .encoder(encoder) .decoder(decoder) .errorDecoder(errorDecoder) .client(client) .retryer(failoverFeignTarget) .options(feignOptions) .target(failoverFeignTarget); }
public static <T> T createProxy( Optional<TrustContext> trustContext, String uri, boolean refreshingHttpClient, Class<T> type, String userAgent) { return Feign.builder() .contract(contract) .encoder(encoder) .decoder(decoder) .errorDecoder(errorDecoder) .retryer(new InterruptHonoringRetryer()) .client(refreshingHttpClient ? FeignOkHttpClients.newRefreshingOkHttpClient(trustContext, Optional.empty(), userAgent) : FeignOkHttpClients.newOkHttpClient(trustContext, Optional.empty(), userAgent)) .target(type, uri); }
@Test public void clientDoesNotRetryAtTheOkHttpLevel() { OkHttpClient okHttpClient = FeignOkHttpClients.newRawOkHttpClient(Optional.empty(), Optional.empty(), "userAgent"); assertThat(okHttpClient.retryOnConnectionFailure()).isFalse(); } }
/** * Returns a Feign {@link Client} wrapping an {@link okhttp3.OkHttpClient}. This {@link Client} recreates * itself in the event that either {@link CounterBackedRefreshingClient#DEFAULT_REQUEST_COUNT_BEFORE_REFRESH} * requests have been made, or if {@link ExceptionCountingRefreshingClient#DEFAULT_EXCEPTION_COUNT_BEFORE_REFRESH} * consecutive exceptions have been thrown by the underlying client. */ public static Client newRefreshingOkHttpClient( Optional<TrustContext> trustContext, Optional<ProxySelector> proxySelector, String userAgent) { Supplier<Client> clientSupplier = () -> CounterBackedRefreshingClient.createRefreshingClient( () -> newOkHttpClient(trustContext, proxySelector, userAgent)); return ExceptionCountingRefreshingClient.createRefreshingClient(clientSupplier); }
/** * Returns a feign {@link Client} wrapping a {@link okhttp3.OkHttpClient} client with optionally * specified {@link SSLSocketFactory}. */ public static Client newOkHttpClient( Optional<TrustContext> trustContext, Optional<ProxySelector> proxySelector, String userAgent) { return new OkHttpClient(newRawOkHttpClient(trustContext, proxySelector, userAgent)); }
public static <T> T createRsProxy( Optional<TrustContext> trustContext, String uri, Class<T> type, String userAgent) { return Feign.builder() .contract(contract) .encoder(encoder) .decoder(decoder) .errorDecoder(new RsErrorDecoder()) .client(FeignOkHttpClients.newOkHttpClient(trustContext, Optional.empty(), userAgent)) .target(type, uri); }