From 1005749eb530767b3e51e846fb43319e47bbf5b2 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Tue, 6 Jul 2021 14:52:01 +0000 Subject: [PATCH 01/12] Update SNAPSHOT to 2.2.9.RELEASE --- docs/pom.xml | 2 +- pom.xml | 8 +- spring-cloud-openfeign-core/pom.xml | 2 +- .../openfeign/FeignClientFactoryBean.java | 3 +- ...adBalancerResponseStatusCodeException.java | 6 +- ...ryableFeignBlockingLoadBalancerClient.java | 4 +- ...eFeignBlockingLoadBalancerClientTests.java | 26 +++--- .../openfeign/valid/FeignClientTests.java | 86 +++++++++---------- spring-cloud-openfeign-dependencies/pom.xml | 4 +- spring-cloud-starter-openfeign/pom.xml | 2 +- 10 files changed, 72 insertions(+), 71 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 327ae75b..a3174077 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.BUILD-SNAPSHOT + 2.2.9.RELEASE spring-cloud-openfeign-docs pom diff --git a/pom.xml b/pom.xml index e0ad978f..2d1c2cd3 100644 --- a/pom.xml +++ b/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-cloud-openfeign - 2.2.9.BUILD-SNAPSHOT + 2.2.9.RELEASE pom Spring Cloud OpenFeign Spring Cloud OpenFeign org.springframework.cloud spring-cloud-build - 2.3.4.RELEASE + 2.3.5.RELEASE @@ -26,8 +26,8 @@ ${basedir} 2.11.3 - 2.2.9.BUILD-SNAPSHOT - 2.2.9.BUILD-SNAPSHOT + 2.2.9.RELEASE + 2.2.9.RELEASE 2.10 diff --git a/spring-cloud-openfeign-core/pom.xml b/spring-cloud-openfeign-core/pom.xml index c50b5720..ed012d1a 100644 --- a/spring-cloud-openfeign-core/pom.xml +++ b/spring-cloud-openfeign-core/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.BUILD-SNAPSHOT + 2.2.9.RELEASE .. spring-cloud-openfeign-core diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java index ac24747f..59c8b23f 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java @@ -375,7 +375,8 @@ public class FeignClientFactoryBean implements FactoryBean, Initializing if (!StringUtils.hasText(url)) { if (LOG.isInfoEnabled()) { - LOG.info("For '" + name + "' URL not provided. Will try picking an instance via load-balancing."); + LOG.info("For '" + name + + "' URL not provided. Will try picking an instance via load-balancing."); } if (!name.startsWith("http")) { url = "http://" + name; diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java index 0e7017f8..9bcfc1fa 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java @@ -28,11 +28,13 @@ import org.springframework.cloud.client.loadbalancer.RetryableStatusCodeExceptio * * @author Ryan Baxter */ -public class LoadBalancerResponseStatusCodeException extends RetryableStatusCodeException { +public class LoadBalancerResponseStatusCodeException + extends RetryableStatusCodeException { private final Response response; - public LoadBalancerResponseStatusCodeException(String serviceId, Response response, byte[] body, URI uri) { + public LoadBalancerResponseStatusCodeException(String serviceId, Response response, + byte[] body, URI uri) { super(serviceId, response.status(), response, uri); this.response = Response.builder() .body(new ByteArrayInputStream(body), body.length) diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java index 342bb534..157eebaf 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java @@ -113,10 +113,10 @@ public class RetryableFeignBlockingLoadBalancerClient implements Client { String.format("Retrying on status code: %d", responseStatus)); } byte[] byteArray = response.body() == null ? new byte[] {} - : StreamUtils.copyToByteArray(response.body().asInputStream()); + : StreamUtils.copyToByteArray(response.body().asInputStream()); response.close(); throw new LoadBalancerResponseStatusCodeException(serviceId, response, - byteArray, URI.create(request.url())); + byteArray, URI.create(request.url())); } return response; }, new LoadBalancedRecoveryCallback() { diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java index ca175318..5862d425 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java @@ -119,8 +119,10 @@ class RetryableFeignBlockingLoadBalancerClientTests { private Response testResponse(int status, String body) { // ByteArrayInputStream ignores close() and must be wrapped - InputStream reallyCloseable = new BufferedInputStream(new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8))); - return Response.builder().request(testRequest()).status(status).body(reallyCloseable, null).build(); + InputStream reallyCloseable = new BufferedInputStream( + new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8))); + return Response.builder().request(testRequest()).status(status) + .body(reallyCloseable, null).build(); } @@ -163,23 +165,23 @@ class RetryableFeignBlockingLoadBalancerClientTests { void shouldExposeResponseBodyOnRetry() throws IOException { properties.getRetryableStatusCodes().add(503); Request request = testRequest(); - when(delegate.execute(any(), any())) - .thenReturn(testResponse(503, "foo"), testResponse(503, "foo")); + when(delegate.execute(any(), any())).thenReturn(testResponse(503, "foo"), + testResponse(503, "foo")); when(retryFactory.createRetryPolicy(any(), eq(loadBalancerClient))) - .thenReturn(new BlockingLoadBalancedRetryPolicy("test", - loadBalancerClient, properties)); + .thenReturn(new BlockingLoadBalancedRetryPolicy("test", + loadBalancerClient, properties)); when(loadBalancerClient.reconstructURI(serviceInstance, - URI.create("http://test/path"))) - .thenReturn(URI.create("http://testhost:80/path")); + URI.create("http://test/path"))) + .thenReturn(URI.create("http://testhost:80/path")); - Response response = feignBlockingLoadBalancerClient.execute(request, new Request.Options()); + Response response = feignBlockingLoadBalancerClient.execute(request, + new Request.Options()); - String bodyContent = IOUtils.toString(response.body().asReader(StandardCharsets.UTF_8)); + String bodyContent = IOUtils + .toString(response.body().asReader(StandardCharsets.UTF_8)); assertThat(bodyContent).isEqualTo("foo"); } - - @Test void shouldPassCorrectRequestToDelegate() throws IOException { Request request = testRequest(); diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java index c747eda0..73d89ca0 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java @@ -181,7 +181,7 @@ public class FeignClientTests { public void testClient() { assertThat(testClient).as("testClient was null").isNotNull(); assertThat(Proxy.isProxyClass(testClient.getClass())) - .as("testClient is not a java Proxy").isTrue(); + .as("testClient is not a java Proxy").isTrue(); InvocationHandler invocationHandler = Proxy.getInvocationHandler(testClient); assertThat(invocationHandler).as("invocationHandler was null").isNotNull(); } @@ -198,7 +198,7 @@ public class FeignClientTests { Hello hello = testClient.getHello(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -219,9 +219,9 @@ public class FeignClientTests { List headers = testClient.getHelloHeaders(); assertThat(headers).as("headers was null").isNotNull(); assertThat(headers.contains("myheader1value")) - .as("headers didn't contain myheader1value").isTrue(); + .as("headers didn't contain myheader1value").isTrue(); assertThat(headers.contains("myheader2value")) - .as("headers didn't contain myheader2value").isTrue(); + .as("headers didn't contain myheader2value").isTrue(); } @Test @@ -241,12 +241,11 @@ public class FeignClientTests { @Test public void testServiceId() { - assertThat(testClientServiceId).as("testClientServiceId was null") - .isNotNull(); + assertThat(testClientServiceId).as("testClientServiceId was null").isNotNull(); final Hello hello = testClientServiceId.getHello(); assertThat(hello).as("The hello response was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -260,7 +259,7 @@ public class FeignClientTests { @Test public void testFormattedParams() { List list = Arrays.asList(LocalDate.of(2001, 1, 1), - LocalDate.of(2018, 6, 10)); + LocalDate.of(2018, 6, 10)); List params = testClient.getFormattedParams(list); assertThat(params).as("params was null").isNotNull(); assertThat(params).as("params not converted correctly").isEqualTo(list); @@ -271,13 +270,13 @@ public class FeignClientTests { HystrixCommand> command = testClient.getHellosHystrix(); assertThat(command).as("command was null").isNotNull(); assertThat(command.getCommandGroup().name()).as( - "Hystrix command group name should match the name of the feign client") - .isEqualTo("localapp"); + "Hystrix command group name should match the name of the feign client") + .isEqualTo("localapp"); String configKey = Feign.configKey(TestClient.class, - TestClient.class.getMethod("getHellosHystrix", (Class[]) null)); + TestClient.class.getMethod("getHellosHystrix", (Class[]) null)); assertThat(command.getCommandKey().name()) - .as("Hystrix command key name should match the feign config key") - .isEqualTo(configKey); + .as("Hystrix command key name should match the feign config key") + .isEqualTo(configKey); List hellos = command.execute(); assertThat(hellos).as("hellos was null").isNotNull(); assertThat(getHelloList()).as("hellos didn't match").isEqualTo(hellos); @@ -290,7 +289,7 @@ public class FeignClientTests { Hello hello = single.toBlocking().value(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -298,7 +297,7 @@ public class FeignClientTests { ResponseEntity response = testClient.noContent(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.NO_CONTENT); + .isEqualTo(HttpStatus.NO_CONTENT); } @Test @@ -306,7 +305,7 @@ public class FeignClientTests { ResponseEntity response = testClient.head(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.OK); + .isEqualTo(HttpStatus.OK); } @Test @@ -316,7 +315,7 @@ public class FeignClientTests { Hello hello = entity.getBody(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -324,7 +323,7 @@ public class FeignClientTests { String response = testClient.moreComplexContentType("{\"value\":\"OK\"}"); assertThat(response).as("response was null").isNotNull(); assertThat(response).as("didn't respond with {\"value\":\"OK\"}") - .isEqualTo("{\"value\":\"OK\"}"); + .isEqualTo("{\"value\":\"OK\"}"); } @Test @@ -332,7 +331,7 @@ public class FeignClientTests { ResponseEntity response = decodingTestClient.notFound(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.NOT_FOUND); + .isEqualTo(HttpStatus.NOT_FOUND); assertThat(response.getBody()).as("response body was not null").isNull(); } @@ -371,7 +370,7 @@ public class FeignClientTests { Hello hello = single.toBlocking().value(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbacksingle"); + .isEqualTo("fallbacksingle"); } @Test @@ -381,7 +380,7 @@ public class FeignClientTests { Hello hello = command.execute(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackcommand"); + .isEqualTo("fallbackcommand"); } @Test @@ -391,7 +390,7 @@ public class FeignClientTests { Hello hello = observable.toBlocking().first(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackobservable"); + .isEqualTo("fallbackobservable"); } @Test @@ -401,7 +400,7 @@ public class FeignClientTests { Hello hello = future.get(1, TimeUnit.SECONDS); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackfuture"); + .isEqualTo("fallbackfuture"); } @Test @@ -410,8 +409,8 @@ public class FeignClientTests { assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("hello#message was null").isNotNull(); assertThat(hello.getMessage().contains("500")).as( - "hello#message did not contain the cause (status code) of the fallback invocation") - .isTrue(); + "hello#message did not contain the cause (status code) of the fallback invocation") + .isTrue(); } @Test(expected = HystrixRuntimeException.class) @@ -439,17 +438,17 @@ public class FeignClientTests { @Test public void testHystrixSetterFactory() { HystrixCommand> command = hystrixSetterFactoryClient - .getHellosHystrix(); + .getHellosHystrix(); assertThat(command).as("command was null").isNotNull(); String setterPrefix = TestHystrixSetterFactoryClientConfig.SETTER_PREFIX; assertThat(command.getCommandGroup().name()).as( - "Hystrix command group name should match the name of the feign client with a prefix of " - + setterPrefix) - .isEqualTo(setterPrefix + "localapp5"); + "Hystrix command group name should match the name of the feign client with a prefix of " + + setterPrefix) + .isEqualTo(setterPrefix + "localapp5"); assertThat(command.getCommandKey().name()).as( - "Hystrix command key name should match the request method (space) request path with a prefix of " - + setterPrefix) - .isEqualTo(setterPrefix + "GET /hellos"); + "Hystrix command key name should match the request method (space) request path with a prefix of " + + setterPrefix) + .isEqualTo(setterPrefix + "GET /hellos"); List hellos = command.execute(); assertThat(hellos).as("hellos was null").isNotNull(); assertThat(getHelloList()).as("hellos didn't match").isEqualTo(hellos); @@ -481,8 +480,7 @@ public class FeignClientTests { Hello pojo2 = new Hello(OI_TERRA_2); MockMultipartFile file = new MockMultipartFile("file", "hello.bin", null, "hello".getBytes()); - String response = multipartClient.multipartPojo("abc", "123", pojo1, pojo2, - file); + String response = multipartClient.multipartPojo("abc", "123", pojo1, pojo2, file); assertThat(response).isEqualTo("abc123hello world 1oi terra 2hello.bin"); } @@ -507,9 +505,8 @@ public class FeignClientTests { "hello".getBytes()); MockMultipartFile file2 = new MockMultipartFile("file2", "hello2.bin", null, "hello".getBytes()); - String response = multipartClient - .requestPartListOfPojosAndListOfMultipartFiles( - Arrays.asList(pojo1, pojo2), Arrays.asList(file1, file2)); + String response = multipartClient.requestPartListOfPojosAndListOfMultipartFiles( + Arrays.asList(pojo1, pojo2), Arrays.asList(file1, file2)); assertThat(response).isEqualTo("hello world 1oi terra 2hello1.binhello2.bin"); } @@ -624,7 +621,7 @@ public class FeignClientTests { String getToString(@RequestParam("arg") Arg arg); @PostMapping(path = "/form-urlencoded", - consumes = APPLICATION_FORM_URLENCODED_VALUE) + consumes = APPLICATION_FORM_URLENCODED_VALUE) Hello postFormUrlEncoded(Hello hello); @RequestMapping(method = RequestMethod.GET, path = "/tostring2") @@ -824,8 +821,7 @@ public class FeignClientTests { public HystrixClientWithFallBackFactory create(final Throwable cause) { return () -> { assertThat(cause).isNotNull().as("Cause was null"); - return new Hello( - "Hello from the fallback side: " + cause.getMessage()); + return new Hello("Hello from the fallback side: " + cause.getMessage()); }; } @@ -888,12 +884,12 @@ public class FeignClientTests { return (target, method) -> { String groupKey = SETTER_PREFIX + target.name(); RequestMapping requestMapping = method - .getAnnotation(RequestMapping.class); + .getAnnotation(RequestMapping.class); String commandKey = SETTER_PREFIX + requestMapping.method()[0] + " " - + requestMapping.path()[0]; + + requestMapping.path()[0]; return HystrixCommand.Setter - .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) - .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)); + .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) + .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)); }; } @@ -1161,7 +1157,7 @@ public class FeignClientTests { } @PostMapping(path = "/form-urlencoded", - consumes = APPLICATION_FORM_URLENCODED_VALUE) + consumes = APPLICATION_FORM_URLENCODED_VALUE) Hello postFormUrlEncoded(Hello hello) { return hello; } diff --git a/spring-cloud-openfeign-dependencies/pom.xml b/spring-cloud-openfeign-dependencies/pom.xml index e2f459ca..3b3653b9 100644 --- a/spring-cloud-openfeign-dependencies/pom.xml +++ b/spring-cloud-openfeign-dependencies/pom.xml @@ -6,11 +6,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.3.5.BUILD-SNAPSHOT + 2.3.5.RELEASE spring-cloud-openfeign-dependencies - 2.2.9.BUILD-SNAPSHOT + 2.2.9.RELEASE pom spring-cloud-openfeign-dependencies Spring Cloud OpenFeign Dependencies diff --git a/spring-cloud-starter-openfeign/pom.xml b/spring-cloud-starter-openfeign/pom.xml index b76067c0..34b2f184 100644 --- a/spring-cloud-starter-openfeign/pom.xml +++ b/spring-cloud-starter-openfeign/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.BUILD-SNAPSHOT + 2.2.9.RELEASE .. spring-cloud-starter-openfeign From 190f5a90839a90630cdaed23ce4a2e3ce24a4d90 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Tue, 6 Jul 2021 14:53:53 +0000 Subject: [PATCH 02/12] Going back to snapshots --- docs/pom.xml | 2 +- pom.xml | 8 +- spring-cloud-openfeign-core/pom.xml | 2 +- .../openfeign/FeignClientFactoryBean.java | 3 +- ...adBalancerResponseStatusCodeException.java | 6 +- ...ryableFeignBlockingLoadBalancerClient.java | 4 +- ...eFeignBlockingLoadBalancerClientTests.java | 26 +++--- .../openfeign/valid/FeignClientTests.java | 86 ++++++++++--------- spring-cloud-openfeign-dependencies/pom.xml | 4 +- spring-cloud-starter-openfeign/pom.xml | 2 +- 10 files changed, 71 insertions(+), 72 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index a3174077..327ae75b 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.RELEASE + 2.2.9.BUILD-SNAPSHOT spring-cloud-openfeign-docs pom diff --git a/pom.xml b/pom.xml index 2d1c2cd3..e0ad978f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-cloud-openfeign - 2.2.9.RELEASE + 2.2.9.BUILD-SNAPSHOT pom Spring Cloud OpenFeign Spring Cloud OpenFeign org.springframework.cloud spring-cloud-build - 2.3.5.RELEASE + 2.3.4.RELEASE @@ -26,8 +26,8 @@ ${basedir} 2.11.3 - 2.2.9.RELEASE - 2.2.9.RELEASE + 2.2.9.BUILD-SNAPSHOT + 2.2.9.BUILD-SNAPSHOT 2.10 diff --git a/spring-cloud-openfeign-core/pom.xml b/spring-cloud-openfeign-core/pom.xml index ed012d1a..c50b5720 100644 --- a/spring-cloud-openfeign-core/pom.xml +++ b/spring-cloud-openfeign-core/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.RELEASE + 2.2.9.BUILD-SNAPSHOT .. spring-cloud-openfeign-core diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java index 59c8b23f..ac24747f 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java @@ -375,8 +375,7 @@ public class FeignClientFactoryBean implements FactoryBean, Initializing if (!StringUtils.hasText(url)) { if (LOG.isInfoEnabled()) { - LOG.info("For '" + name - + "' URL not provided. Will try picking an instance via load-balancing."); + LOG.info("For '" + name + "' URL not provided. Will try picking an instance via load-balancing."); } if (!name.startsWith("http")) { url = "http://" + name; diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java index 9bcfc1fa..0e7017f8 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java @@ -28,13 +28,11 @@ import org.springframework.cloud.client.loadbalancer.RetryableStatusCodeExceptio * * @author Ryan Baxter */ -public class LoadBalancerResponseStatusCodeException - extends RetryableStatusCodeException { +public class LoadBalancerResponseStatusCodeException extends RetryableStatusCodeException { private final Response response; - public LoadBalancerResponseStatusCodeException(String serviceId, Response response, - byte[] body, URI uri) { + public LoadBalancerResponseStatusCodeException(String serviceId, Response response, byte[] body, URI uri) { super(serviceId, response.status(), response, uri); this.response = Response.builder() .body(new ByteArrayInputStream(body), body.length) diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java index 157eebaf..342bb534 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java @@ -113,10 +113,10 @@ public class RetryableFeignBlockingLoadBalancerClient implements Client { String.format("Retrying on status code: %d", responseStatus)); } byte[] byteArray = response.body() == null ? new byte[] {} - : StreamUtils.copyToByteArray(response.body().asInputStream()); + : StreamUtils.copyToByteArray(response.body().asInputStream()); response.close(); throw new LoadBalancerResponseStatusCodeException(serviceId, response, - byteArray, URI.create(request.url())); + byteArray, URI.create(request.url())); } return response; }, new LoadBalancedRecoveryCallback() { diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java index 5862d425..ca175318 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java @@ -119,10 +119,8 @@ class RetryableFeignBlockingLoadBalancerClientTests { private Response testResponse(int status, String body) { // ByteArrayInputStream ignores close() and must be wrapped - InputStream reallyCloseable = new BufferedInputStream( - new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8))); - return Response.builder().request(testRequest()).status(status) - .body(reallyCloseable, null).build(); + InputStream reallyCloseable = new BufferedInputStream(new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8))); + return Response.builder().request(testRequest()).status(status).body(reallyCloseable, null).build(); } @@ -165,23 +163,23 @@ class RetryableFeignBlockingLoadBalancerClientTests { void shouldExposeResponseBodyOnRetry() throws IOException { properties.getRetryableStatusCodes().add(503); Request request = testRequest(); - when(delegate.execute(any(), any())).thenReturn(testResponse(503, "foo"), - testResponse(503, "foo")); + when(delegate.execute(any(), any())) + .thenReturn(testResponse(503, "foo"), testResponse(503, "foo")); when(retryFactory.createRetryPolicy(any(), eq(loadBalancerClient))) - .thenReturn(new BlockingLoadBalancedRetryPolicy("test", - loadBalancerClient, properties)); + .thenReturn(new BlockingLoadBalancedRetryPolicy("test", + loadBalancerClient, properties)); when(loadBalancerClient.reconstructURI(serviceInstance, - URI.create("http://test/path"))) - .thenReturn(URI.create("http://testhost:80/path")); + URI.create("http://test/path"))) + .thenReturn(URI.create("http://testhost:80/path")); - Response response = feignBlockingLoadBalancerClient.execute(request, - new Request.Options()); + Response response = feignBlockingLoadBalancerClient.execute(request, new Request.Options()); - String bodyContent = IOUtils - .toString(response.body().asReader(StandardCharsets.UTF_8)); + String bodyContent = IOUtils.toString(response.body().asReader(StandardCharsets.UTF_8)); assertThat(bodyContent).isEqualTo("foo"); } + + @Test void shouldPassCorrectRequestToDelegate() throws IOException { Request request = testRequest(); diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java index 73d89ca0..c747eda0 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java @@ -181,7 +181,7 @@ public class FeignClientTests { public void testClient() { assertThat(testClient).as("testClient was null").isNotNull(); assertThat(Proxy.isProxyClass(testClient.getClass())) - .as("testClient is not a java Proxy").isTrue(); + .as("testClient is not a java Proxy").isTrue(); InvocationHandler invocationHandler = Proxy.getInvocationHandler(testClient); assertThat(invocationHandler).as("invocationHandler was null").isNotNull(); } @@ -198,7 +198,7 @@ public class FeignClientTests { Hello hello = testClient.getHello(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -219,9 +219,9 @@ public class FeignClientTests { List headers = testClient.getHelloHeaders(); assertThat(headers).as("headers was null").isNotNull(); assertThat(headers.contains("myheader1value")) - .as("headers didn't contain myheader1value").isTrue(); + .as("headers didn't contain myheader1value").isTrue(); assertThat(headers.contains("myheader2value")) - .as("headers didn't contain myheader2value").isTrue(); + .as("headers didn't contain myheader2value").isTrue(); } @Test @@ -241,11 +241,12 @@ public class FeignClientTests { @Test public void testServiceId() { - assertThat(testClientServiceId).as("testClientServiceId was null").isNotNull(); + assertThat(testClientServiceId).as("testClientServiceId was null") + .isNotNull(); final Hello hello = testClientServiceId.getHello(); assertThat(hello).as("The hello response was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -259,7 +260,7 @@ public class FeignClientTests { @Test public void testFormattedParams() { List list = Arrays.asList(LocalDate.of(2001, 1, 1), - LocalDate.of(2018, 6, 10)); + LocalDate.of(2018, 6, 10)); List params = testClient.getFormattedParams(list); assertThat(params).as("params was null").isNotNull(); assertThat(params).as("params not converted correctly").isEqualTo(list); @@ -270,13 +271,13 @@ public class FeignClientTests { HystrixCommand> command = testClient.getHellosHystrix(); assertThat(command).as("command was null").isNotNull(); assertThat(command.getCommandGroup().name()).as( - "Hystrix command group name should match the name of the feign client") - .isEqualTo("localapp"); + "Hystrix command group name should match the name of the feign client") + .isEqualTo("localapp"); String configKey = Feign.configKey(TestClient.class, - TestClient.class.getMethod("getHellosHystrix", (Class[]) null)); + TestClient.class.getMethod("getHellosHystrix", (Class[]) null)); assertThat(command.getCommandKey().name()) - .as("Hystrix command key name should match the feign config key") - .isEqualTo(configKey); + .as("Hystrix command key name should match the feign config key") + .isEqualTo(configKey); List hellos = command.execute(); assertThat(hellos).as("hellos was null").isNotNull(); assertThat(getHelloList()).as("hellos didn't match").isEqualTo(hellos); @@ -289,7 +290,7 @@ public class FeignClientTests { Hello hello = single.toBlocking().value(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -297,7 +298,7 @@ public class FeignClientTests { ResponseEntity response = testClient.noContent(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.NO_CONTENT); + .isEqualTo(HttpStatus.NO_CONTENT); } @Test @@ -305,7 +306,7 @@ public class FeignClientTests { ResponseEntity response = testClient.head(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.OK); + .isEqualTo(HttpStatus.OK); } @Test @@ -315,7 +316,7 @@ public class FeignClientTests { Hello hello = entity.getBody(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -323,7 +324,7 @@ public class FeignClientTests { String response = testClient.moreComplexContentType("{\"value\":\"OK\"}"); assertThat(response).as("response was null").isNotNull(); assertThat(response).as("didn't respond with {\"value\":\"OK\"}") - .isEqualTo("{\"value\":\"OK\"}"); + .isEqualTo("{\"value\":\"OK\"}"); } @Test @@ -331,7 +332,7 @@ public class FeignClientTests { ResponseEntity response = decodingTestClient.notFound(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.NOT_FOUND); + .isEqualTo(HttpStatus.NOT_FOUND); assertThat(response.getBody()).as("response body was not null").isNull(); } @@ -370,7 +371,7 @@ public class FeignClientTests { Hello hello = single.toBlocking().value(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbacksingle"); + .isEqualTo("fallbacksingle"); } @Test @@ -380,7 +381,7 @@ public class FeignClientTests { Hello hello = command.execute(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackcommand"); + .isEqualTo("fallbackcommand"); } @Test @@ -390,7 +391,7 @@ public class FeignClientTests { Hello hello = observable.toBlocking().first(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackobservable"); + .isEqualTo("fallbackobservable"); } @Test @@ -400,7 +401,7 @@ public class FeignClientTests { Hello hello = future.get(1, TimeUnit.SECONDS); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackfuture"); + .isEqualTo("fallbackfuture"); } @Test @@ -409,8 +410,8 @@ public class FeignClientTests { assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("hello#message was null").isNotNull(); assertThat(hello.getMessage().contains("500")).as( - "hello#message did not contain the cause (status code) of the fallback invocation") - .isTrue(); + "hello#message did not contain the cause (status code) of the fallback invocation") + .isTrue(); } @Test(expected = HystrixRuntimeException.class) @@ -438,17 +439,17 @@ public class FeignClientTests { @Test public void testHystrixSetterFactory() { HystrixCommand> command = hystrixSetterFactoryClient - .getHellosHystrix(); + .getHellosHystrix(); assertThat(command).as("command was null").isNotNull(); String setterPrefix = TestHystrixSetterFactoryClientConfig.SETTER_PREFIX; assertThat(command.getCommandGroup().name()).as( - "Hystrix command group name should match the name of the feign client with a prefix of " - + setterPrefix) - .isEqualTo(setterPrefix + "localapp5"); + "Hystrix command group name should match the name of the feign client with a prefix of " + + setterPrefix) + .isEqualTo(setterPrefix + "localapp5"); assertThat(command.getCommandKey().name()).as( - "Hystrix command key name should match the request method (space) request path with a prefix of " - + setterPrefix) - .isEqualTo(setterPrefix + "GET /hellos"); + "Hystrix command key name should match the request method (space) request path with a prefix of " + + setterPrefix) + .isEqualTo(setterPrefix + "GET /hellos"); List hellos = command.execute(); assertThat(hellos).as("hellos was null").isNotNull(); assertThat(getHelloList()).as("hellos didn't match").isEqualTo(hellos); @@ -480,7 +481,8 @@ public class FeignClientTests { Hello pojo2 = new Hello(OI_TERRA_2); MockMultipartFile file = new MockMultipartFile("file", "hello.bin", null, "hello".getBytes()); - String response = multipartClient.multipartPojo("abc", "123", pojo1, pojo2, file); + String response = multipartClient.multipartPojo("abc", "123", pojo1, pojo2, + file); assertThat(response).isEqualTo("abc123hello world 1oi terra 2hello.bin"); } @@ -505,8 +507,9 @@ public class FeignClientTests { "hello".getBytes()); MockMultipartFile file2 = new MockMultipartFile("file2", "hello2.bin", null, "hello".getBytes()); - String response = multipartClient.requestPartListOfPojosAndListOfMultipartFiles( - Arrays.asList(pojo1, pojo2), Arrays.asList(file1, file2)); + String response = multipartClient + .requestPartListOfPojosAndListOfMultipartFiles( + Arrays.asList(pojo1, pojo2), Arrays.asList(file1, file2)); assertThat(response).isEqualTo("hello world 1oi terra 2hello1.binhello2.bin"); } @@ -621,7 +624,7 @@ public class FeignClientTests { String getToString(@RequestParam("arg") Arg arg); @PostMapping(path = "/form-urlencoded", - consumes = APPLICATION_FORM_URLENCODED_VALUE) + consumes = APPLICATION_FORM_URLENCODED_VALUE) Hello postFormUrlEncoded(Hello hello); @RequestMapping(method = RequestMethod.GET, path = "/tostring2") @@ -821,7 +824,8 @@ public class FeignClientTests { public HystrixClientWithFallBackFactory create(final Throwable cause) { return () -> { assertThat(cause).isNotNull().as("Cause was null"); - return new Hello("Hello from the fallback side: " + cause.getMessage()); + return new Hello( + "Hello from the fallback side: " + cause.getMessage()); }; } @@ -884,12 +888,12 @@ public class FeignClientTests { return (target, method) -> { String groupKey = SETTER_PREFIX + target.name(); RequestMapping requestMapping = method - .getAnnotation(RequestMapping.class); + .getAnnotation(RequestMapping.class); String commandKey = SETTER_PREFIX + requestMapping.method()[0] + " " - + requestMapping.path()[0]; + + requestMapping.path()[0]; return HystrixCommand.Setter - .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) - .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)); + .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) + .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)); }; } @@ -1157,7 +1161,7 @@ public class FeignClientTests { } @PostMapping(path = "/form-urlencoded", - consumes = APPLICATION_FORM_URLENCODED_VALUE) + consumes = APPLICATION_FORM_URLENCODED_VALUE) Hello postFormUrlEncoded(Hello hello) { return hello; } diff --git a/spring-cloud-openfeign-dependencies/pom.xml b/spring-cloud-openfeign-dependencies/pom.xml index 3b3653b9..e2f459ca 100644 --- a/spring-cloud-openfeign-dependencies/pom.xml +++ b/spring-cloud-openfeign-dependencies/pom.xml @@ -6,11 +6,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.3.5.RELEASE + 2.3.5.BUILD-SNAPSHOT spring-cloud-openfeign-dependencies - 2.2.9.RELEASE + 2.2.9.BUILD-SNAPSHOT pom spring-cloud-openfeign-dependencies Spring Cloud OpenFeign Dependencies diff --git a/spring-cloud-starter-openfeign/pom.xml b/spring-cloud-starter-openfeign/pom.xml index 34b2f184..b76067c0 100644 --- a/spring-cloud-starter-openfeign/pom.xml +++ b/spring-cloud-starter-openfeign/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.RELEASE + 2.2.9.BUILD-SNAPSHOT .. spring-cloud-starter-openfeign From d60cda824dc1c4474246f1ccba20c117f7fc550d Mon Sep 17 00:00:00 2001 From: buildmaster Date: Tue, 6 Jul 2021 14:53:53 +0000 Subject: [PATCH 03/12] Bumping versions to 2.2.10.BUILD-SNAPSHOT after release --- docs/pom.xml | 2 +- pom.xml | 8 ++++---- spring-cloud-openfeign-core/pom.xml | 2 +- spring-cloud-openfeign-dependencies/pom.xml | 4 ++-- spring-cloud-starter-openfeign/pom.xml | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 327ae75b..22905352 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.BUILD-SNAPSHOT + 2.2.10.BUILD-SNAPSHOT spring-cloud-openfeign-docs pom diff --git a/pom.xml b/pom.xml index e0ad978f..bb12c895 100644 --- a/pom.xml +++ b/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-cloud-openfeign - 2.2.9.BUILD-SNAPSHOT + 2.2.10.BUILD-SNAPSHOT pom Spring Cloud OpenFeign Spring Cloud OpenFeign org.springframework.cloud spring-cloud-build - 2.3.4.RELEASE + 2.3.6.BUILD-SNAPSHOT @@ -26,8 +26,8 @@ ${basedir} 2.11.3 - 2.2.9.BUILD-SNAPSHOT - 2.2.9.BUILD-SNAPSHOT + 2.2.10.BUILD-SNAPSHOT + 2.2.10.BUILD-SNAPSHOT 2.10 diff --git a/spring-cloud-openfeign-core/pom.xml b/spring-cloud-openfeign-core/pom.xml index c50b5720..33d0b085 100644 --- a/spring-cloud-openfeign-core/pom.xml +++ b/spring-cloud-openfeign-core/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.BUILD-SNAPSHOT + 2.2.10.BUILD-SNAPSHOT .. spring-cloud-openfeign-core diff --git a/spring-cloud-openfeign-dependencies/pom.xml b/spring-cloud-openfeign-dependencies/pom.xml index e2f459ca..6fa855e4 100644 --- a/spring-cloud-openfeign-dependencies/pom.xml +++ b/spring-cloud-openfeign-dependencies/pom.xml @@ -6,11 +6,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.3.5.BUILD-SNAPSHOT + 2.3.6.BUILD-SNAPSHOT spring-cloud-openfeign-dependencies - 2.2.9.BUILD-SNAPSHOT + 2.2.10.BUILD-SNAPSHOT pom spring-cloud-openfeign-dependencies Spring Cloud OpenFeign Dependencies diff --git a/spring-cloud-starter-openfeign/pom.xml b/spring-cloud-starter-openfeign/pom.xml index b76067c0..326594f2 100644 --- a/spring-cloud-starter-openfeign/pom.xml +++ b/spring-cloud-starter-openfeign/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.BUILD-SNAPSHOT + 2.2.10.BUILD-SNAPSHOT .. spring-cloud-starter-openfeign From f7e490c4666fea1679d0cae920c801747ac3b82d Mon Sep 17 00:00:00 2001 From: Olga MaciaszekSharma Date: Wed, 7 Jul 2021 14:37:03 +0200 Subject: [PATCH 04/12] Revert "Bumping versions to 2.2.10.BUILD-SNAPSHOT after release" This reverts commit d60cda824dc1c4474246f1ccba20c117f7fc550d. --- docs/pom.xml | 2 +- pom.xml | 8 ++++---- spring-cloud-openfeign-core/pom.xml | 2 +- spring-cloud-openfeign-dependencies/pom.xml | 4 ++-- spring-cloud-starter-openfeign/pom.xml | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 22905352..327ae75b 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.10.BUILD-SNAPSHOT + 2.2.9.BUILD-SNAPSHOT spring-cloud-openfeign-docs pom diff --git a/pom.xml b/pom.xml index bb12c895..e0ad978f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-cloud-openfeign - 2.2.10.BUILD-SNAPSHOT + 2.2.9.BUILD-SNAPSHOT pom Spring Cloud OpenFeign Spring Cloud OpenFeign org.springframework.cloud spring-cloud-build - 2.3.6.BUILD-SNAPSHOT + 2.3.4.RELEASE @@ -26,8 +26,8 @@ ${basedir} 2.11.3 - 2.2.10.BUILD-SNAPSHOT - 2.2.10.BUILD-SNAPSHOT + 2.2.9.BUILD-SNAPSHOT + 2.2.9.BUILD-SNAPSHOT 2.10 diff --git a/spring-cloud-openfeign-core/pom.xml b/spring-cloud-openfeign-core/pom.xml index 33d0b085..c50b5720 100644 --- a/spring-cloud-openfeign-core/pom.xml +++ b/spring-cloud-openfeign-core/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.10.BUILD-SNAPSHOT + 2.2.9.BUILD-SNAPSHOT .. spring-cloud-openfeign-core diff --git a/spring-cloud-openfeign-dependencies/pom.xml b/spring-cloud-openfeign-dependencies/pom.xml index 6fa855e4..e2f459ca 100644 --- a/spring-cloud-openfeign-dependencies/pom.xml +++ b/spring-cloud-openfeign-dependencies/pom.xml @@ -6,11 +6,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.3.6.BUILD-SNAPSHOT + 2.3.5.BUILD-SNAPSHOT spring-cloud-openfeign-dependencies - 2.2.10.BUILD-SNAPSHOT + 2.2.9.BUILD-SNAPSHOT pom spring-cloud-openfeign-dependencies Spring Cloud OpenFeign Dependencies diff --git a/spring-cloud-starter-openfeign/pom.xml b/spring-cloud-starter-openfeign/pom.xml index 326594f2..b76067c0 100644 --- a/spring-cloud-starter-openfeign/pom.xml +++ b/spring-cloud-starter-openfeign/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.10.BUILD-SNAPSHOT + 2.2.9.BUILD-SNAPSHOT .. spring-cloud-starter-openfeign From 6479db0a54f55fb84356aa80be3bd044fe50c2e1 Mon Sep 17 00:00:00 2001 From: Olga MaciaszekSharma Date: Wed, 7 Jul 2021 14:37:39 +0200 Subject: [PATCH 05/12] Revert "Going back to snapshots" This reverts commit 190f5a90839a90630cdaed23ce4a2e3ce24a4d90. --- docs/pom.xml | 2 +- pom.xml | 8 +- spring-cloud-openfeign-core/pom.xml | 2 +- .../openfeign/FeignClientFactoryBean.java | 3 +- ...adBalancerResponseStatusCodeException.java | 6 +- ...ryableFeignBlockingLoadBalancerClient.java | 4 +- ...eFeignBlockingLoadBalancerClientTests.java | 26 +++--- .../openfeign/valid/FeignClientTests.java | 86 +++++++++---------- spring-cloud-openfeign-dependencies/pom.xml | 4 +- spring-cloud-starter-openfeign/pom.xml | 2 +- 10 files changed, 72 insertions(+), 71 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 327ae75b..a3174077 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.BUILD-SNAPSHOT + 2.2.9.RELEASE spring-cloud-openfeign-docs pom diff --git a/pom.xml b/pom.xml index e0ad978f..2d1c2cd3 100644 --- a/pom.xml +++ b/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-cloud-openfeign - 2.2.9.BUILD-SNAPSHOT + 2.2.9.RELEASE pom Spring Cloud OpenFeign Spring Cloud OpenFeign org.springframework.cloud spring-cloud-build - 2.3.4.RELEASE + 2.3.5.RELEASE @@ -26,8 +26,8 @@ ${basedir} 2.11.3 - 2.2.9.BUILD-SNAPSHOT - 2.2.9.BUILD-SNAPSHOT + 2.2.9.RELEASE + 2.2.9.RELEASE 2.10 diff --git a/spring-cloud-openfeign-core/pom.xml b/spring-cloud-openfeign-core/pom.xml index c50b5720..ed012d1a 100644 --- a/spring-cloud-openfeign-core/pom.xml +++ b/spring-cloud-openfeign-core/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.BUILD-SNAPSHOT + 2.2.9.RELEASE .. spring-cloud-openfeign-core diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java index ac24747f..59c8b23f 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java @@ -375,7 +375,8 @@ public class FeignClientFactoryBean implements FactoryBean, Initializing if (!StringUtils.hasText(url)) { if (LOG.isInfoEnabled()) { - LOG.info("For '" + name + "' URL not provided. Will try picking an instance via load-balancing."); + LOG.info("For '" + name + + "' URL not provided. Will try picking an instance via load-balancing."); } if (!name.startsWith("http")) { url = "http://" + name; diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java index 0e7017f8..9bcfc1fa 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java @@ -28,11 +28,13 @@ import org.springframework.cloud.client.loadbalancer.RetryableStatusCodeExceptio * * @author Ryan Baxter */ -public class LoadBalancerResponseStatusCodeException extends RetryableStatusCodeException { +public class LoadBalancerResponseStatusCodeException + extends RetryableStatusCodeException { private final Response response; - public LoadBalancerResponseStatusCodeException(String serviceId, Response response, byte[] body, URI uri) { + public LoadBalancerResponseStatusCodeException(String serviceId, Response response, + byte[] body, URI uri) { super(serviceId, response.status(), response, uri); this.response = Response.builder() .body(new ByteArrayInputStream(body), body.length) diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java index 342bb534..157eebaf 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java @@ -113,10 +113,10 @@ public class RetryableFeignBlockingLoadBalancerClient implements Client { String.format("Retrying on status code: %d", responseStatus)); } byte[] byteArray = response.body() == null ? new byte[] {} - : StreamUtils.copyToByteArray(response.body().asInputStream()); + : StreamUtils.copyToByteArray(response.body().asInputStream()); response.close(); throw new LoadBalancerResponseStatusCodeException(serviceId, response, - byteArray, URI.create(request.url())); + byteArray, URI.create(request.url())); } return response; }, new LoadBalancedRecoveryCallback() { diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java index ca175318..5862d425 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java @@ -119,8 +119,10 @@ class RetryableFeignBlockingLoadBalancerClientTests { private Response testResponse(int status, String body) { // ByteArrayInputStream ignores close() and must be wrapped - InputStream reallyCloseable = new BufferedInputStream(new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8))); - return Response.builder().request(testRequest()).status(status).body(reallyCloseable, null).build(); + InputStream reallyCloseable = new BufferedInputStream( + new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8))); + return Response.builder().request(testRequest()).status(status) + .body(reallyCloseable, null).build(); } @@ -163,23 +165,23 @@ class RetryableFeignBlockingLoadBalancerClientTests { void shouldExposeResponseBodyOnRetry() throws IOException { properties.getRetryableStatusCodes().add(503); Request request = testRequest(); - when(delegate.execute(any(), any())) - .thenReturn(testResponse(503, "foo"), testResponse(503, "foo")); + when(delegate.execute(any(), any())).thenReturn(testResponse(503, "foo"), + testResponse(503, "foo")); when(retryFactory.createRetryPolicy(any(), eq(loadBalancerClient))) - .thenReturn(new BlockingLoadBalancedRetryPolicy("test", - loadBalancerClient, properties)); + .thenReturn(new BlockingLoadBalancedRetryPolicy("test", + loadBalancerClient, properties)); when(loadBalancerClient.reconstructURI(serviceInstance, - URI.create("http://test/path"))) - .thenReturn(URI.create("http://testhost:80/path")); + URI.create("http://test/path"))) + .thenReturn(URI.create("http://testhost:80/path")); - Response response = feignBlockingLoadBalancerClient.execute(request, new Request.Options()); + Response response = feignBlockingLoadBalancerClient.execute(request, + new Request.Options()); - String bodyContent = IOUtils.toString(response.body().asReader(StandardCharsets.UTF_8)); + String bodyContent = IOUtils + .toString(response.body().asReader(StandardCharsets.UTF_8)); assertThat(bodyContent).isEqualTo("foo"); } - - @Test void shouldPassCorrectRequestToDelegate() throws IOException { Request request = testRequest(); diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java index c747eda0..73d89ca0 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java @@ -181,7 +181,7 @@ public class FeignClientTests { public void testClient() { assertThat(testClient).as("testClient was null").isNotNull(); assertThat(Proxy.isProxyClass(testClient.getClass())) - .as("testClient is not a java Proxy").isTrue(); + .as("testClient is not a java Proxy").isTrue(); InvocationHandler invocationHandler = Proxy.getInvocationHandler(testClient); assertThat(invocationHandler).as("invocationHandler was null").isNotNull(); } @@ -198,7 +198,7 @@ public class FeignClientTests { Hello hello = testClient.getHello(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -219,9 +219,9 @@ public class FeignClientTests { List headers = testClient.getHelloHeaders(); assertThat(headers).as("headers was null").isNotNull(); assertThat(headers.contains("myheader1value")) - .as("headers didn't contain myheader1value").isTrue(); + .as("headers didn't contain myheader1value").isTrue(); assertThat(headers.contains("myheader2value")) - .as("headers didn't contain myheader2value").isTrue(); + .as("headers didn't contain myheader2value").isTrue(); } @Test @@ -241,12 +241,11 @@ public class FeignClientTests { @Test public void testServiceId() { - assertThat(testClientServiceId).as("testClientServiceId was null") - .isNotNull(); + assertThat(testClientServiceId).as("testClientServiceId was null").isNotNull(); final Hello hello = testClientServiceId.getHello(); assertThat(hello).as("The hello response was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -260,7 +259,7 @@ public class FeignClientTests { @Test public void testFormattedParams() { List list = Arrays.asList(LocalDate.of(2001, 1, 1), - LocalDate.of(2018, 6, 10)); + LocalDate.of(2018, 6, 10)); List params = testClient.getFormattedParams(list); assertThat(params).as("params was null").isNotNull(); assertThat(params).as("params not converted correctly").isEqualTo(list); @@ -271,13 +270,13 @@ public class FeignClientTests { HystrixCommand> command = testClient.getHellosHystrix(); assertThat(command).as("command was null").isNotNull(); assertThat(command.getCommandGroup().name()).as( - "Hystrix command group name should match the name of the feign client") - .isEqualTo("localapp"); + "Hystrix command group name should match the name of the feign client") + .isEqualTo("localapp"); String configKey = Feign.configKey(TestClient.class, - TestClient.class.getMethod("getHellosHystrix", (Class[]) null)); + TestClient.class.getMethod("getHellosHystrix", (Class[]) null)); assertThat(command.getCommandKey().name()) - .as("Hystrix command key name should match the feign config key") - .isEqualTo(configKey); + .as("Hystrix command key name should match the feign config key") + .isEqualTo(configKey); List hellos = command.execute(); assertThat(hellos).as("hellos was null").isNotNull(); assertThat(getHelloList()).as("hellos didn't match").isEqualTo(hellos); @@ -290,7 +289,7 @@ public class FeignClientTests { Hello hello = single.toBlocking().value(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -298,7 +297,7 @@ public class FeignClientTests { ResponseEntity response = testClient.noContent(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.NO_CONTENT); + .isEqualTo(HttpStatus.NO_CONTENT); } @Test @@ -306,7 +305,7 @@ public class FeignClientTests { ResponseEntity response = testClient.head(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.OK); + .isEqualTo(HttpStatus.OK); } @Test @@ -316,7 +315,7 @@ public class FeignClientTests { Hello hello = entity.getBody(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -324,7 +323,7 @@ public class FeignClientTests { String response = testClient.moreComplexContentType("{\"value\":\"OK\"}"); assertThat(response).as("response was null").isNotNull(); assertThat(response).as("didn't respond with {\"value\":\"OK\"}") - .isEqualTo("{\"value\":\"OK\"}"); + .isEqualTo("{\"value\":\"OK\"}"); } @Test @@ -332,7 +331,7 @@ public class FeignClientTests { ResponseEntity response = decodingTestClient.notFound(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.NOT_FOUND); + .isEqualTo(HttpStatus.NOT_FOUND); assertThat(response.getBody()).as("response body was not null").isNull(); } @@ -371,7 +370,7 @@ public class FeignClientTests { Hello hello = single.toBlocking().value(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbacksingle"); + .isEqualTo("fallbacksingle"); } @Test @@ -381,7 +380,7 @@ public class FeignClientTests { Hello hello = command.execute(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackcommand"); + .isEqualTo("fallbackcommand"); } @Test @@ -391,7 +390,7 @@ public class FeignClientTests { Hello hello = observable.toBlocking().first(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackobservable"); + .isEqualTo("fallbackobservable"); } @Test @@ -401,7 +400,7 @@ public class FeignClientTests { Hello hello = future.get(1, TimeUnit.SECONDS); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackfuture"); + .isEqualTo("fallbackfuture"); } @Test @@ -410,8 +409,8 @@ public class FeignClientTests { assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("hello#message was null").isNotNull(); assertThat(hello.getMessage().contains("500")).as( - "hello#message did not contain the cause (status code) of the fallback invocation") - .isTrue(); + "hello#message did not contain the cause (status code) of the fallback invocation") + .isTrue(); } @Test(expected = HystrixRuntimeException.class) @@ -439,17 +438,17 @@ public class FeignClientTests { @Test public void testHystrixSetterFactory() { HystrixCommand> command = hystrixSetterFactoryClient - .getHellosHystrix(); + .getHellosHystrix(); assertThat(command).as("command was null").isNotNull(); String setterPrefix = TestHystrixSetterFactoryClientConfig.SETTER_PREFIX; assertThat(command.getCommandGroup().name()).as( - "Hystrix command group name should match the name of the feign client with a prefix of " - + setterPrefix) - .isEqualTo(setterPrefix + "localapp5"); + "Hystrix command group name should match the name of the feign client with a prefix of " + + setterPrefix) + .isEqualTo(setterPrefix + "localapp5"); assertThat(command.getCommandKey().name()).as( - "Hystrix command key name should match the request method (space) request path with a prefix of " - + setterPrefix) - .isEqualTo(setterPrefix + "GET /hellos"); + "Hystrix command key name should match the request method (space) request path with a prefix of " + + setterPrefix) + .isEqualTo(setterPrefix + "GET /hellos"); List hellos = command.execute(); assertThat(hellos).as("hellos was null").isNotNull(); assertThat(getHelloList()).as("hellos didn't match").isEqualTo(hellos); @@ -481,8 +480,7 @@ public class FeignClientTests { Hello pojo2 = new Hello(OI_TERRA_2); MockMultipartFile file = new MockMultipartFile("file", "hello.bin", null, "hello".getBytes()); - String response = multipartClient.multipartPojo("abc", "123", pojo1, pojo2, - file); + String response = multipartClient.multipartPojo("abc", "123", pojo1, pojo2, file); assertThat(response).isEqualTo("abc123hello world 1oi terra 2hello.bin"); } @@ -507,9 +505,8 @@ public class FeignClientTests { "hello".getBytes()); MockMultipartFile file2 = new MockMultipartFile("file2", "hello2.bin", null, "hello".getBytes()); - String response = multipartClient - .requestPartListOfPojosAndListOfMultipartFiles( - Arrays.asList(pojo1, pojo2), Arrays.asList(file1, file2)); + String response = multipartClient.requestPartListOfPojosAndListOfMultipartFiles( + Arrays.asList(pojo1, pojo2), Arrays.asList(file1, file2)); assertThat(response).isEqualTo("hello world 1oi terra 2hello1.binhello2.bin"); } @@ -624,7 +621,7 @@ public class FeignClientTests { String getToString(@RequestParam("arg") Arg arg); @PostMapping(path = "/form-urlencoded", - consumes = APPLICATION_FORM_URLENCODED_VALUE) + consumes = APPLICATION_FORM_URLENCODED_VALUE) Hello postFormUrlEncoded(Hello hello); @RequestMapping(method = RequestMethod.GET, path = "/tostring2") @@ -824,8 +821,7 @@ public class FeignClientTests { public HystrixClientWithFallBackFactory create(final Throwable cause) { return () -> { assertThat(cause).isNotNull().as("Cause was null"); - return new Hello( - "Hello from the fallback side: " + cause.getMessage()); + return new Hello("Hello from the fallback side: " + cause.getMessage()); }; } @@ -888,12 +884,12 @@ public class FeignClientTests { return (target, method) -> { String groupKey = SETTER_PREFIX + target.name(); RequestMapping requestMapping = method - .getAnnotation(RequestMapping.class); + .getAnnotation(RequestMapping.class); String commandKey = SETTER_PREFIX + requestMapping.method()[0] + " " - + requestMapping.path()[0]; + + requestMapping.path()[0]; return HystrixCommand.Setter - .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) - .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)); + .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) + .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)); }; } @@ -1161,7 +1157,7 @@ public class FeignClientTests { } @PostMapping(path = "/form-urlencoded", - consumes = APPLICATION_FORM_URLENCODED_VALUE) + consumes = APPLICATION_FORM_URLENCODED_VALUE) Hello postFormUrlEncoded(Hello hello) { return hello; } diff --git a/spring-cloud-openfeign-dependencies/pom.xml b/spring-cloud-openfeign-dependencies/pom.xml index e2f459ca..3b3653b9 100644 --- a/spring-cloud-openfeign-dependencies/pom.xml +++ b/spring-cloud-openfeign-dependencies/pom.xml @@ -6,11 +6,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.3.5.BUILD-SNAPSHOT + 2.3.5.RELEASE spring-cloud-openfeign-dependencies - 2.2.9.BUILD-SNAPSHOT + 2.2.9.RELEASE pom spring-cloud-openfeign-dependencies Spring Cloud OpenFeign Dependencies diff --git a/spring-cloud-starter-openfeign/pom.xml b/spring-cloud-starter-openfeign/pom.xml index b76067c0..34b2f184 100644 --- a/spring-cloud-starter-openfeign/pom.xml +++ b/spring-cloud-starter-openfeign/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.BUILD-SNAPSHOT + 2.2.9.RELEASE .. spring-cloud-starter-openfeign From 28b50401c54bd45ce3eba0fc212737280db3e14b Mon Sep 17 00:00:00 2001 From: Olga MaciaszekSharma Date: Wed, 7 Jul 2021 14:38:12 +0200 Subject: [PATCH 06/12] Revert "Update SNAPSHOT to 2.2.9.RELEASE" This reverts commit 1005749eb530767b3e51e846fb43319e47bbf5b2. --- docs/pom.xml | 2 +- pom.xml | 8 +- spring-cloud-openfeign-core/pom.xml | 2 +- .../openfeign/FeignClientFactoryBean.java | 3 +- ...adBalancerResponseStatusCodeException.java | 6 +- ...ryableFeignBlockingLoadBalancerClient.java | 4 +- ...eFeignBlockingLoadBalancerClientTests.java | 26 +++--- .../openfeign/valid/FeignClientTests.java | 86 ++++++++++--------- spring-cloud-openfeign-dependencies/pom.xml | 4 +- spring-cloud-starter-openfeign/pom.xml | 2 +- 10 files changed, 71 insertions(+), 72 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index a3174077..327ae75b 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.RELEASE + 2.2.9.BUILD-SNAPSHOT spring-cloud-openfeign-docs pom diff --git a/pom.xml b/pom.xml index 2d1c2cd3..e0ad978f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-cloud-openfeign - 2.2.9.RELEASE + 2.2.9.BUILD-SNAPSHOT pom Spring Cloud OpenFeign Spring Cloud OpenFeign org.springframework.cloud spring-cloud-build - 2.3.5.RELEASE + 2.3.4.RELEASE @@ -26,8 +26,8 @@ ${basedir} 2.11.3 - 2.2.9.RELEASE - 2.2.9.RELEASE + 2.2.9.BUILD-SNAPSHOT + 2.2.9.BUILD-SNAPSHOT 2.10 diff --git a/spring-cloud-openfeign-core/pom.xml b/spring-cloud-openfeign-core/pom.xml index ed012d1a..c50b5720 100644 --- a/spring-cloud-openfeign-core/pom.xml +++ b/spring-cloud-openfeign-core/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.RELEASE + 2.2.9.BUILD-SNAPSHOT .. spring-cloud-openfeign-core diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java index 59c8b23f..ac24747f 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java @@ -375,8 +375,7 @@ public class FeignClientFactoryBean implements FactoryBean, Initializing if (!StringUtils.hasText(url)) { if (LOG.isInfoEnabled()) { - LOG.info("For '" + name - + "' URL not provided. Will try picking an instance via load-balancing."); + LOG.info("For '" + name + "' URL not provided. Will try picking an instance via load-balancing."); } if (!name.startsWith("http")) { url = "http://" + name; diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java index 9bcfc1fa..0e7017f8 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java @@ -28,13 +28,11 @@ import org.springframework.cloud.client.loadbalancer.RetryableStatusCodeExceptio * * @author Ryan Baxter */ -public class LoadBalancerResponseStatusCodeException - extends RetryableStatusCodeException { +public class LoadBalancerResponseStatusCodeException extends RetryableStatusCodeException { private final Response response; - public LoadBalancerResponseStatusCodeException(String serviceId, Response response, - byte[] body, URI uri) { + public LoadBalancerResponseStatusCodeException(String serviceId, Response response, byte[] body, URI uri) { super(serviceId, response.status(), response, uri); this.response = Response.builder() .body(new ByteArrayInputStream(body), body.length) diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java index 157eebaf..342bb534 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java @@ -113,10 +113,10 @@ public class RetryableFeignBlockingLoadBalancerClient implements Client { String.format("Retrying on status code: %d", responseStatus)); } byte[] byteArray = response.body() == null ? new byte[] {} - : StreamUtils.copyToByteArray(response.body().asInputStream()); + : StreamUtils.copyToByteArray(response.body().asInputStream()); response.close(); throw new LoadBalancerResponseStatusCodeException(serviceId, response, - byteArray, URI.create(request.url())); + byteArray, URI.create(request.url())); } return response; }, new LoadBalancedRecoveryCallback() { diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java index 5862d425..ca175318 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java @@ -119,10 +119,8 @@ class RetryableFeignBlockingLoadBalancerClientTests { private Response testResponse(int status, String body) { // ByteArrayInputStream ignores close() and must be wrapped - InputStream reallyCloseable = new BufferedInputStream( - new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8))); - return Response.builder().request(testRequest()).status(status) - .body(reallyCloseable, null).build(); + InputStream reallyCloseable = new BufferedInputStream(new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8))); + return Response.builder().request(testRequest()).status(status).body(reallyCloseable, null).build(); } @@ -165,23 +163,23 @@ class RetryableFeignBlockingLoadBalancerClientTests { void shouldExposeResponseBodyOnRetry() throws IOException { properties.getRetryableStatusCodes().add(503); Request request = testRequest(); - when(delegate.execute(any(), any())).thenReturn(testResponse(503, "foo"), - testResponse(503, "foo")); + when(delegate.execute(any(), any())) + .thenReturn(testResponse(503, "foo"), testResponse(503, "foo")); when(retryFactory.createRetryPolicy(any(), eq(loadBalancerClient))) - .thenReturn(new BlockingLoadBalancedRetryPolicy("test", - loadBalancerClient, properties)); + .thenReturn(new BlockingLoadBalancedRetryPolicy("test", + loadBalancerClient, properties)); when(loadBalancerClient.reconstructURI(serviceInstance, - URI.create("http://test/path"))) - .thenReturn(URI.create("http://testhost:80/path")); + URI.create("http://test/path"))) + .thenReturn(URI.create("http://testhost:80/path")); - Response response = feignBlockingLoadBalancerClient.execute(request, - new Request.Options()); + Response response = feignBlockingLoadBalancerClient.execute(request, new Request.Options()); - String bodyContent = IOUtils - .toString(response.body().asReader(StandardCharsets.UTF_8)); + String bodyContent = IOUtils.toString(response.body().asReader(StandardCharsets.UTF_8)); assertThat(bodyContent).isEqualTo("foo"); } + + @Test void shouldPassCorrectRequestToDelegate() throws IOException { Request request = testRequest(); diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java index 73d89ca0..c747eda0 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java @@ -181,7 +181,7 @@ public class FeignClientTests { public void testClient() { assertThat(testClient).as("testClient was null").isNotNull(); assertThat(Proxy.isProxyClass(testClient.getClass())) - .as("testClient is not a java Proxy").isTrue(); + .as("testClient is not a java Proxy").isTrue(); InvocationHandler invocationHandler = Proxy.getInvocationHandler(testClient); assertThat(invocationHandler).as("invocationHandler was null").isNotNull(); } @@ -198,7 +198,7 @@ public class FeignClientTests { Hello hello = testClient.getHello(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -219,9 +219,9 @@ public class FeignClientTests { List headers = testClient.getHelloHeaders(); assertThat(headers).as("headers was null").isNotNull(); assertThat(headers.contains("myheader1value")) - .as("headers didn't contain myheader1value").isTrue(); + .as("headers didn't contain myheader1value").isTrue(); assertThat(headers.contains("myheader2value")) - .as("headers didn't contain myheader2value").isTrue(); + .as("headers didn't contain myheader2value").isTrue(); } @Test @@ -241,11 +241,12 @@ public class FeignClientTests { @Test public void testServiceId() { - assertThat(testClientServiceId).as("testClientServiceId was null").isNotNull(); + assertThat(testClientServiceId).as("testClientServiceId was null") + .isNotNull(); final Hello hello = testClientServiceId.getHello(); assertThat(hello).as("The hello response was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -259,7 +260,7 @@ public class FeignClientTests { @Test public void testFormattedParams() { List list = Arrays.asList(LocalDate.of(2001, 1, 1), - LocalDate.of(2018, 6, 10)); + LocalDate.of(2018, 6, 10)); List params = testClient.getFormattedParams(list); assertThat(params).as("params was null").isNotNull(); assertThat(params).as("params not converted correctly").isEqualTo(list); @@ -270,13 +271,13 @@ public class FeignClientTests { HystrixCommand> command = testClient.getHellosHystrix(); assertThat(command).as("command was null").isNotNull(); assertThat(command.getCommandGroup().name()).as( - "Hystrix command group name should match the name of the feign client") - .isEqualTo("localapp"); + "Hystrix command group name should match the name of the feign client") + .isEqualTo("localapp"); String configKey = Feign.configKey(TestClient.class, - TestClient.class.getMethod("getHellosHystrix", (Class[]) null)); + TestClient.class.getMethod("getHellosHystrix", (Class[]) null)); assertThat(command.getCommandKey().name()) - .as("Hystrix command key name should match the feign config key") - .isEqualTo(configKey); + .as("Hystrix command key name should match the feign config key") + .isEqualTo(configKey); List hellos = command.execute(); assertThat(hellos).as("hellos was null").isNotNull(); assertThat(getHelloList()).as("hellos didn't match").isEqualTo(hellos); @@ -289,7 +290,7 @@ public class FeignClientTests { Hello hello = single.toBlocking().value(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -297,7 +298,7 @@ public class FeignClientTests { ResponseEntity response = testClient.noContent(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.NO_CONTENT); + .isEqualTo(HttpStatus.NO_CONTENT); } @Test @@ -305,7 +306,7 @@ public class FeignClientTests { ResponseEntity response = testClient.head(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.OK); + .isEqualTo(HttpStatus.OK); } @Test @@ -315,7 +316,7 @@ public class FeignClientTests { Hello hello = entity.getBody(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -323,7 +324,7 @@ public class FeignClientTests { String response = testClient.moreComplexContentType("{\"value\":\"OK\"}"); assertThat(response).as("response was null").isNotNull(); assertThat(response).as("didn't respond with {\"value\":\"OK\"}") - .isEqualTo("{\"value\":\"OK\"}"); + .isEqualTo("{\"value\":\"OK\"}"); } @Test @@ -331,7 +332,7 @@ public class FeignClientTests { ResponseEntity response = decodingTestClient.notFound(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.NOT_FOUND); + .isEqualTo(HttpStatus.NOT_FOUND); assertThat(response.getBody()).as("response body was not null").isNull(); } @@ -370,7 +371,7 @@ public class FeignClientTests { Hello hello = single.toBlocking().value(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbacksingle"); + .isEqualTo("fallbacksingle"); } @Test @@ -380,7 +381,7 @@ public class FeignClientTests { Hello hello = command.execute(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackcommand"); + .isEqualTo("fallbackcommand"); } @Test @@ -390,7 +391,7 @@ public class FeignClientTests { Hello hello = observable.toBlocking().first(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackobservable"); + .isEqualTo("fallbackobservable"); } @Test @@ -400,7 +401,7 @@ public class FeignClientTests { Hello hello = future.get(1, TimeUnit.SECONDS); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackfuture"); + .isEqualTo("fallbackfuture"); } @Test @@ -409,8 +410,8 @@ public class FeignClientTests { assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("hello#message was null").isNotNull(); assertThat(hello.getMessage().contains("500")).as( - "hello#message did not contain the cause (status code) of the fallback invocation") - .isTrue(); + "hello#message did not contain the cause (status code) of the fallback invocation") + .isTrue(); } @Test(expected = HystrixRuntimeException.class) @@ -438,17 +439,17 @@ public class FeignClientTests { @Test public void testHystrixSetterFactory() { HystrixCommand> command = hystrixSetterFactoryClient - .getHellosHystrix(); + .getHellosHystrix(); assertThat(command).as("command was null").isNotNull(); String setterPrefix = TestHystrixSetterFactoryClientConfig.SETTER_PREFIX; assertThat(command.getCommandGroup().name()).as( - "Hystrix command group name should match the name of the feign client with a prefix of " - + setterPrefix) - .isEqualTo(setterPrefix + "localapp5"); + "Hystrix command group name should match the name of the feign client with a prefix of " + + setterPrefix) + .isEqualTo(setterPrefix + "localapp5"); assertThat(command.getCommandKey().name()).as( - "Hystrix command key name should match the request method (space) request path with a prefix of " - + setterPrefix) - .isEqualTo(setterPrefix + "GET /hellos"); + "Hystrix command key name should match the request method (space) request path with a prefix of " + + setterPrefix) + .isEqualTo(setterPrefix + "GET /hellos"); List hellos = command.execute(); assertThat(hellos).as("hellos was null").isNotNull(); assertThat(getHelloList()).as("hellos didn't match").isEqualTo(hellos); @@ -480,7 +481,8 @@ public class FeignClientTests { Hello pojo2 = new Hello(OI_TERRA_2); MockMultipartFile file = new MockMultipartFile("file", "hello.bin", null, "hello".getBytes()); - String response = multipartClient.multipartPojo("abc", "123", pojo1, pojo2, file); + String response = multipartClient.multipartPojo("abc", "123", pojo1, pojo2, + file); assertThat(response).isEqualTo("abc123hello world 1oi terra 2hello.bin"); } @@ -505,8 +507,9 @@ public class FeignClientTests { "hello".getBytes()); MockMultipartFile file2 = new MockMultipartFile("file2", "hello2.bin", null, "hello".getBytes()); - String response = multipartClient.requestPartListOfPojosAndListOfMultipartFiles( - Arrays.asList(pojo1, pojo2), Arrays.asList(file1, file2)); + String response = multipartClient + .requestPartListOfPojosAndListOfMultipartFiles( + Arrays.asList(pojo1, pojo2), Arrays.asList(file1, file2)); assertThat(response).isEqualTo("hello world 1oi terra 2hello1.binhello2.bin"); } @@ -621,7 +624,7 @@ public class FeignClientTests { String getToString(@RequestParam("arg") Arg arg); @PostMapping(path = "/form-urlencoded", - consumes = APPLICATION_FORM_URLENCODED_VALUE) + consumes = APPLICATION_FORM_URLENCODED_VALUE) Hello postFormUrlEncoded(Hello hello); @RequestMapping(method = RequestMethod.GET, path = "/tostring2") @@ -821,7 +824,8 @@ public class FeignClientTests { public HystrixClientWithFallBackFactory create(final Throwable cause) { return () -> { assertThat(cause).isNotNull().as("Cause was null"); - return new Hello("Hello from the fallback side: " + cause.getMessage()); + return new Hello( + "Hello from the fallback side: " + cause.getMessage()); }; } @@ -884,12 +888,12 @@ public class FeignClientTests { return (target, method) -> { String groupKey = SETTER_PREFIX + target.name(); RequestMapping requestMapping = method - .getAnnotation(RequestMapping.class); + .getAnnotation(RequestMapping.class); String commandKey = SETTER_PREFIX + requestMapping.method()[0] + " " - + requestMapping.path()[0]; + + requestMapping.path()[0]; return HystrixCommand.Setter - .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) - .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)); + .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) + .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)); }; } @@ -1157,7 +1161,7 @@ public class FeignClientTests { } @PostMapping(path = "/form-urlencoded", - consumes = APPLICATION_FORM_URLENCODED_VALUE) + consumes = APPLICATION_FORM_URLENCODED_VALUE) Hello postFormUrlEncoded(Hello hello) { return hello; } diff --git a/spring-cloud-openfeign-dependencies/pom.xml b/spring-cloud-openfeign-dependencies/pom.xml index 3b3653b9..e2f459ca 100644 --- a/spring-cloud-openfeign-dependencies/pom.xml +++ b/spring-cloud-openfeign-dependencies/pom.xml @@ -6,11 +6,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.3.5.RELEASE + 2.3.5.BUILD-SNAPSHOT spring-cloud-openfeign-dependencies - 2.2.9.RELEASE + 2.2.9.BUILD-SNAPSHOT pom spring-cloud-openfeign-dependencies Spring Cloud OpenFeign Dependencies diff --git a/spring-cloud-starter-openfeign/pom.xml b/spring-cloud-starter-openfeign/pom.xml index 34b2f184..b76067c0 100644 --- a/spring-cloud-starter-openfeign/pom.xml +++ b/spring-cloud-starter-openfeign/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.RELEASE + 2.2.9.BUILD-SNAPSHOT .. spring-cloud-starter-openfeign From e9e38d0274424053e687362444b277ce63576508 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Wed, 7 Jul 2021 14:07:20 +0000 Subject: [PATCH 07/12] Bumping versions --- docs/pom.xml | 2 +- pom.xml | 8 +- spring-cloud-openfeign-core/pom.xml | 2 +- .../openfeign/FeignClientFactoryBean.java | 3 +- ...adBalancerResponseStatusCodeException.java | 6 +- ...ryableFeignBlockingLoadBalancerClient.java | 4 +- ...eFeignBlockingLoadBalancerClientTests.java | 26 +++--- .../openfeign/valid/FeignClientTests.java | 86 +++++++++---------- spring-cloud-openfeign-dependencies/pom.xml | 4 +- spring-cloud-starter-openfeign/pom.xml | 2 +- 10 files changed, 72 insertions(+), 71 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 327ae75b..a3174077 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.BUILD-SNAPSHOT + 2.2.9.RELEASE spring-cloud-openfeign-docs pom diff --git a/pom.xml b/pom.xml index e0ad978f..2d1c2cd3 100644 --- a/pom.xml +++ b/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-cloud-openfeign - 2.2.9.BUILD-SNAPSHOT + 2.2.9.RELEASE pom Spring Cloud OpenFeign Spring Cloud OpenFeign org.springframework.cloud spring-cloud-build - 2.3.4.RELEASE + 2.3.5.RELEASE @@ -26,8 +26,8 @@ ${basedir} 2.11.3 - 2.2.9.BUILD-SNAPSHOT - 2.2.9.BUILD-SNAPSHOT + 2.2.9.RELEASE + 2.2.9.RELEASE 2.10 diff --git a/spring-cloud-openfeign-core/pom.xml b/spring-cloud-openfeign-core/pom.xml index c50b5720..ed012d1a 100644 --- a/spring-cloud-openfeign-core/pom.xml +++ b/spring-cloud-openfeign-core/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.BUILD-SNAPSHOT + 2.2.9.RELEASE .. spring-cloud-openfeign-core diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java index ac24747f..59c8b23f 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java @@ -375,7 +375,8 @@ public class FeignClientFactoryBean implements FactoryBean, Initializing if (!StringUtils.hasText(url)) { if (LOG.isInfoEnabled()) { - LOG.info("For '" + name + "' URL not provided. Will try picking an instance via load-balancing."); + LOG.info("For '" + name + + "' URL not provided. Will try picking an instance via load-balancing."); } if (!name.startsWith("http")) { url = "http://" + name; diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java index 0e7017f8..9bcfc1fa 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java @@ -28,11 +28,13 @@ import org.springframework.cloud.client.loadbalancer.RetryableStatusCodeExceptio * * @author Ryan Baxter */ -public class LoadBalancerResponseStatusCodeException extends RetryableStatusCodeException { +public class LoadBalancerResponseStatusCodeException + extends RetryableStatusCodeException { private final Response response; - public LoadBalancerResponseStatusCodeException(String serviceId, Response response, byte[] body, URI uri) { + public LoadBalancerResponseStatusCodeException(String serviceId, Response response, + byte[] body, URI uri) { super(serviceId, response.status(), response, uri); this.response = Response.builder() .body(new ByteArrayInputStream(body), body.length) diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java index 342bb534..157eebaf 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java @@ -113,10 +113,10 @@ public class RetryableFeignBlockingLoadBalancerClient implements Client { String.format("Retrying on status code: %d", responseStatus)); } byte[] byteArray = response.body() == null ? new byte[] {} - : StreamUtils.copyToByteArray(response.body().asInputStream()); + : StreamUtils.copyToByteArray(response.body().asInputStream()); response.close(); throw new LoadBalancerResponseStatusCodeException(serviceId, response, - byteArray, URI.create(request.url())); + byteArray, URI.create(request.url())); } return response; }, new LoadBalancedRecoveryCallback() { diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java index ca175318..5862d425 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java @@ -119,8 +119,10 @@ class RetryableFeignBlockingLoadBalancerClientTests { private Response testResponse(int status, String body) { // ByteArrayInputStream ignores close() and must be wrapped - InputStream reallyCloseable = new BufferedInputStream(new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8))); - return Response.builder().request(testRequest()).status(status).body(reallyCloseable, null).build(); + InputStream reallyCloseable = new BufferedInputStream( + new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8))); + return Response.builder().request(testRequest()).status(status) + .body(reallyCloseable, null).build(); } @@ -163,23 +165,23 @@ class RetryableFeignBlockingLoadBalancerClientTests { void shouldExposeResponseBodyOnRetry() throws IOException { properties.getRetryableStatusCodes().add(503); Request request = testRequest(); - when(delegate.execute(any(), any())) - .thenReturn(testResponse(503, "foo"), testResponse(503, "foo")); + when(delegate.execute(any(), any())).thenReturn(testResponse(503, "foo"), + testResponse(503, "foo")); when(retryFactory.createRetryPolicy(any(), eq(loadBalancerClient))) - .thenReturn(new BlockingLoadBalancedRetryPolicy("test", - loadBalancerClient, properties)); + .thenReturn(new BlockingLoadBalancedRetryPolicy("test", + loadBalancerClient, properties)); when(loadBalancerClient.reconstructURI(serviceInstance, - URI.create("http://test/path"))) - .thenReturn(URI.create("http://testhost:80/path")); + URI.create("http://test/path"))) + .thenReturn(URI.create("http://testhost:80/path")); - Response response = feignBlockingLoadBalancerClient.execute(request, new Request.Options()); + Response response = feignBlockingLoadBalancerClient.execute(request, + new Request.Options()); - String bodyContent = IOUtils.toString(response.body().asReader(StandardCharsets.UTF_8)); + String bodyContent = IOUtils + .toString(response.body().asReader(StandardCharsets.UTF_8)); assertThat(bodyContent).isEqualTo("foo"); } - - @Test void shouldPassCorrectRequestToDelegate() throws IOException { Request request = testRequest(); diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java index c747eda0..73d89ca0 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java @@ -181,7 +181,7 @@ public class FeignClientTests { public void testClient() { assertThat(testClient).as("testClient was null").isNotNull(); assertThat(Proxy.isProxyClass(testClient.getClass())) - .as("testClient is not a java Proxy").isTrue(); + .as("testClient is not a java Proxy").isTrue(); InvocationHandler invocationHandler = Proxy.getInvocationHandler(testClient); assertThat(invocationHandler).as("invocationHandler was null").isNotNull(); } @@ -198,7 +198,7 @@ public class FeignClientTests { Hello hello = testClient.getHello(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -219,9 +219,9 @@ public class FeignClientTests { List headers = testClient.getHelloHeaders(); assertThat(headers).as("headers was null").isNotNull(); assertThat(headers.contains("myheader1value")) - .as("headers didn't contain myheader1value").isTrue(); + .as("headers didn't contain myheader1value").isTrue(); assertThat(headers.contains("myheader2value")) - .as("headers didn't contain myheader2value").isTrue(); + .as("headers didn't contain myheader2value").isTrue(); } @Test @@ -241,12 +241,11 @@ public class FeignClientTests { @Test public void testServiceId() { - assertThat(testClientServiceId).as("testClientServiceId was null") - .isNotNull(); + assertThat(testClientServiceId).as("testClientServiceId was null").isNotNull(); final Hello hello = testClientServiceId.getHello(); assertThat(hello).as("The hello response was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -260,7 +259,7 @@ public class FeignClientTests { @Test public void testFormattedParams() { List list = Arrays.asList(LocalDate.of(2001, 1, 1), - LocalDate.of(2018, 6, 10)); + LocalDate.of(2018, 6, 10)); List params = testClient.getFormattedParams(list); assertThat(params).as("params was null").isNotNull(); assertThat(params).as("params not converted correctly").isEqualTo(list); @@ -271,13 +270,13 @@ public class FeignClientTests { HystrixCommand> command = testClient.getHellosHystrix(); assertThat(command).as("command was null").isNotNull(); assertThat(command.getCommandGroup().name()).as( - "Hystrix command group name should match the name of the feign client") - .isEqualTo("localapp"); + "Hystrix command group name should match the name of the feign client") + .isEqualTo("localapp"); String configKey = Feign.configKey(TestClient.class, - TestClient.class.getMethod("getHellosHystrix", (Class[]) null)); + TestClient.class.getMethod("getHellosHystrix", (Class[]) null)); assertThat(command.getCommandKey().name()) - .as("Hystrix command key name should match the feign config key") - .isEqualTo(configKey); + .as("Hystrix command key name should match the feign config key") + .isEqualTo(configKey); List hellos = command.execute(); assertThat(hellos).as("hellos was null").isNotNull(); assertThat(getHelloList()).as("hellos didn't match").isEqualTo(hellos); @@ -290,7 +289,7 @@ public class FeignClientTests { Hello hello = single.toBlocking().value(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -298,7 +297,7 @@ public class FeignClientTests { ResponseEntity response = testClient.noContent(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.NO_CONTENT); + .isEqualTo(HttpStatus.NO_CONTENT); } @Test @@ -306,7 +305,7 @@ public class FeignClientTests { ResponseEntity response = testClient.head(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.OK); + .isEqualTo(HttpStatus.OK); } @Test @@ -316,7 +315,7 @@ public class FeignClientTests { Hello hello = entity.getBody(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -324,7 +323,7 @@ public class FeignClientTests { String response = testClient.moreComplexContentType("{\"value\":\"OK\"}"); assertThat(response).as("response was null").isNotNull(); assertThat(response).as("didn't respond with {\"value\":\"OK\"}") - .isEqualTo("{\"value\":\"OK\"}"); + .isEqualTo("{\"value\":\"OK\"}"); } @Test @@ -332,7 +331,7 @@ public class FeignClientTests { ResponseEntity response = decodingTestClient.notFound(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.NOT_FOUND); + .isEqualTo(HttpStatus.NOT_FOUND); assertThat(response.getBody()).as("response body was not null").isNull(); } @@ -371,7 +370,7 @@ public class FeignClientTests { Hello hello = single.toBlocking().value(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbacksingle"); + .isEqualTo("fallbacksingle"); } @Test @@ -381,7 +380,7 @@ public class FeignClientTests { Hello hello = command.execute(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackcommand"); + .isEqualTo("fallbackcommand"); } @Test @@ -391,7 +390,7 @@ public class FeignClientTests { Hello hello = observable.toBlocking().first(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackobservable"); + .isEqualTo("fallbackobservable"); } @Test @@ -401,7 +400,7 @@ public class FeignClientTests { Hello hello = future.get(1, TimeUnit.SECONDS); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackfuture"); + .isEqualTo("fallbackfuture"); } @Test @@ -410,8 +409,8 @@ public class FeignClientTests { assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("hello#message was null").isNotNull(); assertThat(hello.getMessage().contains("500")).as( - "hello#message did not contain the cause (status code) of the fallback invocation") - .isTrue(); + "hello#message did not contain the cause (status code) of the fallback invocation") + .isTrue(); } @Test(expected = HystrixRuntimeException.class) @@ -439,17 +438,17 @@ public class FeignClientTests { @Test public void testHystrixSetterFactory() { HystrixCommand> command = hystrixSetterFactoryClient - .getHellosHystrix(); + .getHellosHystrix(); assertThat(command).as("command was null").isNotNull(); String setterPrefix = TestHystrixSetterFactoryClientConfig.SETTER_PREFIX; assertThat(command.getCommandGroup().name()).as( - "Hystrix command group name should match the name of the feign client with a prefix of " - + setterPrefix) - .isEqualTo(setterPrefix + "localapp5"); + "Hystrix command group name should match the name of the feign client with a prefix of " + + setterPrefix) + .isEqualTo(setterPrefix + "localapp5"); assertThat(command.getCommandKey().name()).as( - "Hystrix command key name should match the request method (space) request path with a prefix of " - + setterPrefix) - .isEqualTo(setterPrefix + "GET /hellos"); + "Hystrix command key name should match the request method (space) request path with a prefix of " + + setterPrefix) + .isEqualTo(setterPrefix + "GET /hellos"); List hellos = command.execute(); assertThat(hellos).as("hellos was null").isNotNull(); assertThat(getHelloList()).as("hellos didn't match").isEqualTo(hellos); @@ -481,8 +480,7 @@ public class FeignClientTests { Hello pojo2 = new Hello(OI_TERRA_2); MockMultipartFile file = new MockMultipartFile("file", "hello.bin", null, "hello".getBytes()); - String response = multipartClient.multipartPojo("abc", "123", pojo1, pojo2, - file); + String response = multipartClient.multipartPojo("abc", "123", pojo1, pojo2, file); assertThat(response).isEqualTo("abc123hello world 1oi terra 2hello.bin"); } @@ -507,9 +505,8 @@ public class FeignClientTests { "hello".getBytes()); MockMultipartFile file2 = new MockMultipartFile("file2", "hello2.bin", null, "hello".getBytes()); - String response = multipartClient - .requestPartListOfPojosAndListOfMultipartFiles( - Arrays.asList(pojo1, pojo2), Arrays.asList(file1, file2)); + String response = multipartClient.requestPartListOfPojosAndListOfMultipartFiles( + Arrays.asList(pojo1, pojo2), Arrays.asList(file1, file2)); assertThat(response).isEqualTo("hello world 1oi terra 2hello1.binhello2.bin"); } @@ -624,7 +621,7 @@ public class FeignClientTests { String getToString(@RequestParam("arg") Arg arg); @PostMapping(path = "/form-urlencoded", - consumes = APPLICATION_FORM_URLENCODED_VALUE) + consumes = APPLICATION_FORM_URLENCODED_VALUE) Hello postFormUrlEncoded(Hello hello); @RequestMapping(method = RequestMethod.GET, path = "/tostring2") @@ -824,8 +821,7 @@ public class FeignClientTests { public HystrixClientWithFallBackFactory create(final Throwable cause) { return () -> { assertThat(cause).isNotNull().as("Cause was null"); - return new Hello( - "Hello from the fallback side: " + cause.getMessage()); + return new Hello("Hello from the fallback side: " + cause.getMessage()); }; } @@ -888,12 +884,12 @@ public class FeignClientTests { return (target, method) -> { String groupKey = SETTER_PREFIX + target.name(); RequestMapping requestMapping = method - .getAnnotation(RequestMapping.class); + .getAnnotation(RequestMapping.class); String commandKey = SETTER_PREFIX + requestMapping.method()[0] + " " - + requestMapping.path()[0]; + + requestMapping.path()[0]; return HystrixCommand.Setter - .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) - .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)); + .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) + .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)); }; } @@ -1161,7 +1157,7 @@ public class FeignClientTests { } @PostMapping(path = "/form-urlencoded", - consumes = APPLICATION_FORM_URLENCODED_VALUE) + consumes = APPLICATION_FORM_URLENCODED_VALUE) Hello postFormUrlEncoded(Hello hello) { return hello; } diff --git a/spring-cloud-openfeign-dependencies/pom.xml b/spring-cloud-openfeign-dependencies/pom.xml index e2f459ca..3b3653b9 100644 --- a/spring-cloud-openfeign-dependencies/pom.xml +++ b/spring-cloud-openfeign-dependencies/pom.xml @@ -6,11 +6,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.3.5.BUILD-SNAPSHOT + 2.3.5.RELEASE spring-cloud-openfeign-dependencies - 2.2.9.BUILD-SNAPSHOT + 2.2.9.RELEASE pom spring-cloud-openfeign-dependencies Spring Cloud OpenFeign Dependencies diff --git a/spring-cloud-starter-openfeign/pom.xml b/spring-cloud-starter-openfeign/pom.xml index b76067c0..34b2f184 100644 --- a/spring-cloud-starter-openfeign/pom.xml +++ b/spring-cloud-starter-openfeign/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.BUILD-SNAPSHOT + 2.2.9.RELEASE .. spring-cloud-starter-openfeign From 3acf5f9e926a55999e7a1ba5cc6c4ab25d8b6be7 Mon Sep 17 00:00:00 2001 From: Olga MaciaszekSharma Date: Wed, 7 Jul 2021 18:46:20 +0200 Subject: [PATCH 08/12] Going back to snapshots This reverts commit 6479db0a54f55fb84356aa80be3bd044fe50c2e1. --- docs/pom.xml | 2 +- pom.xml | 8 +- spring-cloud-openfeign-core/pom.xml | 2 +- .../openfeign/FeignClientFactoryBean.java | 3 +- ...adBalancerResponseStatusCodeException.java | 6 +- ...ryableFeignBlockingLoadBalancerClient.java | 4 +- ...eFeignBlockingLoadBalancerClientTests.java | 26 +++--- .../openfeign/valid/FeignClientTests.java | 86 ++++++++++--------- spring-cloud-openfeign-dependencies/pom.xml | 4 +- spring-cloud-starter-openfeign/pom.xml | 2 +- 10 files changed, 71 insertions(+), 72 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index a3174077..327ae75b 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.RELEASE + 2.2.9.BUILD-SNAPSHOT spring-cloud-openfeign-docs pom diff --git a/pom.xml b/pom.xml index 2d1c2cd3..e0ad978f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-cloud-openfeign - 2.2.9.RELEASE + 2.2.9.BUILD-SNAPSHOT pom Spring Cloud OpenFeign Spring Cloud OpenFeign org.springframework.cloud spring-cloud-build - 2.3.5.RELEASE + 2.3.4.RELEASE @@ -26,8 +26,8 @@ ${basedir} 2.11.3 - 2.2.9.RELEASE - 2.2.9.RELEASE + 2.2.9.BUILD-SNAPSHOT + 2.2.9.BUILD-SNAPSHOT 2.10 diff --git a/spring-cloud-openfeign-core/pom.xml b/spring-cloud-openfeign-core/pom.xml index ed012d1a..c50b5720 100644 --- a/spring-cloud-openfeign-core/pom.xml +++ b/spring-cloud-openfeign-core/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.RELEASE + 2.2.9.BUILD-SNAPSHOT .. spring-cloud-openfeign-core diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java index 59c8b23f..ac24747f 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java @@ -375,8 +375,7 @@ public class FeignClientFactoryBean implements FactoryBean, Initializing if (!StringUtils.hasText(url)) { if (LOG.isInfoEnabled()) { - LOG.info("For '" + name - + "' URL not provided. Will try picking an instance via load-balancing."); + LOG.info("For '" + name + "' URL not provided. Will try picking an instance via load-balancing."); } if (!name.startsWith("http")) { url = "http://" + name; diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java index 9bcfc1fa..0e7017f8 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java @@ -28,13 +28,11 @@ import org.springframework.cloud.client.loadbalancer.RetryableStatusCodeExceptio * * @author Ryan Baxter */ -public class LoadBalancerResponseStatusCodeException - extends RetryableStatusCodeException { +public class LoadBalancerResponseStatusCodeException extends RetryableStatusCodeException { private final Response response; - public LoadBalancerResponseStatusCodeException(String serviceId, Response response, - byte[] body, URI uri) { + public LoadBalancerResponseStatusCodeException(String serviceId, Response response, byte[] body, URI uri) { super(serviceId, response.status(), response, uri); this.response = Response.builder() .body(new ByteArrayInputStream(body), body.length) diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java index 157eebaf..342bb534 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java @@ -113,10 +113,10 @@ public class RetryableFeignBlockingLoadBalancerClient implements Client { String.format("Retrying on status code: %d", responseStatus)); } byte[] byteArray = response.body() == null ? new byte[] {} - : StreamUtils.copyToByteArray(response.body().asInputStream()); + : StreamUtils.copyToByteArray(response.body().asInputStream()); response.close(); throw new LoadBalancerResponseStatusCodeException(serviceId, response, - byteArray, URI.create(request.url())); + byteArray, URI.create(request.url())); } return response; }, new LoadBalancedRecoveryCallback() { diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java index 5862d425..ca175318 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java @@ -119,10 +119,8 @@ class RetryableFeignBlockingLoadBalancerClientTests { private Response testResponse(int status, String body) { // ByteArrayInputStream ignores close() and must be wrapped - InputStream reallyCloseable = new BufferedInputStream( - new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8))); - return Response.builder().request(testRequest()).status(status) - .body(reallyCloseable, null).build(); + InputStream reallyCloseable = new BufferedInputStream(new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8))); + return Response.builder().request(testRequest()).status(status).body(reallyCloseable, null).build(); } @@ -165,23 +163,23 @@ class RetryableFeignBlockingLoadBalancerClientTests { void shouldExposeResponseBodyOnRetry() throws IOException { properties.getRetryableStatusCodes().add(503); Request request = testRequest(); - when(delegate.execute(any(), any())).thenReturn(testResponse(503, "foo"), - testResponse(503, "foo")); + when(delegate.execute(any(), any())) + .thenReturn(testResponse(503, "foo"), testResponse(503, "foo")); when(retryFactory.createRetryPolicy(any(), eq(loadBalancerClient))) - .thenReturn(new BlockingLoadBalancedRetryPolicy("test", - loadBalancerClient, properties)); + .thenReturn(new BlockingLoadBalancedRetryPolicy("test", + loadBalancerClient, properties)); when(loadBalancerClient.reconstructURI(serviceInstance, - URI.create("http://test/path"))) - .thenReturn(URI.create("http://testhost:80/path")); + URI.create("http://test/path"))) + .thenReturn(URI.create("http://testhost:80/path")); - Response response = feignBlockingLoadBalancerClient.execute(request, - new Request.Options()); + Response response = feignBlockingLoadBalancerClient.execute(request, new Request.Options()); - String bodyContent = IOUtils - .toString(response.body().asReader(StandardCharsets.UTF_8)); + String bodyContent = IOUtils.toString(response.body().asReader(StandardCharsets.UTF_8)); assertThat(bodyContent).isEqualTo("foo"); } + + @Test void shouldPassCorrectRequestToDelegate() throws IOException { Request request = testRequest(); diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java index 73d89ca0..c747eda0 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java @@ -181,7 +181,7 @@ public class FeignClientTests { public void testClient() { assertThat(testClient).as("testClient was null").isNotNull(); assertThat(Proxy.isProxyClass(testClient.getClass())) - .as("testClient is not a java Proxy").isTrue(); + .as("testClient is not a java Proxy").isTrue(); InvocationHandler invocationHandler = Proxy.getInvocationHandler(testClient); assertThat(invocationHandler).as("invocationHandler was null").isNotNull(); } @@ -198,7 +198,7 @@ public class FeignClientTests { Hello hello = testClient.getHello(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -219,9 +219,9 @@ public class FeignClientTests { List headers = testClient.getHelloHeaders(); assertThat(headers).as("headers was null").isNotNull(); assertThat(headers.contains("myheader1value")) - .as("headers didn't contain myheader1value").isTrue(); + .as("headers didn't contain myheader1value").isTrue(); assertThat(headers.contains("myheader2value")) - .as("headers didn't contain myheader2value").isTrue(); + .as("headers didn't contain myheader2value").isTrue(); } @Test @@ -241,11 +241,12 @@ public class FeignClientTests { @Test public void testServiceId() { - assertThat(testClientServiceId).as("testClientServiceId was null").isNotNull(); + assertThat(testClientServiceId).as("testClientServiceId was null") + .isNotNull(); final Hello hello = testClientServiceId.getHello(); assertThat(hello).as("The hello response was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -259,7 +260,7 @@ public class FeignClientTests { @Test public void testFormattedParams() { List list = Arrays.asList(LocalDate.of(2001, 1, 1), - LocalDate.of(2018, 6, 10)); + LocalDate.of(2018, 6, 10)); List params = testClient.getFormattedParams(list); assertThat(params).as("params was null").isNotNull(); assertThat(params).as("params not converted correctly").isEqualTo(list); @@ -270,13 +271,13 @@ public class FeignClientTests { HystrixCommand> command = testClient.getHellosHystrix(); assertThat(command).as("command was null").isNotNull(); assertThat(command.getCommandGroup().name()).as( - "Hystrix command group name should match the name of the feign client") - .isEqualTo("localapp"); + "Hystrix command group name should match the name of the feign client") + .isEqualTo("localapp"); String configKey = Feign.configKey(TestClient.class, - TestClient.class.getMethod("getHellosHystrix", (Class[]) null)); + TestClient.class.getMethod("getHellosHystrix", (Class[]) null)); assertThat(command.getCommandKey().name()) - .as("Hystrix command key name should match the feign config key") - .isEqualTo(configKey); + .as("Hystrix command key name should match the feign config key") + .isEqualTo(configKey); List hellos = command.execute(); assertThat(hellos).as("hellos was null").isNotNull(); assertThat(getHelloList()).as("hellos didn't match").isEqualTo(hellos); @@ -289,7 +290,7 @@ public class FeignClientTests { Hello hello = single.toBlocking().value(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -297,7 +298,7 @@ public class FeignClientTests { ResponseEntity response = testClient.noContent(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.NO_CONTENT); + .isEqualTo(HttpStatus.NO_CONTENT); } @Test @@ -305,7 +306,7 @@ public class FeignClientTests { ResponseEntity response = testClient.head(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.OK); + .isEqualTo(HttpStatus.OK); } @Test @@ -315,7 +316,7 @@ public class FeignClientTests { Hello hello = entity.getBody(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -323,7 +324,7 @@ public class FeignClientTests { String response = testClient.moreComplexContentType("{\"value\":\"OK\"}"); assertThat(response).as("response was null").isNotNull(); assertThat(response).as("didn't respond with {\"value\":\"OK\"}") - .isEqualTo("{\"value\":\"OK\"}"); + .isEqualTo("{\"value\":\"OK\"}"); } @Test @@ -331,7 +332,7 @@ public class FeignClientTests { ResponseEntity response = decodingTestClient.notFound(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.NOT_FOUND); + .isEqualTo(HttpStatus.NOT_FOUND); assertThat(response.getBody()).as("response body was not null").isNull(); } @@ -370,7 +371,7 @@ public class FeignClientTests { Hello hello = single.toBlocking().value(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbacksingle"); + .isEqualTo("fallbacksingle"); } @Test @@ -380,7 +381,7 @@ public class FeignClientTests { Hello hello = command.execute(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackcommand"); + .isEqualTo("fallbackcommand"); } @Test @@ -390,7 +391,7 @@ public class FeignClientTests { Hello hello = observable.toBlocking().first(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackobservable"); + .isEqualTo("fallbackobservable"); } @Test @@ -400,7 +401,7 @@ public class FeignClientTests { Hello hello = future.get(1, TimeUnit.SECONDS); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackfuture"); + .isEqualTo("fallbackfuture"); } @Test @@ -409,8 +410,8 @@ public class FeignClientTests { assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("hello#message was null").isNotNull(); assertThat(hello.getMessage().contains("500")).as( - "hello#message did not contain the cause (status code) of the fallback invocation") - .isTrue(); + "hello#message did not contain the cause (status code) of the fallback invocation") + .isTrue(); } @Test(expected = HystrixRuntimeException.class) @@ -438,17 +439,17 @@ public class FeignClientTests { @Test public void testHystrixSetterFactory() { HystrixCommand> command = hystrixSetterFactoryClient - .getHellosHystrix(); + .getHellosHystrix(); assertThat(command).as("command was null").isNotNull(); String setterPrefix = TestHystrixSetterFactoryClientConfig.SETTER_PREFIX; assertThat(command.getCommandGroup().name()).as( - "Hystrix command group name should match the name of the feign client with a prefix of " - + setterPrefix) - .isEqualTo(setterPrefix + "localapp5"); + "Hystrix command group name should match the name of the feign client with a prefix of " + + setterPrefix) + .isEqualTo(setterPrefix + "localapp5"); assertThat(command.getCommandKey().name()).as( - "Hystrix command key name should match the request method (space) request path with a prefix of " - + setterPrefix) - .isEqualTo(setterPrefix + "GET /hellos"); + "Hystrix command key name should match the request method (space) request path with a prefix of " + + setterPrefix) + .isEqualTo(setterPrefix + "GET /hellos"); List hellos = command.execute(); assertThat(hellos).as("hellos was null").isNotNull(); assertThat(getHelloList()).as("hellos didn't match").isEqualTo(hellos); @@ -480,7 +481,8 @@ public class FeignClientTests { Hello pojo2 = new Hello(OI_TERRA_2); MockMultipartFile file = new MockMultipartFile("file", "hello.bin", null, "hello".getBytes()); - String response = multipartClient.multipartPojo("abc", "123", pojo1, pojo2, file); + String response = multipartClient.multipartPojo("abc", "123", pojo1, pojo2, + file); assertThat(response).isEqualTo("abc123hello world 1oi terra 2hello.bin"); } @@ -505,8 +507,9 @@ public class FeignClientTests { "hello".getBytes()); MockMultipartFile file2 = new MockMultipartFile("file2", "hello2.bin", null, "hello".getBytes()); - String response = multipartClient.requestPartListOfPojosAndListOfMultipartFiles( - Arrays.asList(pojo1, pojo2), Arrays.asList(file1, file2)); + String response = multipartClient + .requestPartListOfPojosAndListOfMultipartFiles( + Arrays.asList(pojo1, pojo2), Arrays.asList(file1, file2)); assertThat(response).isEqualTo("hello world 1oi terra 2hello1.binhello2.bin"); } @@ -621,7 +624,7 @@ public class FeignClientTests { String getToString(@RequestParam("arg") Arg arg); @PostMapping(path = "/form-urlencoded", - consumes = APPLICATION_FORM_URLENCODED_VALUE) + consumes = APPLICATION_FORM_URLENCODED_VALUE) Hello postFormUrlEncoded(Hello hello); @RequestMapping(method = RequestMethod.GET, path = "/tostring2") @@ -821,7 +824,8 @@ public class FeignClientTests { public HystrixClientWithFallBackFactory create(final Throwable cause) { return () -> { assertThat(cause).isNotNull().as("Cause was null"); - return new Hello("Hello from the fallback side: " + cause.getMessage()); + return new Hello( + "Hello from the fallback side: " + cause.getMessage()); }; } @@ -884,12 +888,12 @@ public class FeignClientTests { return (target, method) -> { String groupKey = SETTER_PREFIX + target.name(); RequestMapping requestMapping = method - .getAnnotation(RequestMapping.class); + .getAnnotation(RequestMapping.class); String commandKey = SETTER_PREFIX + requestMapping.method()[0] + " " - + requestMapping.path()[0]; + + requestMapping.path()[0]; return HystrixCommand.Setter - .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) - .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)); + .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) + .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)); }; } @@ -1157,7 +1161,7 @@ public class FeignClientTests { } @PostMapping(path = "/form-urlencoded", - consumes = APPLICATION_FORM_URLENCODED_VALUE) + consumes = APPLICATION_FORM_URLENCODED_VALUE) Hello postFormUrlEncoded(Hello hello) { return hello; } diff --git a/spring-cloud-openfeign-dependencies/pom.xml b/spring-cloud-openfeign-dependencies/pom.xml index 3b3653b9..e2f459ca 100644 --- a/spring-cloud-openfeign-dependencies/pom.xml +++ b/spring-cloud-openfeign-dependencies/pom.xml @@ -6,11 +6,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.3.5.RELEASE + 2.3.5.BUILD-SNAPSHOT spring-cloud-openfeign-dependencies - 2.2.9.RELEASE + 2.2.9.BUILD-SNAPSHOT pom spring-cloud-openfeign-dependencies Spring Cloud OpenFeign Dependencies diff --git a/spring-cloud-starter-openfeign/pom.xml b/spring-cloud-starter-openfeign/pom.xml index 34b2f184..b76067c0 100644 --- a/spring-cloud-starter-openfeign/pom.xml +++ b/spring-cloud-starter-openfeign/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.RELEASE + 2.2.9.BUILD-SNAPSHOT .. spring-cloud-starter-openfeign From c4b9492a9b06d52949e91d6f1c8bfb4855558336 Mon Sep 17 00:00:00 2001 From: Olga MaciaszekSharma Date: Wed, 7 Jul 2021 18:46:53 +0200 Subject: [PATCH 09/12] Bumping versions to 2.2.10.BUILD-SNAPSHOT after release This reverts commit f7e490c4666fea1679d0cae920c801747ac3b82d. --- docs/pom.xml | 2 +- pom.xml | 8 ++++---- spring-cloud-openfeign-core/pom.xml | 2 +- spring-cloud-openfeign-dependencies/pom.xml | 4 ++-- spring-cloud-starter-openfeign/pom.xml | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 327ae75b..22905352 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.BUILD-SNAPSHOT + 2.2.10.BUILD-SNAPSHOT spring-cloud-openfeign-docs pom diff --git a/pom.xml b/pom.xml index e0ad978f..bb12c895 100644 --- a/pom.xml +++ b/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-cloud-openfeign - 2.2.9.BUILD-SNAPSHOT + 2.2.10.BUILD-SNAPSHOT pom Spring Cloud OpenFeign Spring Cloud OpenFeign org.springframework.cloud spring-cloud-build - 2.3.4.RELEASE + 2.3.6.BUILD-SNAPSHOT @@ -26,8 +26,8 @@ ${basedir} 2.11.3 - 2.2.9.BUILD-SNAPSHOT - 2.2.9.BUILD-SNAPSHOT + 2.2.10.BUILD-SNAPSHOT + 2.2.10.BUILD-SNAPSHOT 2.10 diff --git a/spring-cloud-openfeign-core/pom.xml b/spring-cloud-openfeign-core/pom.xml index c50b5720..33d0b085 100644 --- a/spring-cloud-openfeign-core/pom.xml +++ b/spring-cloud-openfeign-core/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.BUILD-SNAPSHOT + 2.2.10.BUILD-SNAPSHOT .. spring-cloud-openfeign-core diff --git a/spring-cloud-openfeign-dependencies/pom.xml b/spring-cloud-openfeign-dependencies/pom.xml index e2f459ca..6fa855e4 100644 --- a/spring-cloud-openfeign-dependencies/pom.xml +++ b/spring-cloud-openfeign-dependencies/pom.xml @@ -6,11 +6,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.3.5.BUILD-SNAPSHOT + 2.3.6.BUILD-SNAPSHOT spring-cloud-openfeign-dependencies - 2.2.9.BUILD-SNAPSHOT + 2.2.10.BUILD-SNAPSHOT pom spring-cloud-openfeign-dependencies Spring Cloud OpenFeign Dependencies diff --git a/spring-cloud-starter-openfeign/pom.xml b/spring-cloud-starter-openfeign/pom.xml index b76067c0..326594f2 100644 --- a/spring-cloud-starter-openfeign/pom.xml +++ b/spring-cloud-starter-openfeign/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.9.BUILD-SNAPSHOT + 2.2.10.BUILD-SNAPSHOT .. spring-cloud-starter-openfeign From 1275875ddb4e2ba03e4ff080c9d9c38863494321 Mon Sep 17 00:00:00 2001 From: Olga MaciaszekSharma Date: Wed, 7 Jul 2021 18:58:48 +0200 Subject: [PATCH 10/12] Reformat. --- .../openfeign/FeignClientFactoryBean.java | 3 +- ...adBalancerResponseStatusCodeException.java | 6 +- ...ryableFeignBlockingLoadBalancerClient.java | 4 +- ...eFeignBlockingLoadBalancerClientTests.java | 26 +++--- .../openfeign/valid/FeignClientTests.java | 86 +++++++++---------- 5 files changed, 63 insertions(+), 62 deletions(-) diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java index ac24747f..59c8b23f 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java @@ -375,7 +375,8 @@ public class FeignClientFactoryBean implements FactoryBean, Initializing if (!StringUtils.hasText(url)) { if (LOG.isInfoEnabled()) { - LOG.info("For '" + name + "' URL not provided. Will try picking an instance via load-balancing."); + LOG.info("For '" + name + + "' URL not provided. Will try picking an instance via load-balancing."); } if (!name.startsWith("http")) { url = "http://" + name; diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java index 0e7017f8..9bcfc1fa 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/LoadBalancerResponseStatusCodeException.java @@ -28,11 +28,13 @@ import org.springframework.cloud.client.loadbalancer.RetryableStatusCodeExceptio * * @author Ryan Baxter */ -public class LoadBalancerResponseStatusCodeException extends RetryableStatusCodeException { +public class LoadBalancerResponseStatusCodeException + extends RetryableStatusCodeException { private final Response response; - public LoadBalancerResponseStatusCodeException(String serviceId, Response response, byte[] body, URI uri) { + public LoadBalancerResponseStatusCodeException(String serviceId, Response response, + byte[] body, URI uri) { super(serviceId, response.status(), response, uri); this.response = Response.builder() .body(new ByteArrayInputStream(body), body.length) diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java index 342bb534..157eebaf 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClient.java @@ -113,10 +113,10 @@ public class RetryableFeignBlockingLoadBalancerClient implements Client { String.format("Retrying on status code: %d", responseStatus)); } byte[] byteArray = response.body() == null ? new byte[] {} - : StreamUtils.copyToByteArray(response.body().asInputStream()); + : StreamUtils.copyToByteArray(response.body().asInputStream()); response.close(); throw new LoadBalancerResponseStatusCodeException(serviceId, response, - byteArray, URI.create(request.url())); + byteArray, URI.create(request.url())); } return response; }, new LoadBalancedRecoveryCallback() { diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java index ca175318..5862d425 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/loadbalancer/RetryableFeignBlockingLoadBalancerClientTests.java @@ -119,8 +119,10 @@ class RetryableFeignBlockingLoadBalancerClientTests { private Response testResponse(int status, String body) { // ByteArrayInputStream ignores close() and must be wrapped - InputStream reallyCloseable = new BufferedInputStream(new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8))); - return Response.builder().request(testRequest()).status(status).body(reallyCloseable, null).build(); + InputStream reallyCloseable = new BufferedInputStream( + new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8))); + return Response.builder().request(testRequest()).status(status) + .body(reallyCloseable, null).build(); } @@ -163,23 +165,23 @@ class RetryableFeignBlockingLoadBalancerClientTests { void shouldExposeResponseBodyOnRetry() throws IOException { properties.getRetryableStatusCodes().add(503); Request request = testRequest(); - when(delegate.execute(any(), any())) - .thenReturn(testResponse(503, "foo"), testResponse(503, "foo")); + when(delegate.execute(any(), any())).thenReturn(testResponse(503, "foo"), + testResponse(503, "foo")); when(retryFactory.createRetryPolicy(any(), eq(loadBalancerClient))) - .thenReturn(new BlockingLoadBalancedRetryPolicy("test", - loadBalancerClient, properties)); + .thenReturn(new BlockingLoadBalancedRetryPolicy("test", + loadBalancerClient, properties)); when(loadBalancerClient.reconstructURI(serviceInstance, - URI.create("http://test/path"))) - .thenReturn(URI.create("http://testhost:80/path")); + URI.create("http://test/path"))) + .thenReturn(URI.create("http://testhost:80/path")); - Response response = feignBlockingLoadBalancerClient.execute(request, new Request.Options()); + Response response = feignBlockingLoadBalancerClient.execute(request, + new Request.Options()); - String bodyContent = IOUtils.toString(response.body().asReader(StandardCharsets.UTF_8)); + String bodyContent = IOUtils + .toString(response.body().asReader(StandardCharsets.UTF_8)); assertThat(bodyContent).isEqualTo("foo"); } - - @Test void shouldPassCorrectRequestToDelegate() throws IOException { Request request = testRequest(); diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java index c747eda0..73d89ca0 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java @@ -181,7 +181,7 @@ public class FeignClientTests { public void testClient() { assertThat(testClient).as("testClient was null").isNotNull(); assertThat(Proxy.isProxyClass(testClient.getClass())) - .as("testClient is not a java Proxy").isTrue(); + .as("testClient is not a java Proxy").isTrue(); InvocationHandler invocationHandler = Proxy.getInvocationHandler(testClient); assertThat(invocationHandler).as("invocationHandler was null").isNotNull(); } @@ -198,7 +198,7 @@ public class FeignClientTests { Hello hello = testClient.getHello(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -219,9 +219,9 @@ public class FeignClientTests { List headers = testClient.getHelloHeaders(); assertThat(headers).as("headers was null").isNotNull(); assertThat(headers.contains("myheader1value")) - .as("headers didn't contain myheader1value").isTrue(); + .as("headers didn't contain myheader1value").isTrue(); assertThat(headers.contains("myheader2value")) - .as("headers didn't contain myheader2value").isTrue(); + .as("headers didn't contain myheader2value").isTrue(); } @Test @@ -241,12 +241,11 @@ public class FeignClientTests { @Test public void testServiceId() { - assertThat(testClientServiceId).as("testClientServiceId was null") - .isNotNull(); + assertThat(testClientServiceId).as("testClientServiceId was null").isNotNull(); final Hello hello = testClientServiceId.getHello(); assertThat(hello).as("The hello response was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -260,7 +259,7 @@ public class FeignClientTests { @Test public void testFormattedParams() { List list = Arrays.asList(LocalDate.of(2001, 1, 1), - LocalDate.of(2018, 6, 10)); + LocalDate.of(2018, 6, 10)); List params = testClient.getFormattedParams(list); assertThat(params).as("params was null").isNotNull(); assertThat(params).as("params not converted correctly").isEqualTo(list); @@ -271,13 +270,13 @@ public class FeignClientTests { HystrixCommand> command = testClient.getHellosHystrix(); assertThat(command).as("command was null").isNotNull(); assertThat(command.getCommandGroup().name()).as( - "Hystrix command group name should match the name of the feign client") - .isEqualTo("localapp"); + "Hystrix command group name should match the name of the feign client") + .isEqualTo("localapp"); String configKey = Feign.configKey(TestClient.class, - TestClient.class.getMethod("getHellosHystrix", (Class[]) null)); + TestClient.class.getMethod("getHellosHystrix", (Class[]) null)); assertThat(command.getCommandKey().name()) - .as("Hystrix command key name should match the feign config key") - .isEqualTo(configKey); + .as("Hystrix command key name should match the feign config key") + .isEqualTo(configKey); List hellos = command.execute(); assertThat(hellos).as("hellos was null").isNotNull(); assertThat(getHelloList()).as("hellos didn't match").isEqualTo(hellos); @@ -290,7 +289,7 @@ public class FeignClientTests { Hello hello = single.toBlocking().value(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -298,7 +297,7 @@ public class FeignClientTests { ResponseEntity response = testClient.noContent(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.NO_CONTENT); + .isEqualTo(HttpStatus.NO_CONTENT); } @Test @@ -306,7 +305,7 @@ public class FeignClientTests { ResponseEntity response = testClient.head(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.OK); + .isEqualTo(HttpStatus.OK); } @Test @@ -316,7 +315,7 @@ public class FeignClientTests { Hello hello = entity.getBody(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello).as("first hello didn't match") - .isEqualTo(new Hello(HELLO_WORLD_1)); + .isEqualTo(new Hello(HELLO_WORLD_1)); } @Test @@ -324,7 +323,7 @@ public class FeignClientTests { String response = testClient.moreComplexContentType("{\"value\":\"OK\"}"); assertThat(response).as("response was null").isNotNull(); assertThat(response).as("didn't respond with {\"value\":\"OK\"}") - .isEqualTo("{\"value\":\"OK\"}"); + .isEqualTo("{\"value\":\"OK\"}"); } @Test @@ -332,7 +331,7 @@ public class FeignClientTests { ResponseEntity response = decodingTestClient.notFound(); assertThat(response).as("response was null").isNotNull(); assertThat(response.getStatusCode()).as("status code was wrong") - .isEqualTo(HttpStatus.NOT_FOUND); + .isEqualTo(HttpStatus.NOT_FOUND); assertThat(response.getBody()).as("response body was not null").isNull(); } @@ -371,7 +370,7 @@ public class FeignClientTests { Hello hello = single.toBlocking().value(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbacksingle"); + .isEqualTo("fallbacksingle"); } @Test @@ -381,7 +380,7 @@ public class FeignClientTests { Hello hello = command.execute(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackcommand"); + .isEqualTo("fallbackcommand"); } @Test @@ -391,7 +390,7 @@ public class FeignClientTests { Hello hello = observable.toBlocking().first(); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackobservable"); + .isEqualTo("fallbackobservable"); } @Test @@ -401,7 +400,7 @@ public class FeignClientTests { Hello hello = future.get(1, TimeUnit.SECONDS); assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("message was wrong") - .isEqualTo("fallbackfuture"); + .isEqualTo("fallbackfuture"); } @Test @@ -410,8 +409,8 @@ public class FeignClientTests { assertThat(hello).as("hello was null").isNotNull(); assertThat(hello.getMessage()).as("hello#message was null").isNotNull(); assertThat(hello.getMessage().contains("500")).as( - "hello#message did not contain the cause (status code) of the fallback invocation") - .isTrue(); + "hello#message did not contain the cause (status code) of the fallback invocation") + .isTrue(); } @Test(expected = HystrixRuntimeException.class) @@ -439,17 +438,17 @@ public class FeignClientTests { @Test public void testHystrixSetterFactory() { HystrixCommand> command = hystrixSetterFactoryClient - .getHellosHystrix(); + .getHellosHystrix(); assertThat(command).as("command was null").isNotNull(); String setterPrefix = TestHystrixSetterFactoryClientConfig.SETTER_PREFIX; assertThat(command.getCommandGroup().name()).as( - "Hystrix command group name should match the name of the feign client with a prefix of " - + setterPrefix) - .isEqualTo(setterPrefix + "localapp5"); + "Hystrix command group name should match the name of the feign client with a prefix of " + + setterPrefix) + .isEqualTo(setterPrefix + "localapp5"); assertThat(command.getCommandKey().name()).as( - "Hystrix command key name should match the request method (space) request path with a prefix of " - + setterPrefix) - .isEqualTo(setterPrefix + "GET /hellos"); + "Hystrix command key name should match the request method (space) request path with a prefix of " + + setterPrefix) + .isEqualTo(setterPrefix + "GET /hellos"); List hellos = command.execute(); assertThat(hellos).as("hellos was null").isNotNull(); assertThat(getHelloList()).as("hellos didn't match").isEqualTo(hellos); @@ -481,8 +480,7 @@ public class FeignClientTests { Hello pojo2 = new Hello(OI_TERRA_2); MockMultipartFile file = new MockMultipartFile("file", "hello.bin", null, "hello".getBytes()); - String response = multipartClient.multipartPojo("abc", "123", pojo1, pojo2, - file); + String response = multipartClient.multipartPojo("abc", "123", pojo1, pojo2, file); assertThat(response).isEqualTo("abc123hello world 1oi terra 2hello.bin"); } @@ -507,9 +505,8 @@ public class FeignClientTests { "hello".getBytes()); MockMultipartFile file2 = new MockMultipartFile("file2", "hello2.bin", null, "hello".getBytes()); - String response = multipartClient - .requestPartListOfPojosAndListOfMultipartFiles( - Arrays.asList(pojo1, pojo2), Arrays.asList(file1, file2)); + String response = multipartClient.requestPartListOfPojosAndListOfMultipartFiles( + Arrays.asList(pojo1, pojo2), Arrays.asList(file1, file2)); assertThat(response).isEqualTo("hello world 1oi terra 2hello1.binhello2.bin"); } @@ -624,7 +621,7 @@ public class FeignClientTests { String getToString(@RequestParam("arg") Arg arg); @PostMapping(path = "/form-urlencoded", - consumes = APPLICATION_FORM_URLENCODED_VALUE) + consumes = APPLICATION_FORM_URLENCODED_VALUE) Hello postFormUrlEncoded(Hello hello); @RequestMapping(method = RequestMethod.GET, path = "/tostring2") @@ -824,8 +821,7 @@ public class FeignClientTests { public HystrixClientWithFallBackFactory create(final Throwable cause) { return () -> { assertThat(cause).isNotNull().as("Cause was null"); - return new Hello( - "Hello from the fallback side: " + cause.getMessage()); + return new Hello("Hello from the fallback side: " + cause.getMessage()); }; } @@ -888,12 +884,12 @@ public class FeignClientTests { return (target, method) -> { String groupKey = SETTER_PREFIX + target.name(); RequestMapping requestMapping = method - .getAnnotation(RequestMapping.class); + .getAnnotation(RequestMapping.class); String commandKey = SETTER_PREFIX + requestMapping.method()[0] + " " - + requestMapping.path()[0]; + + requestMapping.path()[0]; return HystrixCommand.Setter - .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) - .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)); + .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) + .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)); }; } @@ -1161,7 +1157,7 @@ public class FeignClientTests { } @PostMapping(path = "/form-urlencoded", - consumes = APPLICATION_FORM_URLENCODED_VALUE) + consumes = APPLICATION_FORM_URLENCODED_VALUE) Hello postFormUrlEncoded(Hello hello) { return hello; } From d6783a6f1ec8dd08fafe76ecd072913d4e6f66b9 Mon Sep 17 00:00:00 2001 From: Olga MaciaszekSharma Date: Mon, 11 Oct 2021 15:14:46 +0200 Subject: [PATCH 11/12] Block clas-level request mapping on Feign clients. --- README.adoc | 18 +--- .../main/asciidoc/spring-cloud-openfeign.adoc | 5 +- .../openfeign/support/SpringMvcContract.java | 43 ++------- .../support/SpringMvcContractTests.java | 90 ++++++------------- 4 files changed, 40 insertions(+), 116 deletions(-) diff --git a/README.adoc b/README.adoc index 12399cd6..1faffeb8 100644 --- a/README.adoc +++ b/README.adoc @@ -66,23 +66,9 @@ the `.mvn` configuration, so if you find you have to do it to make a build succeed, please raise a ticket to get the settings added to source control. -For hints on how to build the project look in `.travis.yml` if there -is one. There should be a "script" and maybe "install" command. Also -look at the "services" section to see if any services need to be -running locally (e.g. mongo or rabbit). Ignore the git-related bits -that you might find in "before_install" since they're related to setting git -credentials and you already have those. +The projects that require middleware (i.e. Redis) for testing generally +require that a local instance of [Docker](https://www.docker.com/get-started) is installed and running. -The projects that require middleware generally include a -`docker-compose.yml`, so consider using -https://docs.docker.com/compose/[Docker Compose] to run the middeware servers -in Docker containers. See the README in the -https://github.com/spring-cloud-samples/scripts[scripts demo -repository] for specific instructions about the common cases of mongo, -rabbit and redis. - -NOTE: If all else fails, build with the command from `.travis.yml` (usually -`./mvnw install`). === Documentation diff --git a/docs/src/main/asciidoc/spring-cloud-openfeign.adoc b/docs/src/main/asciidoc/spring-cloud-openfeign.adoc index daf4c129..21a1a524 100644 --- a/docs/src/main/asciidoc/spring-cloud-openfeign.adoc +++ b/docs/src/main/asciidoc/spring-cloud-openfeign.adoc @@ -523,10 +523,7 @@ public interface UserClient extends UserService { } ---- -NOTE: It is generally not advisable to share an interface between a -server and a client. It introduces tight coupling, and also actually -doesn't work with Spring MVC in its current form (method parameter -mapping is not inherited). +WARNING: `@FeignClient` interfaces should not be shared between server and client and annotating `@FeignClient` interfaces with `@RequestMapping` on class level is no longer supported. === Feign request/response compression diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SpringMvcContract.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SpringMvcContract.java index a589eb69..11cd1b77 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SpringMvcContract.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SpringMvcContract.java @@ -35,6 +35,8 @@ import feign.Feign; import feign.MethodMetadata; import feign.Param; import feign.Request; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.cloud.openfeign.AnnotatedParameterProcessor; import org.springframework.cloud.openfeign.CollectionFormat; @@ -83,6 +85,8 @@ import static org.springframework.core.annotation.AnnotatedElementUtils.findMerg public class SpringMvcContract extends Contract.BaseContract implements ResourceLoaderAware { + private static final Log LOG = LogFactory.getLog(SpringMvcContract.class); + private static final String ACCEPT = "Accept"; private static final String CONTENT_TYPE = "Content-Type"; @@ -181,49 +185,20 @@ public class SpringMvcContract extends Contract.BaseContract @Override protected void processAnnotationOnClass(MethodMetadata data, Class clz) { - if (clz.getInterfaces().length == 0) { RequestMapping classAnnotation = findMergedAnnotation(clz, RequestMapping.class); if (classAnnotation != null) { - // Prepend path from class annotation if specified - if (classAnnotation.value().length > 0) { - String pathValue = emptyToNull(classAnnotation.value()[0]); - pathValue = resolve(pathValue); - if (!pathValue.startsWith("/")) { - pathValue = "/" + pathValue; - } - data.template().uri(pathValue); - if (data.template().decodeSlash() != decodeSlash) { - data.template().decodeSlash(decodeSlash); - } - } + LOG.error("Cannot process class: " + clz.getName() + + ". @RequestMapping annotation is not allowed on @FeignClient interfaces."); + throw new IllegalArgumentException( + "@RequestMapping annotation not allowed on @FeignClient interfaces"); } - } } @Override public MethodMetadata parseAndValidateMetadata(Class targetType, Method method) { processedMethods.put(Feign.configKey(targetType, method), method); - MethodMetadata md = super.parseAndValidateMetadata(targetType, method); - - RequestMapping classAnnotation = findMergedAnnotation(targetType, - RequestMapping.class); - if (classAnnotation != null) { - // produces - use from class annotation only if method has not specified this - if (!md.template().headers().containsKey(ACCEPT)) { - parseProduces(md, method, classAnnotation); - } - - // consumes -- use from class annotation only if method has not specified this - if (!md.template().headers().containsKey(CONTENT_TYPE)) { - parseConsumes(md, method, classAnnotation); - } - - // headers -- class annotation is inherited to methods, always write these if - // present - parseHeaders(md, method, classAnnotation); - } - return md; + return super.parseAndValidateMetadata(targetType, method); } @Override diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringMvcContractTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringMvcContractTests.java index 757bcc69..ff16f723 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringMvcContractTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringMvcContractTests.java @@ -62,6 +62,7 @@ import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY; import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; import static feign.CollectionFormat.SSV; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.junit.Assume.assumeTrue; /** @@ -182,28 +183,23 @@ public class SpringMvcContractTests { } @Test - public void testProcessAnnotations_Class_AnnotationsGetSpecificTest() - throws Exception { - Method method = TestTemplate_Class_Annotations.class - .getDeclaredMethod("getSpecificTest", String.class, String.class); - MethodMetadata data = contract - .parseAndValidateMetadata(method.getDeclaringClass(), method); - - assertThat(data.template().url()).isEqualTo("/prepend/{classId}/test/{testId}"); - assertThat(data.template().method()).isEqualTo("GET"); - - assertThat(data.indexToName().get(0).iterator().next()).isEqualTo("classId"); - assertThat(data.indexToName().get(1).iterator().next()).isEqualTo("testId"); + public void testProcessAnnotations_Class_Annotations_RequestMapping() { + assertThatIllegalArgumentException() + .isThrownBy(() -> { + Method method = TestTemplate_Class_RequestMapping.class + .getDeclaredMethod("getSpecificTest", String.class, String.class); + contract.parseAndValidateMetadata(method.getDeclaringClass(), method); + }); } @Test public void testProcessAnnotations_Class_AnnotationsGetAllTests() throws Exception { Method method = TestTemplate_Class_Annotations.class - .getDeclaredMethod("getAllTests", String.class); + .getDeclaredMethod("getAllTests", String.class); MethodMetadata data = contract - .parseAndValidateMetadata(method.getDeclaringClass(), method); + .parseAndValidateMetadata(method.getDeclaringClass(), method); - assertThat(data.template().url()).isEqualTo("/prepend/{classId}"); + assertThat(data.template().url()).isEqualTo("/"); assertThat(data.template().method()).isEqualTo("GET"); assertThat(data.indexToName().get(0).iterator().next()).isEqualTo("classId"); @@ -211,22 +207,6 @@ public class SpringMvcContractTests { assertThat(data.template().decodeSlash()).isTrue(); } - @Test - public void testProcessAnnotations_Class_AnnotationsGetAllTests_EncodeSlash() - throws Exception { - contract = new SpringMvcContract(Collections.emptyList(), getConversionService(), - false); - - Method method = TestTemplate_Class_Annotations.class - .getDeclaredMethod("getAllTests", String.class); - MethodMetadata data = contract - .parseAndValidateMetadata(method.getDeclaringClass(), method); - - assertThat(data.template().url()).isEqualTo("/prepend/{classId}"); - - assertThat(data.template().decodeSlash()).isFalse(); - } - @Test public void testProcessAnnotations_ExtendedInterface() throws Exception { Method extendedMethod = TestTemplate_Extended.class.getMethod("getAllTests", @@ -249,27 +229,6 @@ public class SpringMvcContractTests { assertThat(data.template().decodeSlash()).isTrue(); } - @Test - public void testProcessAnnotations_ExtendedInterface_EncodeSlash() throws Exception { - contract = new SpringMvcContract(Collections.emptyList(), getConversionService(), - false); - - Method extendedMethod = TestTemplate_Extended.class.getMethod("getAllTests", - String.class); - MethodMetadata extendedData = contract.parseAndValidateMetadata( - extendedMethod.getDeclaringClass(), extendedMethod); - - Method method = TestTemplate_Class_Annotations.class - .getDeclaredMethod("getAllTests", String.class); - MethodMetadata data = contract - .parseAndValidateMetadata(method.getDeclaringClass(), method); - - assertThat(data.template().url()).isEqualTo(extendedData.template().url()); - assertThat(data.template().method()).isEqualTo(extendedData.template().method()); - - assertThat(data.template().decodeSlash()).isFalse(); - } - @Test public void testProcessAnnotations_SimplePost() throws Exception { Method method = TestTemplate_Simple.class.getDeclaredMethod("postTest", @@ -306,7 +265,7 @@ public class SpringMvcContractTests { .parseAndValidateMetadata(method.getDeclaringClass(), method); assertThat(data.template().url()) - .isEqualTo("/advanced/test/{id}?amount=" + "{amount}"); + .isEqualTo("/test/{id}?amount=" + "{amount}"); assertThat(data.template().method()).isEqualTo("PUT"); assertThat(data.template().headers().get("Accept").iterator().next()) .isEqualTo(MediaType.APPLICATION_JSON_VALUE); @@ -342,7 +301,7 @@ public class SpringMvcContractTests { .parseAndValidateMetadata(method.getDeclaringClass(), method); assertThat(data.template().url()) - .isEqualTo("/advanced/test/{id}?amount=" + "{amount}"); + .isEqualTo("/test/{id}?amount=" + "{amount}"); assertThat(data.template().method()).isEqualTo("PUT"); assertThat(data.template().headers().get("Accept").iterator().next()) .isEqualTo(MediaType.APPLICATION_JSON_VALUE); @@ -367,7 +326,7 @@ public class SpringMvcContractTests { .parseAndValidateMetadata(method.getDeclaringClass(), method); assertThat(data.template().url()) - .isEqualTo("/advanced/test2?amount=" + "{amount}"); + .isEqualTo("/test2?amount=" + "{amount}"); assertThat(data.template().method()).isEqualTo("PUT"); assertThat(data.template().headers().get("Accept").iterator().next()) .isEqualTo(MediaType.APPLICATION_JSON_VALUE); @@ -427,12 +386,12 @@ public class SpringMvcContractTests { public void testProcessAnnotations_Advanced2() throws Exception { Method method = TestTemplate_Advanced.class.getDeclaredMethod("getTest"); MethodMetadata data = contract - .parseAndValidateMetadata(method.getDeclaringClass(), method); + .parseAndValidateMetadata(method.getDeclaringClass(), method); - assertThat(data.template().url()).isEqualTo("/advanced"); + assertThat(data.template().url()).isEqualTo("/"); assertThat(data.template().method()).isEqualTo("GET"); assertThat(data.template().headers().get("Accept").iterator().next()) - .isEqualTo(MediaType.APPLICATION_JSON_VALUE); + .isEqualTo(MediaType.APPLICATION_JSON_VALUE); } @Test @@ -539,7 +498,7 @@ public class SpringMvcContractTests { .parseAndValidateMetadata(method.getDeclaringClass(), method); assertThat(data.template().url()) - .isEqualTo("/advanced/testfallback/{id}?amount=" + "{amount}"); + .isEqualTo("/testfallback/{id}?amount=" + "{amount}"); assertThat(data.template().method()).isEqualTo("PUT"); assertThat(data.template().headers().get("Accept").iterator().next()) .isEqualTo(MediaType.APPLICATION_JSON_VALUE); @@ -699,7 +658,7 @@ public class SpringMvcContractTests { ResponseEntity getMappingTest(@PathVariable("id") String id); @RequestMapping(method = RequestMethod.POST, - produces = MediaType.APPLICATION_JSON_VALUE) + produces = MediaType.APPLICATION_JSON_VALUE) TestObject postTest(@RequestBody TestObject object); @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE) @@ -708,11 +667,19 @@ public class SpringMvcContractTests { } @RequestMapping("/prepend/{classId}") + public interface TestTemplate_Class_RequestMapping { + + @RequestMapping(value = "/test/{testId}", method = RequestMethod.GET) + TestObject getSpecificTest(@PathVariable("classId") String classId, + @PathVariable("testId") String testId); + + } + public interface TestTemplate_Class_Annotations { @RequestMapping(value = "/test/{testId}", method = RequestMethod.GET) TestObject getSpecificTest(@PathVariable("classId") String classId, - @PathVariable("testId") String testId); + @PathVariable("testId") String testId); @RequestMapping(method = RequestMethod.GET) TestObject getAllTests(@PathVariable("classId") String classId); @@ -812,7 +779,6 @@ public class SpringMvcContractTests { } @JsonAutoDetect - @RequestMapping("/advanced") public interface TestTemplate_Advanced { @CollectionFormat(SSV) From 17d0161faf73876ff5ec39ee80e3fa654f9dbd91 Mon Sep 17 00:00:00 2001 From: Olga MaciaszekSharma Date: Thu, 21 Oct 2021 12:40:20 +0200 Subject: [PATCH 12/12] Reformat. --- .../openfeign/support/SpringMvcContract.java | 15 ++++---- .../support/SpringMvcContractTests.java | 34 ++++++++----------- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SpringMvcContract.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SpringMvcContract.java index 11cd1b77..57f7b7d1 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SpringMvcContract.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SpringMvcContract.java @@ -185,14 +185,13 @@ public class SpringMvcContract extends Contract.BaseContract @Override protected void processAnnotationOnClass(MethodMetadata data, Class clz) { - RequestMapping classAnnotation = findMergedAnnotation(clz, - RequestMapping.class); - if (classAnnotation != null) { - LOG.error("Cannot process class: " + clz.getName() - + ". @RequestMapping annotation is not allowed on @FeignClient interfaces."); - throw new IllegalArgumentException( - "@RequestMapping annotation not allowed on @FeignClient interfaces"); - } + RequestMapping classAnnotation = findMergedAnnotation(clz, RequestMapping.class); + if (classAnnotation != null) { + LOG.error("Cannot process class: " + clz.getName() + + ". @RequestMapping annotation is not allowed on @FeignClient interfaces."); + throw new IllegalArgumentException( + "@RequestMapping annotation not allowed on @FeignClient interfaces"); + } } @Override diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringMvcContractTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringMvcContractTests.java index ff16f723..3fa52ca0 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringMvcContractTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringMvcContractTests.java @@ -184,20 +184,19 @@ public class SpringMvcContractTests { @Test public void testProcessAnnotations_Class_Annotations_RequestMapping() { - assertThatIllegalArgumentException() - .isThrownBy(() -> { - Method method = TestTemplate_Class_RequestMapping.class + assertThatIllegalArgumentException().isThrownBy(() -> { + Method method = TestTemplate_Class_RequestMapping.class .getDeclaredMethod("getSpecificTest", String.class, String.class); - contract.parseAndValidateMetadata(method.getDeclaringClass(), method); - }); + contract.parseAndValidateMetadata(method.getDeclaringClass(), method); + }); } @Test public void testProcessAnnotations_Class_AnnotationsGetAllTests() throws Exception { Method method = TestTemplate_Class_Annotations.class - .getDeclaredMethod("getAllTests", String.class); + .getDeclaredMethod("getAllTests", String.class); MethodMetadata data = contract - .parseAndValidateMetadata(method.getDeclaringClass(), method); + .parseAndValidateMetadata(method.getDeclaringClass(), method); assertThat(data.template().url()).isEqualTo("/"); assertThat(data.template().method()).isEqualTo("GET"); @@ -264,8 +263,7 @@ public class SpringMvcContractTests { MethodMetadata data = contract .parseAndValidateMetadata(method.getDeclaringClass(), method); - assertThat(data.template().url()) - .isEqualTo("/test/{id}?amount=" + "{amount}"); + assertThat(data.template().url()).isEqualTo("/test/{id}?amount=" + "{amount}"); assertThat(data.template().method()).isEqualTo("PUT"); assertThat(data.template().headers().get("Accept").iterator().next()) .isEqualTo(MediaType.APPLICATION_JSON_VALUE); @@ -300,8 +298,7 @@ public class SpringMvcContractTests { MethodMetadata data = contract .parseAndValidateMetadata(method.getDeclaringClass(), method); - assertThat(data.template().url()) - .isEqualTo("/test/{id}?amount=" + "{amount}"); + assertThat(data.template().url()).isEqualTo("/test/{id}?amount=" + "{amount}"); assertThat(data.template().method()).isEqualTo("PUT"); assertThat(data.template().headers().get("Accept").iterator().next()) .isEqualTo(MediaType.APPLICATION_JSON_VALUE); @@ -325,8 +322,7 @@ public class SpringMvcContractTests { MethodMetadata data = contract .parseAndValidateMetadata(method.getDeclaringClass(), method); - assertThat(data.template().url()) - .isEqualTo("/test2?amount=" + "{amount}"); + assertThat(data.template().url()).isEqualTo("/test2?amount=" + "{amount}"); assertThat(data.template().method()).isEqualTo("PUT"); assertThat(data.template().headers().get("Accept").iterator().next()) .isEqualTo(MediaType.APPLICATION_JSON_VALUE); @@ -386,12 +382,12 @@ public class SpringMvcContractTests { public void testProcessAnnotations_Advanced2() throws Exception { Method method = TestTemplate_Advanced.class.getDeclaredMethod("getTest"); MethodMetadata data = contract - .parseAndValidateMetadata(method.getDeclaringClass(), method); + .parseAndValidateMetadata(method.getDeclaringClass(), method); assertThat(data.template().url()).isEqualTo("/"); assertThat(data.template().method()).isEqualTo("GET"); assertThat(data.template().headers().get("Accept").iterator().next()) - .isEqualTo(MediaType.APPLICATION_JSON_VALUE); + .isEqualTo(MediaType.APPLICATION_JSON_VALUE); } @Test @@ -498,7 +494,7 @@ public class SpringMvcContractTests { .parseAndValidateMetadata(method.getDeclaringClass(), method); assertThat(data.template().url()) - .isEqualTo("/testfallback/{id}?amount=" + "{amount}"); + .isEqualTo("/testfallback/{id}?amount=" + "{amount}"); assertThat(data.template().method()).isEqualTo("PUT"); assertThat(data.template().headers().get("Accept").iterator().next()) .isEqualTo(MediaType.APPLICATION_JSON_VALUE); @@ -658,7 +654,7 @@ public class SpringMvcContractTests { ResponseEntity getMappingTest(@PathVariable("id") String id); @RequestMapping(method = RequestMethod.POST, - produces = MediaType.APPLICATION_JSON_VALUE) + produces = MediaType.APPLICATION_JSON_VALUE) TestObject postTest(@RequestBody TestObject object); @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE) @@ -671,7 +667,7 @@ public class SpringMvcContractTests { @RequestMapping(value = "/test/{testId}", method = RequestMethod.GET) TestObject getSpecificTest(@PathVariable("classId") String classId, - @PathVariable("testId") String testId); + @PathVariable("testId") String testId); } @@ -679,7 +675,7 @@ public class SpringMvcContractTests { @RequestMapping(value = "/test/{testId}", method = RequestMethod.GET) TestObject getSpecificTest(@PathVariable("classId") String classId, - @PathVariable("testId") String testId); + @PathVariable("testId") String testId); @RequestMapping(method = RequestMethod.GET) TestObject getAllTests(@PathVariable("classId") String classId);