Skip to content

Commit

Permalink
Merge pull request #17 from palantir/feature/feign-options
Browse files Browse the repository at this point in the history
FeignClientFactory can be configured with timeout Request.Options
  • Loading branch information
markelliot committed Jan 7, 2016
2 parents fe8c9c5 + 06a6497 commit ecb409a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import feign.Client;
import feign.Contract;
import feign.Feign;
import feign.Request;
import feign.codec.Decoder;
import feign.codec.Encoder;
import feign.codec.ErrorDecoder;
Expand All @@ -42,20 +43,23 @@ public final class FeignClientFactory {
private final ErrorDecoder errorDecoder;
private final Function<Optional<SSLSocketFactory>, Client> clientSupplier;
private final BackoffStrategy backoffStrategy;
private final Request.Options options;

private FeignClientFactory(
Contract contract,
Encoder encoder,
Decoder decoder,
ErrorDecoder errorDecoder,
Function<Optional<SSLSocketFactory>, Client> clientSupplier,
BackoffStrategy backoffStrategy) {
BackoffStrategy backoffStrategy,
Request.Options options) {
this.contract = contract;
this.encoder = encoder;
this.decoder = decoder;
this.errorDecoder = errorDecoder;
this.clientSupplier = clientSupplier;
this.backoffStrategy = backoffStrategy;
this.options = options;
}

/**
Expand All @@ -69,8 +73,8 @@ public static FeignClientFactory of(
Decoder decoder,
ErrorDecoder errorDecoder,
Function<Optional<SSLSocketFactory>, Client> clientSupplier) {
return new FeignClientFactory(
contract, encoder, decoder, errorDecoder, clientSupplier, NeverRetryingBackoffStrategy.INSTANCE);
return new FeignClientFactory(contract, encoder, decoder, errorDecoder, clientSupplier,
NeverRetryingBackoffStrategy.INSTANCE, new Request.Options());
}

/**
Expand All @@ -82,9 +86,10 @@ public static FeignClientFactory of(
Decoder decoder,
ErrorDecoder errorDecoder,
Function<Optional<SSLSocketFactory>, Client> clientSupplier,
BackoffStrategy backoffStrategy) {
BackoffStrategy backoffStrategy,
Request.Options options) {
return new FeignClientFactory(
contract, encoder, decoder, errorDecoder, clientSupplier, backoffStrategy);
contract, encoder, decoder, errorDecoder, clientSupplier, backoffStrategy, options);
}

/**
Expand All @@ -98,6 +103,7 @@ public <T> T createProxy(Optional<SSLSocketFactory> sslSocketFactory, String uri
.decoder(decoder)
.errorDecoder(errorDecoder)
.client(clientSupplier.apply(sslSocketFactory))
.options(options)
.target(type, uri);
}

Expand All @@ -117,6 +123,7 @@ public <T> T createProxy(Optional<SSLSocketFactory> sslSocketFactory, Set<String
.errorDecoder(errorDecoder)
.client(client)
.retryer(target)
.options(options)
.target(target);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.palantir.remoting.http.errors.SerializableErrorErrorDecoder;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
import feign.Request;
import feign.RetryableException;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
Expand Down Expand Up @@ -98,7 +99,8 @@ public void testBackoff() throws Exception {
new JacksonDecoder(ObjectMappers.guavaJdk7()),
SerializableErrorErrorDecoder.INSTANCE,
FeignClientFactory.okHttpClient(),
backoffStrategy)
backoffStrategy,
new Request.Options())
.createProxy(Optional.<SSLSocketFactory>absent(),
ImmutableSet.of("http://localhost:" + server1.getPort(),
"http://localhost:" + server2.getPort()),
Expand Down

0 comments on commit ecb409a

Please sign in to comment.