From 5a19a0a128fc2efab39b8411c88b9102b61cc504 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Thu, 17 Feb 2022 16:53:23 +0000 Subject: [PATCH 1/5] Update SNAPSHOT to 3.1.1 --- README.adoc | 3 ++- docs/pom.xml | 2 +- pom.xml | 6 +++--- spring-cloud-openfeign-core/pom.xml | 2 +- spring-cloud-openfeign-dependencies/pom.xml | 4 ++-- spring-cloud-starter-openfeign/pom.xml | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.adoc b/README.adoc index 36916d6e..cb097fff 100644 --- a/README.adoc +++ b/README.adoc @@ -40,7 +40,8 @@ and binding to the Spring Environment and other Spring programming model idioms. == Building -:jdkversion: 1.8 + +:jdkversion: 17 === Basic Compile and Test diff --git a/docs/pom.xml b/docs/pom.xml index f91e9fdb..b5cf0503 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 3.1.1-SNAPSHOT + 3.1.1 spring-cloud-openfeign-docs jar diff --git a/pom.xml b/pom.xml index 0410dc39..52116d83 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 - 3.1.1-SNAPSHOT + 3.1.1 pom Spring Cloud OpenFeign Spring Cloud OpenFeign org.springframework.cloud spring-cloud-build - 3.1.1-SNAPSHOT + 3.1.1 @@ -26,7 +26,7 @@ ${basedir} 2.11.3 - 3.1.1-SNAPSHOT + 3.1.1 2.10 diff --git a/spring-cloud-openfeign-core/pom.xml b/spring-cloud-openfeign-core/pom.xml index 79e3d743..4f102efc 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 - 3.1.1-SNAPSHOT + 3.1.1 .. spring-cloud-openfeign-core diff --git a/spring-cloud-openfeign-dependencies/pom.xml b/spring-cloud-openfeign-dependencies/pom.xml index d2c5dc9a..ef88d8c3 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 - 3.1.0 + 3.1.1 spring-cloud-openfeign-dependencies - 3.1.1-SNAPSHOT + 3.1.1 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 5318f05b..76da4e1a 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 - 3.1.1-SNAPSHOT + 3.1.1 .. spring-cloud-starter-openfeign From 973c048be59c8f12d49360d5c3918534b4881001 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Thu, 17 Feb 2022 16:55:45 +0000 Subject: [PATCH 2/5] Going back to snapshots --- README.adoc | 3 +-- docs/pom.xml | 2 +- pom.xml | 6 +++--- spring-cloud-openfeign-core/pom.xml | 2 +- spring-cloud-openfeign-dependencies/pom.xml | 4 ++-- spring-cloud-starter-openfeign/pom.xml | 2 +- 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/README.adoc b/README.adoc index cb097fff..36916d6e 100644 --- a/README.adoc +++ b/README.adoc @@ -40,8 +40,7 @@ and binding to the Spring Environment and other Spring programming model idioms. == Building - -:jdkversion: 17 +:jdkversion: 1.8 === Basic Compile and Test diff --git a/docs/pom.xml b/docs/pom.xml index b5cf0503..f91e9fdb 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 3.1.1 + 3.1.1-SNAPSHOT spring-cloud-openfeign-docs jar diff --git a/pom.xml b/pom.xml index 52116d83..0410dc39 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 - 3.1.1 + 3.1.1-SNAPSHOT pom Spring Cloud OpenFeign Spring Cloud OpenFeign org.springframework.cloud spring-cloud-build - 3.1.1 + 3.1.1-SNAPSHOT @@ -26,7 +26,7 @@ ${basedir} 2.11.3 - 3.1.1 + 3.1.1-SNAPSHOT 2.10 diff --git a/spring-cloud-openfeign-core/pom.xml b/spring-cloud-openfeign-core/pom.xml index 4f102efc..79e3d743 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 - 3.1.1 + 3.1.1-SNAPSHOT .. spring-cloud-openfeign-core diff --git a/spring-cloud-openfeign-dependencies/pom.xml b/spring-cloud-openfeign-dependencies/pom.xml index ef88d8c3..d2c5dc9a 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 - 3.1.1 + 3.1.0 spring-cloud-openfeign-dependencies - 3.1.1 + 3.1.1-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 76da4e1a..5318f05b 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 - 3.1.1 + 3.1.1-SNAPSHOT .. spring-cloud-starter-openfeign From aa4b8a280d6817ed02f4819152ca48a5daca0a69 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Thu, 17 Feb 2022 16:55:45 +0000 Subject: [PATCH 3/5] Bumping versions to 3.1.2-SNAPSHOT after release --- docs/pom.xml | 2 +- pom.xml | 6 +++--- spring-cloud-openfeign-core/pom.xml | 2 +- spring-cloud-openfeign-dependencies/pom.xml | 4 ++-- spring-cloud-starter-openfeign/pom.xml | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index f91e9fdb..3da8838a 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT spring-cloud-openfeign-docs jar diff --git a/pom.xml b/pom.xml index 0410dc39..a32f4a75 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 - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT pom Spring Cloud OpenFeign Spring Cloud OpenFeign org.springframework.cloud spring-cloud-build - 3.1.1-SNAPSHOT + 3.1.1 @@ -26,7 +26,7 @@ ${basedir} 2.11.3 - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT 2.10 diff --git a/spring-cloud-openfeign-core/pom.xml b/spring-cloud-openfeign-core/pom.xml index 79e3d743..10865ee1 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 - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT .. spring-cloud-openfeign-core diff --git a/spring-cloud-openfeign-dependencies/pom.xml b/spring-cloud-openfeign-dependencies/pom.xml index d2c5dc9a..bf008436 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 - 3.1.0 + 3.1.2-SNAPSHOT spring-cloud-openfeign-dependencies - 3.1.1-SNAPSHOT + 3.1.2-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 5318f05b..65d55e91 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 - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT .. spring-cloud-starter-openfeign From f662c0547d955683e588c4235ca3b826db01c539 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Thu, 24 Feb 2022 10:53:13 +0000 Subject: [PATCH 4/5] Bumping versions --- README.adoc | 3 ++- pom.xml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.adoc b/README.adoc index 36916d6e..cb097fff 100644 --- a/README.adoc +++ b/README.adoc @@ -40,7 +40,8 @@ and binding to the Spring Environment and other Spring programming model idioms. == Building -:jdkversion: 1.8 + +:jdkversion: 17 === Basic Compile and Test diff --git a/pom.xml b/pom.xml index a32f4a75..bb395696 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-build - 3.1.1 + 3.1.2-SNAPSHOT From 75fc0f6b2eb354645d6ba6b9e54d9778c89b55b2 Mon Sep 17 00:00:00 2001 From: Olga Maciaszek-Sharma Date: Thu, 24 Feb 2022 12:35:02 +0100 Subject: [PATCH 5/5] Unwrap cb exception (#683) --- .../FeignCircuitBreakerInvocationHandler.java | 20 ++++++- .../circuitbreaker/CircuitBreakerTests.java | 54 ++++++++++++++++++- 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignCircuitBreakerInvocationHandler.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignCircuitBreakerInvocationHandler.java index da76d175..a85cf471 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignCircuitBreakerInvocationHandler.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignCircuitBreakerInvocationHandler.java @@ -17,6 +17,7 @@ package org.springframework.cloud.openfeign; import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.LinkedHashMap; @@ -29,6 +30,7 @@ import feign.Target; import org.springframework.cloud.client.circuitbreaker.CircuitBreaker; import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; +import org.springframework.cloud.client.circuitbreaker.NoFallbackAvailableException; import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestContextHolder; @@ -95,15 +97,29 @@ class FeignCircuitBreakerInvocationHandler implements InvocationHandler { try { return this.fallbackMethodMap.get(method).invoke(fallback, args); } - catch (Exception e) { - throw new IllegalStateException(e); + catch (Exception exception) { + unwrapAndRethrow(exception); } + return null; }; return circuitBreaker.run(supplier, fallbackFunction); } return circuitBreaker.run(supplier); } + private void unwrapAndRethrow(Exception exception) { + if (exception instanceof InvocationTargetException || exception instanceof NoFallbackAvailableException) { + Throwable underlyingException = exception.getCause(); + if (underlyingException instanceof RuntimeException) { + throw (RuntimeException) underlyingException; + } + if (underlyingException != null) { + throw new IllegalStateException(underlyingException); + } + throw new IllegalStateException(exception); + } + } + private Supplier asSupplier(final Method method, final Object[] args) { final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); return () -> { diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/circuitbreaker/CircuitBreakerTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/circuitbreaker/CircuitBreakerTests.java index 1cc4e830..8ca49724 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/circuitbreaker/CircuitBreakerTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/circuitbreaker/CircuitBreakerTests.java @@ -16,6 +16,7 @@ package org.springframework.cloud.openfeign.circuitbreaker; +import java.io.IOException; import java.util.function.Function; import org.apache.commons.logging.Log; @@ -47,6 +48,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Spencer Gibb @@ -62,6 +64,9 @@ class CircuitBreakerTests { @Autowired TestClient testClient; + @Autowired + ExceptionClient exceptionClient; + @Autowired TestClientWithFactory testClientWithFactory; @@ -108,6 +113,17 @@ class CircuitBreakerTests { assertThat(testClientWithFactory.getException()).isEqualTo("Fixed response"); } + @Test + void testRuntimeExceptionUnwrapped() { + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> exceptionClient.getRuntimeException()); + } + + @Test + void testCheckedExceptionWrapped() { + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> exceptionClient.getCheckedException()); + } + @FeignClient(name = "test", url = "http://localhost:${server.port}/", fallback = Fallback.class) protected interface TestClient { @@ -119,6 +135,18 @@ class CircuitBreakerTests { } + @FeignClient(name = "exceptionClient", url = "http://localhost:${server.port}/", + fallbackFactory = ExceptionThrowingFallbackFactory.class) + protected interface ExceptionClient { + + @GetMapping("/runtimeException") + Hello getRuntimeException(); + + @GetMapping("/runtimeException") + Hello getCheckedException() throws IOException; + + } + @Component static class Fallback implements TestClient { @@ -156,6 +184,25 @@ class CircuitBreakerTests { } + static class ExceptionThrowingFallbackFactory implements FallbackFactory { + + @Override + public ExceptionClient create(Throwable cause) { + return new ExceptionClient() { + @Override + public Hello getRuntimeException() { + throw new UnsupportedOperationException("Not implemented!"); + } + + @Override + public Hello getCheckedException() throws IOException { + throw new IOException(); + } + }; + } + + } + static class FallbackWithFactory implements TestClientWithFactory { @Override @@ -173,7 +220,7 @@ class CircuitBreakerTests { @Configuration(proxyBeanMethods = false) @EnableAutoConfiguration @RestController - @EnableFeignClients(clients = { TestClient.class, TestClientWithFactory.class }) + @EnableFeignClients(clients = { TestClient.class, TestClientWithFactory.class, ExceptionClient.class }) @Import(NoSecurityConfiguration.class) protected static class Application implements TestClient { @@ -225,6 +272,11 @@ class CircuitBreakerTests { return new TestFallbackFactory(); } + @Bean + ExceptionThrowingFallbackFactory exceptionThrowingFallbackFactory() { + return new ExceptionThrowingFallbackFactory(); + } + } }