From d27d385e1a1673446aa1f6a778a91fbaa2442679 Mon Sep 17 00:00:00 2001 From: mroccyen Date: Fri, 20 May 2022 18:41:55 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9Aissue=201420=20(#1620)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/main/java/feign/Contract.java | 3 ++- core/src/test/java/feign/OptionsTest.java | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/feign/Contract.java b/core/src/main/java/feign/Contract.java index 112e4076..9f6a4880 100644 --- a/core/src/main/java/feign/Contract.java +++ b/core/src/main/java/feign/Contract.java @@ -132,7 +132,8 @@ public interface Contract { if (parameterTypes[i] == URI.class) { data.urlIndex(i); - } else if (!isHttpAnnotation && parameterTypes[i] != Request.Options.class) { + } else if (!isHttpAnnotation + && !Request.Options.class.isAssignableFrom(parameterTypes[i])) { if (data.isAlreadyProcessed(i)) { checkState(data.formParams().isEmpty() || data.bodyIndex() == null, "Body parameters cannot be used with form parameters.%s", data.warnings()); diff --git a/core/src/test/java/feign/OptionsTest.java b/core/src/test/java/feign/OptionsTest.java index 0d701501..04b06e10 100644 --- a/core/src/test/java/feign/OptionsTest.java +++ b/core/src/test/java/feign/OptionsTest.java @@ -29,10 +29,19 @@ import static org.assertj.core.api.Assertions.assertThat; @SuppressWarnings("deprecation") public class OptionsTest { + static class ChildOptions extends Request.Options { + public ChildOptions(int connectTimeoutMillis, int readTimeoutMillis) { + super(connectTimeoutMillis, readTimeoutMillis); + } + } + interface OptionsInterface { @RequestLine("GET /") String get(Request.Options options); + @RequestLine("POST /") + String getChildOptions(ChildOptions options); + @RequestLine("GET /") String get(); } @@ -66,4 +75,16 @@ public class OptionsTest { assertThat(api.get(new Request.Options(1000, 4 * 1000))).isEqualTo("foo"); } + + @Test + public void normalResponseForChildOptionsTest() { + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody("foo").setBodyDelay(3, TimeUnit.SECONDS)); + + final OptionsInterface api = Feign.builder() + .options(new ChildOptions(1000, 1000)) + .target(OptionsInterface.class, server.url("/").toString()); + + assertThat(api.getChildOptions(new ChildOptions(1000, 4 * 1000))).isEqualTo("foo"); + } }