From cd9e26ab3577abda20b7567eddbc221597d66dba Mon Sep 17 00:00:00 2001 From: Haotian Zhang <928016560@qq.com> Date: Tue, 27 May 2025 22:11:36 +0800 Subject: [PATCH] feat:support spring cloud 2024. --- .github/workflows/junit.yml | 2 + .github/workflows/license-checker.yml | 2 + .github/workflows/snapshot.yml | 1 + CHANGELOG.md | 60 +------------------ README-zh.md | 5 +- README.md | 5 +- changes/changes-1.13.0.md | 4 -- changes/changes-1.13.1.md | 4 -- pom.xml | 14 ++--- .../common/PolarisResultToErrorCode.java | 6 +- .../PolarisCircuitBreakerHttpResponse.java | 11 ++-- ...PolarisCircuitBreakerHttpResponseTest.java | 8 +-- .../filter/QuotaCheckReactiveFilterTest.java | 6 +- ...outerLabelRestTemplateInterceptorTest.java | 7 +++ spring-cloud-tencent-dependencies/pom.xml | 10 ++-- .../consumer/proxy/ProviderDemoService.java | 2 +- .../filter/EnhancedReactiveFilter.java | 15 ++++- .../EnhancedRestTemplateWrapInterceptor.java | 2 +- ...hancedRestTemplateWrapInterceptorTest.java | 11 +--- 19 files changed, 63 insertions(+), 112 deletions(-) delete mode 100644 changes/changes-1.13.0.md delete mode 100644 changes/changes-1.13.1.md diff --git a/.github/workflows/junit.yml b/.github/workflows/junit.yml index 34bb4153f..59c2a323a 100644 --- a/.github/workflows/junit.yml +++ b/.github/workflows/junit.yml @@ -10,6 +10,7 @@ on: - 2020 - hoxton - greenwich + - release/* pull_request: branches: - 2024 @@ -19,6 +20,7 @@ on: - 2020 - hoxton - greenwich + - release/* jobs: set-jdks: diff --git a/.github/workflows/license-checker.yml b/.github/workflows/license-checker.yml index 524788527..9ecb84425 100644 --- a/.github/workflows/license-checker.yml +++ b/.github/workflows/license-checker.yml @@ -10,6 +10,7 @@ on: - 2020 - hoxton - greenwich + - release/* pull_request: branches: - 2024 @@ -19,6 +20,7 @@ on: - 2020 - hoxton - greenwich + - release/* jobs: check-license: runs-on: ubuntu-latest diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index 70b426b15..ec0a94033 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -10,6 +10,7 @@ on: - 2020 - hoxton - greenwich + - release/* jobs: check-snapshot: diff --git a/CHANGELOG.md b/CHANGELOG.md index 19869d37d..fe6f0ec95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,62 +1,4 @@ # Change Log --- -- [fix: fix RouterLabelRestTemplateInterceptor add response headers exception with httpclient5.](https://github.com/Tencent/spring-cloud-tencent/pull/1239) -- [feat: support lossless online and offline](https://github.com/Tencent/spring-cloud-tencent/pull/1254) -- [feat: support lane router](https://github.com/Tencent/spring-cloud-tencent/pull/1256) -- [feat: add lane router examples](https://github.com/Tencent/spring-cloud-tencent/pull/1260) -- [feat:upgrade jackson version.](https://github.com/Tencent/spring-cloud-tencent/pull/1262) -- [fix: fix the lossless provider override in multiple registries scenario](https://github.com/Tencent/spring-cloud-tencent/pull/1263) -- [refactor:let the configuration SDK context stand alone.](https://github.com/Tencent/spring-cloud-tencent/pull/1266) -- [fix:fix nearby router properties loading bug.](https://github.com/Tencent/spring-cloud-tencent/pull/1272) -- [fix: fix grammar issues for lane router example & optimize the gateway dependency](https://github.com/Tencent/spring-cloud-tencent/pull/1274) -- [fix: fix lossless deregister failed when no healthcheck configured](https://github.com/Tencent/spring-cloud-tencent/pull/1279) -- [fix:fix ApplicationContextAwareUtils NPE bug.](https://github.com/Tencent/spring-cloud-tencent/pull/1297) -- [feat:upgrade jacoco version.](https://github.com/Tencent/spring-cloud-tencent/pull/1310) -- [fix:fix no registry when lossless is disabled.](https://github.com/Tencent/spring-cloud-tencent/pull/1312) -- [fix:fix the ratelimit bug for 2023](https://github.com/Tencent/spring-cloud-tencent/pull/1316) -- [fix:update spring boot version](https://github.com/Tencent/spring-cloud-tencent/pull/1333) -- [feat:add scg-mvc example](https://github.com/Tencent/spring-cloud-tencent/pull/1367) -- [feat:add zero protection.](https://github.com/Tencent/spring-cloud-tencent/pull/1408) -- [feat:add Tencent Cloud TSF support.](https://github.com/Tencent/spring-cloud-tencent/pull/1409) -- [feat:support consul config.](https://github.com/Tencent/spring-cloud-tencent/pull/1410) -- [feat:add trace report support.](https://github.com/Tencent/spring-cloud-tencent/pull/1411) -- [fix: fix lossless test case unstable issues.](https://github.com/Tencent/spring-cloud-tencent/pull/1412) -- [feat:support consul service update task.](https://github.com/Tencent/spring-cloud-tencent/pull/1413) -- [fix:fix app starting failed when user using custom OpenAPI bean.](https://github.com/Tencent/spring-cloud-tencent/pull/1414) -- [fix: move ConditionalOnTsfEnabled to spring-cloud-tencent-commons and fix PolarisInetUtilsAutoConfiguration.](https://github.com/Tencent/spring-cloud-tencent/pull/1415) -- [fix: memory cost too many when using wildcard feign calls](https://github.com/Tencent/spring-cloud-tencent/pull/1416) -- [feat:support consul config data. ](https://github.com/Tencent/spring-cloud-tencent/pull/1417) -- [feat: support otel trace](https://github.com/Tencent/spring-cloud-tencent/pull/1419) -- [feat:support TSF router.](https://github.com/Tencent/spring-cloud-tencent/pull/1420) -- [feat:upgrade nearby router and add namespace nearby router.](https://github.com/Tencent/spring-cloud-tencent/pull/1421) -- [fix:fix contract reporting bug when using TSF.](https://github.com/Tencent/spring-cloud-tencent/pull/1422) -- [fix: fix TSF context bootstrap configuration](https://github.com/Tencent/spring-cloud-tencent/pull/1424) -- [fix: fix PolarisCircuitBreakerConfiguration not clear when gateway invoke by wildcard apis](https://github.com/Tencent/spring-cloud-tencent/pull/1426) -- [fix:fix actuator name warning from #1428 .](https://github.com/Tencent/spring-cloud-tencent/pull/1431) -- [feat:upgrade api circuit breaker.](https://github.com/Tencent/spring-cloud-tencent/pull/1442) -- [feat: support lossless config from console & support warmup.](https://github.com/Tencent/spring-cloud-tencent/pull/1445) -- [feat:add admin http handler.](https://github.com/Tencent/spring-cloud-tencent/pull/1450) -- [feat:upgrade spring cloud 2023 version.](https://github.com/Tencent/spring-cloud-tencent/pull/1451) -- [feat:support concurrency rate limit.](https://github.com/Tencent/spring-cloud-tencent/pull/1455) -- [feat:support auth.](https://github.com/Tencent/spring-cloud-tencent/pull/1479) -- [feat:upgrade trace plugin.](https://github.com/Tencent/spring-cloud-tencent/pull/1480) -- [feat:support smooth upgrade from tsf.](https://github.com/Tencent/spring-cloud-tencent/pull/1482) -- [fix:fix caller disposable metadata handle when using tracing.](https://github.com/Tencent/spring-cloud-tencent/pull/1483) -- [refactor:update registry status.](https://github.com/Tencent/spring-cloud-tencent/pull/1484) -- [feat:support polaris route for gateway mvc.](https://github.com/Tencent/spring-cloud-tencent/pull/1493) -- [feat: implement circuit breaker in enhance plugin, support listen config group, support refresh single config in refresh_context mode.](https://github.com/Tencent/spring-cloud-tencent/pull/1501) -- [feat:support polaris event.](https://github.com/Tencent/spring-cloud-tencent/pull/1502) -- [feat:support circuit breaker metrics reporting.](https://github.com/Tencent/spring-cloud-tencent/pull/1503) -- [feat: support gateway context, feign eager-load support default value.](https://github.com/Tencent/spring-cloud-tencent/pull/1504) -- [feat:use polaris-all for shading third-party dependencies.](https://github.com/Tencent/spring-cloud-tencent/pull/1505) -- [feat:support default instance circuit breaker rule.](https://github.com/Tencent/spring-cloud-tencent/pull/1506) -- [docs:update JDK version configuration in GitHub Actions.](https://github.com/Tencent/spring-cloud-tencent/pull/1507) -- [fix: fix count circuit breaker in gateway & return 404 when context api does not match.](https://github.com/Tencent/spring-cloud-tencent/pull/1509) -- [fix:fix watch tsf config, fix bean refresh with RefreshScope and ConfigurationProperties.](https://github.com/Tencent/spring-cloud-tencent/pull/1512) -- [docs:simplify GitHub Actions.](https://github.com/Tencent/spring-cloud-tencent/pull/1513) -- [feat: support config event.](https://github.com/Tencent/spring-cloud-tencent/pull/1535) -- [feat:support stat and event report with service discovery.](https://github.com/Tencent/spring-cloud-tencent/pull/1537) -- [fix: update EnhancedRequestContext toString method.](https://github.com/Tencent/spring-cloud-tencent/pull/1546) -- [docs: update GitHub Actions.](https://github.com/Tencent/spring-cloud-tencent/pull/1556) -- [fix: fix javaagent ratelimit pb method not found error](https://github.com/Tencent/spring-cloud-tencent/pull/1569) \ No newline at end of file +- feat:support spring cloud 2024. \ No newline at end of file diff --git a/README-zh.md b/README-zh.md index e3868d465..429830b0a 100644 --- a/README-zh.md +++ b/README-zh.md @@ -6,7 +6,7 @@ [![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause) [![Test with Junit](https://github.com/Tencent/spring-cloud-tencent/actions/workflows/junit_test17.yml/badge.svg?branch=2023)](https://github.com/Tencent/spring-cloud-tencent/actions/workflows/junit_test17.yml) -[![codecov.io](https://codecov.io/gh/Tencent/spring-cloud-tencent/branch/2023/graph/badge.svg)](https://codecov.io/gh/Tencent/spring-cloud-tencent?branch=2023) +[![codecov.io](https://codecov.io/gh/Tencent/spring-cloud-tencent/branch/2023/graph/badge.svg)](https://codecov.io/gh/Tencent/spring-cloud-tencent?branch=2024) [English](./README.md) | 简体中文 @@ -60,9 +60,6 @@ Spring Cloud 集成北极星可以解决以下问题: Spring Cloud Tencent 所有组件都已上传到 Maven 中央仓库,只需要引入依赖即可。 > 注意: -> -> 支持Spring Cloud 版本:2023、2022、2021、2020、Hoxton。 -> > Spring Cloud Tencent > 的版本列表可以查看 > [Spring Cloud Tencent 版本管理](https://github.com/Tencent/spring-cloud-tencent/wiki/Spring-Cloud-Tencent-%E7%89%88%E6%9C%AC%E7%AE%A1%E7%90%86) diff --git a/README.md b/README.md index 9b89a0617..31871b7e0 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause) [![Junit Test](https://github.com/Tencent/spring-cloud-tencent/actions/workflows/junit.yml/badge.svg?branch=2023)](https://github.com/Tencent/spring-cloud-tencent/actions/workflows/junit.yml) -[![codecov.io](https://codecov.io/gh/Tencent/spring-cloud-tencent/branch/2023/graph/badge.svg)](https://codecov.io/gh/Tencent/spring-cloud-tencent?branch=2023) +[![codecov.io](https://codecov.io/gh/Tencent/spring-cloud-tencent/branch/2023/graph/badge.svg)](https://codecov.io/gh/Tencent/spring-cloud-tencent?branch=2024) English | [简体中文](./README-zh.md) @@ -62,9 +62,6 @@ All the components of Spring Cloud Tencent have been uploaded to the Maven centr dependencies. > Notice: -> -> Support Spring Cloud 2023, 2022, 2021, 2020, Hoxton. -> > The version list of Spring Cloud Tencent can be found > in > [Spring Cloud Tencent Version Management](https://github.com/Tencent/spring-cloud-tencent/wiki/Spring-Cloud-Tencent-%E7%89%88%E6%9C%AC%E7%AE%A1%E7%90%86) diff --git a/changes/changes-1.13.0.md b/changes/changes-1.13.0.md deleted file mode 100644 index 483437371..000000000 --- a/changes/changes-1.13.0.md +++ /dev/null @@ -1,4 +0,0 @@ -# Change Log ---- - -- fix:fix NullPointerException when properties contain kv with null value. diff --git a/changes/changes-1.13.1.md b/changes/changes-1.13.1.md deleted file mode 100644 index f309a4354..000000000 --- a/changes/changes-1.13.1.md +++ /dev/null @@ -1,4 +0,0 @@ -# Change Log ---- - -[fix: fix RouterLabelRestTemplateInterceptor add response headers exception with httpclient5.](https://github.com/Tencent/spring-cloud-tencent/pull/1239) diff --git a/pom.xml b/pom.xml index 41bb7f1af..8dc5fb339 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-build - 4.1.3 + 4.2.1 4.0.0 @@ -16,7 +16,7 @@ ${revision} Spring Cloud Tencent Spring Cloud Tencent - https://github.com/Tencent/spring-cloud-tencent/tree/2023 + https://github.com/Tencent/spring-cloud-tencent/tree/2024 Tencent @@ -26,7 +26,7 @@ The BSD 3-Clause License (BSD3) - https://raw.githubusercontent.com/Tencent/spring-cloud-tencent/2023/LICENSE + https://raw.githubusercontent.com/Tencent/spring-cloud-tencent/2024/LICENSE repo @@ -90,16 +90,16 @@ - 2.0.1.0-2023.0.3-SNAPSHOT + 2.0.2.0-2024.0.1-SNAPSHOT - 6.1.14 + 6.2.7 - 3.3.5 + 3.4.5 - 2023.0.3 + 2024.0.1 0.8.12 diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/common/PolarisResultToErrorCode.java b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/common/PolarisResultToErrorCode.java index 946f9a6ae..9e208b139 100644 --- a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/common/PolarisResultToErrorCode.java +++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/common/PolarisResultToErrorCode.java @@ -40,7 +40,7 @@ public class PolarisResultToErrorCode implements ResultToErrorCode { public int onError(Throwable e) { if (checkClassExist("org.springframework.web.client.RestClientResponseException") && e instanceof RestClientResponseException) { - return ((RestClientResponseException) e).getRawStatusCode(); + return ((RestClientResponseException) e).getStatusCode().value(); } else if (checkClassExist("feign.FeignException") && e instanceof FeignException) { @@ -48,10 +48,10 @@ public class PolarisResultToErrorCode implements ResultToErrorCode { } else if (checkClassExist("org.springframework.web.reactive.function.client.WebClientResponseException") && e instanceof WebClientResponseException) { - return ((WebClientResponseException) e).getRawStatusCode(); + return ((WebClientResponseException) e).getStatusCode().value(); } else if (e instanceof CircuitBreakerStatusCodeException) { - return ((CircuitBreakerStatusCodeException) e).getRawStatusCode(); + return ((CircuitBreakerStatusCodeException) e).getStatusCode().value(); } return -1; } diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/instrument/resttemplate/PolarisCircuitBreakerHttpResponse.java b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/instrument/resttemplate/PolarisCircuitBreakerHttpResponse.java index 9b8bb2283..ad22e6882 100644 --- a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/instrument/resttemplate/PolarisCircuitBreakerHttpResponse.java +++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/instrument/resttemplate/PolarisCircuitBreakerHttpResponse.java @@ -26,14 +26,15 @@ import com.tencent.polaris.api.pojo.CircuitBreakerStatus; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; -import org.springframework.http.client.AbstractClientHttpResponse; +import org.springframework.http.HttpStatusCode; +import org.springframework.http.client.ClientHttpResponse; /** * PolarisCircuitBreakerHttpResponse. * * @author sean yu */ -public class PolarisCircuitBreakerHttpResponse extends AbstractClientHttpResponse { +public class PolarisCircuitBreakerHttpResponse implements ClientHttpResponse { private final CircuitBreakerStatus.FallbackInfo fallbackInfo; @@ -64,13 +65,13 @@ public class PolarisCircuitBreakerHttpResponse extends AbstractClientHttpRespons } @Override - public final int getRawStatusCode() { - return fallbackInfo.getCode(); + public HttpStatusCode getStatusCode() { + return HttpStatus.valueOf(fallbackInfo.getCode()); } @Override public final String getStatusText() { - HttpStatus status = HttpStatus.resolve(getRawStatusCode()); + HttpStatus status = HttpStatus.resolve(getStatusCode().value()); return (status != null ? status.getReasonPhrase() : ""); } diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/instrument/resttemplate/PolarisCircuitBreakerHttpResponseTest.java b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/instrument/resttemplate/PolarisCircuitBreakerHttpResponseTest.java index f0d00219a..a09a3ae25 100644 --- a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/instrument/resttemplate/PolarisCircuitBreakerHttpResponseTest.java +++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/instrument/resttemplate/PolarisCircuitBreakerHttpResponseTest.java @@ -38,7 +38,7 @@ public class PolarisCircuitBreakerHttpResponseTest { void testConstructorWithCodeOnly() { PolarisCircuitBreakerHttpResponse response = new PolarisCircuitBreakerHttpResponse(200); - Assertions.assertEquals(200, response.getRawStatusCode()); + Assertions.assertEquals(200, response.getStatusCode().value()); Assertions.assertNotNull(response.getHeaders()); Assertions.assertTrue(response.getHeaders().isEmpty()); Assertions.assertNull(response.getBody()); @@ -49,7 +49,7 @@ public class PolarisCircuitBreakerHttpResponseTest { String body = "test body"; PolarisCircuitBreakerHttpResponse response = new PolarisCircuitBreakerHttpResponse(200, body); - Assertions.assertEquals(200, response.getRawStatusCode()); + Assertions.assertEquals(200, response.getStatusCode().value()); Assertions.assertNotNull(response.getHeaders()); Assertions.assertTrue(response.getHeaders().isEmpty()); Assertions.assertNotNull(response.getBody()); @@ -64,7 +64,7 @@ public class PolarisCircuitBreakerHttpResponseTest { PolarisCircuitBreakerHttpResponse response = new PolarisCircuitBreakerHttpResponse(200, headers, body); - Assertions.assertEquals(200, response.getRawStatusCode()); + Assertions.assertEquals(200, response.getStatusCode().value()); Assertions.assertNotNull(response.getHeaders()); Assertions.assertEquals(2, response.getHeaders().size()); Assertions.assertTrue(response.getHeaders().containsKey("Content-Type")); @@ -80,7 +80,7 @@ public class PolarisCircuitBreakerHttpResponseTest { PolarisCircuitBreakerHttpResponse response = new PolarisCircuitBreakerHttpResponse(fallbackInfo); - Assertions.assertEquals(200, response.getRawStatusCode()); + Assertions.assertEquals(200, response.getStatusCode().value()); Assertions.assertEquals(fallbackInfo, response.getFallbackInfo()); Assertions.assertNotNull(response.getHeaders()); Assertions.assertTrue(response.getHeaders().containsKey("Content-Type")); diff --git a/spring-cloud-starter-tencent-polaris-ratelimit/src/test/java/com/tencent/cloud/polaris/ratelimit/filter/QuotaCheckReactiveFilterTest.java b/spring-cloud-starter-tencent-polaris-ratelimit/src/test/java/com/tencent/cloud/polaris/ratelimit/filter/QuotaCheckReactiveFilterTest.java index 20d9b391f..dfdc9ea5e 100644 --- a/spring-cloud-starter-tencent-polaris-ratelimit/src/test/java/com/tencent/cloud/polaris/ratelimit/filter/QuotaCheckReactiveFilterTest.java +++ b/spring-cloud-starter-tencent-polaris-ratelimit/src/test/java/com/tencent/cloud/polaris/ratelimit/filter/QuotaCheckReactiveFilterTest.java @@ -182,7 +182,8 @@ public class QuotaCheckReactiveFilterTest { ServerWebExchange testApp3Exchange = MockServerWebExchange.from(request); quotaCheckReactiveFilter.filter(testApp3Exchange, webFilterChain); ServerHttpResponse response = testApp3Exchange.getResponse(); - assertThat(response.getRawStatusCode()).isEqualTo(419); + assertThat(response.getStatusCode()).isNotNull(); + assertThat(response.getStatusCode().value()).isEqualTo(419); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INSUFFICIENT_SPACE_ON_RESOURCE); assertThat(response.getHeaders() .get(HeaderConstant.INTERNAL_ACTIVE_RULE_NAME)).isEqualTo(Collections.singletonList("MOCK_RULE")); @@ -227,7 +228,8 @@ public class QuotaCheckReactiveFilterTest { MetadataContext.LOCAL_SERVICE = "TestApp3"; quotaCheckWithRateLimiterLimitedFallbackReactiveFilter.filter(exchange, webFilterChain); ServerHttpResponse response = exchange.getResponse(); - assertThat(response.getRawStatusCode()).isEqualTo(polarisRateLimiterLimitedFallback.rejectHttpCode()); + assertThat(response.getStatusCode()).isNotNull(); + assertThat(response.getStatusCode().value()).isEqualTo(polarisRateLimiterLimitedFallback.rejectHttpCode()); assertThat(response.getHeaders().getContentType()).isEqualTo(polarisRateLimiterLimitedFallback.mediaType()); // Exception diff --git a/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/instrument/resttemplate/RouterLabelRestTemplateInterceptorTest.java b/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/instrument/resttemplate/RouterLabelRestTemplateInterceptorTest.java index c06e74a83..4639140d1 100644 --- a/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/instrument/resttemplate/RouterLabelRestTemplateInterceptorTest.java +++ b/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/instrument/resttemplate/RouterLabelRestTemplateInterceptorTest.java @@ -18,6 +18,8 @@ package com.tencent.cloud.polaris.router.instrument.resttemplate; import java.net.URI; +import java.util.HashMap; +import java.util.Map; import com.tencent.cloud.common.constant.OrderConstant; import com.tencent.cloud.common.metadata.MetadataContextHolder; @@ -110,6 +112,11 @@ public class RouterLabelRestTemplateInterceptorTest { return uri; } + @Override + public Map getAttributes() { + return new HashMap<>(); + } + @Override public HttpHeaders getHeaders() { return httpHeaders; diff --git a/spring-cloud-tencent-dependencies/pom.xml b/spring-cloud-tencent-dependencies/pom.xml index 123b354be..106937e37 100644 --- a/spring-cloud-tencent-dependencies/pom.xml +++ b/spring-cloud-tencent-dependencies/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-dependencies-parent - 4.1.3 + 4.2.1 4.0.0 @@ -16,7 +16,7 @@ pom Spring Cloud Tencent Dependencies Spring Cloud Tencent Dependencies - https://github.com/Tencent/spring-cloud-tencent/tree/2023 + https://github.com/Tencent/spring-cloud-tencent/tree/2024 Tencent @@ -26,7 +26,7 @@ The BSD 3-Clause License (BSD3) - https://raw.githubusercontent.com/Tencent/spring-cloud-tencent/2023/LICENSE + https://raw.githubusercontent.com/Tencent/spring-cloud-tencent/2024/LICENSE repo @@ -71,10 +71,10 @@ - 2.0.1.0-2023.0.3-SNAPSHOT + 2.0.2.0-2024.0.1-SNAPSHOT - 2.0.1.0-SNAPSHOT + 2.0.1.0 2.2.0 diff --git a/spring-cloud-tencent-examples/tsf-example/consumer-demo/src/main/java/com/tencent/cloud/tsf/demo/consumer/proxy/ProviderDemoService.java b/spring-cloud-tencent-examples/tsf-example/consumer-demo/src/main/java/com/tencent/cloud/tsf/demo/consumer/proxy/ProviderDemoService.java index a9c5b5907..adce6af05 100644 --- a/spring-cloud-tencent-examples/tsf-example/consumer-demo/src/main/java/com/tencent/cloud/tsf/demo/consumer/proxy/ProviderDemoService.java +++ b/spring-cloud-tencent-examples/tsf-example/consumer-demo/src/main/java/com/tencent/cloud/tsf/demo/consumer/proxy/ProviderDemoService.java @@ -23,7 +23,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; -@FeignClient(name = "provider-demo") +@FeignClient(name = "${provider.name:provider-demo}") public interface ProviderDemoService { @RequestMapping(value = "/echo/{str}", method = RequestMethod.GET) String echo(@PathVariable("str") String str); diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/instrument/filter/EnhancedReactiveFilter.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/instrument/filter/EnhancedReactiveFilter.java index a830ea79e..36861b160 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/instrument/filter/EnhancedReactiveFilter.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/instrument/filter/EnhancedReactiveFilter.java @@ -23,9 +23,12 @@ import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginRunner; import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginType; import com.tencent.cloud.rpc.enhancement.plugin.EnhancedRequestContext; import com.tencent.cloud.rpc.enhancement.plugin.EnhancedResponseContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import reactor.core.publisher.Mono; import org.springframework.core.Ordered; +import org.springframework.http.HttpStatusCode; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.WebFilter; import org.springframework.web.server.WebFilterChain; @@ -37,6 +40,8 @@ import org.springframework.web.server.WebFilterChain; */ public class EnhancedReactiveFilter implements WebFilter, Ordered { + private static final Logger LOGGER = LoggerFactory.getLogger(EnhancedReactiveFilter.class); + private final EnhancedPluginRunner pluginRunner; public EnhancedReactiveFilter(EnhancedPluginRunner pluginRunner) { @@ -64,8 +69,16 @@ public class EnhancedReactiveFilter implements WebFilter, Ordered { .doOnSuccess(v -> { enhancedPluginContext.setDelay(System.currentTimeMillis() - startMillis); + HttpStatusCode httpStatusCode = exchange.getResponse().getStatusCode(); + int httpStatus = 200; + if (httpStatusCode != null) { + httpStatus = httpStatusCode.value(); + } + else { + LOGGER.warn("httpStatusCode is null with response {}", exchange.getResponse()); + } EnhancedResponseContext enhancedResponseContext = EnhancedResponseContext.builder() - .httpStatus(exchange.getResponse().getRawStatusCode()) + .httpStatus(httpStatus) .httpHeaders(exchange.getResponse().getHeaders()) .build(); enhancedPluginContext.setResponse(enhancedResponseContext); diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/instrument/resttemplate/EnhancedRestTemplateWrapInterceptor.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/instrument/resttemplate/EnhancedRestTemplateWrapInterceptor.java index f2bed62c0..5b9b85c09 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/instrument/resttemplate/EnhancedRestTemplateWrapInterceptor.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/instrument/resttemplate/EnhancedRestTemplateWrapInterceptor.java @@ -92,7 +92,7 @@ public class EnhancedRestTemplateWrapInterceptor { enhancedPluginContext.setDelay(System.currentTimeMillis() - startMillis); EnhancedResponseContext enhancedResponseContext = EnhancedResponseContext.builder() - .httpStatus(response.getRawStatusCode()) + .httpStatus(response.getStatusCode().value()) .httpHeaders(response.getHeaders()) .build(); enhancedPluginContext.setResponse(enhancedResponseContext); diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/instrument/resttemplate/EnhancedRestTemplateWrapInterceptorTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/instrument/resttemplate/EnhancedRestTemplateWrapInterceptorTest.java index 21a3f3611..b480d78be 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/instrument/resttemplate/EnhancedRestTemplateWrapInterceptorTest.java +++ b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/instrument/resttemplate/EnhancedRestTemplateWrapInterceptorTest.java @@ -103,7 +103,7 @@ class EnhancedRestTemplateWrapInterceptorTest { when(request.getMethod()).thenReturn(HttpMethod.GET); when(pluginRunner.getLocalServiceInstance()).thenReturn(localServiceInstance); when(delegate.execute(any(), any())).thenReturn(response); - when(response.getRawStatusCode()).thenReturn(200); + when(response.getStatusCode()).thenReturn(HttpStatus.OK); when(response.getHeaders()).thenReturn(new HttpHeaders()); // Act @@ -138,7 +138,7 @@ class EnhancedRestTemplateWrapInterceptorTest { when(request.getURI()).thenReturn(originalUri); when(pluginRunner.getLocalServiceInstance()).thenReturn(localServiceInstance); when(delegate.execute(any(), any())).thenReturn(response); - when(response.getRawStatusCode()).thenReturn(200); + when(response.getStatusCode()).thenReturn(HttpStatus.OK); when(response.getHeaders()).thenReturn(new HttpHeaders()); // Act @@ -227,7 +227,7 @@ class EnhancedRestTemplateWrapInterceptorTest { when(request.getMethod()).thenReturn(HttpMethod.GET); when(pluginRunner.getLocalServiceInstance()).thenReturn(null); when(delegate.execute(any(), any())).thenReturn(response); - when(response.getRawStatusCode()).thenReturn(200); + when(response.getStatusCode()).thenReturn(HttpStatus.OK); when(response.getHeaders()).thenReturn(new HttpHeaders()); // Act @@ -274,11 +274,6 @@ class EnhancedRestTemplateWrapInterceptorTest { return null; } - @Override - public int getRawStatusCode() throws IOException { - return 0; - } - @Override public String getStatusText() throws IOException { return null;