commit
1f81434c33
6
spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/resttemplate/MetadataRestTemplateInterceptor.java → spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/Metadata2HeaderRestTemplateInterceptor.java
6
spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/resttemplate/MetadataRestTemplateInterceptor.java → spring-cloud-starter-tencent-metadata-transfer/src/main/java/com/tencent/cloud/metadata/core/interceptor/Metadata2HeaderRestTemplateInterceptor.java
16
spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/feign/Metadata2HeaderFeignInterceptorTest.java → spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/Metadata2HeaderFeignInterceptorTest.java
16
spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/feign/Metadata2HeaderFeignInterceptorTest.java → spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/Metadata2HeaderFeignInterceptorTest.java
17
spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/resttemplate/MetadataRestTemplateInterceptorTest.java → spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/Metadata2HeaderRestTemplateInterceptorTest.java
17
spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/resttemplate/MetadataRestTemplateInterceptorTest.java → spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/intercepter/Metadata2HeaderRestTemplateInterceptorTest.java
@ -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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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<MetadataServletFilter> metadataServletFilterRegistrationBean(
|
||||||
|
MetadataServletFilter metadataServletFilter) {
|
||||||
|
FilterRegistrationBean<MetadataServletFilter> 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,3 +1,3 @@
|
|||||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
com.tencent.cloud.common.util.ApplicationContextAwareUtils,\
|
com.tencent.cloud.common.util.ApplicationContextAwareUtils,\
|
||||||
com.tencent.cloud.common.metadata.MetadataAutoConfiguration
|
com.tencent.cloud.common.metadata.config.MetadataAutoConfiguration
|
||||||
|
@ -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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue