From 9802f97cfb419ea1984a35ae388c182e55f755bc Mon Sep 17 00:00:00 2001
From: SkyeBeFreeman <928016560@qq.com>
Date: Wed, 30 Mar 2022 14:40:35 +0800
Subject: [PATCH] feat:optimize metadata module.
---
.../pom.xml | 1 +
.../MetadataTransferAutoConfiguration.java | 119 ++++----------
.../{scg => }/Metadata2HeaderScgFilter.java | 2 +-
.../{zuul => }/Metadata2HeaderZuulFilter.java | 2 +-
.../Metadata2HeaderFeignInterceptor.java | 4 +-
...tadata2HeaderRestTemplateInterceptor.java} | 6 +-
...MetadataTransferAutoConfigurationTest.java | 98 ++----------
.../Metadata2HeaderFeignInterceptorTest.java | 16 +-
...ta2HeaderRestTemplateInterceptorTest.java} | 17 +-
.../pom.xml | 5 -
.../feign/PolarisFeignClient.java | 7 +-
.../discovery/PolarisDiscoveryHandler.java | 7 +-
.../registry/PolarisServiceRegistry.java | 2 +-
...larisServiceRegistryAutoConfiguration.java | 2 +-
.../pom.xml | 5 -
.../filter/QuotaCheckReactiveFilter.java | 21 +--
.../filter/QuotaCheckServletFilter.java | 14 +-
.../pom.xml | 5 -
.../router/PolarisRoutingLoadBalancer.java | 21 +--
spring-cloud-tencent-commons/pom.xml | 18 +++
.../common/constant/MetadataConstant.java | 32 +---
.../metadata/MetadataAutoConfiguration.java | 23 ---
.../common/metadata/MetadataContext.java | 16 +-
.../metadata/MetadataContextHolder.java | 23 +--
.../config/MetadataAutoConfiguration.java | 140 +++++++++++++++++
.../{ => config}/MetadataLocalProperties.java | 2 +-
.../gateway}/MetadataFirstScgFilter.java | 8 +-
.../gateway}/MetadataFirstZuulFilter.java | 6 +-
.../filter/web/MetadataReactiveFilter.java | 17 +-
.../filter/web/MetadataServletFilter.java | 17 +-
.../feign/MetadataFirstFeignInterceptor.java | 8 +-
.../main/resources/META-INF/spring.factories | 2 +-
.../MetadataAutoConfigurationTest.java | 45 ------
.../metadata/MetadataContextHolderTest.java | 10 +-
.../config/MetadataAutoConfigurationTest.java | 145 ++++++++++++++++++
.../MetadataLocalPropertiesTest.java | 2 +-
.../web/MetadataReactiveFilterTest.java | 6 +-
.../filter/web/MetadataServletFilterTest.java | 4 +-
.../src/test/resources/application-test.yml | 4 +
.../polaris-circuitbreaker-example-a/pom.xml | 37 +++--
.../polaris-circuitbreaker-example-b/pom.xml | 8 +-
.../example/ServiceBController.java | 2 +-
.../polaris-circuitbreaker-example/pom.xml | 13 +-
.../callee/DiscoveryCalleeController.java | 13 +-
.../src/main/resources/polaris.yml | 6 +
.../discovery-caller-service/pom.xml | 26 ++--
.../gateway-callee-service/pom.xml | 5 -
.../callee/GatewayCalleeController.java | 11 +-
48 files changed, 502 insertions(+), 501 deletions(-)
rename spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/{scg => }/Metadata2HeaderScgFilter.java (97%)
rename spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/{zuul => }/Metadata2HeaderZuulFilter.java (97%)
rename spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/{feign => }/Metadata2HeaderFeignInterceptor.java (95%)
rename spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/{resttemplate/MetadataRestTemplateInterceptor.java => Metadata2HeaderRestTemplateInterceptor.java} (94%)
rename spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/{feign => }/Metadata2HeaderFeignInterceptorTest.java (86%)
rename spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/{resttemplate/MetadataRestTemplateInterceptorTest.java => Metadata2HeaderRestTemplateInterceptorTest.java} (86%)
delete mode 100644 spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataAutoConfiguration.java
create mode 100644 spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/config/MetadataAutoConfiguration.java
rename spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/{ => config}/MetadataLocalProperties.java (97%)
rename {spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/scg => spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/filter/gateway}/MetadataFirstScgFilter.java (93%)
rename {spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/zuul => spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/filter/gateway}/MetadataFirstZuulFilter.java (93%)
rename {spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core => spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata}/filter/web/MetadataReactiveFilter.java (78%)
rename {spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core => spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata}/filter/web/MetadataServletFilter.java (76%)
rename {spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core => spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata}/interceptor/feign/MetadataFirstFeignInterceptor.java (87%)
delete mode 100644 spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/MetadataAutoConfigurationTest.java
create mode 100644 spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/config/MetadataAutoConfigurationTest.java
rename spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/{ => config}/MetadataLocalPropertiesTest.java (97%)
rename {spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core => spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata}/filter/web/MetadataReactiveFilterTest.java (93%)
rename {spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core => spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata}/filter/web/MetadataServletFilterTest.java (95%)
diff --git a/spring-cloud-starter-tencent-metadata-transfer/pom.xml b/spring-cloud-starter-tencent-metadata-transfer/pom.xml
index 9780238e1..6d86c3352 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/pom.xml
+++ b/spring-cloud-starter-tencent-metadata-transfer/pom.xml
@@ -48,6 +48,7 @@
org.springframework.cloud
spring-cloud-starter-openfeign
+ true
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/config/MetadataTransferAutoConfiguration.java b/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/config/MetadataTransferAutoConfiguration.java
index 530994f3e..eb30f3318 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/config/MetadataTransferAutoConfiguration.java
+++ b/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/config/MetadataTransferAutoConfiguration.java
@@ -21,22 +21,14 @@ import java.util.List;
import java.util.Map;
import com.netflix.zuul.ZuulFilter;
-import com.tencent.cloud.common.constant.MetadataConstant;
-import com.tencent.cloud.metadata.core.filter.gateway.scg.Metadata2HeaderScgFilter;
-import com.tencent.cloud.metadata.core.filter.gateway.scg.MetadataFirstScgFilter;
-import com.tencent.cloud.metadata.core.filter.gateway.zuul.Metadata2HeaderZuulFilter;
-import com.tencent.cloud.metadata.core.filter.gateway.zuul.MetadataFirstZuulFilter;
-import com.tencent.cloud.metadata.core.filter.web.MetadataReactiveFilter;
-import com.tencent.cloud.metadata.core.filter.web.MetadataServletFilter;
-import com.tencent.cloud.metadata.core.interceptor.feign.Metadata2HeaderFeignInterceptor;
-import com.tencent.cloud.metadata.core.interceptor.feign.MetadataFirstFeignInterceptor;
-import com.tencent.cloud.metadata.core.interceptor.resttemplate.MetadataRestTemplateInterceptor;
+import com.tencent.cloud.metadata.core.filter.gateway.Metadata2HeaderScgFilter;
+import com.tencent.cloud.metadata.core.filter.gateway.Metadata2HeaderZuulFilter;
+import com.tencent.cloud.metadata.core.interceptor.Metadata2HeaderFeignInterceptor;
+import com.tencent.cloud.metadata.core.interceptor.Metadata2HeaderRestTemplateInterceptor;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
-import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
@@ -46,12 +38,6 @@ import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestTemplate;
-import static javax.servlet.DispatcherType.ASYNC;
-import static javax.servlet.DispatcherType.ERROR;
-import static javax.servlet.DispatcherType.FORWARD;
-import static javax.servlet.DispatcherType.INCLUDE;
-import static javax.servlet.DispatcherType.REQUEST;
-
/**
* Metadata transfer auto configuration.
*
@@ -60,56 +46,12 @@ import static javax.servlet.DispatcherType.REQUEST;
@Configuration
public class MetadataTransferAutoConfiguration {
- /**
- * Create when web application type is SERVLET.
- */
- @Configuration
- @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
- static class MetadataServletFilterConfig {
-
- @Bean
- public FilterRegistrationBean metadataServletFilterRegistrationBean(
- MetadataServletFilter metadataServletFilter) {
- FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean<>(
- metadataServletFilter);
- filterRegistrationBean.setDispatcherTypes(ASYNC, ERROR, FORWARD, INCLUDE,
- REQUEST);
- filterRegistrationBean.setOrder(MetadataConstant.OrderConstant.FILTER_ORDER);
- return filterRegistrationBean;
- }
-
- @Bean
- public MetadataServletFilter metadataServletFilter() {
- return new MetadataServletFilter();
- }
-
- }
-
- /**
- * Create when web application type is REACTIVE.
- */
- @Configuration
- @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
- static class MetadataReactiveFilterConfig {
-
- @Bean
- public MetadataReactiveFilter metadataReactiveFilter() {
- return new MetadataReactiveFilter();
- }
-
- }
-
/**
* Create when gateway application is Zuul.
*/
@Configuration
@ConditionalOnClass(name = "com.netflix.zuul.http.ZuulServlet")
- static class MetadataZuulFilterConfig {
-
- @Bean
- public ZuulFilter metadataFirstZuulFilter() {
- return new MetadataFirstZuulFilter();
- }
+ static class MetadataTransferZuulFilterConfig {
@Bean
public ZuulFilter metadata2HeaderZuulFilter() {
@@ -123,12 +65,7 @@ public class MetadataTransferAutoConfiguration {
*/
@Configuration
@ConditionalOnClass(name = "org.springframework.cloud.gateway.filter.GlobalFilter")
- static class MetadataScgFilterConfig {
-
- @Bean
- public GlobalFilter metadataFirstScgFilter() {
- return new MetadataFirstScgFilter();
- }
+ static class MetadataTransferScgFilterConfig {
@Bean
public GlobalFilter metadata2HeaderScgFilter() {
@@ -142,15 +79,10 @@ public class MetadataTransferAutoConfiguration {
*/
@Configuration
@ConditionalOnClass(name = "feign.Feign")
- static class MetadataFeignPluginConfig {
-
- @Bean
- public MetadataFirstFeignInterceptor metadataFirstFeignInterceptor() {
- return new MetadataFirstFeignInterceptor();
- }
+ static class MetadataTransferFeignInterceptorConfig {
@Bean
- public Metadata2HeaderFeignInterceptor metadataFeignInterceptor() {
+ public Metadata2HeaderFeignInterceptor metadata2HeaderFeignInterceptor() {
return new Metadata2HeaderFeignInterceptor();
}
@@ -161,18 +93,18 @@ public class MetadataTransferAutoConfiguration {
*/
@Configuration
@ConditionalOnClass(name = "org.springframework.web.client.RestTemplate")
- static class MetadataRestTemplateConfig implements ApplicationContextAware {
+ static class MetadataTransferRestTemplateConfig implements ApplicationContextAware {
private ApplicationContext context;
@Bean
- public MetadataRestTemplateInterceptor metadataRestTemplateInterceptor() {
- return new MetadataRestTemplateInterceptor();
+ public Metadata2HeaderRestTemplateInterceptor metadata2HeaderRestTemplateInterceptor() {
+ return new Metadata2HeaderRestTemplateInterceptor();
}
@Bean
- BeanPostProcessor metadataRestTemplatePostProcessor(
- MetadataRestTemplateInterceptor metadataRestTemplateInterceptor) {
+ BeanPostProcessor metadata2HeaderRestTemplatePostProcessor(
+ Metadata2HeaderRestTemplateInterceptor metadata2HeaderRestTemplateInterceptor) {
// Coping with multiple bean injection scenarios
Map beans = this.context
.getBeansOfType(RestTemplate.class);
@@ -184,14 +116,15 @@ public class MetadataTransferAutoConfiguration {
List interceptors = restTemplate
.getInterceptors();
// Avoid setting interceptor repeatedly.
- if (null != interceptors
- && !interceptors.contains(metadataRestTemplateInterceptor)) {
- interceptors.add(metadataRestTemplateInterceptor);
+ if (null != interceptors && !interceptors
+ .contains(metadata2HeaderRestTemplateInterceptor)) {
+ interceptors.add(metadata2HeaderRestTemplateInterceptor);
restTemplate.setInterceptors(interceptors);
}
}
}
- return new MetadataRestTemplatePostProcessor(metadataRestTemplateInterceptor);
+ return new Metadata2HeaderRestTemplatePostProcessor(
+ metadata2HeaderRestTemplateInterceptor);
}
@Override
@@ -200,14 +133,14 @@ public class MetadataTransferAutoConfiguration {
this.context = applicationContext;
}
- public static class MetadataRestTemplatePostProcessor
+ public static class Metadata2HeaderRestTemplatePostProcessor
implements BeanPostProcessor {
- private MetadataRestTemplateInterceptor metadataRestTemplateInterceptor;
+ private Metadata2HeaderRestTemplateInterceptor metadata2HeaderRestTemplateInterceptor;
- MetadataRestTemplatePostProcessor(
- MetadataRestTemplateInterceptor metadataRestTemplateInterceptor) {
- this.metadataRestTemplateInterceptor = metadataRestTemplateInterceptor;
+ Metadata2HeaderRestTemplatePostProcessor(
+ Metadata2HeaderRestTemplateInterceptor metadata2HeaderRestTemplateInterceptor) {
+ this.metadata2HeaderRestTemplateInterceptor = metadata2HeaderRestTemplateInterceptor;
}
@Override
@@ -222,9 +155,9 @@ public class MetadataTransferAutoConfiguration {
List interceptors = restTemplate
.getInterceptors();
// Avoid setting interceptor repeatedly.
- if (null != interceptors
- && !interceptors.contains(metadataRestTemplateInterceptor)) {
- interceptors.add(this.metadataRestTemplateInterceptor);
+ if (null != interceptors && !interceptors
+ .contains(metadata2HeaderRestTemplateInterceptor)) {
+ interceptors.add(this.metadata2HeaderRestTemplateInterceptor);
restTemplate.setInterceptors(interceptors);
}
}
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/scg/Metadata2HeaderScgFilter.java b/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/Metadata2HeaderScgFilter.java
similarity index 97%
rename from spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/scg/Metadata2HeaderScgFilter.java
rename to spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/Metadata2HeaderScgFilter.java
index 190237b76..ce81ad8e1 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/scg/Metadata2HeaderScgFilter.java
+++ b/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/Metadata2HeaderScgFilter.java
@@ -15,7 +15,7 @@
* specific language governing permissions and limitations under the License.
*/
-package com.tencent.cloud.metadata.core.filter.gateway.scg;
+package com.tencent.cloud.metadata.core.filter.gateway;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/zuul/Metadata2HeaderZuulFilter.java b/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/Metadata2HeaderZuulFilter.java
similarity index 97%
rename from spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/zuul/Metadata2HeaderZuulFilter.java
rename to spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/Metadata2HeaderZuulFilter.java
index 5ea5e2dac..a2e2a334e 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/zuul/Metadata2HeaderZuulFilter.java
+++ b/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/Metadata2HeaderZuulFilter.java
@@ -15,7 +15,7 @@
* specific language governing permissions and limitations under the License.
*/
-package com.tencent.cloud.metadata.core.filter.gateway.zuul;
+package com.tencent.cloud.metadata.core.filter.gateway;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/feign/Metadata2HeaderFeignInterceptor.java b/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/Metadata2HeaderFeignInterceptor.java
similarity index 95%
rename from spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/feign/Metadata2HeaderFeignInterceptor.java
rename to spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/Metadata2HeaderFeignInterceptor.java
index 641111a74..99cb21d68 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/feign/Metadata2HeaderFeignInterceptor.java
+++ b/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/Metadata2HeaderFeignInterceptor.java
@@ -15,7 +15,7 @@
* specific language governing permissions and limitations under the License.
*/
-package com.tencent.cloud.metadata.core.interceptor.feign;
+package com.tencent.cloud.metadata.core.interceptor;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
@@ -48,7 +48,7 @@ public class Metadata2HeaderFeignInterceptor implements RequestInterceptor, Orde
@Override
public int getOrder() {
- return MetadataConstant.OrderConstant.METADATA_2_HEADER_FEIGN_INTERCEPTOR_ORDER;
+ return MetadataConstant.OrderConstant.METADATA_2_HEADER_INTERCEPTOR_ORDER;
}
@Override
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/resttemplate/MetadataRestTemplateInterceptor.java b/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/Metadata2HeaderRestTemplateInterceptor.java
similarity index 94%
rename from spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/resttemplate/MetadataRestTemplateInterceptor.java
rename to spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/Metadata2HeaderRestTemplateInterceptor.java
index a200091cc..2ce9d5875 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/resttemplate/MetadataRestTemplateInterceptor.java
+++ b/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/Metadata2HeaderRestTemplateInterceptor.java
@@ -15,7 +15,7 @@
* specific language governing permissions and limitations under the License.
*/
-package com.tencent.cloud.metadata.core.interceptor.resttemplate;
+package com.tencent.cloud.metadata.core.interceptor;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
@@ -41,12 +41,12 @@ import org.springframework.util.StringUtils;
*
* @author Haotian Zhang
*/
-public class MetadataRestTemplateInterceptor
+public class Metadata2HeaderRestTemplateInterceptor
implements ClientHttpRequestInterceptor, Ordered {
@Override
public int getOrder() {
- return MetadataConstant.OrderConstant.INTERCEPTOR_ORDER;
+ return MetadataConstant.OrderConstant.METADATA_2_HEADER_INTERCEPTOR_ORDER;
}
@Override
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/config/MetadataTransferAutoConfigurationTest.java b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/config/MetadataTransferAutoConfigurationTest.java
index 02f647f62..5b1c7aaeb 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/config/MetadataTransferAutoConfigurationTest.java
+++ b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/config/MetadataTransferAutoConfigurationTest.java
@@ -17,18 +17,15 @@
package com.tencent.cloud.metadata.config;
-import com.tencent.cloud.metadata.core.filter.web.MetadataReactiveFilter;
-import com.tencent.cloud.metadata.core.filter.web.MetadataServletFilter;
-import com.tencent.cloud.metadata.core.interceptor.feign.Metadata2HeaderFeignInterceptor;
-import com.tencent.cloud.metadata.core.interceptor.feign.MetadataFirstFeignInterceptor;
-import com.tencent.cloud.metadata.core.interceptor.resttemplate.MetadataRestTemplateInterceptor;
+import com.tencent.cloud.metadata.core.filter.gateway.Metadata2HeaderZuulFilter;
+import com.tencent.cloud.metadata.core.interceptor.Metadata2HeaderFeignInterceptor;
+import com.tencent.cloud.metadata.core.interceptor.Metadata2HeaderRestTemplateInterceptor;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
-import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
-import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
+import org.springframework.cloud.gateway.filter.GlobalFilter;
/**
* Test for {@link MetadataTransferAutoConfiguration}
@@ -39,10 +36,6 @@ public class MetadataTransferAutoConfigurationTest {
private final ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner();
- private final WebApplicationContextRunner webApplicationContextRunner = new WebApplicationContextRunner();
-
- private final ReactiveWebApplicationContextRunner reactiveWebApplicationContextRunner = new ReactiveWebApplicationContextRunner();
-
/**
* No any web application.
*/
@@ -52,90 +45,23 @@ public class MetadataTransferAutoConfigurationTest {
.withConfiguration(
AutoConfigurations.of(MetadataTransferAutoConfiguration.class))
.run(context -> {
- Assertions.assertThat(context).doesNotHaveBean(
- MetadataTransferAutoConfiguration.MetadataReactiveFilterConfig.class);
- Assertions.assertThat(context)
- .doesNotHaveBean(MetadataReactiveFilter.class);
- Assertions.assertThat(context).doesNotHaveBean(
- MetadataTransferAutoConfiguration.MetadataServletFilterConfig.class);
- Assertions.assertThat(context)
- .doesNotHaveBean(MetadataServletFilter.class);
- Assertions.assertThat(context).hasSingleBean(
- MetadataTransferAutoConfiguration.MetadataFeignPluginConfig.class);
- Assertions.assertThat(context)
- .hasSingleBean(MetadataFirstFeignInterceptor.class);
- Assertions.assertThat(context)
- .hasSingleBean(Metadata2HeaderFeignInterceptor.class);
- Assertions.assertThat(context).hasSingleBean(
- MetadataTransferAutoConfiguration.MetadataRestTemplateConfig.class);
- Assertions.assertThat(context)
- .hasSingleBean(MetadataRestTemplateInterceptor.class);
- Assertions.assertThat(context).hasSingleBean(
- MetadataTransferAutoConfiguration.MetadataRestTemplateConfig.MetadataRestTemplatePostProcessor.class);
- });
- }
-
- /**
- * web application.
- */
- @Test
- public void test2() {
- this.webApplicationContextRunner
- .withConfiguration(
- AutoConfigurations.of(MetadataTransferAutoConfiguration.class))
- .run(context -> {
- Assertions.assertThat(context).doesNotHaveBean(
- MetadataTransferAutoConfiguration.MetadataReactiveFilterConfig.class);
- Assertions.assertThat(context)
- .doesNotHaveBean(MetadataReactiveFilter.class);
- Assertions.assertThat(context).hasSingleBean(
- MetadataTransferAutoConfiguration.MetadataServletFilterConfig.class);
- Assertions.assertThat(context)
- .hasSingleBean(MetadataServletFilter.class);
Assertions.assertThat(context).hasSingleBean(
- MetadataTransferAutoConfiguration.MetadataFeignPluginConfig.class);
- Assertions.assertThat(context)
- .hasSingleBean(MetadataFirstFeignInterceptor.class);
+ MetadataTransferAutoConfiguration.MetadataTransferFeignInterceptorConfig.class);
Assertions.assertThat(context)
.hasSingleBean(Metadata2HeaderFeignInterceptor.class);
Assertions.assertThat(context).hasSingleBean(
- MetadataTransferAutoConfiguration.MetadataRestTemplateConfig.class);
- Assertions.assertThat(context)
- .hasSingleBean(MetadataRestTemplateInterceptor.class);
- Assertions.assertThat(context).hasSingleBean(
- MetadataTransferAutoConfiguration.MetadataRestTemplateConfig.MetadataRestTemplatePostProcessor.class);
- });
- }
-
- /**
- * reactive web application.
- */
- @Test
- public void test3() {
- this.reactiveWebApplicationContextRunner
- .withConfiguration(
- AutoConfigurations.of(MetadataTransferAutoConfiguration.class))
- .run(context -> {
- Assertions.assertThat(context).hasSingleBean(
- MetadataTransferAutoConfiguration.MetadataReactiveFilterConfig.class);
- Assertions.assertThat(context)
- .hasSingleBean(MetadataReactiveFilter.class);
- Assertions.assertThat(context).doesNotHaveBean(
- MetadataTransferAutoConfiguration.MetadataServletFilterConfig.class);
+ MetadataTransferAutoConfiguration.MetadataTransferRestTemplateConfig.class);
Assertions.assertThat(context)
- .doesNotHaveBean(MetadataServletFilter.class);
+ .hasSingleBean(Metadata2HeaderRestTemplateInterceptor.class);
Assertions.assertThat(context).hasSingleBean(
- MetadataTransferAutoConfiguration.MetadataFeignPluginConfig.class);
- Assertions.assertThat(context)
- .hasSingleBean(MetadataFirstFeignInterceptor.class);
- Assertions.assertThat(context)
- .hasSingleBean(Metadata2HeaderFeignInterceptor.class);
+ MetadataTransferAutoConfiguration.MetadataTransferRestTemplateConfig.Metadata2HeaderRestTemplatePostProcessor.class);
Assertions.assertThat(context).hasSingleBean(
- MetadataTransferAutoConfiguration.MetadataRestTemplateConfig.class);
+ MetadataTransferAutoConfiguration.MetadataTransferZuulFilterConfig.class);
Assertions.assertThat(context)
- .hasSingleBean(MetadataRestTemplateInterceptor.class);
+ .hasSingleBean(Metadata2HeaderZuulFilter.class);
Assertions.assertThat(context).hasSingleBean(
- MetadataTransferAutoConfiguration.MetadataRestTemplateConfig.MetadataRestTemplatePostProcessor.class);
+ MetadataTransferAutoConfiguration.MetadataTransferScgFilterConfig.class);
+ Assertions.assertThat(context).hasSingleBean(GlobalFilter.class);
});
}
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/feign/Metadata2HeaderFeignInterceptorTest.java b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/Metadata2HeaderFeignInterceptorTest.java
similarity index 86%
rename from spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/feign/Metadata2HeaderFeignInterceptorTest.java
rename to spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/Metadata2HeaderFeignInterceptorTest.java
index aa1284b68..97ee8a787 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/feign/Metadata2HeaderFeignInterceptorTest.java
+++ b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/Metadata2HeaderFeignInterceptorTest.java
@@ -15,18 +15,16 @@
* specific language governing permissions and limitations under the License.
*/
-package com.tencent.cloud.metadata.core.intercepter.feign;
+package com.tencent.cloud.metadata.core.intercepter;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.tencent.cloud.common.constant.MetadataConstant;
import com.tencent.cloud.common.metadata.MetadataContextHolder;
-import com.tencent.cloud.common.metadata.MetadataLocalProperties;
+import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
import com.tencent.cloud.common.util.JacksonUtils;
-import com.tencent.cloud.metadata.core.interceptor.feign.Metadata2HeaderFeignInterceptor;
+import com.tencent.cloud.metadata.core.interceptor.Metadata2HeaderFeignInterceptor;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.assertj.core.api.Assertions;
@@ -65,12 +63,10 @@ public class Metadata2HeaderFeignInterceptorTest {
private TestApplication.TestFeign testFeign;
@Test
- public void test1() throws JsonProcessingException {
+ public void test1() {
String metadata = testFeign.test();
- ObjectMapper mapper = new ObjectMapper();
- Assertions.assertThat(metadata).isEqualTo(
- "{\"a\":\"11\",\"b\":\"22\",\"c\":\"33\"}{\"LOCAL_SERVICE\":\"test"
- + "\",\"LOCAL_PATH\":\"/test\",\"LOCAL_NAMESPACE\":\"default\"}");
+ Assertions.assertThat(metadata)
+ .isEqualTo("{\"a\":\"11\",\"b\":\"22\",\"c\":\"33\"}{}");
Assertions.assertThat(metadataLocalProperties.getContent().get("a"))
.isEqualTo("1");
Assertions.assertThat(metadataLocalProperties.getContent().get("b"))
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/resttemplate/MetadataRestTemplateInterceptorTest.java b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/Metadata2HeaderRestTemplateInterceptorTest.java
similarity index 86%
rename from spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/resttemplate/MetadataRestTemplateInterceptorTest.java
rename to spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/Metadata2HeaderRestTemplateInterceptorTest.java
index 50dd5226e..353f57918 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/resttemplate/MetadataRestTemplateInterceptorTest.java
+++ b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/Metadata2HeaderRestTemplateInterceptorTest.java
@@ -15,16 +15,16 @@
* specific language governing permissions and limitations under the License.
*/
-package com.tencent.cloud.metadata.core.intercepter.resttemplate;
+package com.tencent.cloud.metadata.core.intercepter;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import com.tencent.cloud.common.constant.MetadataConstant;
import com.tencent.cloud.common.metadata.MetadataContextHolder;
-import com.tencent.cloud.common.metadata.MetadataLocalProperties;
+import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
import com.tencent.cloud.common.util.JacksonUtils;
-import com.tencent.cloud.metadata.core.interceptor.resttemplate.MetadataRestTemplateInterceptor;
+import com.tencent.cloud.metadata.core.interceptor.Metadata2HeaderRestTemplateInterceptor;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -46,15 +46,15 @@ import org.springframework.web.client.RestTemplate;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
/**
- * Test for {@link MetadataRestTemplateInterceptor}
+ * Test for {@link Metadata2HeaderRestTemplateInterceptor}
*
* @author Haotian Zhang
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = RANDOM_PORT,
- classes = MetadataRestTemplateInterceptorTest.TestApplication.class,
+ classes = Metadata2HeaderRestTemplateInterceptorTest.TestApplication.class,
properties = { "spring.config.location = classpath:application-test.yml" })
-public class MetadataRestTemplateInterceptorTest {
+public class Metadata2HeaderRestTemplateInterceptorTest {
@Autowired
private MetadataLocalProperties metadataLocalProperties;
@@ -75,9 +75,8 @@ public class MetadataRestTemplateInterceptorTest {
.exchange("http://localhost:" + localServerPort + "/test", HttpMethod.GET,
httpEntity, String.class)
.getBody();
- Assertions.assertThat(metadata).isEqualTo(
- "{\"a\":\"11\",\"b\":\"22\",\"c\":\"33\"}{\"LOCAL_SERVICE\":\"test"
- + "\",\"LOCAL_PATH\":\"/test\",\"LOCAL_NAMESPACE\":\"default\"}");
+ Assertions.assertThat(metadata)
+ .isEqualTo("{\"a\":\"11\",\"b\":\"22\",\"c\":\"33\"}{}");
Assertions.assertThat(metadataLocalProperties.getContent().get("a"))
.isEqualTo("1");
Assertions.assertThat(metadataLocalProperties.getContent().get("b"))
diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/pom.xml b/spring-cloud-starter-tencent-polaris-circuitbreaker/pom.xml
index 6496dd855..414a90738 100644
--- a/spring-cloud-starter-tencent-polaris-circuitbreaker/pom.xml
+++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/pom.xml
@@ -23,11 +23,6 @@
com.tencent.cloud
spring-cloud-tencent-polaris-context
-
-
- com.tencent.cloud
- spring-cloud-starter-tencent-metadata-transfer
-
diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/feign/PolarisFeignClient.java b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/feign/PolarisFeignClient.java
index 6e5d80f07..0170fc344 100644
--- a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/feign/PolarisFeignClient.java
+++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/feign/PolarisFeignClient.java
@@ -84,16 +84,13 @@ public class PolarisFeignClient implements Client {
String method = metadataContext.getSystemMetadata(SystemMetadataKey.PEER_PATH);
resultRequest.setMethod(method);
resultRequest.setRetStatus(RetStatus.RetSuccess);
- String sourceNamespace = metadataContext
- .getSystemMetadata(SystemMetadataKey.LOCAL_NAMESPACE);
- String sourceService = metadataContext
- .getSystemMetadata(SystemMetadataKey.LOCAL_SERVICE);
+ String sourceNamespace = MetadataContext.LOCAL_NAMESPACE;
+ String sourceService = MetadataContext.LOCAL_SERVICE;
if (StringUtils.isNotBlank(sourceNamespace)
&& StringUtils.isNotBlank(sourceService)) {
resultRequest
.setCallerService(new ServiceKey(sourceNamespace, sourceService));
}
-
URI uri = URI.create(request.url());
resultRequest.setHost(uri.getHost());
resultRequest.setPort(uri.getPort());
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryHandler.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryHandler.java
index 298cc4515..167c029b6 100644
--- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryHandler.java
+++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/discovery/PolarisDiscoveryHandler.java
@@ -20,6 +20,7 @@ package com.tencent.cloud.polaris.discovery;
import java.util.Map;
import com.tencent.cloud.common.constant.MetadataConstant.SystemMetadataKey;
+import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.metadata.MetadataContextHolder;
import com.tencent.cloud.polaris.PolarisProperties;
import com.tencent.polaris.api.core.ConsumerAPI;
@@ -65,10 +66,8 @@ public class PolarisDiscoveryHandler {
String method = MetadataContextHolder.get()
.getSystemMetadata(SystemMetadataKey.PEER_PATH);
getInstancesRequest.setMethod(method);
- String localNamespace = MetadataContextHolder.get()
- .getSystemMetadata(SystemMetadataKey.LOCAL_NAMESPACE);
- String localService = MetadataContextHolder.get()
- .getSystemMetadata(SystemMetadataKey.LOCAL_SERVICE);
+ String localNamespace = MetadataContext.LOCAL_NAMESPACE;
+ String localService = MetadataContext.LOCAL_SERVICE;
Map allTransitiveCustomMetadata = MetadataContextHolder.get()
.getAllTransitiveCustomMetadata();
if (StringUtils.isNotBlank(localNamespace) || StringUtils.isNotBlank(localService)
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java
index d4ff68882..d15966820 100644
--- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java
+++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java
@@ -21,7 +21,7 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
-import com.tencent.cloud.common.metadata.MetadataLocalProperties;
+import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
import com.tencent.cloud.polaris.PolarisProperties;
import com.tencent.cloud.polaris.discovery.PolarisDiscoveryHandler;
import com.tencent.cloud.polaris.util.OkHttpUtil;
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistryAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistryAutoConfiguration.java
index a3209fb7e..bee238321 100644
--- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistryAutoConfiguration.java
+++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistryAutoConfiguration.java
@@ -17,7 +17,7 @@
package com.tencent.cloud.polaris.registry;
-import com.tencent.cloud.common.metadata.MetadataLocalProperties;
+import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
import com.tencent.cloud.polaris.PolarisProperties;
import com.tencent.cloud.polaris.discovery.ConditionalOnPolarisDiscoveryEnabled;
import com.tencent.cloud.polaris.discovery.PolarisDiscoveryAutoConfiguration;
diff --git a/spring-cloud-starter-tencent-polaris-ratelimit/pom.xml b/spring-cloud-starter-tencent-polaris-ratelimit/pom.xml
index 4d4750096..282c82097 100644
--- a/spring-cloud-starter-tencent-polaris-ratelimit/pom.xml
+++ b/spring-cloud-starter-tencent-polaris-ratelimit/pom.xml
@@ -24,11 +24,6 @@
com.tencent.cloud
spring-cloud-tencent-polaris-context
-
-
- com.tencent.cloud
- spring-cloud-starter-tencent-metadata-transfer
-
diff --git a/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/filter/QuotaCheckReactiveFilter.java b/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/filter/QuotaCheckReactiveFilter.java
index 80b262207..1727a018b 100644
--- a/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/filter/QuotaCheckReactiveFilter.java
+++ b/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/filter/QuotaCheckReactiveFilter.java
@@ -21,9 +21,7 @@ import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
-import com.tencent.cloud.common.constant.MetadataConstant;
import com.tencent.cloud.common.metadata.MetadataContext;
-import com.tencent.cloud.common.metadata.MetadataContextHolder;
import com.tencent.cloud.polaris.ratelimit.constant.RateLimitConstant;
import com.tencent.cloud.polaris.ratelimit.utils.QuotaCheckUtils;
import com.tencent.polaris.ratelimit.api.core.LimitAPI;
@@ -66,22 +64,9 @@ public class QuotaCheckReactiveFilter implements WebFilter, Ordered {
@Override
public Mono filter(ServerWebExchange exchange, WebFilterChain chain) {
- // get metadata of current thread
- MetadataContext metadataContext = exchange
- .getAttribute(MetadataConstant.HeaderName.METADATA_CONTEXT);
-
- if (metadataContext == null) {
- metadataContext = MetadataContextHolder.get();
- }
-
- String localNamespace = metadataContext
- .getSystemMetadata(MetadataConstant.SystemMetadataKey.LOCAL_NAMESPACE);
- String localService = metadataContext
- .getSystemMetadata(MetadataConstant.SystemMetadataKey.LOCAL_SERVICE);
-
- // TODO Get path
- String method = metadataContext
- .getSystemMetadata(MetadataConstant.SystemMetadataKey.LOCAL_PATH);
+ String localNamespace = MetadataContext.LOCAL_NAMESPACE;
+ String localService = MetadataContext.LOCAL_SERVICE;
+ String method = exchange.getRequest().getURI().getPath();
Map labels = null;
if (StringUtils.isNotBlank(method)) {
labels = new HashMap<>();
diff --git a/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/filter/QuotaCheckServletFilter.java b/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/filter/QuotaCheckServletFilter.java
index 8aca82fd1..dd19def58 100644
--- a/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/filter/QuotaCheckServletFilter.java
+++ b/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/filter/QuotaCheckServletFilter.java
@@ -26,8 +26,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import com.tencent.cloud.common.constant.MetadataConstant.SystemMetadataKey;
-import com.tencent.cloud.common.metadata.MetadataContextHolder;
+import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.polaris.ratelimit.constant.RateLimitConstant;
import com.tencent.cloud.polaris.ratelimit.utils.QuotaCheckUtils;
import com.tencent.polaris.ratelimit.api.core.LimitAPI;
@@ -63,14 +62,9 @@ public class QuotaCheckServletFilter extends OncePerRequestFilter {
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
- String localNamespace = MetadataContextHolder.get()
- .getSystemMetadata(SystemMetadataKey.LOCAL_NAMESPACE);
- String localService = MetadataContextHolder.get()
- .getSystemMetadata(SystemMetadataKey.LOCAL_SERVICE);
-
- // TODO Get path
- String method = MetadataContextHolder.get()
- .getSystemMetadata(SystemMetadataKey.LOCAL_PATH);
+ String localNamespace = MetadataContext.LOCAL_NAMESPACE;
+ String localService = MetadataContext.LOCAL_SERVICE;
+ String method = request.getRequestURI();
Map labels = null;
if (StringUtils.isNotBlank(method)) {
labels = new HashMap<>();
diff --git a/spring-cloud-starter-tencent-polaris-router/pom.xml b/spring-cloud-starter-tencent-polaris-router/pom.xml
index d94e8422b..48c14a357 100644
--- a/spring-cloud-starter-tencent-polaris-router/pom.xml
+++ b/spring-cloud-starter-tencent-polaris-router/pom.xml
@@ -24,11 +24,6 @@
com.tencent.cloud
spring-cloud-tencent-polaris-context
-
-
- com.tencent.cloud
- spring-cloud-starter-tencent-metadata-transfer
-
diff --git a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/PolarisRoutingLoadBalancer.java b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/PolarisRoutingLoadBalancer.java
index 7c9804e45..e10150979 100644
--- a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/PolarisRoutingLoadBalancer.java
+++ b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/PolarisRoutingLoadBalancer.java
@@ -29,6 +29,7 @@ import com.netflix.loadbalancer.PollingServerListUpdater;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
import com.tencent.cloud.common.constant.MetadataConstant.SystemMetadataKey;
+import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.metadata.MetadataContextHolder;
import com.tencent.cloud.common.pojo.PolarisServer;
import com.tencent.polaris.api.pojo.DefaultInstance;
@@ -72,8 +73,7 @@ public class PolarisRoutingLoadBalancer extends DynamicServerListLoadBalancer instances = new ArrayList<>(8);
for (Server server : allServers) {
DefaultInstance instance = new DefaultInstance();
- instance.setNamespace(MetadataContextHolder.LOCAL_NAMESPACE);
+ instance.setNamespace(MetadataContext.LOCAL_NAMESPACE);
instance.setService(serviceName);
instance.setHealthy(server.isAlive());
instance.setProtocol(server.getScheme());
@@ -103,14 +102,10 @@ public class PolarisRoutingLoadBalancer extends DynamicServerListLoadBalancer transitiveCustomMetadata = MetadataContextHolder.get()
- .getAllTransitiveCustomMetadata();
- String method = MetadataContextHolder.get()
- .getSystemMetadata(SystemMetadataKey.PEER_PATH);
+ String srcNamespace = MetadataContext.LOCAL_NAMESPACE;
+ String srcService = MetadataContext.LOCAL_SERVICE;
+ Map transitiveCustomMetadata = MetadataContextHolder.get().getAllTransitiveCustomMetadata();
+ String method = MetadataContextHolder.get().getSystemMetadata(SystemMetadataKey.PEER_PATH);
processRoutersRequest.setMethod(method);
if (StringUtils.isNotBlank(srcNamespace) && StringUtils.isNotBlank(srcService)) {
ServiceInfo serviceInfo = new ServiceInfo();
diff --git a/spring-cloud-tencent-commons/pom.xml b/spring-cloud-tencent-commons/pom.xml
index 77ef6e71d..6e16264a0 100644
--- a/spring-cloud-tencent-commons/pom.xml
+++ b/spring-cloud-tencent-commons/pom.xml
@@ -75,6 +75,24 @@
${commons.io.version}
+
+ org.springframework.cloud
+ spring-cloud-starter-netflix-zuul
+ true
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-gateway
+ true
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-openfeign
+ true
+
+
org.springframework.boot
spring-boot-starter-test
diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/constant/MetadataConstant.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/constant/MetadataConstant.java
index 09401c98e..ce498126b 100644
--- a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/constant/MetadataConstant.java
+++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/constant/MetadataConstant.java
@@ -31,21 +31,6 @@ public final class MetadataConstant {
*/
public static class SystemMetadataKey {
- /**
- * Local namespace.
- */
- public static String LOCAL_NAMESPACE = "LOCAL_NAMESPACE";
-
- /**
- * Local service.
- */
- public static String LOCAL_SERVICE = "LOCAL_SERVICE";
-
- /**
- * Local path.
- */
- public static String LOCAL_PATH = "LOCAL_PATH";
-
/**
* Peer namespace.
*/
@@ -71,13 +56,7 @@ public final class MetadataConstant {
/**
* Order of filter.
*/
- public static final int FILTER_ORDER = Ordered.HIGHEST_PRECEDENCE + 13;
-
- /**
- * Order of MetadataFirstFeignPlugin.
- */
- public static int METADATA_FIRST_FEIGN_PLUGIN_ORDER = Ordered.HIGHEST_PRECEDENCE
- + 1;
+ public static final int WEB_FILTER_ORDER = Ordered.HIGHEST_PRECEDENCE + 13;
/**
* Order of MetadataFirstFeignInterceptor.
@@ -86,14 +65,9 @@ public final class MetadataConstant {
+ 1;
/**
- * Order of Metadata2HeaderFeignInterceptor.
- */
- public static int METADATA_2_HEADER_FEIGN_INTERCEPTOR_ORDER = Ordered.LOWEST_PRECEDENCE;
-
- /**
- * Order of interceptor.
+ * Order of Metadata2HeaderInterceptor.
*/
- public static int INTERCEPTOR_ORDER = Ordered.LOWEST_PRECEDENCE;
+ public static int METADATA_2_HEADER_INTERCEPTOR_ORDER = Ordered.LOWEST_PRECEDENCE;
}
diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataAutoConfiguration.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataAutoConfiguration.java
deleted file mode 100644
index e956c91f2..000000000
--- a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataAutoConfiguration.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.tencent.cloud.common.metadata;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * Metadata auto configuration.
- *
- * @author Haotian Zhang
- */
-@Configuration
-public class MetadataAutoConfiguration {
-
- /**
- * metadata properties.
- * @return metadata properties
- */
- @Bean
- public MetadataLocalProperties metadataLocalProperties() {
- return new MetadataLocalProperties();
- }
-
-}
diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataContext.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataContext.java
index 18aeba466..cf4e59b84 100644
--- a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataContext.java
+++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataContext.java
@@ -21,15 +21,29 @@ import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
import com.tencent.cloud.common.util.JacksonUtils;
/**
- * Transitive Metadata Context.
+ * Metadata Context.
*
* @author Haotian Zhang
*/
public class MetadataContext {
+ /**
+ * Namespace of local instance.
+ */
+ public static final String LOCAL_NAMESPACE = ApplicationContextAwareUtils
+ .getProperties("spring.cloud.polaris.discovery.namespace", "default");
+
+ /**
+ * Service name of local instance.
+ */
+ public static final String LOCAL_SERVICE = ApplicationContextAwareUtils.getProperties(
+ "spring.cloud.polaris.discovery.service",
+ ApplicationContextAwareUtils.getProperties("spring.application.name", null));
+
/**
* Transitive custom metadata content.
*/
diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataContextHolder.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataContextHolder.java
index a7a46e9a8..b8811f8a5 100644
--- a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataContextHolder.java
+++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataContextHolder.java
@@ -21,7 +21,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import com.tencent.cloud.common.constant.MetadataConstant;
+import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
import org.springframework.util.CollectionUtils;
@@ -33,23 +33,8 @@ import org.springframework.util.CollectionUtils;
*/
public final class MetadataContextHolder {
- /**
- * Namespace of local instance.
- */
- public static final String LOCAL_NAMESPACE = ApplicationContextAwareUtils
- .getProperties("spring.cloud" + ".polaris.discovery.namespace", "default");
-
private static final ThreadLocal METADATA_CONTEXT = new InheritableThreadLocal<>();
- private static final String LOCAL_SPRING_APPLICATION_NAME = ApplicationContextAwareUtils
- .getProperties("spring.application.name", null);
-
- /**
- * Service name of local instance.
- */
- public static final String LOCAL_SERVICE = ApplicationContextAwareUtils.getProperties(
- "spring.cloud.polaris" + ".discovery.service", LOCAL_SPRING_APPLICATION_NAME);
-
private static MetadataLocalProperties metadataLocalProperties;
private MetadataContextHolder() {
@@ -74,12 +59,6 @@ public final class MetadataContextHolder {
metadataLocalProperties.getTransitive());
metadataContext.putAllTransitiveCustomMetadata(transitiveMetadataMap);
- // init system metadata
- metadataContext.putSystemMetadata(
- MetadataConstant.SystemMetadataKey.LOCAL_NAMESPACE, LOCAL_NAMESPACE);
- metadataContext.putSystemMetadata(
- MetadataConstant.SystemMetadataKey.LOCAL_SERVICE, LOCAL_SERVICE);
-
METADATA_CONTEXT.set(metadataContext);
}
return METADATA_CONTEXT.get();
diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/config/MetadataAutoConfiguration.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/config/MetadataAutoConfiguration.java
new file mode 100644
index 000000000..b7254737f
--- /dev/null
+++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/config/MetadataAutoConfiguration.java
@@ -0,0 +1,140 @@
+/*
+ * Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
+ *
+ * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
+ *
+ * Licensed under the BSD 3-Clause License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed
+ * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.tencent.cloud.common.metadata.config;
+
+import com.netflix.zuul.ZuulFilter;
+import com.tencent.cloud.common.constant.MetadataConstant;
+import com.tencent.cloud.common.metadata.filter.gateway.MetadataFirstScgFilter;
+import com.tencent.cloud.common.metadata.filter.gateway.MetadataFirstZuulFilter;
+import com.tencent.cloud.common.metadata.filter.web.MetadataReactiveFilter;
+import com.tencent.cloud.common.metadata.filter.web.MetadataServletFilter;
+import com.tencent.cloud.common.metadata.interceptor.feign.MetadataFirstFeignInterceptor;
+
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
+import org.springframework.boot.web.servlet.FilterRegistrationBean;
+import org.springframework.cloud.gateway.filter.GlobalFilter;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import static javax.servlet.DispatcherType.ASYNC;
+import static javax.servlet.DispatcherType.ERROR;
+import static javax.servlet.DispatcherType.FORWARD;
+import static javax.servlet.DispatcherType.INCLUDE;
+import static javax.servlet.DispatcherType.REQUEST;
+
+/**
+ * Metadata auto configuration.
+ *
+ * @author Haotian Zhang
+ */
+@Configuration
+public class MetadataAutoConfiguration {
+
+ /**
+ * metadata properties.
+ * @return metadata properties
+ */
+ @Bean
+ public MetadataLocalProperties metadataLocalProperties() {
+ return new MetadataLocalProperties();
+ }
+
+ /**
+ * Create when web application type is SERVLET.
+ */
+ @Configuration
+ @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
+ static class MetadataServletFilterConfig {
+
+ @Bean
+ public FilterRegistrationBean metadataServletFilterRegistrationBean(
+ MetadataServletFilter metadataServletFilter) {
+ FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean<>(
+ metadataServletFilter);
+ filterRegistrationBean.setDispatcherTypes(ASYNC, ERROR, FORWARD, INCLUDE,
+ REQUEST);
+ filterRegistrationBean
+ .setOrder(MetadataConstant.OrderConstant.WEB_FILTER_ORDER);
+ return filterRegistrationBean;
+ }
+
+ @Bean
+ public MetadataServletFilter metadataServletFilter() {
+ return new MetadataServletFilter();
+ }
+
+ }
+
+ /**
+ * Create when web application type is REACTIVE.
+ */
+ @Configuration
+ @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
+ static class MetadataReactiveFilterConfig {
+
+ @Bean
+ public MetadataReactiveFilter metadataReactiveFilter() {
+ return new MetadataReactiveFilter();
+ }
+
+ }
+
+ /**
+ * Create when Feign exists.
+ */
+ @Configuration
+ @ConditionalOnClass(name = "feign.Feign")
+ static class MetadataFeignInterceptorConfig {
+
+ @Bean
+ public MetadataFirstFeignInterceptor metadataFirstFeignInterceptor() {
+ return new MetadataFirstFeignInterceptor();
+ }
+
+ }
+
+ /**
+ * Create when gateway application is Zuul.
+ */
+ @Configuration
+ @ConditionalOnClass(name = "com.netflix.zuul.http.ZuulServlet")
+ static class MetadataZuulFilterConfig {
+
+ @Bean
+ public ZuulFilter metadataFirstZuulFilter() {
+ return new MetadataFirstZuulFilter();
+ }
+
+ }
+
+ /**
+ * Create when gateway application is SCG.
+ */
+ @Configuration
+ @ConditionalOnClass(name = "org.springframework.cloud.gateway.filter.GlobalFilter")
+ static class MetadataScgFilterConfig {
+
+ @Bean
+ public GlobalFilter metadataFirstScgFilter() {
+ return new MetadataFirstScgFilter();
+ }
+
+ }
+
+}
diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataLocalProperties.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/config/MetadataLocalProperties.java
similarity index 97%
rename from spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataLocalProperties.java
rename to spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/config/MetadataLocalProperties.java
index 249bb401b..e65a80ccd 100644
--- a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataLocalProperties.java
+++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/config/MetadataLocalProperties.java
@@ -15,7 +15,7 @@
* specific language governing permissions and limitations under the License.
*/
-package com.tencent.cloud.common.metadata;
+package com.tencent.cloud.common.metadata.config;
import java.util.ArrayList;
import java.util.HashMap;
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/scg/MetadataFirstScgFilter.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/filter/gateway/MetadataFirstScgFilter.java
similarity index 93%
rename from spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/scg/MetadataFirstScgFilter.java
rename to spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/filter/gateway/MetadataFirstScgFilter.java
index 6d014a755..13952a6c5 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/scg/MetadataFirstScgFilter.java
+++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/filter/gateway/MetadataFirstScgFilter.java
@@ -16,7 +16,7 @@
*
*/
-package com.tencent.cloud.metadata.core.filter.gateway.scg;
+package com.tencent.cloud.common.metadata.filter.gateway;
import com.tencent.cloud.common.constant.MetadataConstant;
import com.tencent.cloud.common.metadata.MetadataContext;
@@ -57,12 +57,14 @@ public class MetadataFirstScgFilter implements GlobalFilter, Ordered {
// get metadata of current thread
MetadataContext metadataContext = exchange
.getAttribute(MetadataConstant.HeaderName.METADATA_CONTEXT);
+ if (metadataContext == null) {
+ metadataContext = MetadataContextHolder.get();
+ }
// TODO The peer namespace is temporarily the same as the local namespace
metadataContext.putSystemMetadata(
MetadataConstant.SystemMetadataKey.PEER_NAMESPACE,
- MetadataContextHolder.get().getSystemMetadata(
- MetadataConstant.SystemMetadataKey.LOCAL_NAMESPACE));
+ MetadataContext.LOCAL_NAMESPACE);
metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_SERVICE,
route.getId());
metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_PATH,
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/zuul/MetadataFirstZuulFilter.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/filter/gateway/MetadataFirstZuulFilter.java
similarity index 93%
rename from spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/zuul/MetadataFirstZuulFilter.java
rename to spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/filter/gateway/MetadataFirstZuulFilter.java
index 542826d83..acb2acc87 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/gateway/zuul/MetadataFirstZuulFilter.java
+++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/filter/gateway/MetadataFirstZuulFilter.java
@@ -14,11 +14,12 @@
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
-package com.tencent.cloud.metadata.core.filter.gateway.zuul;
+package com.tencent.cloud.common.metadata.filter.gateway;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.tencent.cloud.common.constant.MetadataConstant;
+import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.metadata.MetadataContextHolder;
import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_DECORATION_FILTER_ORDER;
@@ -56,8 +57,7 @@ public class MetadataFirstZuulFilter extends ZuulFilter {
// TODO The peer namespace is temporarily the same as the local namespace
MetadataContextHolder.get().putSystemMetadata(
MetadataConstant.SystemMetadataKey.PEER_NAMESPACE,
- MetadataContextHolder.get().getSystemMetadata(
- MetadataConstant.SystemMetadataKey.LOCAL_NAMESPACE));
+ MetadataContext.LOCAL_NAMESPACE);
MetadataContextHolder.get().putSystemMetadata(
MetadataConstant.SystemMetadataKey.PEER_SERVICE,
(String) requestContext.get(SERVICE_ID_KEY));
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/web/MetadataReactiveFilter.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/filter/web/MetadataReactiveFilter.java
similarity index 78%
rename from spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/web/MetadataReactiveFilter.java
rename to spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/filter/web/MetadataReactiveFilter.java
index c124f6a92..adbf4a780 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/web/MetadataReactiveFilter.java
+++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/filter/web/MetadataReactiveFilter.java
@@ -15,11 +15,10 @@
* specific language governing permissions and limitations under the License.
*/
-package com.tencent.cloud.metadata.core.filter.web;
+package com.tencent.cloud.common.metadata.filter.web;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
-import java.util.HashMap;
import java.util.Map;
import com.tencent.cloud.common.constant.MetadataConstant;
@@ -37,10 +36,6 @@ import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
-import static com.tencent.cloud.common.constant.MetadataConstant.SystemMetadataKey.LOCAL_NAMESPACE;
-import static com.tencent.cloud.common.constant.MetadataConstant.SystemMetadataKey.LOCAL_PATH;
-import static com.tencent.cloud.common.constant.MetadataConstant.SystemMetadataKey.LOCAL_SERVICE;
-
/**
* Filter used for storing the metadata from upstream temporarily when web application is
* REACTIVE.
@@ -54,7 +49,7 @@ public class MetadataReactiveFilter implements WebFilter, Ordered {
@Override
public int getOrder() {
- return MetadataConstant.OrderConstant.FILTER_ORDER;
+ return MetadataConstant.OrderConstant.WEB_FILTER_ORDER;
}
@Override
@@ -79,13 +74,7 @@ public class MetadataReactiveFilter implements WebFilter, Ordered {
Map upstreamCustomMetadataMap = JacksonUtils
.deserialize2Map(customMetadataStr);
- // create system metadata.
- Map systemMetadataMap = new HashMap<>();
- systemMetadataMap.put(LOCAL_NAMESPACE, MetadataContextHolder.LOCAL_NAMESPACE);
- systemMetadataMap.put(LOCAL_SERVICE, MetadataContextHolder.LOCAL_SERVICE);
- systemMetadataMap.put(LOCAL_PATH, serverHttpRequest.getURI().getPath());
-
- MetadataContextHolder.init(upstreamCustomMetadataMap, systemMetadataMap);
+ MetadataContextHolder.init(upstreamCustomMetadataMap, null);
// Save to ServerWebExchange.
serverWebExchange.getAttributes().put(
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/web/MetadataServletFilter.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/filter/web/MetadataServletFilter.java
similarity index 76%
rename from spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/web/MetadataServletFilter.java
rename to spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/filter/web/MetadataServletFilter.java
index 8cb8be6aa..018313ec4 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/filter/web/MetadataServletFilter.java
+++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/filter/web/MetadataServletFilter.java
@@ -15,12 +15,11 @@
* specific language governing permissions and limitations under the License.
*/
-package com.tencent.cloud.metadata.core.filter.web;
+package com.tencent.cloud.common.metadata.filter.web;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
-import java.util.HashMap;
import java.util.Map;
import javax.servlet.FilterChain;
@@ -38,17 +37,13 @@ import org.springframework.core.annotation.Order;
import org.springframework.util.StringUtils;
import org.springframework.web.filter.OncePerRequestFilter;
-import static com.tencent.cloud.common.constant.MetadataConstant.SystemMetadataKey.LOCAL_NAMESPACE;
-import static com.tencent.cloud.common.constant.MetadataConstant.SystemMetadataKey.LOCAL_PATH;
-import static com.tencent.cloud.common.constant.MetadataConstant.SystemMetadataKey.LOCAL_SERVICE;
-
/**
* Filter used for storing the metadata from upstream temporarily when web application is
* SERVLET.
*
* @author Haotian Zhang
*/
-@Order(MetadataConstant.OrderConstant.FILTER_ORDER)
+@Order(MetadataConstant.OrderConstant.WEB_FILTER_ORDER)
public class MetadataServletFilter extends OncePerRequestFilter {
private static final Logger LOG = LoggerFactory
@@ -75,14 +70,8 @@ public class MetadataServletFilter extends OncePerRequestFilter {
Map upstreamCustomMetadataMap = JacksonUtils
.deserialize2Map(customMetadataStr);
- // create system metadata.
- Map systemMetadataMap = new HashMap<>();
- systemMetadataMap.put(LOCAL_NAMESPACE, MetadataContextHolder.LOCAL_NAMESPACE);
- systemMetadataMap.put(LOCAL_SERVICE, MetadataContextHolder.LOCAL_SERVICE);
- systemMetadataMap.put(LOCAL_PATH, httpServletRequest.getRequestURI());
-
try {
- MetadataContextHolder.init(upstreamCustomMetadataMap, systemMetadataMap);
+ MetadataContextHolder.init(upstreamCustomMetadataMap, null);
filterChain.doFilter(httpServletRequest, httpServletResponse);
}
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/feign/MetadataFirstFeignInterceptor.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/interceptor/feign/MetadataFirstFeignInterceptor.java
similarity index 87%
rename from spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/feign/MetadataFirstFeignInterceptor.java
rename to spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/interceptor/feign/MetadataFirstFeignInterceptor.java
index 168f45b82..01df01711 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/feign/MetadataFirstFeignInterceptor.java
+++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/interceptor/feign/MetadataFirstFeignInterceptor.java
@@ -15,7 +15,7 @@
* specific language governing permissions and limitations under the License.
*/
-package com.tencent.cloud.metadata.core.interceptor.feign;
+package com.tencent.cloud.common.metadata.interceptor.feign;
import com.tencent.cloud.common.constant.MetadataConstant;
import com.tencent.cloud.common.metadata.MetadataContext;
@@ -43,10 +43,8 @@ public class MetadataFirstFeignInterceptor implements RequestInterceptor, Ordere
MetadataContext metadataContext = MetadataContextHolder.get();
// TODO The peer namespace is temporarily the same as the local namespace
- metadataContext.putSystemMetadata(
- MetadataConstant.SystemMetadataKey.PEER_NAMESPACE,
- MetadataContextHolder.get().getSystemMetadata(
- MetadataConstant.SystemMetadataKey.LOCAL_NAMESPACE));
+ metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_NAMESPACE,
+ MetadataContext.LOCAL_NAMESPACE);
metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_SERVICE,
requestTemplate.feignTarget().name());
metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_PATH,
diff --git a/spring-cloud-tencent-commons/src/main/resources/META-INF/spring.factories b/spring-cloud-tencent-commons/src/main/resources/META-INF/spring.factories
index 2dcb0b913..ba9f2b867 100644
--- a/spring-cloud-tencent-commons/src/main/resources/META-INF/spring.factories
+++ b/spring-cloud-tencent-commons/src/main/resources/META-INF/spring.factories
@@ -1,3 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.cloud.common.util.ApplicationContextAwareUtils,\
- com.tencent.cloud.common.metadata.MetadataAutoConfiguration
+ com.tencent.cloud.common.metadata.config.MetadataAutoConfiguration
diff --git a/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/MetadataAutoConfigurationTest.java b/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/MetadataAutoConfigurationTest.java
deleted file mode 100644
index e10d5a269..000000000
--- a/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/MetadataAutoConfigurationTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
- *
- * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
- *
- * Licensed under the BSD 3-Clause License (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/BSD-3-Clause
- *
- * Unless required by applicable law or agreed to in writing, software distributed
- * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations under the License.
- */
-
-package com.tencent.cloud.common.metadata;
-
-import org.assertj.core.api.Assertions;
-import org.junit.Test;
-
-import org.springframework.boot.autoconfigure.AutoConfigurations;
-import org.springframework.boot.test.context.runner.ApplicationContextRunner;
-
-/**
- * Test for {@link MetadataAutoConfiguration}
- *
- * @author Haotian Zhang
- */
-public class MetadataAutoConfigurationTest {
-
- private final ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner();
-
- @Test
- public void test1() {
- this.applicationContextRunner
- .withConfiguration(AutoConfigurations.of(MetadataAutoConfiguration.class))
- .run(context -> {
- Assertions.assertThat(context)
- .hasSingleBean(MetadataLocalProperties.class);
- });
- }
-
-}
diff --git a/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/MetadataContextHolderTest.java b/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/MetadataContextHolderTest.java
index 0230bd270..6883ae50d 100644
--- a/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/MetadataContextHolderTest.java
+++ b/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/MetadataContextHolderTest.java
@@ -28,8 +28,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
-import static com.tencent.cloud.common.constant.MetadataConstant.SystemMetadataKey.LOCAL_NAMESPACE;
-
/**
* Test for {@link MetadataContextHolder}
*
@@ -61,21 +59,19 @@ public class MetadataContextHolderTest {
customMetadata.put("b", "22");
customMetadata.put("c", "3");
Map systemMetadata = new HashMap<>();
- systemMetadata.put(LOCAL_NAMESPACE, "namespace");
MetadataContextHolder.init(customMetadata, systemMetadata);
metadataContext = MetadataContextHolder.get();
customMetadata = metadataContext.getAllTransitiveCustomMetadata();
- systemMetadata = metadataContext.getAllSystemMetadata();
Assertions.assertThat(customMetadata.get("a")).isEqualTo("1");
Assertions.assertThat(customMetadata.get("b")).isEqualTo("22");
Assertions.assertThat(customMetadata.get("c")).isEqualTo("3");
- Assertions.assertThat(systemMetadata.get(LOCAL_NAMESPACE)).isEqualTo("namespace");
+ Assertions.assertThat(MetadataContext.LOCAL_NAMESPACE).isEqualTo("default");
}
@Test
public void test2() {
- Assertions.assertThat(MetadataContextHolder.LOCAL_NAMESPACE).isEqualTo("default");
- Assertions.assertThat(MetadataContextHolder.LOCAL_SERVICE).isEqualTo("test");
+ Assertions.assertThat(MetadataContext.LOCAL_NAMESPACE).isEqualTo("default");
+ Assertions.assertThat(MetadataContext.LOCAL_SERVICE).isEqualTo("test");
}
@SpringBootApplication
diff --git a/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/config/MetadataAutoConfigurationTest.java b/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/config/MetadataAutoConfigurationTest.java
new file mode 100644
index 000000000..8b871c174
--- /dev/null
+++ b/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/config/MetadataAutoConfigurationTest.java
@@ -0,0 +1,145 @@
+/*
+ * Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
+ *
+ * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
+ *
+ * Licensed under the BSD 3-Clause License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed
+ * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.tencent.cloud.common.metadata.config;
+
+import com.tencent.cloud.common.metadata.filter.gateway.MetadataFirstScgFilter;
+import com.tencent.cloud.common.metadata.filter.gateway.MetadataFirstZuulFilter;
+import com.tencent.cloud.common.metadata.filter.web.MetadataReactiveFilter;
+import com.tencent.cloud.common.metadata.filter.web.MetadataServletFilter;
+import com.tencent.cloud.common.metadata.interceptor.feign.MetadataFirstFeignInterceptor;
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
+import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
+
+/**
+ * Test for {@link MetadataAutoConfiguration}
+ *
+ * @author Haotian Zhang
+ */
+public class MetadataAutoConfigurationTest {
+
+ private final ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner();
+
+ private final WebApplicationContextRunner webApplicationContextRunner = new WebApplicationContextRunner();
+
+ private final ReactiveWebApplicationContextRunner reactiveWebApplicationContextRunner = new ReactiveWebApplicationContextRunner();
+
+ /**
+ * No any web application.
+ */
+ @Test
+ public void test1() {
+ this.applicationContextRunner
+ .withConfiguration(AutoConfigurations.of(MetadataAutoConfiguration.class))
+ .run(context -> {
+ Assertions.assertThat(context)
+ .hasSingleBean(MetadataLocalProperties.class);
+ Assertions.assertThat(context).doesNotHaveBean(
+ MetadataAutoConfiguration.MetadataServletFilterConfig.class);
+ Assertions.assertThat(context)
+ .doesNotHaveBean(MetadataServletFilter.class);
+ Assertions.assertThat(context).doesNotHaveBean(
+ MetadataAutoConfiguration.MetadataReactiveFilterConfig.class);
+ Assertions.assertThat(context)
+ .doesNotHaveBean(MetadataReactiveFilter.class);
+ Assertions.assertThat(context).hasSingleBean(
+ MetadataAutoConfiguration.MetadataFeignInterceptorConfig.class);
+ Assertions.assertThat(context)
+ .hasSingleBean(MetadataFirstFeignInterceptor.class);
+ Assertions.assertThat(context).hasSingleBean(
+ MetadataAutoConfiguration.MetadataZuulFilterConfig.class);
+ Assertions.assertThat(context)
+ .hasSingleBean(MetadataFirstZuulFilter.class);
+ Assertions.assertThat(context).hasSingleBean(
+ MetadataAutoConfiguration.MetadataScgFilterConfig.class);
+ Assertions.assertThat(context)
+ .hasSingleBean(MetadataFirstScgFilter.class);
+ });
+ }
+
+ /**
+ * web application.
+ */
+ @Test
+ public void test2() {
+ this.webApplicationContextRunner
+ .withConfiguration(AutoConfigurations.of(MetadataAutoConfiguration.class))
+ .run(context -> {
+ Assertions.assertThat(context)
+ .hasSingleBean(MetadataLocalProperties.class);
+ Assertions.assertThat(context).hasSingleBean(
+ MetadataAutoConfiguration.MetadataServletFilterConfig.class);
+ Assertions.assertThat(context)
+ .hasSingleBean(MetadataServletFilter.class);
+ Assertions.assertThat(context).doesNotHaveBean(
+ MetadataAutoConfiguration.MetadataReactiveFilterConfig.class);
+ Assertions.assertThat(context)
+ .doesNotHaveBean(MetadataReactiveFilter.class);
+ Assertions.assertThat(context).hasSingleBean(
+ MetadataAutoConfiguration.MetadataFeignInterceptorConfig.class);
+ Assertions.assertThat(context)
+ .hasSingleBean(MetadataFirstFeignInterceptor.class);
+ Assertions.assertThat(context).hasSingleBean(
+ MetadataAutoConfiguration.MetadataZuulFilterConfig.class);
+ Assertions.assertThat(context)
+ .hasSingleBean(MetadataFirstZuulFilter.class);
+ Assertions.assertThat(context).hasSingleBean(
+ MetadataAutoConfiguration.MetadataScgFilterConfig.class);
+ Assertions.assertThat(context)
+ .hasSingleBean(MetadataFirstScgFilter.class);
+ });
+ }
+
+ /**
+ * reactive web application.
+ */
+ @Test
+ public void test3() {
+ this.reactiveWebApplicationContextRunner
+ .withConfiguration(AutoConfigurations.of(MetadataAutoConfiguration.class))
+ .run(context -> {
+ Assertions.assertThat(context)
+ .hasSingleBean(MetadataLocalProperties.class);
+ Assertions.assertThat(context).doesNotHaveBean(
+ MetadataAutoConfiguration.MetadataServletFilterConfig.class);
+ Assertions.assertThat(context)
+ .doesNotHaveBean(MetadataServletFilter.class);
+ Assertions.assertThat(context).hasSingleBean(
+ MetadataAutoConfiguration.MetadataReactiveFilterConfig.class);
+ Assertions.assertThat(context)
+ .hasSingleBean(MetadataReactiveFilter.class);
+ Assertions.assertThat(context).hasSingleBean(
+ MetadataAutoConfiguration.MetadataFeignInterceptorConfig.class);
+ Assertions.assertThat(context)
+ .hasSingleBean(MetadataFirstFeignInterceptor.class);
+ Assertions.assertThat(context).hasSingleBean(
+ MetadataAutoConfiguration.MetadataZuulFilterConfig.class);
+ Assertions.assertThat(context)
+ .hasSingleBean(MetadataFirstZuulFilter.class);
+ Assertions.assertThat(context).hasSingleBean(
+ MetadataAutoConfiguration.MetadataScgFilterConfig.class);
+ Assertions.assertThat(context)
+ .hasSingleBean(MetadataFirstScgFilter.class);
+ });
+ }
+
+}
diff --git a/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/MetadataLocalPropertiesTest.java b/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/config/MetadataLocalPropertiesTest.java
similarity index 97%
rename from spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/MetadataLocalPropertiesTest.java
rename to spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/config/MetadataLocalPropertiesTest.java
index a7e6334f2..44128591c 100644
--- a/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/MetadataLocalPropertiesTest.java
+++ b/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/config/MetadataLocalPropertiesTest.java
@@ -15,7 +15,7 @@
* specific language governing permissions and limitations under the License.
*/
-package com.tencent.cloud.common.metadata;
+package com.tencent.cloud.common.metadata.config;
import org.assertj.core.api.Assertions;
import org.junit.Test;
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/filter/web/MetadataReactiveFilterTest.java b/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/filter/web/MetadataReactiveFilterTest.java
similarity index 93%
rename from spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/filter/web/MetadataReactiveFilterTest.java
rename to spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/filter/web/MetadataReactiveFilterTest.java
index 2a3f0b60d..d32fc77fd 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/filter/web/MetadataReactiveFilterTest.java
+++ b/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/filter/web/MetadataReactiveFilterTest.java
@@ -15,10 +15,10 @@
* specific language governing permissions and limitations under the License.
*/
-package com.tencent.cloud.metadata.core.filter.web;
+package com.tencent.cloud.common.metadata.filter.web;
import com.tencent.cloud.common.constant.MetadataConstant;
-import com.tencent.cloud.common.metadata.MetadataLocalProperties;
+import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
@@ -59,7 +59,7 @@ public class MetadataReactiveFilterTest {
@Test
public void test1() {
Assertions.assertThat(this.metadataReactiveFilter.getOrder())
- .isEqualTo(MetadataConstant.OrderConstant.FILTER_ORDER);
+ .isEqualTo(MetadataConstant.OrderConstant.WEB_FILTER_ORDER);
}
@Test
diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/filter/web/MetadataServletFilterTest.java b/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/filter/web/MetadataServletFilterTest.java
similarity index 95%
rename from spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/filter/web/MetadataServletFilterTest.java
rename to spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/filter/web/MetadataServletFilterTest.java
index eacfca5a9..7b6db59b4 100644
--- a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/filter/web/MetadataServletFilterTest.java
+++ b/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/filter/web/MetadataServletFilterTest.java
@@ -15,7 +15,7 @@
* specific language governing permissions and limitations under the License.
*/
-package com.tencent.cloud.metadata.core.filter.web;
+package com.tencent.cloud.common.metadata.filter.web;
import java.io.IOException;
@@ -23,7 +23,7 @@ import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import com.tencent.cloud.common.constant.MetadataConstant;
-import com.tencent.cloud.common.metadata.MetadataLocalProperties;
+import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-cloud-tencent-commons/src/test/resources/application-test.yml b/spring-cloud-tencent-commons/src/test/resources/application-test.yml
index 40f87a6b9..f0b649a0c 100644
--- a/spring-cloud-tencent-commons/src/test/resources/application-test.yml
+++ b/spring-cloud-tencent-commons/src/test/resources/application-test.yml
@@ -1,6 +1,10 @@
spring:
application:
name: test
+ autoconfigure:
+ exclude:
+ - org.springframework.cloud.gateway.config.GatewayAutoConfiguration
+ - org.springframework.cloud.netflix.zuul.ZuulServerAutoConfiguration
cloud:
tencent:
metadata:
diff --git a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/pom.xml b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/pom.xml
index 26e2ac4b3..5975aabc5 100644
--- a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/pom.xml
+++ b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/pom.xml
@@ -1,22 +1,19 @@
-
- polaris-circuitbreaker-example
- com.tencent.cloud
- ${revision}
- ../pom.xml
-
- 4.0.0
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ polaris-circuitbreaker-example
+ com.tencent.cloud
+ ${revision}
+ ../pom.xml
+
+ 4.0.0
- polaris-circuitbreaker-example-a
+ polaris-circuitbreaker-example-a
+ Polaris Circuit Breaker Example A
-
- 1.8
-
-
-
+
org.springframework.boot
spring-boot-starter-web
@@ -26,6 +23,16 @@
com.tencent.cloud
spring-cloud-starter-tencent-polaris-circuitbreaker
+
+
+ org.springframework.cloud
+ spring-cloud-starter-openfeign
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-netflix-ribbon
+
diff --git a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/pom.xml b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/pom.xml
index 61e33c456..22f3537b9 100644
--- a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/pom.xml
+++ b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/pom.xml
@@ -11,12 +11,9 @@
4.0.0
polaris-circuitbreaker-example-b
+ Polaris Circuit Breaker Example B
-
- 1.8
-
-
-
+
org.springframework.boot
spring-boot-starter-webflux
@@ -51,5 +48,4 @@
-
\ No newline at end of file
diff --git a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/src/main/java/com/tencent/cloud/polaris/circuitbreaker/example/ServiceBController.java b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/src/main/java/com/tencent/cloud/polaris/circuitbreaker/example/ServiceBController.java
index 6fed9f152..edcef56e7 100644
--- a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/src/main/java/com/tencent/cloud/polaris/circuitbreaker/example/ServiceBController.java
+++ b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/src/main/java/com/tencent/cloud/polaris/circuitbreaker/example/ServiceBController.java
@@ -31,7 +31,7 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/example/service/b")
public class ServiceBController {
- @Value("${is-throw-runtime-exception:#{true}}")
+ @Value("${is-throw-runtime-exception:#{false}}")
private boolean isThrowRuntimeException;
/**
diff --git a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/pom.xml b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/pom.xml
index 6e26c6507..115e40e5f 100644
--- a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/pom.xml
+++ b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/pom.xml
@@ -11,6 +11,7 @@
4.0.0
polaris-circuitbreaker-example
+ Polaris Circuit Breaker Example
pom
@@ -20,18 +21,8 @@
- spring-cloud-starter-tencent-polaris-discovery
com.tencent.cloud
-
-
-
- org.springframework.cloud
- spring-cloud-starter-openfeign
-
-
-
- org.springframework.cloud
- spring-cloud-starter-netflix-ribbon
+ spring-cloud-starter-tencent-polaris-discovery
diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/java/com/tencent/cloud/polaris/discovery/service/callee/DiscoveryCalleeController.java b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/java/com/tencent/cloud/polaris/discovery/service/callee/DiscoveryCalleeController.java
index 13793d25e..408469223 100644
--- a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/java/com/tencent/cloud/polaris/discovery/service/callee/DiscoveryCalleeController.java
+++ b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/java/com/tencent/cloud/polaris/discovery/service/callee/DiscoveryCalleeController.java
@@ -17,6 +17,10 @@
package com.tencent.cloud.polaris.discovery.service.callee;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@@ -31,13 +35,19 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/discovery/service/callee")
public class DiscoveryCalleeController {
+ private static Logger LOG = LoggerFactory.getLogger(DiscoveryCalleeController.class);
+
+ @Value("${server.port:0}")
+ private int port;
+
/**
* Get information of callee.
* @return information of callee
*/
@GetMapping("/info")
public String info() {
- return "Discovery Service Callee";
+ LOG.info("Discovery Service Callee [{}] is called.", port);
+ return String.format("Discovery Service Callee [%s] is called.", port);
}
/**
@@ -48,6 +58,7 @@ public class DiscoveryCalleeController {
*/
@GetMapping("/sum")
public int sum(@RequestParam int value1, @RequestParam int value2) {
+ LOG.info("Discovery Service Callee is called and sum is {}.", value1 + value2);
return value1 + value2;
}
diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/polaris.yml b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/polaris.yml
index 15028a106..8be155671 100644
--- a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/polaris.yml
+++ b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/polaris.yml
@@ -1,3 +1,9 @@
+global:
+ system:
+ discoverCluster:
+ sameAsBuiltin: true
+ healthCheckCluster:
+ sameAsBuiltin: true
#global:
# system:
# discoverCluster:
diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/pom.xml b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/pom.xml
index df6a387bf..c8bfaf0cf 100644
--- a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/pom.xml
+++ b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/pom.xml
@@ -23,21 +23,21 @@
spring-cloud-starter-tencent-polaris-discovery
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
-
-
-
-
-
+
+ com.tencent.cloud
+ spring-cloud-starter-tencent-polaris-router
+
+
diff --git a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/pom.xml b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/pom.xml
index 32c823cd4..4cb4412c6 100644
--- a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/pom.xml
+++ b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/pom.xml
@@ -19,11 +19,6 @@
spring-cloud-starter-tencent-polaris-discovery
-
- com.tencent.cloud
- spring-cloud-starter-tencent-metadata-transfer
-
-
org.springframework.boot
spring-boot-starter-web
diff --git a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/src/main/java/com/tencent/cloud/polaris/gateway/example/callee/GatewayCalleeController.java b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/src/main/java/com/tencent/cloud/polaris/gateway/example/callee/GatewayCalleeController.java
index 86015df6c..77f84f518 100644
--- a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/src/main/java/com/tencent/cloud/polaris/gateway/example/callee/GatewayCalleeController.java
+++ b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/src/main/java/com/tencent/cloud/polaris/gateway/example/callee/GatewayCalleeController.java
@@ -24,6 +24,7 @@ import com.tencent.cloud.common.constant.MetadataConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -37,7 +38,10 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/gateway/example/callee")
public class GatewayCalleeController {
- private static Logger logger = LoggerFactory.getLogger(GatewayCalleeController.class);
+ private static Logger LOG = LoggerFactory.getLogger(GatewayCalleeController.class);
+
+ @Value("${server.port:0}")
+ private int port;
/**
* Get information of callee.
@@ -45,7 +49,8 @@ public class GatewayCalleeController {
*/
@RequestMapping("/info")
public String info() {
- return "Gateway Example Callee";
+ LOG.info("Gateway Example Callee [{}] is called.", port);
+ return String.format("Gateway Example Callee [%s] is called.", port);
}
/**
@@ -55,7 +60,7 @@ public class GatewayCalleeController {
public String echoHeader(
@RequestHeader(MetadataConstant.HeaderName.CUSTOM_METADATA) String metadataStr)
throws UnsupportedEncodingException {
- logger.info(URLDecoder.decode(metadataStr, "UTF-8"));
+ LOG.info(URLDecoder.decode(metadataStr, "UTF-8"));
return URLDecoder.decode(metadataStr, "UTF-8");
}