diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/actuate/DubboMetadataEndpointAutoConfiguration.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/actuate/DubboMetadataEndpointAutoConfiguration.java index ea3375269..d260f5d1d 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/actuate/DubboMetadataEndpointAutoConfiguration.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/actuate/DubboMetadataEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,8 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.actuate; +import com.alibaba.cloud.dubbo.actuate.endpoint.DubboRestMetadataEndpoint; + import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -23,15 +26,14 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; -import com.alibaba.cloud.dubbo.actuate.endpoint.DubboRestMetadataEndpoint; - /** - * Dubbo Metadata Endpoints Auto-{@link Configuration} + * Dubbo Metadata Endpoints Auto-{@link Configuration}. * * @author Mercy */ -@ConditionalOnClass(name = "org.springframework.boot.actuate.endpoint.annotation.Endpoint") -@PropertySource(value = "classpath:/META-INF/dubbo/default/actuator-endpoints.properties") +@ConditionalOnClass( + name = "org.springframework.boot.actuate.endpoint.annotation.Endpoint") +@PropertySource("classpath:/META-INF/dubbo/default/actuator-endpoints.properties") @ManagementContextConfiguration public class DubboMetadataEndpointAutoConfiguration { @@ -41,4 +43,5 @@ public class DubboMetadataEndpointAutoConfiguration { public DubboRestMetadataEndpoint dubboRestMetadataEndpoint() { return new DubboRestMetadataEndpoint(); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/actuate/endpoint/DubboRestMetadataEndpoint.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/actuate/endpoint/DubboRestMetadataEndpoint.java index a0cdcbea5..e46a82bec 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/actuate/endpoint/DubboRestMetadataEndpoint.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/actuate/endpoint/DubboRestMetadataEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,18 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.actuate.endpoint; -import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE; +import com.alibaba.cloud.dubbo.service.DubboMetadataService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; -import com.alibaba.cloud.dubbo.service.DubboMetadataService; +import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE; /** - * Dubbo Rest Metadata {@link Endpoint} + * Dubbo Rest Metadata {@link Endpoint}. * * @author Mercy */ @@ -38,4 +39,5 @@ public class DubboRestMetadataEndpoint { public String get() { return dubboMetadataService.getServiceRestMetadata(); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/annotation/DubboTransported.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/annotation/DubboTransported.java index 687eed51d..c8c61700a 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/annotation/DubboTransported.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/annotation/DubboTransported.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.annotation; -import static org.apache.dubbo.rpc.cluster.Constants.DEFAULT_RETRIES; +package com.alibaba.cloud.dubbo.annotation; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; @@ -26,10 +25,13 @@ import java.lang.annotation.Target; import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.rpc.ExporterListener; import org.apache.dubbo.rpc.Filter; + import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.client.RestTemplate; +import static org.apache.dubbo.rpc.cluster.Constants.DEFAULT_RETRIES; + /** * {@link DubboTransported @DubboTransported} annotation indicates that the traditional * Spring Cloud Service-to-Service call is transported by Dubbo under the hood, there are @@ -55,99 +57,108 @@ import org.springframework.web.client.RestTemplate; * @see LoadBalanced */ @Retention(RetentionPolicy.RUNTIME) -@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, +@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER }) @Documented public @interface DubboTransported { /** * The protocol of Dubbo transport whose value could be used the placeholder - * "dubbo.transport.protocol" - * + * "dubbo.transport.protocol". * @return the default protocol is "dubbo" */ String protocol() default "${dubbo.transport.protocol:dubbo}"; /** * The cluster of Dubbo transport whose value could be used the placeholder - * "dubbo.transport.cluster" - * + * "dubbo.transport.cluster". * @return the default cluster is "failover" */ String cluster() default "${dubbo.transport.cluster:failover}"; /** * Whether to reconnect if connection is lost, if not specify, reconnect is enabled by - * default, and the interval for retry connecting is 2000 ms + * default, and the interval for retry connecting is 2000 ms. * * @see Reference#reconnect() + * @return reconnect time */ String reconnect() default "${dubbo.transport.reconnect:2000}"; /** * Maximum connections service provider can accept, default value is 0 - connection is - * shared + * shared. * * @see Reference#connections() + * @return maximum connections */ int connections() default 0; /** - * Service invocation retry times + * Service invocation retry times. * * @see Reference#retries() + * @return retry times */ int retries() default DEFAULT_RETRIES; /** - * Load balance strategy, legal values include: random, roundrobin, leastactive + * Load balance strategy, legal values include: random, roundrobin, leastactive. * * @see Reference#loadbalance() + * @return load balance strategy */ String loadbalance() default "${dubbo.transport.loadbalance:}"; /** - * Maximum active requests allowed, default value is 0 + * Maximum active requests allowed, default value is 0. * * @see Reference#actives() + * @return maximum active requests */ int actives() default 0; /** - * Timeout value for service invocation, default value is 0 + * Timeout value for service invocation, default value is 0. * * @see Reference#timeout() + * @return timeout for service invocation */ int timeout() default 0; /** * Specify cache implementation for service invocation, legal values include: lru, - * threadlocal, jcache + * threadlocal, jcache. * * @see Reference#cache() + * @return specify cache implementation for service invocation */ String cache() default "${dubbo.transport.cache:}"; /** - * Filters for service invocation + * Filters for service invocation. * * @see Filter * @see Reference#filter() + * @return filters for service invocation */ String[] filter() default {}; /** - * Listeners for service exporting and unexporting + * Listeners for service exporting and unexporting. * * @see ExporterListener * @see Reference#listener() + * @return listener */ String[] listener() default {}; /** - * Customized parameter key-value pair, for example: {key1, value1, key2, value2} + * Customized parameter key-value pair, for example: {key1, value1, key2, value2}. * * @see Reference#parameters() + * @return parameters */ String[] parameters() default {}; + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboLoadBalancedRestTemplateAutoConfiguration.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboLoadBalancedRestTemplateAutoConfiguration.java index b1a75923c..23b7987d4 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboLoadBalancedRestTemplateAutoConfiguration.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboLoadBalancedRestTemplateAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,9 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.autoconfigure; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import com.alibaba.cloud.dubbo.annotation.DubboTransported; +import com.alibaba.cloud.dubbo.client.loadbalancer.DubboMetadataInitializerInterceptor; +import com.alibaba.cloud.dubbo.client.loadbalancer.DubboTransporterInterceptor; +import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; +import com.alibaba.cloud.dubbo.metadata.resolver.DubboTransportedAttributesResolver; +import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContextFactory; +import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.SmartInitializingSingleton; @@ -41,17 +54,9 @@ import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.web.client.RestTemplate; -import com.alibaba.cloud.dubbo.annotation.DubboTransported; -import com.alibaba.cloud.dubbo.client.loadbalancer.DubboMetadataInitializerInterceptor; -import com.alibaba.cloud.dubbo.client.loadbalancer.DubboTransporterInterceptor; -import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; -import com.alibaba.cloud.dubbo.metadata.resolver.DubboTransportedAttributesResolver; -import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContextFactory; -import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory; - /** * Dubbo Auto-{@link Configuration} for {@link LoadBalanced @LoadBalanced} - * {@link RestTemplate} + * {@link RestTemplate}. * * @author Mercy */ @@ -99,15 +104,14 @@ public class DubboLoadBalancedRestTemplateAutoConfiguration implements /** * The {@link ClientHttpRequestInterceptor} bean that may be - * {@link LoadBalancerInterceptor} or {@link RetryLoadBalancerInterceptor} + * {@link LoadBalancerInterceptor} or {@link RetryLoadBalancerInterceptor}. */ private ClientHttpRequestInterceptor loadBalancerInterceptorBean; @Override public void afterSingletonsInstantiated() { loadBalancerInterceptorBean = retryLoadBalancerInterceptor != null - ? retryLoadBalancerInterceptor - : loadBalancerInterceptor; + ? retryLoadBalancerInterceptor : loadBalancerInterceptor; } /** @@ -115,7 +119,8 @@ public class DubboLoadBalancedRestTemplateAutoConfiguration implements * {@link LoadBalanced @LoadBalanced} and {@link LoadBalanced @LoadBalanced} when * Spring Boot application started (after the callback of * {@link SmartInitializingSingleton} beans or - * {@link RestTemplateCustomizer#customize(RestTemplate) customization}) + * {@link RestTemplateCustomizer#customize(RestTemplate) customization}). + * @param event spring event */ @EventListener(ContextRefreshedEvent.class) public void adaptRestTemplates(ContextRefreshedEvent event) { @@ -138,10 +143,9 @@ public class DubboLoadBalancedRestTemplateAutoConfiguration implements /** * Gets the annotation attributes {@link RestTemplate} bean being annotated - * {@link DubboTransported @DubboTransported} - * + * {@link DubboTransported @DubboTransported}. * @param beanName the bean name of {@link LoadBalanced @LoadBalanced} - * {@link RestTemplate} + * {@link RestTemplate} * @param attributesResolver {@link DubboTransportedAttributesResolver} * @return non-null {@link Map} */ @@ -164,11 +168,10 @@ public class DubboLoadBalancedRestTemplateAutoConfiguration implements /** * Adapt the instance of {@link DubboTransporterInterceptor} to the * {@link LoadBalancerInterceptor} Bean. - * * @param restTemplate {@link LoadBalanced @LoadBalanced} {@link RestTemplate} Bean * @param dubboTranslatedAttributes the annotation dubboTranslatedAttributes - * {@link RestTemplate} bean being annotated - * {@link DubboTransported @DubboTransported} + * {@link RestTemplate} bean being annotated + * {@link DubboTransported @DubboTransported} */ private void adaptRestTemplate(RestTemplate restTemplate, Map dubboTranslatedAttributes) { diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboMetadataAutoConfiguration.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboMetadataAutoConfiguration.java index 086e4f6e0..5b1cddf7f 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboMetadataAutoConfiguration.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboMetadataAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,15 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.autoconfigure; import java.util.Collection; import java.util.Optional; import java.util.function.Supplier; +import com.alibaba.cloud.dubbo.metadata.DubboProtocolConfigSupplier; +import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; +import com.alibaba.cloud.dubbo.metadata.repository.MetadataServiceInstanceSelector; +import com.alibaba.cloud.dubbo.metadata.resolver.DubboServiceBeanMetadataResolver; +import com.alibaba.cloud.dubbo.metadata.resolver.MetadataResolver; +import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory; +import com.alibaba.cloud.dubbo.service.DubboMetadataServiceExporter; +import com.alibaba.cloud.dubbo.service.DubboMetadataServiceProxy; +import com.alibaba.cloud.dubbo.service.IntrospectiveDubboMetadataService; +import com.alibaba.cloud.dubbo.util.JSONUtils; +import feign.Contract; import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.spring.ServiceBean; import org.apache.dubbo.config.spring.context.event.ServiceBeanExportedEvent; + import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -33,21 +46,8 @@ import org.springframework.context.event.ContextClosedEvent; import org.springframework.context.event.EventListener; import org.springframework.util.CollectionUtils; -import com.alibaba.cloud.dubbo.metadata.DubboProtocolConfigSupplier; -import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; -import com.alibaba.cloud.dubbo.metadata.repository.MetadataServiceInstanceSelector; -import com.alibaba.cloud.dubbo.metadata.resolver.DubboServiceBeanMetadataResolver; -import com.alibaba.cloud.dubbo.metadata.resolver.MetadataResolver; -import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory; -import com.alibaba.cloud.dubbo.service.DubboMetadataServiceExporter; -import com.alibaba.cloud.dubbo.service.DubboMetadataServiceProxy; -import com.alibaba.cloud.dubbo.service.IntrospectiveDubboMetadataService; -import com.alibaba.cloud.dubbo.util.JSONUtils; - -import feign.Contract; - /** - * Spring Boot Auto-Configuration class for Dubbo Metadata + * Spring Boot Auto-Configuration class for Dubbo Metadata. * * @author Mercy */ @@ -75,8 +75,7 @@ public class DubboMetadataAutoConfiguration { @ConditionalOnMissingBean public MetadataServiceInstanceSelector metadataServiceInstanceSelector() { return serviceInstances -> CollectionUtils.isEmpty(serviceInstances) - ? Optional.empty() - : serviceInstances.stream().findAny(); + ? Optional.empty() : serviceInstances.stream().findAny(); } @Bean @@ -118,4 +117,5 @@ public class DubboMetadataAutoConfiguration { private void unExportDubboMetadataConfigService() { dubboMetadataConfigServiceExporter.unexport(); } -} \ No newline at end of file + +} diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboOpenFeignAutoConfiguration.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboOpenFeignAutoConfiguration.java index 0284aaa70..e378e7537 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboOpenFeignAutoConfiguration.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboOpenFeignAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,9 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.autoconfigure; -import static com.alibaba.cloud.dubbo.autoconfigure.DubboOpenFeignAutoConfiguration.TARGETER_CLASS_NAME; +import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; +import com.alibaba.cloud.dubbo.openfeign.TargeterBeanPostProcessor; +import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContextFactory; +import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -23,22 +27,22 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; -import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; -import com.alibaba.cloud.dubbo.openfeign.TargeterBeanPostProcessor; -import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContextFactory; -import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory; +import static com.alibaba.cloud.dubbo.autoconfigure.DubboOpenFeignAutoConfiguration.TARGETER_CLASS_NAME; /** - * Dubbo Feign Auto-{@link Configuration Configuration} + * Dubbo Feign Auto-{@link Configuration Configuration}. * * @author Mercy */ @ConditionalOnClass(name = { "feign.Feign", TARGETER_CLASS_NAME }) -@AutoConfigureAfter(name = { - "org.springframework.cloud.openfeign.FeignAutoConfiguration" }) +@AutoConfigureAfter( + name = { "org.springframework.cloud.openfeign.FeignAutoConfiguration" }) @Configuration public class DubboOpenFeignAutoConfiguration { + /** + * OpenFeign Targeter class name. + */ public static final String TARGETER_CLASS_NAME = "org.springframework.cloud.openfeign.Targeter"; @Bean @@ -50,4 +54,4 @@ public class DubboOpenFeignAutoConfiguration { dubboGenericServiceFactory, contextFactory); } -} \ No newline at end of file +} diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboServiceAutoConfiguration.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboServiceAutoConfiguration.java index b303f8cd5..1e9fe56f2 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboServiceAutoConfiguration.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboServiceAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,8 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.autoconfigure; +import com.alibaba.cloud.dubbo.env.DubboCloudProperties; +import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContextFactory; +import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory; +import com.alibaba.cloud.dubbo.service.parameter.PathVariableServiceParameterResolver; +import com.alibaba.cloud.dubbo.service.parameter.RequestBodyServiceParameterResolver; +import com.alibaba.cloud.dubbo.service.parameter.RequestHeaderServiceParameterResolver; +import com.alibaba.cloud.dubbo.service.parameter.RequestParamServiceParameterResolver; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -25,16 +34,8 @@ import org.springframework.context.annotation.Primary; import org.springframework.core.env.Environment; import org.springframework.core.env.PropertyResolver; -import com.alibaba.cloud.dubbo.env.DubboCloudProperties; -import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContextFactory; -import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory; -import com.alibaba.cloud.dubbo.service.parameter.PathVariableServiceParameterResolver; -import com.alibaba.cloud.dubbo.service.parameter.RequestBodyServiceParameterResolver; -import com.alibaba.cloud.dubbo.service.parameter.RequestHeaderServiceParameterResolver; -import com.alibaba.cloud.dubbo.service.parameter.RequestParamServiceParameterResolver; - /** - * Spring Boot Auto-Configuration class for Dubbo Service + * Spring Boot Auto-Configuration class for Dubbo Service. * * @author Mercy */ @@ -49,8 +50,7 @@ public class DubboServiceAutoConfiguration { } /** - * Build a primary {@link PropertyResolver} bean to {@link Autowired @Autowired} - * + * Build a primary {@link PropertyResolver} bean to {@link Autowired @Autowired}. * @param environment {@link Environment} * @return alias bean for {@link Environment} */ @@ -61,11 +61,13 @@ public class DubboServiceAutoConfiguration { } @Configuration - @Import(value = { DubboGenericServiceExecutionContextFactory.class, + @Import({ DubboGenericServiceExecutionContextFactory.class, RequestParamServiceParameterResolver.class, RequestBodyServiceParameterResolver.class, RequestHeaderServiceParameterResolver.class, PathVariableServiceParameterResolver.class }) static class ParameterResolversConfiguration { + } -} \ No newline at end of file + +} diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboServiceDiscoveryAutoConfiguration.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboServiceDiscoveryAutoConfiguration.java index 0211a7a99..ee1804b5b 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboServiceDiscoveryAutoConfiguration.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboServiceDiscoveryAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,14 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.autoconfigure; -import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceDiscoveryAutoConfiguration.CONSUL_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME; -import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceDiscoveryAutoConfiguration.NACOS_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME; -import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceDiscoveryAutoConfiguration.ZOOKEEPER_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME; -import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME; -import static com.alibaba.cloud.nacos.discovery.NacosDiscoveryClient.hostToServiceInstanceList; -import static org.springframework.util.StringUtils.hasText; +package com.alibaba.cloud.dubbo.autoconfigure; import java.util.Collection; import java.util.LinkedList; @@ -33,7 +27,19 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Predicate; import java.util.stream.Stream; +import com.alibaba.cloud.dubbo.env.DubboCloudProperties; +import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; +import com.alibaba.cloud.dubbo.registry.AbstractSpringCloudRegistry; +import com.alibaba.cloud.dubbo.registry.event.ServiceInstancesChangedEvent; +import com.alibaba.cloud.dubbo.registry.event.SubscribedServicesChangedEvent; +import com.alibaba.cloud.nacos.NacosDiscoveryProperties; import com.alibaba.cloud.nacos.NacosNamingManager; +import com.alibaba.cloud.nacos.discovery.NacosWatch; +import com.alibaba.nacos.api.exception.NacosException; +import com.alibaba.nacos.api.naming.NamingService; +import com.alibaba.nacos.api.naming.listener.NamingEvent; +import com.netflix.discovery.CacheRefreshedEvent; +import com.netflix.discovery.shared.Applications; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.listen.Listenable; import org.apache.curator.framework.listen.ListenerContainer; @@ -49,6 +55,7 @@ import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; @@ -72,23 +79,16 @@ import org.springframework.scheduling.TaskScheduler; import org.springframework.util.AntPathMatcher; import org.springframework.util.ReflectionUtils; -import com.alibaba.cloud.dubbo.env.DubboCloudProperties; -import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; -import com.alibaba.cloud.dubbo.registry.AbstractSpringCloudRegistry; -import com.alibaba.cloud.dubbo.registry.event.ServiceInstancesChangedEvent; -import com.alibaba.cloud.dubbo.registry.event.SubscribedServicesChangedEvent; -import com.alibaba.cloud.nacos.NacosDiscoveryProperties; -import com.alibaba.cloud.nacos.discovery.NacosWatch; -import com.alibaba.nacos.api.exception.NacosException; -import com.alibaba.nacos.api.naming.NamingService; -import com.alibaba.nacos.api.naming.listener.NamingEvent; - -import com.netflix.discovery.CacheRefreshedEvent; -import com.netflix.discovery.shared.Applications; +import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceDiscoveryAutoConfiguration.CONSUL_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME; +import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceDiscoveryAutoConfiguration.NACOS_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME; +import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceDiscoveryAutoConfiguration.ZOOKEEPER_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME; +import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME; +import static com.alibaba.cloud.nacos.discovery.NacosDiscoveryClient.hostToServiceInstanceList; +import static org.springframework.util.StringUtils.hasText; /** * Dubbo Service Discovery Auto {@link Configuration} (after - * {@link DubboServiceRegistrationAutoConfiguration}) + * {@link DubboServiceRegistrationAutoConfiguration}). * * @author Mercy * @see DubboServiceRegistrationAutoConfiguration @@ -98,17 +98,27 @@ import com.netflix.discovery.shared.Applications; @Configuration @ConditionalOnClass(name = "org.springframework.cloud.client.discovery.DiscoveryClient") @ConditionalOnProperty(name = "spring.cloud.discovery.enabled", matchIfMissing = true) -@AutoConfigureAfter(name = { EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME, - ZOOKEEPER_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME, - CONSUL_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME, - NACOS_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME }, value = { - DubboServiceRegistrationAutoConfiguration.class }) +@AutoConfigureAfter( + name = { EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME, + ZOOKEEPER_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME, + CONSUL_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME, + NACOS_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME }, + value = { DubboServiceRegistrationAutoConfiguration.class }) public class DubboServiceDiscoveryAutoConfiguration { + /** + * ZookeeperDiscoveryAutoConfiguration. + */ public static final String ZOOKEEPER_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME = "org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryAutoConfiguration"; + /** + * ConsulDiscoveryClientConfiguration. + */ public static final String CONSUL_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME = "org.springframework.cloud.consul.discovery.ConsulDiscoveryClientConfiguration"; + /** + * NacosDiscoveryAutoConfiguration. + */ public static final String NACOS_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME = "com.alibaba.cloud.nacos.NacosDiscoveryAutoConfiguration"; private final DubboServiceMetadataRepository dubboServiceMetadataRepository; @@ -138,8 +148,7 @@ public class DubboServiceDiscoveryAutoConfiguration { } /** - * Dispatch a {@link ServiceInstancesChangedEvent} - * + * Dispatch a {@link ServiceInstancesChangedEvent}. * @param serviceName the name of service * @param serviceInstances the {@link ServiceInstance instances} of some service * @see AbstractSpringCloudRegistry#registerServiceInstancesChangedEventListener(URL, @@ -209,7 +218,6 @@ public class DubboServiceDiscoveryAutoConfiguration { * implementation could declare a Spring Bean of {@link Predicate} of * {@link HeartbeatEvent} to override {@link #defaultHeartbeatEventChangePredicate() * default one}. - * * @param event the instance of {@link HeartbeatEvent} * @see HeartbeatEvent */ @@ -238,8 +246,7 @@ public class DubboServiceDiscoveryAutoConfiguration { * The default {@link Predicate} implementation of {@link HeartbeatEvent} based on the * comparison between previous and current {@link HeartbeatEvent#getValue() state * value}, the {@link DiscoveryClient} implementation may override current. - * - * @return {@link Predicate} + * @return {@link Predicate} {@link HeartbeatEvent} * @see EurekaConfiguration#heartbeatEventChangedPredicate() */ @Bean @@ -254,7 +261,7 @@ public class DubboServiceDiscoveryAutoConfiguration { } /** - * Eureka Customized Configuration + * Eureka Customized Configuration. */ @Configuration @ConditionalOnBean(name = EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME) @@ -267,6 +274,7 @@ public class DubboServiceDiscoveryAutoConfiguration { * {@link Applications} and current. * * @see Applications#getAppsHashCode() + * @return HeartbeatEvent Predicate */ @Bean public Predicate heartbeatEventChangedPredicate() { @@ -280,34 +288,36 @@ public class DubboServiceDiscoveryAutoConfiguration { && !Objects.equals(oldAppsHashCode, appsHashCode); }; } + } /** - * Zookeeper Customized Configuration + * Zookeeper Customized Configuration. */ @Configuration @ConditionalOnBean(name = ZOOKEEPER_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME) @Aspect public class ZookeeperConfiguration implements ApplicationListener { + /** * The pointcut expression for - * {@link ZookeeperServiceWatch#childEvent(CuratorFramework, TreeCacheEvent)} + * {@link ZookeeperServiceWatch#childEvent(CuratorFramework, TreeCacheEvent)}. */ public static final String CHILD_EVENT_POINTCUT_EXPRESSION = "execution(void org.springframework.cloud.zookeeper.discovery.ZookeeperServiceWatch.childEvent(..)) && args(client,event)"; /** - * The path separator of Zookeeper node + * The path separator of Zookeeper node. */ public static final String NODE_PATH_SEPARATOR = "/"; /** - * The path variable name for the name of service + * The path variable name for the name of service. */ private static final String SERVICE_NAME_PATH_VARIABLE_NAME = "serviceName"; /** - * The path variable name for the id of {@link ServiceInstance service instance} + * The path variable name for the id of {@link ServiceInstance service instance}. */ private static final String SERVICE_INSTANCE_ID_PATH_VARIABLE_NAME = "serviceInstanceId"; @@ -321,7 +331,7 @@ public class DubboServiceDiscoveryAutoConfiguration { * Ant Path pattern for {@link ServiceInstance} : *

*

- * ${{@link #rootPath}}/{serviceName}/{serviceInstanceId} + * ${{@link #rootPath}}/{serviceName}/{serviceInstanceId}. * * @see #rootPath * @see #SERVICE_NAME_PATH_VARIABLE_NAME @@ -330,7 +340,7 @@ public class DubboServiceDiscoveryAutoConfiguration { private final String serviceInstancePathPattern; /** - * The {@link ThreadLocal} holds the processed service name + * The {@link ThreadLocal} holds the processed service name. */ private final ThreadLocal processedServiceNameThreadLocal; @@ -348,8 +358,7 @@ public class DubboServiceDiscoveryAutoConfiguration { /** * Zookeeper uses {@link TreeCacheEvent} to trigger * {@link #dispatchServiceInstancesChangedEvent(String, Collection)} , thus - * {@link HeartbeatEvent} handle is always ignored - * + * {@link HeartbeatEvent} handle is always ignored. * @return false forever */ @Bean @@ -359,8 +368,7 @@ public class DubboServiceDiscoveryAutoConfiguration { /** * Handle on {@link InstanceRegisteredEvent} after - * {@link ZookeeperServiceWatch#onApplicationEvent(InstanceRegisteredEvent)} - * + * {@link ZookeeperServiceWatch#onApplicationEvent(InstanceRegisteredEvent)}. * @param event {@link InstanceRegisteredEvent} * @see #reattachTreeCacheListeners() */ @@ -370,7 +378,7 @@ public class DubboServiceDiscoveryAutoConfiguration { } /** - * Re-attach the {@link TreeCacheListener TreeCacheListeners} + * Re-attach the {@link TreeCacheListener TreeCacheListeners}. */ private void reattachTreeCacheListeners() { @@ -381,7 +389,7 @@ public class DubboServiceDiscoveryAutoConfiguration { /** * All registered TreeCacheListeners except {@link ZookeeperServiceWatch}. * Usually, "otherListeners" will be empty because Spring Cloud Zookeeper only - * adds "zookeeperServiceWatch" bean as {@link TreeCacheListener} + * adds "zookeeperServiceWatch" bean as {@link TreeCacheListener}. */ List otherListeners = new LinkedList<>(); @@ -392,7 +400,7 @@ public class DubboServiceDiscoveryAutoConfiguration { * Even though "listener" is an instance of * {@link ZookeeperServiceWatch}, "zookeeperServiceWatch" bean that * was enhanced by AOP is different from the former, thus it's - * required to exclude "listener" + * required to exclude "listener". */ if (!(listener instanceof ZookeeperServiceWatch)) { otherListeners.add(listener); @@ -420,8 +428,7 @@ public class DubboServiceDiscoveryAutoConfiguration { * Try to {@link #dispatchServiceInstancesChangedEvent(String, Collection) * dispatch} {@link ServiceInstancesChangedEvent} before * {@link ZookeeperServiceWatch#childEvent(CuratorFramework, TreeCacheEvent)} - * execution if required - * + * execution if required. * @param client {@link CuratorFramework} * @param event {@link TreeCacheEvent} */ @@ -441,8 +448,7 @@ public class DubboServiceDiscoveryAutoConfiguration { } /** - * Resolve the name of service - * + * Resolve the name of service. * @param event {@link TreeCacheEvent} * @return If the Zookeeper's {@link ChildData#getPath() node path} that was * notified comes from {@link ServiceInstance the service instance}, return it's @@ -467,8 +473,7 @@ public class DubboServiceDiscoveryAutoConfiguration { } /** - * The {@link TreeCacheEvent#getType() event type} is supported or not - * + * The {@link TreeCacheEvent#getType() event type} is supported or not. * @param event {@link TreeCacheEvent} * @return the rule is same as * {@link ZookeeperServiceWatch#childEvent(CuratorFramework, TreeCacheEvent)} @@ -480,10 +485,11 @@ public class DubboServiceDiscoveryAutoConfiguration { || eventType.equals(TreeCacheEvent.Type.NODE_REMOVED) || eventType.equals(TreeCacheEvent.Type.NODE_UPDATED); } + } /** - * Consul Customized Configuration + * Consul Customized Configuration. */ @Configuration @ConditionalOnBean(name = CONSUL_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME) @@ -492,7 +498,7 @@ public class DubboServiceDiscoveryAutoConfiguration { } /** - * Nacos Customized Configuration + * Nacos Customized Configuration. */ @Configuration @ConditionalOnBean(name = NACOS_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME) @@ -501,7 +507,7 @@ public class DubboServiceDiscoveryAutoConfiguration { private final NamingService namingService; /** - * the set of services is listening + * the set of services is listening. */ private final Set listeningServices; @@ -511,10 +517,9 @@ public class DubboServiceDiscoveryAutoConfiguration { } /** - * Nacos uses {@link EventListener} to trigger + * Nacos uses {@link EventListener} to trigger. * {@link #dispatchServiceInstancesChangedEvent(String, Collection)} , thus * {@link HeartbeatEvent} handle is always ignored - * * @return false forever */ @Bean @@ -547,5 +552,7 @@ public class DubboServiceDiscoveryAutoConfiguration { } } } + } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboServiceRegistrationAutoConfiguration.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboServiceRegistrationAutoConfiguration.java index 2a5c7afd5..855b43819 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboServiceRegistrationAutoConfiguration.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboServiceRegistrationAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,23 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.autoconfigure; -import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.CONSUL_AUTO_SERVICE_AUTO_CONFIGURATION_CLASS_NAME; -import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME; -import static com.alibaba.cloud.dubbo.registry.SpringCloudRegistryFactory.ADDRESS; -import static com.alibaba.cloud.dubbo.registry.SpringCloudRegistryFactory.PROTOCOL; -import static org.springframework.util.ObjectUtils.isEmpty; +package com.alibaba.cloud.dubbo.autoconfigure; import java.util.Collection; import java.util.List; import java.util.Map; +import com.alibaba.cloud.dubbo.autoconfigure.condition.MissingSpringCloudRegistryConfigPropertyCondition; +import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; +import com.alibaba.cloud.dubbo.registry.DubboServiceRegistrationEventPublishingAspect; +import com.alibaba.cloud.dubbo.registry.event.ServiceInstancePreRegisteredEvent; +import com.ecwid.consul.v1.agent.model.NewService; +import com.netflix.appinfo.InstanceInfo; import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.spring.ServiceBean; import org.aspectj.lang.annotation.Aspect; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.SmartInitializingSingleton; @@ -51,34 +53,45 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.event.EventListener; -import com.alibaba.cloud.dubbo.autoconfigure.condition.MissingSpringCloudRegistryConfigPropertyCondition; -import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; -import com.alibaba.cloud.dubbo.registry.DubboServiceRegistrationEventPublishingAspect; -import com.alibaba.cloud.dubbo.registry.event.ServiceInstancePreRegisteredEvent; - -import com.ecwid.consul.v1.agent.model.NewService; -import com.netflix.appinfo.InstanceInfo; +import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.CONSUL_AUTO_SERVICE_AUTO_CONFIGURATION_CLASS_NAME; +import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME; +import static com.alibaba.cloud.dubbo.registry.SpringCloudRegistryFactory.ADDRESS; +import static com.alibaba.cloud.dubbo.registry.SpringCloudRegistryFactory.PROTOCOL; +import static org.springframework.util.ObjectUtils.isEmpty; /** - * Dubbo Service Registration Auto-{@link Configuration} + * Dubbo Service Registration Auto-{@link Configuration}. * * @author Mercy */ @Configuration @Import({ DubboServiceRegistrationEventPublishingAspect.class }) -@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true) +@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", + matchIfMissing = true) @AutoConfigureAfter(name = { EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME, CONSUL_AUTO_SERVICE_AUTO_CONFIGURATION_CLASS_NAME, - "org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationAutoConfiguration" }, value = { - DubboMetadataAutoConfiguration.class }) + "org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationAutoConfiguration" }, + value = { DubboMetadataAutoConfiguration.class }) public class DubboServiceRegistrationAutoConfiguration { + /** + * EurekaClientAutoConfiguration. + */ public static final String EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME = "org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration"; + /** + * ConsulAutoServiceRegistrationAutoConfiguration. + */ public static final String CONSUL_AUTO_SERVICE_AUTO_CONFIGURATION_CLASS_NAME = "org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistrationAutoConfiguration"; + /** + * ConsulAutoRegistration. + */ public static final String CONSUL_AUTO_SERVICE_AUTO_REGISTRATION_CLASS_NAME = "org.springframework.cloud.consul.serviceregistry.ConsulAutoRegistration"; + /** + * ZookeeperAutoServiceRegistrationAutoConfiguration. + */ public static final String ZOOKEEPER_AUTO_SERVICE_AUTO_CONFIGURATION_CLASS_NAME = "org.springframework.cloud.zookeeper.serviceregistry.ZookeeperAutoServiceRegistrationAutoConfiguration"; private static final Logger logger = LoggerFactory @@ -88,7 +101,7 @@ public class DubboServiceRegistrationAutoConfiguration { private DubboServiceMetadataRepository dubboServiceMetadataRepository; @Bean - @Conditional(value = { MissingSpringCloudRegistryConfigPropertyCondition.class }) + @Conditional({ MissingSpringCloudRegistryConfigPropertyCondition.class }) public RegistryConfig defaultSpringCloudRegistryConfig() { return new RegistryConfig(ADDRESS, PROTOCOL); } @@ -150,6 +163,7 @@ public class DubboServiceRegistrationAutoConfiguration { serviceBeans.forEach(ServiceBean::export); } } + } @Configuration @@ -158,8 +172,7 @@ public class DubboServiceRegistrationAutoConfiguration { class ConsulConfiguration { /** - * Handle the pre-registered event of {@link ServiceInstance} for Consul - * + * Handle the pre-registered event of {@link ServiceInstance} for Consul. * @param event {@link ServiceInstancePreRegisteredEvent} */ @EventListener(ServiceInstancePreRegisteredEvent.class) @@ -186,5 +199,7 @@ public class DubboServiceRegistrationAutoConfiguration { } } } + } -} \ No newline at end of file + +} diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboServiceRegistrationNonWebApplicationAutoConfiguration.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboServiceRegistrationNonWebApplicationAutoConfiguration.java index 3eea3bc43..9c411506d 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboServiceRegistrationNonWebApplicationAutoConfiguration.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/DubboServiceRegistrationNonWebApplicationAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,18 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.autoconfigure; -import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.CONSUL_AUTO_SERVICE_AUTO_CONFIGURATION_CLASS_NAME; -import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.ZOOKEEPER_AUTO_SERVICE_AUTO_CONFIGURATION_CLASS_NAME; +package com.alibaba.cloud.dubbo.autoconfigure; import java.util.List; +import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; +import com.alibaba.cloud.dubbo.registry.event.ServiceInstancePreRegisteredEvent; +import com.ecwid.consul.v1.agent.model.NewService; import org.apache.dubbo.common.URL; import org.apache.dubbo.config.spring.ServiceBean; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; + import org.springframework.beans.factory.SmartInitializingSingleton; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -41,19 +43,18 @@ import org.springframework.cloud.zookeeper.serviceregistry.ServiceInstanceRegist import org.springframework.context.annotation.Configuration; import org.springframework.context.event.EventListener; -import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; -import com.alibaba.cloud.dubbo.registry.event.ServiceInstancePreRegisteredEvent; - -import com.ecwid.consul.v1.agent.model.NewService; +import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.CONSUL_AUTO_SERVICE_AUTO_CONFIGURATION_CLASS_NAME; +import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.ZOOKEEPER_AUTO_SERVICE_AUTO_CONFIGURATION_CLASS_NAME; /** - * Dubbo Service Registration Auto-{@link Configuration} for Non-Web application + * Dubbo Service Registration Auto-{@link Configuration} for Non-Web application. * * @author Mercy */ @Configuration @ConditionalOnNotWebApplication -@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true) +@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", + matchIfMissing = true) @AutoConfigureAfter(DubboServiceRegistrationAutoConfiguration.class) @Aspect public class DubboServiceRegistrationNonWebApplicationAutoConfiguration { @@ -134,6 +135,7 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration { // before register registration.getServiceInstance(); } + } @Configuration @@ -141,8 +143,7 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration { class ConsulConfiguration { /** - * Handle the pre-registered event of {@link ServiceInstance} for Consul - * + * Handle the pre-registered event of {@link ServiceInstance} for Consul. * @param event {@link ServiceInstancePreRegisteredEvent} */ @EventListener(ServiceInstancePreRegisteredEvent.class) @@ -154,8 +155,7 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration { } /** - * Set port on Non-Web Application - * + * Set port on Non-Web Application. * @param consulRegistration {@link ConsulRegistration} */ private void setPort(ConsulAutoRegistration consulRegistration) { @@ -165,6 +165,7 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration { newService.setPort(port); } } + } -} \ No newline at end of file +} diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/condition/MissingSpringCloudRegistryConfigPropertyCondition.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/condition/MissingSpringCloudRegistryConfigPropertyCondition.java index b83d799d6..598904297 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/condition/MissingSpringCloudRegistryConfigPropertyCondition.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/autoconfigure/condition/MissingSpringCloudRegistryConfigPropertyCondition.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.autoconfigure.condition; -import static com.alibaba.cloud.dubbo.registry.SpringCloudRegistryFactory.PROTOCOL; -import static org.apache.dubbo.config.spring.util.PropertySourcesUtils.getSubProperties; +package com.alibaba.cloud.dubbo.autoconfigure.condition; import java.util.Map; +import com.alibaba.cloud.dubbo.registry.SpringCloudRegistry; + import org.springframework.boot.autoconfigure.condition.ConditionOutcome; import org.springframework.boot.autoconfigure.condition.SpringBootCondition; import org.springframework.context.annotation.Condition; @@ -28,10 +28,11 @@ import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.util.StringUtils; -import com.alibaba.cloud.dubbo.registry.SpringCloudRegistry; +import static com.alibaba.cloud.dubbo.registry.SpringCloudRegistryFactory.PROTOCOL; +import static org.apache.dubbo.config.spring.util.PropertySourcesUtils.getSubProperties; /** - * Missing {@link SpringCloudRegistry} Property {@link Condition} + * Missing {@link SpringCloudRegistry} Property {@link Condition}. * * @author Mercy * @see SpringCloudRegistry @@ -76,4 +77,5 @@ public class MissingSpringCloudRegistryConfigPropertyCondition "'spring-cloud' protocol was found in 'dubbo.registries.*'") : ConditionOutcome.match(); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/client/loadbalancer/DubboClientHttpResponse.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/client/loadbalancer/DubboClientHttpResponse.java index f0b9e89dd..87513d0b8 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/client/loadbalancer/DubboClientHttpResponse.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/client/loadbalancer/DubboClientHttpResponse.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,18 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.client.loadbalancer; import java.io.IOException; import java.io.InputStream; import org.apache.dubbo.rpc.service.GenericException; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.client.ClientHttpResponse; /** - * Dubbo {@link ClientHttpResponse} implementation + * Dubbo {@link ClientHttpResponse} implementation. * * @author Mercy * @see DubboTransporterInterceptor @@ -39,7 +41,7 @@ class DubboClientHttpResponse implements ClientHttpResponse { private final DubboHttpOutputMessage httpOutputMessage; - public DubboClientHttpResponse(DubboHttpOutputMessage httpOutputMessage, + DubboClientHttpResponse(DubboHttpOutputMessage httpOutputMessage, GenericException exception) { this.httpStatus = exception != null ? HttpStatus.INTERNAL_SERVER_ERROR : HttpStatus.OK; @@ -77,4 +79,5 @@ class DubboClientHttpResponse implements ClientHttpResponse { public HttpHeaders getHeaders() { return httpHeaders; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/client/loadbalancer/DubboClientHttpResponseFactory.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/client/loadbalancer/DubboClientHttpResponseFactory.java index 6bec0ae20..110f388e0 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/client/loadbalancer/DubboClientHttpResponseFactory.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/client/loadbalancer/DubboClientHttpResponseFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,23 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.client.loadbalancer; import java.io.IOException; import java.util.List; -import org.apache.dubbo.rpc.service.GenericException; -import org.springframework.http.MediaType; -import org.springframework.http.client.ClientHttpResponse; -import org.springframework.http.converter.HttpMessageConverter; - import com.alibaba.cloud.dubbo.http.converter.HttpMessageConverterHolder; import com.alibaba.cloud.dubbo.http.util.HttpMessageConverterResolver; import com.alibaba.cloud.dubbo.metadata.RequestMetadata; import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; +import org.apache.dubbo.rpc.service.GenericException; + +import org.springframework.http.MediaType; +import org.springframework.http.client.ClientHttpResponse; +import org.springframework.http.converter.HttpMessageConverter; /** - * Dubbo {@link ClientHttpResponse} Factory + * Dubbo {@link ClientHttpResponse} Factory. * * @author Mercy */ @@ -37,7 +38,7 @@ class DubboClientHttpResponseFactory { private final HttpMessageConverterResolver httpMessageConverterResolver; - public DubboClientHttpResponseFactory(List> messageConverters, + DubboClientHttpResponseFactory(List> messageConverters, ClassLoader classLoader) { this.httpMessageConverterResolver = new HttpMessageConverterResolver( messageConverters, classLoader); @@ -64,4 +65,5 @@ class DubboClientHttpResponseFactory { return new DubboClientHttpResponse(httpOutputMessage, exception); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/client/loadbalancer/DubboHttpOutputMessage.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/client/loadbalancer/DubboHttpOutputMessage.java index 38353a777..8c727e751 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/client/loadbalancer/DubboHttpOutputMessage.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/client/loadbalancer/DubboHttpOutputMessage.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.client.loadbalancer; import java.io.IOException; @@ -22,7 +23,7 @@ import org.springframework.http.HttpOutputMessage; import org.springframework.util.FastByteArrayOutputStream; /** - * Dubbo {@link HttpOutputMessage} implementation + * Dubbo {@link HttpOutputMessage} implementation. * * @author Mercy */ @@ -41,4 +42,5 @@ class DubboHttpOutputMessage implements HttpOutputMessage { public HttpHeaders getHeaders() { return httpHeaders; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/client/loadbalancer/DubboMetadataInitializerInterceptor.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/client/loadbalancer/DubboMetadataInitializerInterceptor.java index 0a41f96ce..f0424b65b 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/client/loadbalancer/DubboMetadataInitializerInterceptor.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/client/loadbalancer/DubboMetadataInitializerInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,21 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.client.loadbalancer; import java.io.IOException; import java.net.URI; +import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; + import org.springframework.http.HttpRequest; import org.springframework.http.client.ClientHttpRequestExecution; import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.http.client.ClientHttpResponse; -import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; - /** * Dubbo Metadata {@link ClientHttpRequestInterceptor} Initializing Interceptor executes - * intercept before {@link DubboTransporterInterceptor} + * intercept before {@link DubboTransporterInterceptor}. * * @author Mercy */ @@ -53,4 +54,5 @@ public class DubboMetadataInitializerInterceptor implements ClientHttpRequestInt // Execute next return execution.execute(request, body); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/client/loadbalancer/DubboTransporterInterceptor.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/client/loadbalancer/DubboTransporterInterceptor.java index 5ca52d738..b6544f644 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/client/loadbalancer/DubboTransporterInterceptor.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/client/loadbalancer/DubboTransporterInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,17 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.client.loadbalancer; -import static org.springframework.web.util.UriComponentsBuilder.fromUri; +package com.alibaba.cloud.dubbo.client.loadbalancer; import java.io.IOException; import java.net.URI; import java.util.List; import java.util.Map; +import com.alibaba.cloud.dubbo.http.MutableHttpServerRequest; +import com.alibaba.cloud.dubbo.metadata.DubboRestServiceMetadata; +import com.alibaba.cloud.dubbo.metadata.RequestMetadata; +import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; +import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; +import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContext; +import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContextFactory; +import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory; import org.apache.dubbo.rpc.service.GenericException; import org.apache.dubbo.rpc.service.GenericService; + import org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor; import org.springframework.http.HttpRequest; import org.springframework.http.client.ClientHttpRequestExecution; @@ -35,17 +43,10 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.PathMatcher; import org.springframework.web.util.UriComponents; -import com.alibaba.cloud.dubbo.http.MutableHttpServerRequest; -import com.alibaba.cloud.dubbo.metadata.DubboRestServiceMetadata; -import com.alibaba.cloud.dubbo.metadata.RequestMetadata; -import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; -import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; -import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContext; -import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContextFactory; -import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory; +import static org.springframework.web.util.UriComponentsBuilder.fromUri; /** - * Dubbo Transporter {@link ClientHttpRequestInterceptor} implementation + * Dubbo Transporter {@link ClientHttpRequestInterceptor} implementation. * * @author Mercy * @see LoadBalancerInterceptor @@ -148,4 +149,5 @@ public class DubboTransporterInterceptor implements ClientHttpRequestInterceptor requestMetadata.setHeaders(request.getHeaders()); return requestMetadata; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/context/DubboServiceRegistrationApplicationContextInitializer.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/context/DubboServiceRegistrationApplicationContextInitializer.java index 5e98b26eb..873caea04 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/context/DubboServiceRegistrationApplicationContextInitializer.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/context/DubboServiceRegistrationApplicationContextInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.context; +import com.alibaba.cloud.dubbo.registry.SpringCloudRegistryFactory; + import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; -import com.alibaba.cloud.dubbo.registry.SpringCloudRegistryFactory; - /** * The Dubbo services will be registered as the specified Spring cloud applications that * will not be considered normal ones, but only are used to Dubbo's service discovery even @@ -37,4 +38,5 @@ public class DubboServiceRegistrationApplicationContextInitializer // Register SpringCloudRegistryFactory.setApplicationContext(applicationContext); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/env/DubboCloudProperties.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/env/DubboCloudProperties.java index 7cbc088bc..80a0a072d 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/env/DubboCloudProperties.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/env/DubboCloudProperties.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,11 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.env; -import static org.springframework.util.StringUtils.commaDelimitedListToStringArray; -import static org.springframework.util.StringUtils.hasText; -import static org.springframework.util.StringUtils.trimAllWhitespace; +package com.alibaba.cloud.dubbo.env; import java.util.Collections; import java.util.LinkedHashSet; @@ -25,8 +22,12 @@ import java.util.Set; import org.springframework.boot.context.properties.ConfigurationProperties; +import static org.springframework.util.StringUtils.commaDelimitedListToStringArray; +import static org.springframework.util.StringUtils.hasText; +import static org.springframework.util.StringUtils.trimAllWhitespace; + /** - * Dubbo Cloud {@link ConfigurationProperties Properties} + * Dubbo Cloud {@link ConfigurationProperties Properties}. * * @author Mercy */ @@ -34,7 +35,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; public class DubboCloudProperties { /** - * All services of Dubbo + * All services of Dubbo. */ public static final String ALL_DUBBO_SERVICES = "*"; @@ -56,7 +57,6 @@ public class DubboCloudProperties { /** * Get the subscribed services as a {@link Set} with configuration order. - * * @return non-null Read-only {@link Set} */ public Set subscribedServices() { @@ -78,4 +78,5 @@ public class DubboCloudProperties { return Collections.unmodifiableSet(subscribedServices); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/env/DubboNonWebApplicationEnvironmentPostProcessor.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/env/DubboNonWebApplicationEnvironmentPostProcessor.java index 4f1dd4d18..77b7c9420 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/env/DubboNonWebApplicationEnvironmentPostProcessor.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/env/DubboNonWebApplicationEnvironmentPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.env; -import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_PROTOCOL; -import static org.apache.dubbo.config.spring.util.PropertySourcesUtils.getSubProperties; +package com.alibaba.cloud.dubbo.env; import java.util.HashMap; import java.util.Map; @@ -24,6 +22,7 @@ import java.util.Properties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.boot.SpringApplication; import org.springframework.boot.WebApplicationType; import org.springframework.boot.env.EnvironmentPostProcessor; @@ -35,9 +34,12 @@ import org.springframework.core.env.PropertySource; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_PROTOCOL; +import static org.apache.dubbo.config.spring.util.PropertySourcesUtils.getSubProperties; + /** * Dubbo {@link WebApplicationType#NONE Non-Web Application} - * {@link EnvironmentPostProcessor} + * {@link EnvironmentPostProcessor}. * * @author Mercy */ @@ -110,10 +112,9 @@ public class DubboNonWebApplicationEnvironmentPostProcessor /** * Reset server port property if it's absent, whose value is configured by - * "dubbbo.protocol.port" or "dubbo.protcols.rest.port" - * - * @param environment - * @param defaultProperties + * "dubbbo.protocol.port" or "dubbo.protcols.rest.port". + * @param environment Spring Environment + * @param defaultProperties defaultProperties */ private void resetServerPort(ConfigurableEnvironment environment, Map defaultProperties) { @@ -140,8 +141,7 @@ public class DubboNonWebApplicationEnvironmentPostProcessor DEFAULT_PROTOCOL); return isRestProtocol(protocol) - ? environment.getProperty(PROTOCOL_PORT_PROPERTY_NAME) - : null; + ? environment.getProperty(PROTOCOL_PORT_PROPERTY_NAME) : null; } private String getRestPortFromProtocolsProperties( @@ -191,8 +191,7 @@ public class DubboNonWebApplicationEnvironmentPostProcessor } /** - * Copy from BusEnvironmentPostProcessor#addOrReplace(MutablePropertySources, Map) - * + * Copy from BusEnvironmentPostProcessor#addOrReplace(MutablePropertySources, Map). * @param propertySources {@link MutablePropertySources} * @param map Default Dubbo Properties */ @@ -222,4 +221,5 @@ public class DubboNonWebApplicationEnvironmentPostProcessor public int getOrder() { // Keep LOWEST_PRECEDENCE return LOWEST_PRECEDENCE; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/ByteArrayHttpInputMessage.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/ByteArrayHttpInputMessage.java index 35ce27640..f431b849f 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/ByteArrayHttpInputMessage.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/ByteArrayHttpInputMessage.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,17 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http; import java.io.IOException; import java.io.InputStream; import org.apache.dubbo.common.io.UnsafeByteArrayInputStream; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpInputMessage; /** - * Byte array {@link HttpInputMessage} implementation + * Byte array {@link HttpInputMessage} implementation. * * @author Mercy */ @@ -33,11 +35,11 @@ class ByteArrayHttpInputMessage implements HttpInputMessage { private final InputStream inputStream; - public ByteArrayHttpInputMessage(byte[] body) { + ByteArrayHttpInputMessage(byte[] body) { this(new HttpHeaders(), body); } - public ByteArrayHttpInputMessage(HttpHeaders httpHeaders, byte[] body) { + ByteArrayHttpInputMessage(HttpHeaders httpHeaders, byte[] body) { this.httpHeaders = httpHeaders; this.inputStream = new UnsafeByteArrayInputStream(body); } @@ -51,4 +53,5 @@ class ByteArrayHttpInputMessage implements HttpInputMessage { public HttpHeaders getHeaders() { return httpHeaders; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/DefaultHttpRequest.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/DefaultHttpRequest.java index 3bb56e9d3..714f296eb 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/DefaultHttpRequest.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/DefaultHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.http; -import static org.springframework.web.util.UriComponentsBuilder.fromPath; +package com.alibaba.cloud.dubbo.http; import java.net.URI; import java.util.List; @@ -28,8 +27,10 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.util.UriComponentsBuilder; +import static org.springframework.web.util.UriComponentsBuilder.fromPath; + /** - * Default {@link HttpRequest} implementation + * Default {@link HttpRequest} implementation. * * @author Mercy */ @@ -79,7 +80,7 @@ public class DefaultHttpRequest implements HttpRequest { } /** - * {@link HttpRequest} Builder + * {@link HttpRequest} Builder. */ public static class Builder { @@ -124,6 +125,7 @@ public class DefaultHttpRequest implements HttpRequest { public HttpRequest build() { return new DefaultHttpRequest(method, path, params, headers); } + } } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/HttpServerRequest.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/HttpServerRequest.java index 32b67efbe..9ec78d50e 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/HttpServerRequest.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/HttpServerRequest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http; import org.springframework.http.HttpInputMessage; @@ -20,21 +21,21 @@ import org.springframework.http.HttpRequest; import org.springframework.util.MultiValueMap; /** - * HTTP Server Request + * HTTP Server Request. * * @author Mercy */ public interface HttpServerRequest extends HttpRequest, HttpInputMessage { /** - * Return a path of current HTTP request - * - * @return + * Return a path of current HTTP request. + * @return the path */ String getPath(); /** * Return a map with parsed and decoded query parameter values. + * @return the query params */ MultiValueMap getQueryParams(); diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/MutableHttpServerRequest.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/MutableHttpServerRequest.java index 032de84a2..89fc25a07 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/MutableHttpServerRequest.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/MutableHttpServerRequest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.http; -import static com.alibaba.cloud.dubbo.http.util.HttpUtils.getParameters; +package com.alibaba.cloud.dubbo.http; import java.io.IOException; import java.io.InputStream; @@ -28,8 +27,10 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpRequest; import org.springframework.util.MultiValueMap; +import static com.alibaba.cloud.dubbo.http.util.HttpUtils.getParameters; + /** - * Mutable {@link HttpServerRequest} implementation + * Mutable {@link HttpServerRequest} implementation. * * @author Mercy */ @@ -96,4 +97,5 @@ public class MutableHttpServerRequest implements HttpServerRequest { public MultiValueMap getQueryParams() { return queryParams; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/converter/HttpMessageConverterHolder.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/converter/HttpMessageConverterHolder.java index a4076b254..a8747961d 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/converter/HttpMessageConverterHolder.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/converter/HttpMessageConverterHolder.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.converter; import org.springframework.http.MediaType; @@ -42,4 +43,5 @@ public class HttpMessageConverterHolder { public HttpMessageConverter getConverter() { return converter; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/AbstractHttpRequestMatcher.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/AbstractHttpRequestMatcher.java index cc4994d00..a2d3ea751 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/AbstractHttpRequestMatcher.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/AbstractHttpRequestMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.matcher; import java.util.Collection; import java.util.Iterator; /** - * Abstract {@link HttpRequestMatcher} implementation + * Abstract {@link HttpRequestMatcher} implementation. * * @author Rossen Stoyanchev * @author Mercy @@ -30,7 +31,6 @@ public abstract class AbstractHttpRequestMatcher implements HttpRequestMatcher { * Return the discrete items a request condition is composed of. *

* For example URL patterns, HTTP request methods, param expressions, etc. - * * @return a collection of objects, never {@code null} */ protected abstract Collection getContent(); @@ -72,4 +72,5 @@ public abstract class AbstractHttpRequestMatcher implements HttpRequestMatcher { builder.append("]"); return builder.toString(); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/AbstractMediaTypeExpression.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/AbstractMediaTypeExpression.java index 67b759570..b7a7ccf75 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/AbstractMediaTypeExpression.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/AbstractMediaTypeExpression.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.matcher; import org.springframework.http.MediaType; /** * The some source code is scratched from - * org.springframework.web.servlet.mvc.condition.AbstractMediaTypeExpression + * org.springframework.web.servlet.mvc.condition.AbstractMediaTypeExpression. * * @author Arjen Poutsma * @author Rossen Stoyanchev @@ -91,4 +92,5 @@ public class AbstractMediaTypeExpression builder.append(this.mediaType.toString()); return builder.toString(); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/AbstractNameValueExpression.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/AbstractNameValueExpression.java index c5a6fc01e..611cd22dd 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/AbstractNameValueExpression.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/AbstractNameValueExpression.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,17 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.http.matcher; -import static org.springframework.util.StringUtils.trimWhitespace; +package com.alibaba.cloud.dubbo.http.matcher; import org.springframework.http.HttpRequest; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; +import static org.springframework.util.StringUtils.trimWhitespace; + /** * The some source code is scratched from - * org.springframework.web.servlet.mvc.condition.AbstractNameValueExpression + * org.springframework.web.servlet.mvc.condition.AbstractNameValueExpression. * * @author Rossen Stoyanchev * @author Arjen Poutsma @@ -63,9 +64,8 @@ abstract class AbstractNameValueExpression implements NameValueExpression /** * Exclude the pattern value Expression: "{value}", subclass could override this * method. - * - * @param valueExpression - * @return + * @param valueExpression expression of value + * @return exclude or not */ protected boolean isExcludedValue(String valueExpression) { return StringUtils.hasText(valueExpression) && valueExpression.startsWith("{") diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/CompositeHttpRequestMatcher.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/CompositeHttpRequestMatcher.java index 1ad2fa89a..b10b6317b 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/CompositeHttpRequestMatcher.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/CompositeHttpRequestMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.matcher; import java.util.Arrays; @@ -23,7 +24,7 @@ import java.util.List; import org.springframework.http.HttpRequest; /** - * Composite {@link HttpRequestMatcher} implementation + * Composite {@link HttpRequestMatcher} implementation. * * @author Mercy */ @@ -69,4 +70,5 @@ public abstract class CompositeHttpRequestMatcher extends AbstractHttpRequestMat protected String getToStringInfix() { return " && "; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/ConsumeMediaTypeExpression.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/ConsumeMediaTypeExpression.java index b63ea2edb..08f5cf312 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/ConsumeMediaTypeExpression.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/ConsumeMediaTypeExpression.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.matcher; import org.springframework.http.MediaType; @@ -21,7 +22,7 @@ import org.springframework.http.MediaType; * Parses and matches a single media type expression to a request's 'Content-Type' header. *

* The source code is scratched from - * org.springframework.web.servlet.mvc.condition.ConsumesRequestCondition.ConsumeMediaTypeExpression + * org.springframework.web.servlet.mvc.condition.ConsumesRequestCondition.ConsumeMediaTypeExpression. * * @author Rossen Stoyanchev * @author Arjen Poutsma @@ -40,4 +41,5 @@ class ConsumeMediaTypeExpression extends AbstractMediaTypeExpression { boolean match = getMediaType().includes(contentType); return (!isNegated() ? match : !match); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HeaderExpression.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HeaderExpression.java index ce00f66e7..277a2591f 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HeaderExpression.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HeaderExpression.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.matcher; import org.springframework.http.HttpHeaders; @@ -23,7 +24,7 @@ import org.springframework.util.ObjectUtils; * Parses and matches a single header expression to a request. *

* The some source code is scratched from - * org.springframework.web.servlet.mvc.condition.HeadersRequestCondition.HeaderExpression + * org.springframework.web.servlet.mvc.condition.HeadersRequestCondition.HeaderExpression. * * @author Arjen Poutsma * @author Rossen Stoyanchev @@ -57,4 +58,5 @@ class HeaderExpression extends AbstractNameValueExpression { String headerValue = httpHeaders.getFirst(this.name); return ObjectUtils.nullSafeEquals(this.value, headerValue); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestConsumersMatcher.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestConsumersMatcher.java index d00a99ec2..e97f2559a 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestConsumersMatcher.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestConsumersMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.matcher; import java.util.ArrayList; @@ -27,7 +28,7 @@ import org.springframework.http.HttpRequest; import org.springframework.http.MediaType; /** - * {@link HttpRequest} 'Content-Type' header {@link HttpRequestMatcher matcher} + * {@link HttpRequest} 'Content-Type' header {@link HttpRequestMatcher matcher}. * * @author Arjen Poutsma * @author Rossen Stoyanchev @@ -39,7 +40,6 @@ public class HttpRequestConsumersMatcher extends AbstractHttpRequestMatcher { /** * Creates a new instance from 0 or more "consumes" expressions. - * * @param consumes consumes expressions if 0 expressions are provided, the condition * will match to every request */ @@ -52,7 +52,6 @@ public class HttpRequestConsumersMatcher extends AbstractHttpRequestMatcher { * expressions where the header name is not 'Content-Type' or have no header value * defined are ignored. If 0 expressions are provided in total, the condition will * match to every request - * * @param consumes consumes expressions * @param headers headers expressions */ @@ -122,4 +121,5 @@ public class HttpRequestConsumersMatcher extends AbstractHttpRequestMatcher { protected String getToStringInfix() { return " || "; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestHeadersMatcher.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestHeadersMatcher.java index 34ca04192..af0dbafad 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestHeadersMatcher.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestHeadersMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.matcher; import java.util.Collection; @@ -23,7 +24,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpRequest; /** - * {@link HttpRequest} headers {@link HttpRequestMatcher matcher} + * {@link HttpRequest} headers {@link HttpRequestMatcher matcher}. * * @author Mercy */ @@ -67,4 +68,5 @@ public class HttpRequestHeadersMatcher extends AbstractHttpRequestMatcher { protected String getToStringInfix() { return " && "; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestMatcher.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestMatcher.java index 65ef03de6..3d4855134 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestMatcher.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,22 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.matcher; import org.springframework.http.HttpRequest; /** - * {@link HttpRequest} Matcher + * {@link HttpRequest} Matcher. * * @author Mercy */ public interface HttpRequestMatcher { /** - * Match {@link HttpRequest} or not - * - * @param request The {@link HttpRequest} instance + * Match {@link HttpRequest} or not. + * @param request The {@link HttpRequest} instance. * @return if matched, return true, or false. */ boolean match(HttpRequest request); + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestMethodsMatcher.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestMethodsMatcher.java index 030ed313f..3a9f0ed6b 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestMethodsMatcher.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestMethodsMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.http.matcher; -import static org.springframework.http.HttpMethod.resolve; +package com.alibaba.cloud.dubbo.http.matcher; import java.util.Collection; import java.util.LinkedHashSet; @@ -25,8 +24,10 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpRequest; import org.springframework.util.StringUtils; +import static org.springframework.http.HttpMethod.resolve; + /** - * {@link HttpRequest} {@link HttpMethod methods} {@link HttpRequestMatcher matcher} + * {@link HttpRequest} {@link HttpMethod methods} {@link HttpRequestMatcher matcher}. * * @author Mercy */ @@ -78,4 +79,5 @@ public class HttpRequestMethodsMatcher extends AbstractHttpRequestMatcher { protected String getToStringInfix() { return " || "; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestParamsMatcher.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestParamsMatcher.java index d9c1e912d..159c8746e 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestParamsMatcher.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestParamsMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.matcher; import java.util.Collection; @@ -23,7 +24,7 @@ import org.springframework.http.HttpRequest; import org.springframework.util.CollectionUtils; /** - * {@link HttpRequest} parameters {@link HttpRequestMatcher matcher} + * {@link HttpRequest} parameters {@link HttpRequestMatcher matcher}. * * @author Mercy */ @@ -72,4 +73,5 @@ public class HttpRequestParamsMatcher extends AbstractHttpRequestMatcher { protected String getToStringInfix() { return " && "; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestPathMatcher.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestPathMatcher.java index 9d92654fa..0ce2e74a9 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestPathMatcher.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestPathMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.matcher; import java.net.URI; @@ -29,7 +30,7 @@ import org.springframework.util.PathMatcher; import org.springframework.util.StringUtils; /** - * {@link HttpRequest} {@link URI} {@link HttpRequestMatcher matcher} + * {@link HttpRequest} {@link URI} {@link HttpRequestMatcher matcher}. * * @author Mercy */ @@ -113,4 +114,5 @@ public class HttpRequestPathMatcher extends AbstractHttpRequestMatcher { protected String getToStringInfix() { return " || "; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestProducesMatcher.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestProducesMatcher.java index d35445f4d..a5d93e16e 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestProducesMatcher.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestProducesMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.matcher; import java.util.ArrayList; @@ -27,7 +28,7 @@ import org.springframework.http.HttpRequest; import org.springframework.http.MediaType; /** - * {@link HttpRequest} 'Accept' header {@link HttpRequestMatcher matcher} + * {@link HttpRequest} 'Accept' header {@link HttpRequestMatcher matcher}. * * @author Arjen Poutsma * @author Rossen Stoyanchev @@ -40,7 +41,6 @@ public class HttpRequestProducesMatcher extends AbstractHttpRequestMatcher { /** * Creates a new instance from "produces" expressions. If 0 expressions are provided * in total, this condition will match to any request. - * * @param produces produces expressions */ public HttpRequestProducesMatcher(String... produces) { @@ -52,7 +52,6 @@ public class HttpRequestProducesMatcher extends AbstractHttpRequestMatcher { * expressions where the header name is not 'Accept' or have no header value defined * are ignored. If 0 expressions are provided in total, this condition will match to * any request. - * * @param produces produces expressions * @param headers headers expressions */ @@ -119,4 +118,5 @@ public class HttpRequestProducesMatcher extends AbstractHttpRequestMatcher { protected String getToStringInfix() { return " || "; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/MediaTypeExpression.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/MediaTypeExpression.java index 5638614a5..34078a1a1 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/MediaTypeExpression.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/MediaTypeExpression.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.matcher; import org.springframework.http.MediaType; diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/NameValueExpression.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/NameValueExpression.java index 644c49392..066c662bb 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/NameValueExpression.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/NameValueExpression.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.matcher; /** @@ -20,7 +21,7 @@ package com.alibaba.cloud.dubbo.http.matcher; * parameters and request header in HTTP request *

* The some source code is scratched from - * org.springframework.web.servlet.mvc.condition.NameValueExpression + * org.springframework.web.servlet.mvc.condition.NameValueExpression. * * @param the value type * @author Rossen Stoyanchev diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/ParamExpression.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/ParamExpression.java index cf6bab47d..d98c0f573 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/ParamExpression.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/ParamExpression.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,19 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.http.matcher; -import static com.alibaba.cloud.dubbo.http.util.HttpUtils.getParameters; +package com.alibaba.cloud.dubbo.http.matcher; import org.springframework.http.HttpRequest; import org.springframework.util.MultiValueMap; import org.springframework.util.ObjectUtils; +import static com.alibaba.cloud.dubbo.http.util.HttpUtils.getParameters; + /** * Parses and matches a single param expression to a request. *

* The some source code is scratched from - * org.springframework.web.servlet.mvc.condition.ParamsRequestCondition.ParamExpression + * org.springframework.web.servlet.mvc.condition.ParamsRequestCondition.ParamExpression. * * @author Arjen Poutsma * @author Rossen Stoyanchev @@ -59,4 +60,5 @@ class ParamExpression extends AbstractNameValueExpression { String parameterValue = parametersMap.getFirst(this.name); return ObjectUtils.nullSafeEquals(this.value, parameterValue); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/ProduceMediaTypeExpression.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/ProduceMediaTypeExpression.java index 79b08fd21..4abb97e85 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/ProduceMediaTypeExpression.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/ProduceMediaTypeExpression.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.matcher; import java.util.List; @@ -23,7 +24,7 @@ import org.springframework.http.MediaType; * Parses and matches a single media type expression to a request's 'Accept' header. *

* The source code is scratched from - * org.springframework.web.servlet.mvc.condition.ProducesRequestCondition.ProduceMediaTypeExpression + * org.springframework.web.servlet.mvc.condition.ProducesRequestCondition.ProduceMediaTypeExpression. * * @author Rossen Stoyanchev * @author Arjen Poutsma @@ -51,4 +52,5 @@ class ProduceMediaTypeExpression extends AbstractMediaTypeExpression { } return false; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/RequestMetadataMatcher.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/RequestMetadataMatcher.java index 571173bbf..644e74b79 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/RequestMetadataMatcher.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/matcher/RequestMetadataMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,14 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.http.matcher; -import static com.alibaba.cloud.dubbo.http.util.HttpUtils.toNameAndValues; +package com.alibaba.cloud.dubbo.http.matcher; import com.alibaba.cloud.dubbo.metadata.RequestMetadata; +import static com.alibaba.cloud.dubbo.http.util.HttpUtils.toNameAndValues; + /** - * {@link RequestMetadata} {@link HttpRequestMatcher} implementation + * {@link RequestMetadata} {@link HttpRequestMatcher} implementation. * * @author Mercy */ @@ -43,4 +44,5 @@ public class RequestMetadataMatcher extends CompositeHttpRequestMatcher { new HttpRequestProducesMatcher( metadata.getProduces().toArray(new String[0]))); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/util/HttpMessageConverterResolver.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/util/HttpMessageConverterResolver.java index 0d75a7c92..5798ffc2b 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/util/HttpMessageConverterResolver.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/util/HttpMessageConverterResolver.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.http.util; -import static java.util.Collections.unmodifiableList; +package com.alibaba.cloud.dubbo.http.util; import java.util.ArrayList; import java.util.Collections; @@ -23,23 +22,22 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; -import org.springframework.core.MethodParameter; +import com.alibaba.cloud.dubbo.http.converter.HttpMessageConverterHolder; +import com.alibaba.cloud.dubbo.metadata.RequestMetadata; +import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpRequest; import org.springframework.http.MediaType; import org.springframework.http.converter.GenericHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.server.ServletServerHttpRequest; -import org.springframework.http.server.ServletServerHttpResponse; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; -import com.alibaba.cloud.dubbo.http.converter.HttpMessageConverterHolder; -import com.alibaba.cloud.dubbo.metadata.RequestMetadata; -import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; +import static java.util.Collections.unmodifiableList; /** - * {@link HttpMessageConverter} Resolver + * {@link HttpMessageConverter} Resolver. * * @author Mercy */ @@ -96,11 +94,10 @@ public class HttpMessageConverterResolver { } /** - * Resolve the most match {@link HttpMessageConverter} from {@link RequestMetadata} - * + * Resolve the most match {@link HttpMessageConverter} from {@link RequestMetadata}. * @param requestMetadata {@link RequestMetadata} * @param restMethodMetadata {@link RestMethodMetadata} - * @return + * @return instance of {@link HttpMessageConverterHolder} */ public HttpMessageConverterHolder resolve(RequestMetadata requestMetadata, RestMethodMetadata restMethodMetadata) { @@ -110,7 +107,7 @@ public class HttpMessageConverterResolver { Class returnValueClass = resolveReturnValueClass(restMethodMetadata); /** - * @see AbstractMessageConverterMethodProcessor#writeWithMessageConverters(Object, + * @see AbstractMessageConverterMethodProcessor#writeWithMessageConverters(T, * MethodParameter, ServletServerHttpRequest, ServletServerHttpResponse) */ List requestedMediaTypes = getAcceptableMediaTypes(requestMetadata); @@ -172,8 +169,7 @@ public class HttpMessageConverterResolver { } /** - * Resolve the {@link MediaType media-types} - * + * Resolve the {@link MediaType media-types}. * @param requestMetadata {@link RequestMetadata} from client side * @return non-null {@link List} */ @@ -187,9 +183,8 @@ public class HttpMessageConverterResolver { *

  • The producible media types specified in the request mappings, or *
  • Media types of configured converters that can write the specific return value, * or - *
  • {@link MediaType#ALL} + *
  • {@link MediaType#ALL}. * - * * @param restMethodMetadata {@link RestMethodMetadata} from server side * @param returnValueClass the class of return value * @return non-null {@link List} @@ -218,9 +213,8 @@ public class HttpMessageConverterResolver { /** * Return the media types supported by all provided message converters sorted by * specificity via {@link MediaType#sortBySpecificity(List)}. - * - * @param messageConverters - * @return + * @param messageConverters list of converters + * @return list of MediaTypes */ private List getAllSupportedMediaTypes( List> messageConverters) { @@ -243,4 +237,5 @@ public class HttpMessageConverterResolver { return (MediaType.SPECIFICITY_COMPARATOR.compare(acceptType, produceTypeToUse) <= 0 ? acceptType : produceTypeToUse); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/util/HttpUtils.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/util/HttpUtils.java index 99bcfeb99..28c32921f 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/util/HttpUtils.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/http/util/HttpUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,11 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.http.util; -import static org.springframework.util.StringUtils.delimitedListToStringArray; -import static org.springframework.util.StringUtils.hasText; -import static org.springframework.util.StringUtils.trimAllWhitespace; +package com.alibaba.cloud.dubbo.http.util; import java.io.UnsupportedEncodingException; import java.net.URI; @@ -34,25 +31,44 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; +import static org.springframework.util.StringUtils.delimitedListToStringArray; +import static org.springframework.util.StringUtils.hasText; +import static org.springframework.util.StringUtils.trimAllWhitespace; + /** - * Http Utilities class + * Http Utilities class. * * @author Mercy */ public abstract class HttpUtils { + /** + * Charset value for Http. + */ private static final String UTF_8 = "UTF-8"; + /** + * Equal operator for Http. + */ private static final String EQUAL = "="; + /** + * And operator for Http. + */ private static final String AND = "&"; + /** + * Semicolon operator for Http. + */ private static final String SEMICOLON = ";"; + /** + * Question Mark operation for Http. + */ private static final String QUESTION_MASK = "?"; /** - * The empty value + * The empty value. */ private static final String EMPTY_VALUE = ""; @@ -60,9 +76,8 @@ public abstract class HttpUtils { * Normalize path: *
      *
    1. To remove query string if presents
    2. - *
    3. To remove duplicated slash("/") if exists
    4. + *
    5. To remove duplicated slash("/") if exists.
    6. *
    - * * @param path path to be normalized * @return a normalized path if required */ @@ -79,10 +94,9 @@ public abstract class HttpUtils { } /** - * Get Parameters from the specified {@link HttpRequest request} - * + * Get Parameters from the specified {@link HttpRequest request}. * @param request the specified {@link HttpRequest request} - * @return + * @return map of parameters */ public static MultiValueMap getParameters(HttpRequest request) { URI uri = request.getURI(); @@ -92,7 +106,6 @@ public abstract class HttpUtils { /** * Get Parameters from the specified query string. *

    - * * @param queryString The query string * @return The query parameters */ @@ -103,7 +116,6 @@ public abstract class HttpUtils { /** * Get Parameters from the specified pairs of name-value. *

    - * * @param pairs The pairs of name-value * @return The query parameters */ @@ -124,7 +136,6 @@ public abstract class HttpUtils { /** * Get Parameters from the specified pairs of name-value. *

    - * * @param pairs The pairs of name-value * @return The query parameters */ @@ -163,8 +174,7 @@ public abstract class HttpUtils { // } /** - * To the name and value line sets - * + * To the name and value line sets. * @param nameAndValuesMap {@link MultiValueMap} the map of name and values * @return non-null */ @@ -187,8 +197,8 @@ public abstract class HttpUtils { } /** - * Generate a string of query string from the specified request parameters {@link Map} - * + * Generate a string of query string from the specified request parameters + * {@link Map}. * @param params the specified request parameters {@link Map} * @return non-null */ @@ -201,8 +211,7 @@ public abstract class HttpUtils { } /** - * Decode value - * + * Decode value. * @param value the value requires to decode * @return the decoded value */ @@ -220,8 +229,7 @@ public abstract class HttpUtils { } /** - * encode value - * + * encode value. * @param value the value requires to encode * @return the encoded value */ @@ -243,4 +251,5 @@ public abstract class HttpUtils { } paramsMap.add(trimAllWhitespace(name), paramValue); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/DubboProtocolConfigSupplier.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/DubboProtocolConfigSupplier.java index 5904dc0fc..1dfb8e732 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/DubboProtocolConfigSupplier.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/DubboProtocolConfigSupplier.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,20 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.metadata; -import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_PROTOCOL; -import static org.springframework.util.CollectionUtils.isEmpty; +package com.alibaba.cloud.dubbo.metadata; import java.util.Collection; import java.util.Iterator; import java.util.function.Supplier; import org.apache.dubbo.config.ProtocolConfig; + import org.springframework.beans.factory.ObjectProvider; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_PROTOCOL; +import static org.springframework.util.CollectionUtils.isEmpty; + /** - * Dubbo's {@link ProtocolConfig} {@link Supplier} + * Dubbo's {@link ProtocolConfig} {@link Supplier}. * * @author Mercy */ @@ -68,4 +70,5 @@ public class DubboProtocolConfigSupplier implements Supplier { return protocolConfig; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/DubboRestServiceMetadata.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/DubboRestServiceMetadata.java index b4d6b6182..4671a547b 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/DubboRestServiceMetadata.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/DubboRestServiceMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.metadata; import java.util.Objects; /** - * Dubbo Rest Service Metadata + * Dubbo Rest Service Metadata. * * @author Mercy */ @@ -59,4 +60,5 @@ public class DubboRestServiceMetadata { public int hashCode() { return Objects.hash(serviceRestMetadata, restMethodMetadata); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/DubboTransportedMethodMetadata.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/DubboTransportedMethodMetadata.java index 98ccbc530..935f287b2 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/DubboTransportedMethodMetadata.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/DubboTransportedMethodMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.metadata; import java.lang.reflect.Method; @@ -23,7 +24,7 @@ import java.util.Objects; import com.alibaba.cloud.dubbo.annotation.DubboTransported; /** - * {@link MethodMetadata} annotated {@link DubboTransported @DubboTransported} + * {@link MethodMetadata} annotated {@link DubboTransported @DubboTransported}. * * @author Mercy */ @@ -91,4 +92,5 @@ public class DubboTransportedMethodMetadata { public int hashCode() { return Objects.hash(methodMetadata, attributes); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/MethodMetadata.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/MethodMetadata.java index 69dbd5248..f4536a635 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/MethodMetadata.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/MethodMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.metadata; import java.lang.reflect.Method; @@ -28,7 +29,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; /** - * {@link Method} Metadata + * {@link Method} Metadata. * * @author Mercy */ @@ -132,4 +133,5 @@ public class MethodMetadata { return "MethodMetadata{" + "name='" + name + '\'' + ", returnType='" + returnType + '\'' + ", params=" + params + ", method=" + method + '}'; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/MethodParameterMetadata.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/MethodParameterMetadata.java index 1e26c28ef..959ca8540 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/MethodParameterMetadata.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/MethodParameterMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.metadata; import java.lang.reflect.Method; @@ -21,7 +22,7 @@ import java.util.Objects; import com.fasterxml.jackson.annotation.JsonInclude; /** - * {@link Method} Parameter Metadata + * {@link Method} Parameter Metadata. * * @author Mercy */ @@ -81,4 +82,5 @@ public class MethodParameterMetadata { return "MethodParameterMetadata{" + "index=" + index + ", name='" + name + '\'' + ", type='" + type + '\'' + '}'; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/RequestMetadata.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/RequestMetadata.java index b5499cd0b..eb6485808 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/RequestMetadata.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/RequestMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.metadata; -import static com.alibaba.cloud.dubbo.http.util.HttpUtils.normalizePath; -import static org.springframework.http.MediaType.parseMediaTypes; +package com.alibaba.cloud.dubbo.metadata; import java.util.ArrayList; import java.util.Collection; @@ -30,19 +28,21 @@ import java.util.Objects; import java.util.Set; import java.util.SortedMap; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import feign.RequestTemplate; + import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; - -import feign.RequestTemplate; +import static com.alibaba.cloud.dubbo.http.util.HttpUtils.normalizePath; +import static org.springframework.http.MediaType.parseMediaTypes; /** - * Request Metadata + * Request Metadata. * * @author Mercy */ @@ -73,8 +73,7 @@ public class RequestMetadata { } /** - * Get the best matched {@link RequestMetadata} via specified {@link RequestMetadata} - * + * Get the best matched {@link RequestMetadata} via specified {@link RequestMetadata}. * @param requestMetadataMap the source of {@link NavigableMap} * @param requestMetadata the match object * @return if not matched, return null @@ -270,4 +269,5 @@ public class RequestMetadata { + ", params=" + params + ", headers=" + headers + ", consumes=" + consumes + ", produces=" + produces + '}'; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/RestMethodMetadata.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/RestMethodMetadata.java index ee95a3fa6..71a4d45c0 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/RestMethodMetadata.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/RestMethodMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.metadata; import java.lang.reflect.Type; @@ -21,13 +22,13 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import org.springframework.core.ResolvableType; - import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import org.springframework.core.ResolvableType; + /** - * Method Request Metadata + * Method Request Metadata. * * @author Mercy */ @@ -229,4 +230,5 @@ public class RestMethodMetadata { + ", indexToName=" + indexToName + ", formParams=" + formParams + ", indexToEncoded=" + indexToEncoded + '}'; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/ServiceRestMetadata.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/ServiceRestMetadata.java index 07771bf1c..2f5e6a048 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/ServiceRestMetadata.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/ServiceRestMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.metadata; import java.util.Objects; @@ -21,7 +22,7 @@ import java.util.Set; import com.fasterxml.jackson.annotation.JsonInclude; /** - * Service Rest Metadata + * Service Rest Metadata. * * @author Mercy * @see RestMethodMetadata @@ -65,4 +66,5 @@ public class ServiceRestMetadata { public int hashCode() { return Objects.hash(url, meta); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/repository/DubboServiceMetadataRepository.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/repository/DubboServiceMetadataRepository.java index 3afea1caf..124989c3e 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/repository/DubboServiceMetadataRepository.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/repository/DubboServiceMetadataRepository.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,21 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.metadata.repository; -import static com.alibaba.cloud.dubbo.env.DubboCloudProperties.ALL_DUBBO_SERVICES; -import static com.alibaba.cloud.dubbo.http.DefaultHttpRequest.builder; -import static java.lang.String.format; -import static java.lang.String.valueOf; -import static java.util.Collections.emptyList; -import static java.util.Collections.emptySet; -import static java.util.Collections.unmodifiableList; -import static java.util.Collections.unmodifiableMap; -import static java.util.Collections.unmodifiableSet; -import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; -import static org.springframework.util.CollectionUtils.isEmpty; -import static org.springframework.util.StringUtils.hasText; +package com.alibaba.cloud.dubbo.metadata.repository; import java.util.Collections; import java.util.LinkedHashMap; @@ -41,9 +28,22 @@ import java.util.stream.Stream; import javax.annotation.PostConstruct; +import com.alibaba.cloud.dubbo.env.DubboCloudProperties; +import com.alibaba.cloud.dubbo.http.matcher.RequestMetadataMatcher; +import com.alibaba.cloud.dubbo.metadata.DubboRestServiceMetadata; +import com.alibaba.cloud.dubbo.metadata.RequestMetadata; +import com.alibaba.cloud.dubbo.metadata.ServiceRestMetadata; +import com.alibaba.cloud.dubbo.registry.event.SubscribedServicesChangedEvent; +import com.alibaba.cloud.dubbo.service.DubboMetadataService; +import com.alibaba.cloud.dubbo.service.DubboMetadataServiceExporter; +import com.alibaba.cloud.dubbo.service.DubboMetadataServiceProxy; +import com.alibaba.cloud.dubbo.util.JSONUtils; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.TypeFactory; import org.apache.dubbo.common.URL; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.SmartInitializingSingleton; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -58,22 +58,22 @@ import org.springframework.stereotype.Repository; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -import com.alibaba.cloud.dubbo.env.DubboCloudProperties; -import com.alibaba.cloud.dubbo.http.matcher.RequestMetadataMatcher; -import com.alibaba.cloud.dubbo.metadata.DubboRestServiceMetadata; -import com.alibaba.cloud.dubbo.metadata.RequestMetadata; -import com.alibaba.cloud.dubbo.metadata.ServiceRestMetadata; -import com.alibaba.cloud.dubbo.registry.event.SubscribedServicesChangedEvent; -import com.alibaba.cloud.dubbo.service.DubboMetadataService; -import com.alibaba.cloud.dubbo.service.DubboMetadataServiceExporter; -import com.alibaba.cloud.dubbo.service.DubboMetadataServiceProxy; -import com.alibaba.cloud.dubbo.util.JSONUtils; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.type.TypeFactory; +import static com.alibaba.cloud.dubbo.env.DubboCloudProperties.ALL_DUBBO_SERVICES; +import static com.alibaba.cloud.dubbo.http.DefaultHttpRequest.builder; +import static java.lang.String.format; +import static java.lang.String.valueOf; +import static java.util.Collections.emptyList; +import static java.util.Collections.emptySet; +import static java.util.Collections.unmodifiableList; +import static java.util.Collections.unmodifiableMap; +import static java.util.Collections.unmodifiableSet; +import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; +import static org.springframework.util.CollectionUtils.isEmpty; +import static org.springframework.util.StringUtils.hasText; /** - * Dubbo Service Metadata {@link Repository} + * Dubbo Service Metadata {@link Repository}. * * @author Mercy */ @@ -82,19 +82,19 @@ public class DubboServiceMetadataRepository implements SmartInitializingSingleton, ApplicationEventPublisherAware { /** - * The prefix of {@link DubboMetadataService} : "dubbo.metadata-service." + * The prefix of {@link DubboMetadataService} : "dubbo.metadata-service.". */ public static final String DUBBO_METADATA_SERVICE_PREFIX = "dubbo.metadata-service."; /** * The {@link URL URLs} property name of {@link DubboMetadataService} : - * "dubbo.metadata-service.urls" + * "dubbo.metadata-service.urls". */ public static final String DUBBO_METADATA_SERVICE_URLS_PROPERTY_NAME = DUBBO_METADATA_SERVICE_PREFIX + "urls"; /** - * The {@link String#format(String, Object...) pattern} of dubbo protocols port + * The {@link String#format(String, Object...) pattern} of dubbo protocols port. */ public static final String DUBBO_PROTOCOLS_PORT_PROPERTY_NAME_PATTERN = "dubbo.protocols.%s.port"; @@ -103,17 +103,19 @@ public class DubboServiceMetadataRepository private final ObjectMapper objectMapper = new ObjectMapper(); /** - * Monitor object for synchronization + * Monitor object for synchronization. */ private final Object monitor = new Object(); + /** - * A {@link Set} of service names that had been initialized + * A {@link Set} of service names that had been initialized. */ private final Set initializedServices = new LinkedHashSet<>(); + /** * All exported {@link URL urls} {@link Map} whose key is the return value of * {@link URL#getServiceKey()} method and value is the {@link List} of {@link URL - * URLs} + * URLs}. */ private final MultiValueMap allExportedURLs = new LinkedMultiValueMap<>(); @@ -122,7 +124,7 @@ public class DubboServiceMetadataRepository /** * The subscribed {@link URL urls} {@link Map} of {@link DubboMetadataService}, whose * key is the return value of {@link URL#getServiceKey()} method and value is the - * {@link List} of {@link URL URLs} + * {@link List} of {@link URL URLs}. */ private final MultiValueMap subscribedDubboMetadataServiceURLs = new LinkedMultiValueMap<>(); @@ -137,6 +139,7 @@ public class DubboServiceMetadataRepository * from the annotated methods. */ private final Set serviceRestMetadata = new LinkedHashSet<>(); + private ApplicationEventPublisher applicationEventPublisher; // ==================================================================================== @@ -145,8 +148,10 @@ public class DubboServiceMetadataRepository // =================================== REST Metadata // ================================== // private volatile Set subscribedServices = emptySet(); + /** - * Key is application name Value is Map + * Key is application name Value is Map<RequestMetadata, + * DubboRestServiceMetadata>. */ private Map> dubboRestServiceMetadataRepository = newHashMap(); @@ -202,9 +207,8 @@ public class DubboServiceMetadataRepository } /** - * Initialize {@link #subscribedServices the subscribed services} - * - * @return + * Initialize {@link #subscribedServices the subscribed services}. + * @return stream of subscribed services */ @PostConstruct public Stream initSubscribedServices() { @@ -256,7 +260,7 @@ public class DubboServiceMetadataRepository } /** - * Initialize the metadata + * Initialize the metadata. */ private void initializeMetadata() { doGetSubscribedServices().forEach(this::initializeMetadata); @@ -266,7 +270,8 @@ public class DubboServiceMetadataRepository } /** - * Initialize the metadata of Dubbo Services + * Initialize the metadata of Dubbo Services. + * @param serviceName service of name */ public void initializeMetadata(String serviceName) { synchronized (monitor) { @@ -294,7 +299,7 @@ public class DubboServiceMetadataRepository } /** - * Remove the metadata of Dubbo Services if no there is no service instance + * Remove the metadata of Dubbo Services if no there is no service instance. * @param serviceName the service name */ public void removeInitializedService(String serviceName) { @@ -304,8 +309,7 @@ public class DubboServiceMetadataRepository } /** - * Get the metadata {@link Map} of {@link DubboMetadataService} - * + * Get the metadata {@link Map} of {@link DubboMetadataService}. * @return non-null read-only {@link Map} */ public Map getDubboMetadataServiceMetadata() { @@ -345,8 +349,7 @@ public class DubboServiceMetadataRepository } /** - * Get the property name of Dubbo Protocol - * + * Get the property name of Dubbo Protocol. * @param protocol Dubbo Protocol * @return non-null */ @@ -355,8 +358,7 @@ public class DubboServiceMetadataRepository } /** - * Publish the {@link Set} of {@link ServiceRestMetadata} - * + * Publish the {@link Set} of {@link ServiceRestMetadata}. * @param serviceRestMetadataSet the {@link Set} of {@link ServiceRestMetadata} */ public void publishServiceRestMetadata( @@ -369,8 +371,7 @@ public class DubboServiceMetadataRepository } /** - * Get the {@link Set} of {@link ServiceRestMetadata} - * + * Get the {@link Set} of {@link ServiceRestMetadata}. * @return non-null read-only {@link Set} */ public Set getServiceRestMetadata() { @@ -391,18 +392,15 @@ public class DubboServiceMetadataRepository return emptyList(); } - return hasText(protocol) - ? urls.stream() - .filter(url -> url.getProtocol().equalsIgnoreCase(protocol)) - .collect(Collectors.toList()) - : unmodifiableList(urls); + return hasText(protocol) ? urls.stream() + .filter(url -> url.getProtocol().equalsIgnoreCase(protocol)) + .collect(Collectors.toList()) : unmodifiableList(urls); } /** - * The specified service is subscribe or not - * + * The specified service is subscribe or not. * @param serviceName the service name - * @return + * @return subscribe or not */ public boolean isSubscribedService(String serviceName) { return doGetSubscribedServices().contains(serviceName); @@ -434,7 +432,6 @@ public class DubboServiceMetadataRepository /** * Get all exported {@link URL urls}. - * * @return non-null read-only */ public Map> getAllExportedUrls() { @@ -442,8 +439,7 @@ public class DubboServiceMetadataRepository } /** - * Get all exported {@link URL#getServiceKey() service keys} - * + * Get all exported {@link URL#getServiceKey() service keys}. * @return non-null read-only */ public Set getAllServiceKeys() { @@ -452,8 +448,7 @@ public class DubboServiceMetadataRepository /** * Get the {@link URL urls} that {@link DubboMetadataService} exported by the - * specified {@link ServiceInstance} - * + * specified {@link ServiceInstance}. * @param serviceInstance {@link ServiceInstance} * @return the mutable {@link URL urls} */ @@ -478,8 +473,7 @@ public class DubboServiceMetadataRepository } /** - * Initialize the specified service's {@link ServiceRestMetadata} - * + * Initialize the specified service's {@link ServiceRestMetadata}. * @param serviceName the service name */ protected void initDubboRestServiceMetadataRepository(String serviceName) { @@ -524,8 +518,7 @@ public class DubboServiceMetadataRepository /** * Get a {@link DubboRestServiceMetadata} by the specified service name if - * {@link RequestMetadata} matched - * + * {@link RequestMetadata} matched. * @param serviceName service name * @param requestMetadata {@link RequestMetadata} to be matched * @return {@link DubboRestServiceMetadata} if matched, or null @@ -661,4 +654,5 @@ public class DubboServiceMetadataRepository ApplicationEventPublisher applicationEventPublisher) { this.applicationEventPublisher = applicationEventPublisher; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/repository/MetadataServiceInstanceSelector.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/repository/MetadataServiceInstanceSelector.java index f42ba4f9c..821e3043b 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/repository/MetadataServiceInstanceSelector.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/repository/MetadataServiceInstanceSelector.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,16 +22,17 @@ import java.util.Optional; import org.springframework.cloud.client.ServiceInstance; /** - * metadata service instance selector + * metadata service instance selector. * * @author liuxx */ public interface MetadataServiceInstanceSelector { /** - * choose a service instance to get metadata + * choose a service instance to get metadata. * @param serviceInstances all service instance * @return the service instance to get metadata */ Optional choose(List serviceInstances); + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboServiceBeanMetadataResolver.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboServiceBeanMetadataResolver.java index a070a61af..8ae2d4f25 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboServiceBeanMetadataResolver.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboServiceBeanMetadataResolver.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.metadata.resolver; import java.lang.reflect.Method; @@ -26,22 +27,21 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; +import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; +import com.alibaba.cloud.dubbo.metadata.ServiceRestMetadata; +import feign.Contract; +import feign.Feign; +import feign.MethodMetadata; +import feign.Util; import org.apache.dubbo.common.URL; import org.apache.dubbo.config.spring.ServiceBean; + import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.SmartInitializingSingleton; import org.springframework.util.ClassUtils; -import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; -import com.alibaba.cloud.dubbo.metadata.ServiceRestMetadata; - -import feign.Contract; -import feign.Feign; -import feign.MethodMetadata; -import feign.Util; - /** * The metadata resolver for {@link Feign} for {@link ServiceBean Dubbo Service Bean} in * the provider side. @@ -59,7 +59,7 @@ public class DubboServiceBeanMetadataResolver private ClassLoader classLoader; /** - * Feign Contracts + * Feign Contracts. */ private Collection contracts; @@ -153,9 +153,8 @@ public class DubboServiceBeanMetadataResolver * Select feign contract methods *

    * extract some code from - * {@link Contract.BaseContract#parseAndValidatateMetadata(java.lang.Class)} - * - * @param targetType + * {@link Contract.BaseContract#parseAndValidatateMetadata(java.lang.Class)}. + * @param targetType class of type * @return non-null */ private List selectFeignContractMethods(Class targetType) { @@ -200,4 +199,4 @@ public class DubboServiceBeanMetadataResolver this.classLoader = classLoader; } -} \ No newline at end of file +} diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboTransportedAttributesResolver.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboTransportedAttributesResolver.java index dcc2b93a4..c060ee3f9 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboTransportedAttributesResolver.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboTransportedAttributesResolver.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,19 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.metadata.resolver; -import static org.springframework.core.annotation.AnnotationUtils.getAnnotationAttributes; +package com.alibaba.cloud.dubbo.metadata.resolver; import java.util.LinkedHashMap; import java.util.Map; +import com.alibaba.cloud.dubbo.annotation.DubboTransported; + import org.springframework.core.env.PropertyResolver; -import com.alibaba.cloud.dubbo.annotation.DubboTransported; +import static org.springframework.core.annotation.AnnotationUtils.getAnnotationAttributes; /** - * {@link DubboTransported} annotation attributes resolver + * {@link DubboTransported} annotation attributes resolver. * * @author Mercy */ @@ -53,4 +54,5 @@ public class DubboTransportedAttributesResolver { } return resolvedAttributes; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboTransportedMethodMetadataResolver.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboTransportedMethodMetadataResolver.java index f6dda7f2a..b5834adbf 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboTransportedMethodMetadataResolver.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboTransportedMethodMetadataResolver.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.metadata.resolver; -import static feign.Feign.configKey; +package com.alibaba.cloud.dubbo.metadata.resolver; import java.lang.reflect.Method; import java.util.LinkedHashSet; @@ -23,16 +22,17 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.core.env.PropertyResolver; - import com.alibaba.cloud.dubbo.annotation.DubboTransported; import com.alibaba.cloud.dubbo.metadata.DubboTransportedMethodMetadata; import com.alibaba.cloud.dubbo.metadata.MethodMetadata; import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; - import feign.Contract; +import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.core.env.PropertyResolver; + +import static feign.Feign.configKey; + /** * {@link MethodMetadata} Resolver for the {@link DubboTransported} annotated classes or * methods in client side. @@ -115,4 +115,5 @@ public class DubboTransportedMethodMetadataResolver { } return dubboTransported; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/MetadataResolver.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/MetadataResolver.java index 50af2633d..b71d17781 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/MetadataResolver.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/MetadataResolver.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,35 +13,34 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.metadata.resolver; import java.util.Set; -import org.apache.dubbo.config.spring.ServiceBean; - import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; import com.alibaba.cloud.dubbo.metadata.ServiceRestMetadata; +import org.apache.dubbo.config.spring.ServiceBean; /** - * The REST metadata resolver + * The REST metadata resolver. * * @author Mercy */ public interface MetadataResolver { /** - * Resolve the {@link ServiceRestMetadata} {@link Set set} from {@link ServiceBean} - * + * Resolve the {@link ServiceRestMetadata} {@link Set set} from {@link ServiceBean}. * @param serviceBean {@link ServiceBean} * @return non-null {@link Set} */ Set resolveServiceRestMetadata(ServiceBean serviceBean); /** - * Resolve {@link RestMethodMetadata} {@link Set set} from {@link Class target type} - * + * Resolve {@link RestMethodMetadata} {@link Set set} from {@link Class target type}. * @param targetType {@link Class target type} * @return non-null {@link Set} */ Set resolveMethodRestMetadata(Class targetType); + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/openfeign/DubboInvocationHandler.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/openfeign/DubboInvocationHandler.java index f73538f4b..27917763d 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/openfeign/DubboInvocationHandler.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/openfeign/DubboInvocationHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,23 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.openfeign; -import static org.apache.dubbo.common.utils.PojoUtils.realize; +package com.alibaba.cloud.dubbo.openfeign; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.util.Map; -import org.apache.dubbo.rpc.service.GenericService; -import org.springframework.util.ClassUtils; - import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContext; import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContextFactory; +import org.apache.dubbo.rpc.service.GenericService; + +import org.springframework.util.ClassUtils; + +import static org.apache.dubbo.common.utils.PojoUtils.realize; /** - * Dubbo {@link GenericService} for {@link InvocationHandler} + * Dubbo {@link GenericService} for {@link InvocationHandler}. * * @author Mercy */ @@ -87,4 +88,5 @@ public class DubboInvocationHandler implements InvocationHandler { String returnType = dubboRestMethodMetadata.getReturnType(); return ClassUtils.resolveClassName(returnType, classLoader); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/openfeign/FeignMethodMetadata.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/openfeign/FeignMethodMetadata.java index 285ad1544..8fb561b1d 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/openfeign/FeignMethodMetadata.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/openfeign/FeignMethodMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,16 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.openfeign; import java.lang.reflect.Method; -import org.apache.dubbo.rpc.service.GenericService; - import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; +import org.apache.dubbo.rpc.service.GenericService; /** - * Feign {@link Method} Metadata + * Feign {@link Method} Metadata. * * @author Mercy */ @@ -53,4 +53,5 @@ class FeignMethodMetadata { RestMethodMetadata getFeignMethodMetadata() { return feignMethodMetadata; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/openfeign/TargeterBeanPostProcessor.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/openfeign/TargeterBeanPostProcessor.java index 885e7b5fc..fdb1f288e 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/openfeign/TargeterBeanPostProcessor.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/openfeign/TargeterBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,25 +13,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.openfeign; -import static com.alibaba.cloud.dubbo.autoconfigure.DubboOpenFeignAutoConfiguration.TARGETER_CLASS_NAME; -import static java.lang.reflect.Proxy.newProxyInstance; -import static org.springframework.util.ClassUtils.getUserClass; -import static org.springframework.util.ClassUtils.isPresent; -import static org.springframework.util.ClassUtils.resolveClassName; +import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; +import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContextFactory; +import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.core.env.Environment; -import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; -import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContextFactory; -import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory; +import static com.alibaba.cloud.dubbo.autoconfigure.DubboOpenFeignAutoConfiguration.TARGETER_CLASS_NAME; +import static java.lang.reflect.Proxy.newProxyInstance; +import static org.springframework.util.ClassUtils.getUserClass; +import static org.springframework.util.ClassUtils.isPresent; +import static org.springframework.util.ClassUtils.resolveClassName; /** - * org.springframework.cloud.openfeign.Targeter {@link BeanPostProcessor} + * org.springframework.cloud.openfeign.Targeter {@link BeanPostProcessor}. * * @author Mercy */ @@ -84,4 +85,5 @@ public class TargeterBeanPostProcessor public void setBeanClassLoader(ClassLoader classLoader) { this.classLoader = classLoader; } -} \ No newline at end of file + +} diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/openfeign/TargeterInvocationHandler.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/openfeign/TargeterInvocationHandler.java index db8144ec5..a42474402 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/openfeign/TargeterInvocationHandler.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/openfeign/TargeterInvocationHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.openfeign; -import static java.lang.reflect.Proxy.newProxyInstance; +package com.alibaba.cloud.dubbo.openfeign; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; @@ -23,12 +22,6 @@ import java.lang.reflect.Proxy; import java.util.HashMap; import java.util.Map; -import org.apache.dubbo.rpc.service.GenericService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.cloud.openfeign.FeignContext; -import org.springframework.core.env.Environment; - import com.alibaba.cloud.dubbo.annotation.DubboTransported; import com.alibaba.cloud.dubbo.metadata.DubboRestServiceMetadata; import com.alibaba.cloud.dubbo.metadata.DubboTransportedMethodMetadata; @@ -39,12 +32,19 @@ import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepositor import com.alibaba.cloud.dubbo.metadata.resolver.DubboTransportedMethodMetadataResolver; import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContextFactory; import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory; - import feign.Contract; import feign.Target; +import org.apache.dubbo.rpc.service.GenericService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.cloud.openfeign.FeignContext; +import org.springframework.core.env.Environment; + +import static java.lang.reflect.Proxy.newProxyInstance; /** - * org.springframework.cloud.openfeign.Targeter {@link InvocationHandler} + * org.springframework.cloud.openfeign.Targeter {@link InvocationHandler}. * * @author Mercy */ @@ -84,7 +84,7 @@ class TargeterInvocationHandler implements InvocationHandler { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { /** * args[0]: FeignClientFactoryBean factory args[1]: Feign.Builder feign args[2]: - * FeignContext context args[3]: Target.HardCodedTarget target + * FeignContext context args[3]: Target.HardCodedTarget<T> target */ FeignContext feignContext = cast(args[2]); Target.HardCodedTarget target = cast(args[3]); @@ -183,4 +183,5 @@ class TargeterInvocationHandler implements InvocationHandler { return feignMethodMetadataMap; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/AbstractSpringCloudRegistry.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/AbstractSpringCloudRegistry.java index 7b9df622b..0d4c02576 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/AbstractSpringCloudRegistry.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/AbstractSpringCloudRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,19 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.registry; -import static java.util.Arrays.asList; -import static java.util.Collections.emptyList; -import static org.apache.dubbo.common.URLBuilder.from; -import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; -import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; -import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL; -import static org.apache.dubbo.registry.Constants.ADMIN_PROTOCOL; -import static org.springframework.util.StringUtils.hasText; +package com.alibaba.cloud.dubbo.registry; import java.util.Collection; import java.util.HashSet; @@ -35,48 +24,61 @@ import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; +import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; +import com.alibaba.cloud.dubbo.registry.event.ServiceInstancesChangedEvent; +import com.alibaba.cloud.dubbo.service.DubboMetadataService; +import com.alibaba.cloud.dubbo.service.DubboMetadataServiceProxy; +import com.alibaba.cloud.dubbo.util.JSONUtils; import org.apache.dubbo.common.URL; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.RegistryFactory; import org.apache.dubbo.registry.support.FailbackRegistry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.context.ApplicationListener; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.util.CollectionUtils; -import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; -import com.alibaba.cloud.dubbo.registry.event.ServiceInstancesChangedEvent; -import com.alibaba.cloud.dubbo.service.DubboMetadataService; -import com.alibaba.cloud.dubbo.service.DubboMetadataServiceProxy; -import com.alibaba.cloud.dubbo.util.JSONUtils; +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; +import static org.apache.dubbo.common.URLBuilder.from; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; +import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL; +import static org.apache.dubbo.registry.Constants.ADMIN_PROTOCOL; +import static org.springframework.util.StringUtils.hasText; /** * Abstract Dubbo {@link RegistryFactory} uses Spring Cloud Service Registration - * abstraction, whose protocol is "spring-cloud" + * abstraction, whose protocol is "spring-cloud". * * @author Mercy */ public abstract class AbstractSpringCloudRegistry extends FailbackRegistry { /** - * The parameter name of {@link #servicesLookupInterval} + * The parameter name of {@link #servicesLookupInterval}. */ public static final String SERVICES_LOOKUP_INTERVAL_PARAM_NAME = "dubbo.services.lookup.interval"; protected static final String DUBBO_METADATA_SERVICE_CLASS_NAME = DubboMetadataService.class .getName(); + /** - * Caches the IDs of {@link ApplicationListener} + * Caches the IDs of {@link ApplicationListener}. */ private static final Set registerListeners = new HashSet<>(); protected final Logger logger = LoggerFactory.getLogger(getClass()); /** - * The interval in second of lookup service names(only for Dubbo-OPS) + * The interval in second of lookup service names(only for Dubbo-OPS). */ private final long servicesLookupInterval; @@ -127,8 +129,7 @@ public abstract class AbstractSpringCloudRegistry extends FailbackRegistry { } /** - * The sub-type should implement to register - * + * The sub-type should implement to register. * @param url {@link URL} */ protected abstract void doRegister0(URL url); @@ -142,8 +143,7 @@ public abstract class AbstractSpringCloudRegistry extends FailbackRegistry { } /** - * The sub-type should implement to unregister - * + * The sub-type should implement to unregister. * @param url {@link URL} */ protected abstract void doUnregister0(URL url); @@ -171,8 +171,7 @@ public abstract class AbstractSpringCloudRegistry extends FailbackRegistry { /** * Register a {@link ApplicationListener listener} for - * {@link ServiceInstancesChangedEvent} - * + * {@link ServiceInstancesChangedEvent}. * @param url {@link URL} * @param listener {@link NotifyListener} */ @@ -350,8 +349,8 @@ public abstract class AbstractSpringCloudRegistry extends FailbackRegistry { @Override public final void doUnsubscribe(URL url, NotifyListener listener) { - if (isAdminURL(url)) { - } + // if (isAdminURL(url)) { + // } } @Override @@ -366,4 +365,5 @@ public abstract class AbstractSpringCloudRegistry extends FailbackRegistry { protected boolean isDubboMetadataServiceURL(URL url) { return DUBBO_METADATA_SERVICE_CLASS_NAME.equals(url.getServiceInterface()); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/DelegatingRegistration.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/DelegatingRegistration.java index dcc63796d..1af716f3e 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/DelegatingRegistration.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/DelegatingRegistration.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.registry; import java.net.URI; @@ -31,7 +32,7 @@ class DelegatingRegistration implements Registration { private final ServiceInstance delegate; - public DelegatingRegistration(ServiceInstance delegate) { + DelegatingRegistration(ServiceInstance delegate) { this.delegate = delegate; } @@ -69,4 +70,5 @@ class DelegatingRegistration implements Registration { public String getScheme() { return delegate.getScheme(); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/DubboServiceRegistrationEventPublishingAspect.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/DubboServiceRegistrationEventPublishingAspect.java index 7d4a21fb4..43e679f53 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/DubboServiceRegistrationEventPublishingAspect.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/DubboServiceRegistrationEventPublishingAspect.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,21 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.registry; +import com.alibaba.cloud.dubbo.registry.event.ServiceInstancePreRegisteredEvent; +import com.alibaba.cloud.dubbo.registry.event.ServiceInstanceRegisteredEvent; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; + import org.springframework.cloud.client.serviceregistry.Registration; import org.springframework.cloud.client.serviceregistry.ServiceRegistry; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; -import com.alibaba.cloud.dubbo.registry.event.ServiceInstancePreRegisteredEvent; -import com.alibaba.cloud.dubbo.registry.event.ServiceInstanceRegisteredEvent; - /** - * Dubbo Service Registration Event-Publishing Aspect + * Dubbo Service Registration Event-Publishing Aspect. * * @author Mercy * @see ServiceInstancePreRegisteredEvent @@ -38,7 +39,7 @@ public class DubboServiceRegistrationEventPublishingAspect implements ApplicationEventPublisherAware { /** - * The pointcut expression for {@link ServiceRegistry#register(Registration)} + * The pointcut expression for {@link ServiceRegistry#register(Registration)}. */ public static final String REGISTER_POINTCUT_EXPRESSION = "execution(* org.springframework.cloud.client.serviceregistry.ServiceRegistry.register(*)) && args(registration)"; @@ -61,4 +62,5 @@ public class DubboServiceRegistrationEventPublishingAspect ApplicationEventPublisher applicationEventPublisher) { this.applicationEventPublisher = applicationEventPublisher; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/SpringCloudRegistry.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/SpringCloudRegistry.java index f6a67f1d7..c9caa957a 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/SpringCloudRegistry.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/SpringCloudRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,20 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.registry; +import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; +import com.alibaba.cloud.dubbo.service.DubboMetadataServiceProxy; +import com.alibaba.cloud.dubbo.util.JSONUtils; import org.apache.dubbo.common.URL; import org.apache.dubbo.registry.RegistryFactory; + import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.context.ConfigurableApplicationContext; -import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; -import com.alibaba.cloud.dubbo.service.DubboMetadataServiceProxy; -import com.alibaba.cloud.dubbo.util.JSONUtils; - /** * Dubbo {@link RegistryFactory} uses Spring Cloud Service Registration abstraction, whose - * protocol is "spring-cloud" + * protocol is "spring-cloud". * * @author Mercy */ @@ -52,4 +53,5 @@ public class SpringCloudRegistry extends AbstractSpringCloudRegistry { protected void doUnregister0(URL url) { dubboServiceMetadataRepository.unexportURL(url); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/SpringCloudRegistryFactory.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/SpringCloudRegistryFactory.java index 15f44883e..08e460166 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/SpringCloudRegistryFactory.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/SpringCloudRegistryFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,23 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.registry; -import static java.lang.System.getProperty; +package com.alibaba.cloud.dubbo.registry; +import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; +import com.alibaba.cloud.dubbo.service.DubboMetadataServiceProxy; +import com.alibaba.cloud.dubbo.util.JSONUtils; import org.apache.dubbo.common.URL; import org.apache.dubbo.registry.Registry; import org.apache.dubbo.registry.RegistryFactory; + import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.context.ConfigurableApplicationContext; -import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; -import com.alibaba.cloud.dubbo.service.DubboMetadataServiceProxy; -import com.alibaba.cloud.dubbo.util.JSONUtils; +import static java.lang.System.getProperty; /** * Dubbo {@link RegistryFactory} uses Spring Cloud Service Registration abstraction, whose - * protocol is "spring-cloud" + * protocol is "spring-cloud". * * @author Mercy * @see RegistryFactory @@ -37,8 +38,14 @@ import com.alibaba.cloud.dubbo.util.JSONUtils; */ public class SpringCloudRegistryFactory implements RegistryFactory { + /** + * Spring Cloud Protocol. + */ public static String PROTOCOL = "spring-cloud"; + /** + * Spring Cloud Address. + */ public static String ADDRESS = "localhost"; private static String SERVICES_LOOKUP_SCHEDULER_THREAD_NAME_PREFIX = getProperty( @@ -84,4 +91,5 @@ public class SpringCloudRegistryFactory implements RegistryFactory { dubboServiceMetadataRepository, dubboMetadataConfigServiceProxy, jsonUtils, applicationContext); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/event/ServiceInstancePreRegisteredEvent.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/event/ServiceInstancePreRegisteredEvent.java index fee5a742c..4733fef69 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/event/ServiceInstancePreRegisteredEvent.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/event/ServiceInstancePreRegisteredEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.registry.event; import org.springframework.cloud.client.ServiceInstance; @@ -22,7 +23,7 @@ import org.springframework.context.ApplicationEvent; /** * The before-{@link ServiceRegistry#register(Registration) register} event for - * {@link ServiceInstance} + * {@link ServiceInstance}. * * @author Mercy */ @@ -36,4 +37,5 @@ public class ServiceInstancePreRegisteredEvent extends ApplicationEvent { public Registration getSource() { return (Registration) super.getSource(); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/event/ServiceInstanceRegisteredEvent.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/event/ServiceInstanceRegisteredEvent.java index 7c6c0742d..81b4e2b66 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/event/ServiceInstanceRegisteredEvent.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/event/ServiceInstanceRegisteredEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.registry.event; import org.springframework.cloud.client.serviceregistry.Registration; @@ -21,7 +22,7 @@ import org.springframework.context.ApplicationEvent; /** * The after-{@link ServiceRegistry#register(Registration) register} event for - * {@link Registration} + * {@link Registration}. * * @author Mercy */ @@ -35,4 +36,5 @@ public class ServiceInstanceRegisteredEvent extends ApplicationEvent { public Registration getSource() { return (Registration) super.getSource(); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/event/ServiceInstancesChangedEvent.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/event/ServiceInstancesChangedEvent.java index c00f2fe73..f69954b3a 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/event/ServiceInstancesChangedEvent.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/event/ServiceInstancesChangedEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.registry.event; -import static java.util.Collections.unmodifiableCollection; +package com.alibaba.cloud.dubbo.registry.event; import java.util.Collection; @@ -24,6 +23,8 @@ import org.springframework.context.ApplicationEvent; import org.springframework.context.event.ApplicationEventMulticaster; import org.springframework.context.event.SimpleApplicationEventMulticaster; +import static java.util.Collections.unmodifiableCollection; + /** * An event raised after the {@link ServiceInstance instances} of one service has been * changed. @@ -64,25 +65,25 @@ public class ServiceInstancesChangedEvent extends ApplicationEvent { } /** - * @return all {@link ServiceInstance service instances} + * @return all {@link ServiceInstance service instances}. */ public Collection getServiceInstances() { return serviceInstances; } /** - * Mark current event being processed + * Mark current event being processed. */ public void processed() { processed = true; } /** - * Current event has been processed or not - * + * Current event has been processed or not. * @return if processed, return true, or false */ public boolean isProcessed() { return processed; } -} \ No newline at end of file + +} diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/event/SubscribedServicesChangedEvent.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/event/SubscribedServicesChangedEvent.java index ea66aad42..df8168c09 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/event/SubscribedServicesChangedEvent.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/registry/event/SubscribedServicesChangedEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.registry.event; import java.util.LinkedHashSet; @@ -22,7 +23,7 @@ import java.util.Set; import org.springframework.context.ApplicationEvent; /** - * {@link ApplicationEvent Event} raised when the subscribed services are changed + * {@link ApplicationEvent Event} raised when the subscribed services are changed. *

    * * @author Mercy @@ -38,7 +39,6 @@ public class SubscribedServicesChangedEvent extends ApplicationEvent { /** * Create a new ApplicationEvent. - * * @param source the object on which the event initially occurred (never {@code null}) * @param oldSubscribedServices the subscribed services before changed * @param newSubscribedServices the subscribed services after changed @@ -62,4 +62,5 @@ public class SubscribedServicesChangedEvent extends ApplicationEvent { public boolean isChanged() { return changed; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboGenericServiceExecutionContext.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboGenericServiceExecutionContext.java index 8be35973f..5e9d4877e 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboGenericServiceExecutionContext.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboGenericServiceExecutionContext.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.service; import org.apache.dubbo.rpc.service.GenericService; /** - * Dubbo {@link GenericService} execution context + * Dubbo {@link GenericService} execution context. * * @author Mercy */ @@ -48,4 +49,5 @@ public class DubboGenericServiceExecutionContext { public Object[] getParameters() { return parameters; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboGenericServiceExecutionContextFactory.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboGenericServiceExecutionContextFactory.java index 4d39fab7e..29017ce40 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboGenericServiceExecutionContextFactory.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboGenericServiceExecutionContextFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.service; import java.util.Collections; @@ -22,17 +23,17 @@ import java.util.Map; import javax.annotation.PostConstruct; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.annotation.AnnotationAwareOrderComparator; - import com.alibaba.cloud.dubbo.http.HttpServerRequest; import com.alibaba.cloud.dubbo.metadata.MethodMetadata; import com.alibaba.cloud.dubbo.metadata.MethodParameterMetadata; import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; import com.alibaba.cloud.dubbo.service.parameter.DubboGenericServiceParameterResolver; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.annotation.AnnotationAwareOrderComparator; + /** - * {@link DubboGenericServiceExecutionContext} Factory + * {@link DubboGenericServiceExecutionContext} Factory. * * @author Mercy * @see DubboGenericServiceParameterResolver @@ -154,4 +155,5 @@ public class DubboGenericServiceExecutionContextFactory { return parameters; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboGenericServiceFactory.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboGenericServiceFactory.java index 313abbef2..5fcf8100b 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboGenericServiceFactory.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboGenericServiceFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,12 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.service; -import static java.util.Collections.emptyMap; -import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; -import static org.springframework.util.StringUtils.commaDelimitedListToStringArray; +package com.alibaba.cloud.dubbo.service; import java.beans.PropertyEditorSupport; import java.util.Collection; @@ -30,6 +26,8 @@ import java.util.concurrent.ConcurrentMap; import javax.annotation.PreDestroy; +import com.alibaba.cloud.dubbo.metadata.DubboRestServiceMetadata; +import com.alibaba.cloud.dubbo.metadata.ServiceRestMetadata; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.config.RegistryConfig; @@ -37,6 +35,7 @@ import org.apache.dubbo.config.spring.ReferenceBean; import org.apache.dubbo.rpc.service.GenericService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; @@ -44,11 +43,13 @@ import org.springframework.beans.propertyeditors.StringTrimmerEditor; import org.springframework.util.StringUtils; import org.springframework.validation.DataBinder; -import com.alibaba.cloud.dubbo.metadata.DubboRestServiceMetadata; -import com.alibaba.cloud.dubbo.metadata.ServiceRestMetadata; +import static java.util.Collections.emptyMap; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; +import static org.springframework.util.StringUtils.commaDelimitedListToStringArray; /** - * Dubbo {@link GenericService} Factory + * Dubbo {@link GenericService} Factory. * * @author Mercy */ diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboMetadataService.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboMetadataService.java index 56b884c8d..a6cb949ee 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboMetadataService.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboMetadataService.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,65 +13,62 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.service; import java.util.List; import java.util.Map; import java.util.Set; +import com.alibaba.cloud.dubbo.metadata.ServiceRestMetadata; import org.apache.dubbo.common.URL; import org.apache.dubbo.config.annotation.Service; -import com.alibaba.cloud.dubbo.metadata.ServiceRestMetadata; - /** * Dubbo Metadata Service is a core interface for service subscribers, it must keep the * stable of structure in every evolution , makes sure all subscribers' compatibility. *

    * The interface contract's version must be {@link #VERSION} constant and group must be - * current Dubbo application name + * current Dubbo application name. * * @author Mercy */ public interface DubboMetadataService { /** - * Current version of the interface contract + * Current version of the interface contract. */ String VERSION = "1.0.0"; /** - * Get the json content of {@link ServiceRestMetadata} {@link Set} - * + * Get the json content of {@link ServiceRestMetadata} {@link Set}. * @return null if present */ String getServiceRestMetadata(); /** - * Get all exported {@link URL#getServiceKey() service keys} - * + * Get all exported {@link URL#getServiceKey() service keys}. * @return non-null read-only {@link Set} */ Set getAllServiceKeys(); /** * Get all exported Dubbo's {@link URL URLs} {@link Map} whose key is the return value - * of {@link URL#getServiceKey()} method and value is the json content of List of - * {@link URL URLs} - * + * of {@link URL#getServiceKey()} method and value is the json content of + * List<URL> of {@link URL URLs}. * @return non-null read-only {@link Map} */ Map getAllExportedURLs(); /** - * Get the json content of an exported List of {@link URL URLs} by the - * serviceInterface , group and version - * + * Get the json content of an exported List of {@link URL URLs} by the + * serviceInterface, group and version. * @param serviceInterface The class name of service interface * @param group {@link Service#group() the service group} (optional) - * @param version {@link Service#version() the service version} (optional) + * @param version {@link Service#version() the service version} (optional)~ * @return non-null read-only {@link List} * @see URL */ String getExportedURLs(String serviceInterface, String group, String version); + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboMetadataServiceExporter.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboMetadataServiceExporter.java index cf37dc9b5..e4b0bb555 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboMetadataServiceExporter.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboMetadataServiceExporter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.service; import java.util.List; @@ -26,13 +27,14 @@ import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.ServiceConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; /** - * {@link DubboMetadataService} exporter + * {@link DubboMetadataService} exporter. * * @author Mercy */ @@ -59,8 +61,7 @@ public class DubboMetadataServiceExporter { private ServiceConfig serviceConfig; /** - * export {@link DubboMetadataService} as Dubbo service - * + * export {@link DubboMetadataService} as Dubbo service. * @return the exported {@link URL URLs} */ public List export() { @@ -90,7 +91,7 @@ public class DubboMetadataServiceExporter { } /** - * unexport {@link DubboMetadataService} + * unexport {@link DubboMetadataService}. */ @PreDestroy public void unexport() { @@ -106,4 +107,5 @@ public class DubboMetadataServiceExporter { serviceConfig.toString()); } } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboMetadataServiceInvocationHandler.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboMetadataServiceInvocationHandler.java index bd3741762..ca90a608a 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboMetadataServiceInvocationHandler.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboMetadataServiceInvocationHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.service; import java.lang.reflect.InvocationHandler; @@ -24,7 +25,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * {@link DubboMetadataService} {@link InvocationHandler} + * {@link DubboMetadataService} {@link InvocationHandler}. * * @author Mercy */ @@ -34,7 +35,7 @@ class DubboMetadataServiceInvocationHandler implements InvocationHandler { private final GenericService genericService; - public DubboMetadataServiceInvocationHandler(String serviceName, String version, + DubboMetadataServiceInvocationHandler(String serviceName, String version, DubboGenericServiceFactory dubboGenericServiceFactory) { this.genericService = dubboGenericServiceFactory.create(serviceName, DubboMetadataService.class, version); @@ -60,4 +61,5 @@ class DubboMetadataServiceInvocationHandler implements InvocationHandler { return Stream.of(parameterTypes).map(Class::getName) .toArray(length -> new String[length]); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboMetadataServiceProxy.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboMetadataServiceProxy.java index 55c0ee71a..359ee5e07 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboMetadataServiceProxy.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/DubboMetadataServiceProxy.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.service; -import static java.lang.reflect.Proxy.newProxyInstance; +package com.alibaba.cloud.dubbo.service; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -23,15 +22,19 @@ import java.util.concurrent.ConcurrentHashMap; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.DisposableBean; +import static java.lang.reflect.Proxy.newProxyInstance; + /** - * The proxy of {@link DubboMetadataService} + * The proxy of {@link DubboMetadataService}. * * @author Mercy */ public class DubboMetadataServiceProxy implements BeanClassLoaderAware, DisposableBean { private final DubboGenericServiceFactory dubboGenericServiceFactory; + private final Map dubboMetadataServiceCache = new ConcurrentHashMap<>(); + private ClassLoader classLoader; public DubboMetadataServiceProxy( @@ -40,8 +43,7 @@ public class DubboMetadataServiceProxy implements BeanClassLoaderAware, Disposab } /** - * Initializes {@link DubboMetadataService}'s Proxy - * + * Initializes {@link DubboMetadataService}'s Proxy. * @param serviceName the service name * @param version the service version * @return a {@link DubboMetadataService} proxy @@ -52,7 +54,7 @@ public class DubboMetadataServiceProxy implements BeanClassLoaderAware, Disposab } /** - * Remove {@link DubboMetadataService}'s Proxy by service name + * Remove {@link DubboMetadataService}'s Proxy by service name. * @param serviceName the service name */ public void removeProxy(String serviceName) { @@ -60,8 +62,8 @@ public class DubboMetadataServiceProxy implements BeanClassLoaderAware, Disposab } /** - * Get a proxy instance of {@link DubboMetadataService} via the specified service name - * + * Get a proxy instance of {@link DubboMetadataService} via the specified service + * name. * @param serviceName the service name * @return a {@link DubboMetadataService} proxy */ @@ -80,8 +82,8 @@ public class DubboMetadataServiceProxy implements BeanClassLoaderAware, Disposab } /** - * New a proxy instance of {@link DubboMetadataService} via the specified service name - * + * New a proxy instance of {@link DubboMetadataService} via the specified service + * name. * @param serviceName the service name * @param version the service version * @return a {@link DubboMetadataService} proxy @@ -92,4 +94,5 @@ public class DubboMetadataServiceProxy implements BeanClassLoaderAware, Disposab new DubboMetadataServiceInvocationHandler(serviceName, version, dubboGenericServiceFactory)); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/IntrospectiveDubboMetadataService.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/IntrospectiveDubboMetadataService.java index 1f43aa62d..e30062d67 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/IntrospectiveDubboMetadataService.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/IntrospectiveDubboMetadataService.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.service; -import static java.util.Collections.unmodifiableMap; -import static org.springframework.util.CollectionUtils.isEmpty; +package com.alibaba.cloud.dubbo.service; import java.util.Collections; import java.util.HashMap; @@ -24,18 +22,21 @@ import java.util.List; import java.util.Map; import java.util.Set; +import com.alibaba.cloud.dubbo.metadata.ServiceRestMetadata; +import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; +import com.alibaba.cloud.dubbo.util.JSONUtils; import org.apache.dubbo.common.URL; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; -import com.alibaba.cloud.dubbo.metadata.ServiceRestMetadata; -import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; -import com.alibaba.cloud.dubbo.util.JSONUtils; +import static java.util.Collections.unmodifiableMap; +import static org.springframework.util.CollectionUtils.isEmpty; /** - * Introspective {@link DubboMetadataService} implementation + * Introspective {@link DubboMetadataService} implementation. * * @author Mercy */ @@ -94,4 +95,5 @@ public class IntrospectiveDubboMetadataService implements DubboMetadataService { private DubboServiceMetadataRepository getRepository() { return dubboServiceMetadataRepository.getIfAvailable(); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/AbstractDubboGenericServiceParameterResolver.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/AbstractDubboGenericServiceParameterResolver.java index ec574066a..d7c71993a 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/AbstractDubboGenericServiceParameterResolver.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/AbstractDubboGenericServiceParameterResolver.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.service.parameter; -import static org.springframework.context.ConfigurableApplicationContext.CONVERSION_SERVICE_BEAN_NAME; -import static org.springframework.util.ClassUtils.resolveClassName; +package com.alibaba.cloud.dubbo.service.parameter; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.annotation.Autowired; @@ -24,8 +22,11 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.core.convert.ConversionService; import org.springframework.format.support.DefaultFormattingConversionService; +import static org.springframework.context.ConfigurableApplicationContext.CONVERSION_SERVICE_BEAN_NAME; +import static org.springframework.util.ClassUtils.resolveClassName; + /** - * Abstract {@link DubboGenericServiceParameterResolver} implementation + * Abstract {@link DubboGenericServiceParameterResolver} implementation. * * @author Mercy */ @@ -78,4 +79,5 @@ public abstract class AbstractDubboGenericServiceParameterResolver protected Object resolveValue(Object parameterValue, Class parameterType) { return conversionService.convert(parameterValue, parameterType); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/AbstractNamedValueServiceParameterResolver.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/AbstractNamedValueServiceParameterResolver.java index c436cb0de..2fa4511f8 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/AbstractNamedValueServiceParameterResolver.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/AbstractNamedValueServiceParameterResolver.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,24 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.service.parameter; -import static org.springframework.util.ObjectUtils.isEmpty; +package com.alibaba.cloud.dubbo.service.parameter; import java.util.Collection; import java.util.Collections; import java.util.Map; -import org.springframework.util.CollectionUtils; -import org.springframework.util.MultiValueMap; - import com.alibaba.cloud.dubbo.http.HttpServerRequest; import com.alibaba.cloud.dubbo.metadata.MethodParameterMetadata; import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; +import org.springframework.util.CollectionUtils; +import org.springframework.util.MultiValueMap; + +import static org.springframework.util.ObjectUtils.isEmpty; + /** * Abstract HTTP Names Value {@link DubboGenericServiceParameterResolver Dubbo - * GenericService Parameter Resolver} + * GenericService Parameter Resolver}. * * @author Mercy */ @@ -38,10 +39,9 @@ public abstract class AbstractNamedValueServiceParameterResolver extends AbstractDubboGenericServiceParameterResolver { /** - * Get the {@link MultiValueMap} of names and values - * - * @param request - * @return + * Get the {@link MultiValueMap} of names and values. + * @param request Http server request + * @return map of name and values */ protected abstract MultiValueMap getNameAndValuesMap( HttpServerRequest request); diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/DubboGenericServiceParameterResolver.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/DubboGenericServiceParameterResolver.java index 870523c70..a3a583135 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/DubboGenericServiceParameterResolver.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/DubboGenericServiceParameterResolver.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,17 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.service.parameter; -import org.apache.dubbo.rpc.service.GenericService; -import org.springframework.core.Ordered; +package com.alibaba.cloud.dubbo.service.parameter; import com.alibaba.cloud.dubbo.http.HttpServerRequest; import com.alibaba.cloud.dubbo.metadata.MethodParameterMetadata; import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; +import org.apache.dubbo.rpc.service.GenericService; + +import org.springframework.core.Ordered; /** - * Dubbo {@link GenericService} Parameter Resolver + * Dubbo {@link GenericService} Parameter Resolver. * * @author Mercy */ @@ -31,8 +32,10 @@ public interface DubboGenericServiceParameterResolver extends Ordered { /** * Resolves a method parameter into an argument value from a given request. - * - * @return + * @param restMethodMetadata method request metadata + * @param methodParameterMetadata metadata of method + * @param request Http server request + * @return the result of resolve */ Object resolve(RestMethodMetadata restMethodMetadata, MethodParameterMetadata methodParameterMetadata, HttpServerRequest request); @@ -40,4 +43,5 @@ public interface DubboGenericServiceParameterResolver extends Ordered { Object resolve(RestMethodMetadata restMethodMetadata, MethodParameterMetadata methodParameterMetadata, RestMethodMetadata clientRestMethodMetadata, Object[] arguments); + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/PathVariableServiceParameterResolver.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/PathVariableServiceParameterResolver.java index 99b05908c..047e569c0 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/PathVariableServiceParameterResolver.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/PathVariableServiceParameterResolver.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,21 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.service.parameter; -import org.springframework.util.MultiValueMap; +package com.alibaba.cloud.dubbo.service.parameter; import com.alibaba.cloud.dubbo.http.HttpServerRequest; +import org.springframework.util.MultiValueMap; + /** * HTTP Request Path Variable {@link DubboGenericServiceParameterResolver Dubbo - * GenericService Parameter Resolver} + * GenericService Parameter Resolver}. * * @author Mercy */ public class PathVariableServiceParameterResolver extends AbstractNamedValueServiceParameterResolver { + /** + * default order. + */ public static final int DEFAULT_ORDER = 3; public PathVariableServiceParameterResolver() { @@ -40,4 +44,5 @@ public class PathVariableServiceParameterResolver HttpServerRequest request) { return request.getQueryParams(); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/RequestBodyServiceParameterResolver.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/RequestBodyServiceParameterResolver.java index 7801033e3..2969b5d6d 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/RequestBodyServiceParameterResolver.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/RequestBodyServiceParameterResolver.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.service.parameter; import java.io.IOException; @@ -21,26 +22,29 @@ import java.util.Objects; import javax.annotation.PostConstruct; -import org.springframework.beans.factory.ObjectProvider; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.http.HttpMessageConverters; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.HttpMessageNotReadableException; - import com.alibaba.cloud.dubbo.http.HttpServerRequest; import com.alibaba.cloud.dubbo.http.converter.HttpMessageConverterHolder; import com.alibaba.cloud.dubbo.http.util.HttpMessageConverterResolver; import com.alibaba.cloud.dubbo.metadata.MethodParameterMetadata; import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; +import org.springframework.beans.factory.ObjectProvider; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.http.HttpMessageConverters; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.HttpMessageNotReadableException; + /** - * HTTP Request Body {@link DubboGenericServiceParameterResolver} + * HTTP Request Body {@link DubboGenericServiceParameterResolver}. * * @author Mercy */ public class RequestBodyServiceParameterResolver extends AbstractDubboGenericServiceParameterResolver { + /** + * Default order of RequestBodyServiceParameterResolver. + */ public static final int DEFAULT_ORDER = 7; @Autowired @@ -123,4 +127,5 @@ public class RequestBodyServiceParameterResolver Integer clientBodyIndex = clientRestMethodMetadata.getBodyIndex(); return arguments[clientBodyIndex]; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/RequestHeaderServiceParameterResolver.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/RequestHeaderServiceParameterResolver.java index 8641ea44a..86a531b89 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/RequestHeaderServiceParameterResolver.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/RequestHeaderServiceParameterResolver.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,21 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.service.parameter; -import org.springframework.util.MultiValueMap; +package com.alibaba.cloud.dubbo.service.parameter; import com.alibaba.cloud.dubbo.http.HttpServerRequest; +import org.springframework.util.MultiValueMap; + /** * HTTP Request Header {@link DubboGenericServiceParameterResolver Dubbo GenericService - * Parameter Resolver} + * Parameter Resolver}. * * @author Mercy */ public class RequestHeaderServiceParameterResolver extends AbstractNamedValueServiceParameterResolver { + /** + * default order. + */ public static final int DEFAULT_ORDER = 9; public RequestHeaderServiceParameterResolver() { @@ -40,4 +44,5 @@ public class RequestHeaderServiceParameterResolver HttpServerRequest request) { return request.getHeaders(); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/RequestParamServiceParameterResolver.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/RequestParamServiceParameterResolver.java index c3d4fca7a..e1d0b72dc 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/RequestParamServiceParameterResolver.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/service/parameter/RequestParamServiceParameterResolver.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,21 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.service.parameter; -import org.springframework.util.MultiValueMap; +package com.alibaba.cloud.dubbo.service.parameter; import com.alibaba.cloud.dubbo.http.HttpServerRequest; +import org.springframework.util.MultiValueMap; + /** * HTTP Request Parameter {@link DubboGenericServiceParameterResolver Dubbo GenericService - * Parameter Resolver} + * Parameter Resolver}. * * @author Mercy */ public class RequestParamServiceParameterResolver extends AbstractNamedValueServiceParameterResolver { + /** + * Default order. + */ public static final int DEFAULT_ORDER = 1; public RequestParamServiceParameterResolver() { @@ -40,4 +44,5 @@ public class RequestParamServiceParameterResolver HttpServerRequest request) { return request.getQueryParams(); } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/util/JSONUtils.java b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/util/JSONUtils.java index 3837d5453..7aa2ee4c1 100644 --- a/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/util/JSONUtils.java +++ b/spring-cloud-alibaba-dubbo/src/main/java/com/alibaba/cloud/dubbo/util/JSONUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.util; import java.io.IOException; @@ -23,17 +24,17 @@ import java.util.stream.Collectors; import javax.annotation.PostConstruct; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; import org.apache.dubbo.common.URL; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.util.StringUtils; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; +import org.springframework.util.StringUtils; /** - * JSON Utilities class + * JSON Utilities class. * * @author Mercy */ @@ -84,4 +85,5 @@ public class JSONUtils { } return list; } + } diff --git a/spring-cloud-alibaba-dubbo/src/main/resources/META-INF/dubbo/default/actuator-endpoints.properties b/spring-cloud-alibaba-dubbo/src/main/resources/META-INF/dubbo/default/actuator-endpoints.properties index 4c9e0c57e..19c4bb448 100644 --- a/spring-cloud-alibaba-dubbo/src/main/resources/META-INF/dubbo/default/actuator-endpoints.properties +++ b/spring-cloud-alibaba-dubbo/src/main/resources/META-INF/dubbo/default/actuator-endpoints.properties @@ -4,4 +4,4 @@ management.endpoint.dubborestmetadata.enabled = true # "management.endpoints.web.base-path" should not be configured in this file # Re-defines path-mapping of Dubbo Web Endpoints -management.endpoints.web.path-mapping.dubborestmetadata = dubbo/rest/metadata \ No newline at end of file +management.endpoints.web.path-mapping.dubborestmetadata = dubbo/rest/metadata diff --git a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/autoconfigure/DubboServiceRegistrationAutoConfigurationTest.java b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/autoconfigure/DubboServiceRegistrationAutoConfigurationTest.java index 2ee014469..b3fa84d6f 100644 --- a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/autoconfigure/DubboServiceRegistrationAutoConfigurationTest.java +++ b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/autoconfigure/DubboServiceRegistrationAutoConfigurationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.autoconfigure; import org.springframework.boot.test.context.SpringBootTest; @@ -24,4 +25,5 @@ import org.springframework.boot.test.context.SpringBootTest; */ @SpringBootTest public class DubboServiceRegistrationAutoConfigurationTest { + } diff --git a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/AbstractHttpRequestMatcherTest.java b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/AbstractHttpRequestMatcherTest.java index 3a13282eb..d93aa587b 100644 --- a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/AbstractHttpRequestMatcherTest.java +++ b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/AbstractHttpRequestMatcherTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.matcher; import org.junit.Test; /** - * {@link AbstractHttpRequestMatcher} Test + * {@link AbstractHttpRequestMatcher} Test. * * @author Mercy */ diff --git a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/AbstractMediaTypeExpressionTest.java b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/AbstractMediaTypeExpressionTest.java index dbc3c2aad..e45c040fc 100644 --- a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/AbstractMediaTypeExpressionTest.java +++ b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/AbstractMediaTypeExpressionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,12 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.matcher; import java.lang.reflect.Constructor; import org.junit.Assert; import org.junit.Test; + import org.springframework.beans.BeanUtils; import org.springframework.core.ResolvableType; import org.springframework.http.MediaType; @@ -71,4 +73,5 @@ public abstract class AbstractMediaTypeExpressionTestMercy */ @@ -78,4 +80,5 @@ public abstract class AbstractNameValueExpressionTestMercy */ @@ -42,4 +44,5 @@ public class ConsumeMediaTypeExpressionTest expression = createExpression(MediaType.TEXT_HTML_VALUE); Assert.assertFalse(expression.match(MediaType.APPLICATION_JSON_UTF8)); } + } diff --git a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/HeaderExpressionTest.java b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/HeaderExpressionTest.java index ed3cee370..ec59b6393 100644 --- a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/HeaderExpressionTest.java +++ b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/HeaderExpressionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,16 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.http.matcher; -import static com.alibaba.cloud.dubbo.http.DefaultHttpRequest.builder; +package com.alibaba.cloud.dubbo.http.matcher; import org.junit.Assert; import org.junit.Test; + import org.springframework.http.HttpRequest; +import static com.alibaba.cloud.dubbo.http.DefaultHttpRequest.builder; + /** - * {@link HeaderExpression} Test + * {@link HeaderExpression} Test. * * @author Mercy */ diff --git a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestMethodsMatcherTest.java b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestMethodsMatcherTest.java index e29914859..4a43effef 100644 --- a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestMethodsMatcherTest.java +++ b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestMethodsMatcherTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,16 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.matcher; import java.util.Arrays; import java.util.HashSet; import org.junit.Assert; + import org.springframework.http.HttpMethod; /** - * {@link HttpRequestMethodsMatcher} Test + * {@link HttpRequestMethodsMatcher} Test. * * @author Mercy */ diff --git a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestParamsMatcherTest.java b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestParamsMatcherTest.java index 16fa93a2a..c27059a05 100644 --- a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestParamsMatcherTest.java +++ b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/HttpRequestParamsMatcherTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,16 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.matcher; import java.net.URI; import org.junit.Assert; import org.junit.Test; + import org.springframework.mock.http.client.MockClientHttpRequest; /** - * {@link HttpRequestParamsMatcher} Test + * {@link HttpRequestParamsMatcher} Test. * * @author Mercy */ @@ -92,4 +94,5 @@ public class HttpRequestParamsMatcherTest { request.setURI(URI.create("http://dummy/?d=1")); Assert.assertFalse(matcher.match(request)); } + } diff --git a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/ParamExpressionTest.java b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/ParamExpressionTest.java index 395f834bd..2d1a67e02 100644 --- a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/ParamExpressionTest.java +++ b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/ParamExpressionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,16 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.http.matcher; -import static com.alibaba.cloud.dubbo.http.DefaultHttpRequest.builder; +package com.alibaba.cloud.dubbo.http.matcher; import org.junit.Assert; import org.junit.Test; + import org.springframework.http.HttpRequest; +import static com.alibaba.cloud.dubbo.http.DefaultHttpRequest.builder; + /** - * {@link ParamExpression} Test + * {@link ParamExpression} Test. * * @author Mercy */ diff --git a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/ProduceMediaTypeExpressionTest.java b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/ProduceMediaTypeExpressionTest.java index c7df55b7b..1e4e70add 100644 --- a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/ProduceMediaTypeExpressionTest.java +++ b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/ProduceMediaTypeExpressionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,16 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.matcher; import java.util.Arrays; import org.junit.Assert; import org.junit.Test; + import org.springframework.http.MediaType; /** - * {@link ProduceMediaTypeExpression} Test + * {@link ProduceMediaTypeExpression} Test. * * @author Mercy */ @@ -39,4 +41,5 @@ public class ProduceMediaTypeExpressionTest expression = createExpression(MediaType.APPLICATION_JSON_VALUE); Assert.assertFalse(expression.match(Arrays.asList(MediaType.APPLICATION_XML))); } + } diff --git a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/util/HttpUtilsTest.java b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/util/HttpUtilsTest.java index ef2f86690..c71654280 100644 --- a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/util/HttpUtilsTest.java +++ b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/util/HttpUtilsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.http.util; import org.junit.Assert; import org.junit.Test; /** - * {@link HttpUtils} Test + * {@link HttpUtils} Test. * * @author Mercy */ diff --git a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/metadata/RequestMetadataTest.java b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/metadata/RequestMetadataTest.java index c0741e3a5..f19339f65 100644 --- a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/metadata/RequestMetadataTest.java +++ b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/metadata/RequestMetadataTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.metadata; import java.util.Arrays; @@ -23,7 +24,7 @@ import org.junit.Assert; import org.junit.Test; /** - * {@link RequestMetadata} Test + * {@link RequestMetadata} Test. * * @author Mercy */ diff --git a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboTransportedMethodMetadataResolverTest.java b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboTransportedMethodMetadataResolverTest.java index d255de1e4..8254f1b82 100644 --- a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboTransportedMethodMetadataResolverTest.java +++ b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboTransportedMethodMetadataResolverTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,21 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.metadata.resolver; import java.util.Set; +import com.alibaba.cloud.dubbo.annotation.DubboTransported; +import com.alibaba.cloud.dubbo.metadata.DubboTransportedMethodMetadata; import org.junit.Assert; import org.junit.Before; import org.junit.Test; + import org.springframework.cloud.openfeign.support.SpringMvcContract; import org.springframework.mock.env.MockEnvironment; -import com.alibaba.cloud.dubbo.annotation.DubboTransported; -import com.alibaba.cloud.dubbo.metadata.DubboTransportedMethodMetadata; - /** - * {@link DubboTransportedMethodMetadataResolver} Test + * {@link DubboTransportedMethodMetadataResolver} Test. * * @author Mercy */ @@ -57,4 +58,5 @@ public class DubboTransportedMethodMetadataResolverTest { String test(String message); } + } diff --git a/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/java/com/alibaba/cloud/examples/AcmApplication.java b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/java/com/alibaba/cloud/examples/AcmApplication.java index 16f3ef09f..aa79ec97f 100644 --- a/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/java/com/alibaba/cloud/examples/AcmApplication.java +++ b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/java/com/alibaba/cloud/examples/AcmApplication.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/java/com/alibaba/cloud/examples/EchoController.java b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/java/com/alibaba/cloud/examples/EchoController.java index 5508b8817..04bbc70c7 100644 --- a/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/java/com/alibaba/cloud/examples/EchoController.java +++ b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/java/com/alibaba/cloud/examples/EchoController.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,6 +18,7 @@ package com.alibaba.cloud.examples; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.web.bind.annotation.RequestMapping; @@ -35,9 +36,10 @@ public class EchoController { @Value("${user.id}") private String userId; - @RequestMapping(value = "/") + @RequestMapping("/") public String echo() { LOGGER.info("User id is " + userId); return userId; } + } diff --git a/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/resources/bootstrap.properties b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/resources/bootstrap.properties index e6169cabc..5d7206d0e 100644 --- a/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/resources/bootstrap.properties +++ b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/resources/bootstrap.properties @@ -2,4 +2,4 @@ spring.application.name=acm-local server.port=18089 spring.cloud.alicloud.acm.server-list=127.0.0.1 spring.cloud.alicloud.acm.server-port=8080 -management.endpoints.web.exposure.include=* \ No newline at end of file +management.endpoints.web.exposure.include=* diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java index 4a22d36cb..25fc09389 100644 --- a/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java +++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/com/alibaba/cloud/examples/EchoService.java b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/com/alibaba/cloud/examples/EchoService.java index fb462f09e..7662f6d99 100644 --- a/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/com/alibaba/cloud/examples/EchoService.java +++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/com/alibaba/cloud/examples/EchoService.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,7 +23,7 @@ import org.springframework.web.bind.annotation.RequestParam; /** * @author xiaolongzuo */ -@FeignClient(value = "ans-provider") +@FeignClient("ans-provider") public interface EchoService { @RequestMapping(path = "echo/{str}") diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/com/alibaba/cloud/examples/HomeController.java b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/com/alibaba/cloud/examples/HomeController.java index 9cb9e2682..453b5dd89 100644 --- a/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/com/alibaba/cloud/examples/HomeController.java +++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/com/alibaba/cloud/examples/HomeController.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,9 +18,9 @@ package com.alibaba.cloud.examples; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; /** @@ -43,4 +43,5 @@ public class HomeController { LOGGER.info("收到提供者响应:" + result); return param + "
    " + result; } + } diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/resources/application.properties index ac697b885..19219e43d 100644 --- a/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/resources/application.properties +++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/resources/application.properties @@ -2,4 +2,4 @@ spring.application.name=feign-consumer server.port=18083 # The following configuration can be omitted. spring.cloud.alicloud.ans.server-list=127.0.0.1 -spring.cloud.alicloud.ans.server-port=8080 \ No newline at end of file +spring.cloud.alicloud.ans.server-port=8080 diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java index 1d674cbe3..e83ba6114 100644 --- a/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java +++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/java/com/alibaba/cloud/examples/HomeController.java b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/java/com/alibaba/cloud/examples/HomeController.java index 26e1a08bd..a93c023d9 100644 --- a/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/java/com/alibaba/cloud/examples/HomeController.java +++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/java/com/alibaba/cloud/examples/HomeController.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,10 +18,9 @@ package com.alibaba.cloud.examples; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; @@ -46,4 +45,5 @@ public class HomeController { LOGGER.info("收到提供者响应:" + result); return param + "
    " + result; } + } diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/resources/application.properties index 33a7e5aa5..c78563546 100644 --- a/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/resources/application.properties +++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/resources/application.properties @@ -2,4 +2,4 @@ spring.application.name=ribbon-consumer server.port=18082 # The following configuration can be omitted. spring.cloud.alicloud.ans.server-list=127.0.0.1 -spring.cloud.alicloud.ans.server-port=8080 \ No newline at end of file +spring.cloud.alicloud.ans.server-port=8080 diff --git a/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/java/com/alibaba/cloud/examples/EchoController.java b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/java/com/alibaba/cloud/examples/EchoController.java index 20bea9738..07744adff 100644 --- a/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/java/com/alibaba/cloud/examples/EchoController.java +++ b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/java/com/alibaba/cloud/examples/EchoController.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,7 +18,10 @@ package com.alibaba.cloud.examples; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.web.bind.annotation.*; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; /** * @author xiaolongzuo @@ -36,4 +39,5 @@ public class EchoController { LOGGER.info("提供者返回结果:" + result); return result; } + } diff --git a/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/java/com/alibaba/cloud/examples/ProviderApplication.java b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/java/com/alibaba/cloud/examples/ProviderApplication.java index 97c5592e3..cba3781e7 100644 --- a/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/java/com/alibaba/cloud/examples/ProviderApplication.java +++ b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/java/com/alibaba/cloud/examples/ProviderApplication.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/resources/application.properties index e5f6cdef2..274235154 100644 --- a/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/resources/application.properties +++ b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/resources/application.properties @@ -1,4 +1,4 @@ spring.application.name=ans-provider server.port=18081 spring.cloud.alicloud.ans.server-list=127.0.0.1 -spring.cloud.alicloud.ans.server-port=8080 \ No newline at end of file +spring.cloud.alicloud.ans.server-port=8080 diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/java/com/alibaba/cloud/examples/Application.java b/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/java/com/alibaba/cloud/examples/Application.java index a9cb91eb6..35cec8c38 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/java/com/alibaba/cloud/examples/Application.java +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/java/com/alibaba/cloud/examples/Application.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; import java.io.IOException; @@ -6,6 +22,8 @@ import java.util.Properties; import java.util.concurrent.Executor; import com.alibaba.cloud.nacos.NacosConfigManager; +import com.alibaba.nacos.api.config.listener.Listener; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.ApplicationArguments; @@ -17,17 +35,16 @@ import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.alibaba.cloud.nacos.NacosConfigProperties; -import com.alibaba.nacos.api.config.listener.Listener; - /** * @author xiaojing, Jianwei Mao */ @SpringBootApplication public class Application { + public static void main(String[] args) { SpringApplication.run(Application.class, args); } + } @Component @@ -56,9 +73,8 @@ class SampleRunner implements ApplicationRunner { * For example, config data in Nacos is: * * user.name=Nacos user.age=25 - * * @param configInfo latest config data for specific dataId in Nacos - * server + * server */ @Override public void receiveConfigInfo(String configInfo) { @@ -78,6 +94,7 @@ class SampleRunner implements ApplicationRunner { } }); } + } @RestController @@ -98,4 +115,5 @@ class SampleController { return "Hello Nacos Config!" + "Hello " + userName + " " + age + "!" + nacosConfigManager.getConfigService(); } -} \ No newline at end of file + +} diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/resources/application.properties index c6e216ad7..de11d576c 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/resources/application.properties +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/resources/application.properties @@ -1,2 +1,2 @@ server.port=18084 -management.endpoints.web.exposure.include=* \ No newline at end of file +management.endpoints.web.exposure.include=* diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/resources/bootstrap.properties b/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/resources/bootstrap.properties index 375be66e9..d6906d1c9 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/resources/bootstrap.properties +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/resources/bootstrap.properties @@ -1,4 +1,4 @@ spring.application.name=nacos-config-example spring.cloud.nacos.config.server-addr=127.0.0.1:8848 spring.cloud.nacos.config.shared-data-ids=base-common.properties,common.properties -spring.cloud.nacos.config.refreshable-dataids=common.properties \ No newline at end of file +spring.cloud.nacos.config.refreshable-dataids=common.properties diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java index bed219b80..6f9c98909 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java @@ -1,5 +1,24 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; +import com.alibaba.cloud.examples.ConsumerApplication.EchoService; +import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate; + import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @@ -7,12 +26,11 @@ import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.context.annotation.Bean; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.client.RestTemplate; -import com.alibaba.cloud.examples.ConsumerApplication.EchoService; -import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate; - /** * @author xiaojing */ @@ -39,32 +57,38 @@ public class ConsumerApplication { SpringApplication.run(ConsumerApplication.class, args); } - @FeignClient(name = "service-provider", fallback = EchoServiceFallback.class, configuration = FeignConfiguration.class) + @FeignClient(name = "service-provider", fallback = EchoServiceFallback.class, + configuration = FeignConfiguration.class) public interface EchoService { - @GetMapping(value = "/echo/{str}") + + @GetMapping("/echo/{str}") String echo(@PathVariable("str") String str); - @GetMapping(value = "/divide") + @GetMapping("/divide") String divide(@RequestParam("a") Integer a, @RequestParam("b") Integer b); default String divide(Integer a) { return divide(a, 0); } - @GetMapping(value = "/notFound") + @GetMapping("/notFound") String notFound(); + } } class FeignConfiguration { + @Bean public EchoServiceFallback echoServiceFallback() { return new EchoServiceFallback(); } + } class EchoServiceFallback implements EchoService { + @Override public String echo(@PathVariable("str") String str) { return "echo fallback"; @@ -79,4 +103,5 @@ class EchoServiceFallback implements EchoService { public String notFound() { return "notFound fallback"; } + } diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/src/main/java/com/alibaba/cloud/examples/TestController.java b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/src/main/java/com/alibaba/cloud/examples/TestController.java index 9281e9fcf..3e9946c47 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/src/main/java/com/alibaba/cloud/examples/TestController.java +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/src/main/java/com/alibaba/cloud/examples/TestController.java @@ -1,12 +1,31 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; +import com.alibaba.cloud.examples.ConsumerApplication.EchoService; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.client.discovery.DiscoveryClient; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; -import com.alibaba.cloud.examples.ConsumerApplication.EchoService; - /** * @author xiaojing */ @@ -40,54 +59,55 @@ public class TestController { // }); // } - @GetMapping(value = "/echo-rest/{str}") + @GetMapping("/echo-rest/{str}") public String rest(@PathVariable String str) { return restTemplate.getForObject("http://service-provider/echo/" + str, String.class); } - @GetMapping(value = "/index") + @GetMapping("/index") public String index() { return restTemplate1.getForObject("http://service-provider", String.class); } - @GetMapping(value = "/test") + @GetMapping("/test") public String test() { return restTemplate1.getForObject("http://service-provider/test", String.class); } - @GetMapping(value = "/sleep") + @GetMapping("/sleep") public String sleep() { return restTemplate1.getForObject("http://service-provider/sleep", String.class); } - @GetMapping(value = "/notFound-feign") + @GetMapping("/notFound-feign") public String notFound() { return echoService.notFound(); } - @GetMapping(value = "/divide-feign") + @GetMapping("/divide-feign") public String divide(@RequestParam Integer a, @RequestParam Integer b) { return echoService.divide(a, b); } - @GetMapping(value = "/divide-feign2") + @GetMapping("/divide-feign2") public String divide(@RequestParam Integer a) { return echoService.divide(a); } - @GetMapping(value = "/echo-feign/{str}") + @GetMapping("/echo-feign/{str}") public String feign(@PathVariable String str) { return echoService.echo(str); } - @GetMapping(value = "/services/{service}") + @GetMapping("/services/{service}") public Object client(@PathVariable String service) { return discoveryClient.getInstances(service); } - @GetMapping(value = "/services") + @GetMapping("/services") public Object services() { return discoveryClient.getServices(); } + } diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/src/main/java/com/alibaba/cloud/examples/UrlCleaner.java b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/src/main/java/com/alibaba/cloud/examples/UrlCleaner.java index 68d65d0ba..e0c691af4 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/src/main/java/com/alibaba/cloud/examples/UrlCleaner.java +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/src/main/java/com/alibaba/cloud/examples/UrlCleaner.java @@ -1,6 +1,23 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; public class UrlCleaner { + public static String clean(String url) { System.out.println("enter urlCleaner"); if (url.matches(".*/echo/.*")) { @@ -9,4 +26,5 @@ public class UrlCleaner { } return url; } + } diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/src/main/resources/application.properties index 2d260cb2c..7f236aa9a 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/src/main/resources/application.properties +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/src/main/resources/application.properties @@ -14,4 +14,4 @@ spring.cloud.sentinel.datasource.ds1.file.rule-type=flow spring.cloud.sentinel.datasource.ds2.file.file=classpath: degraderule.json spring.cloud.sentinel.datasource.ds2.file.data-type=json -spring.cloud.sentinel.datasource.ds2.file.rule-type=degrade \ No newline at end of file +spring.cloud.sentinel.datasource.ds2.file.rule-type=degrade diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/java/com/alibaba/cloud/examples/ProviderApplication.java b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/java/com/alibaba/cloud/examples/ProviderApplication.java index 2be2adb42..94a842598 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/java/com/alibaba/cloud/examples/ProviderApplication.java +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/java/com/alibaba/cloud/examples/ProviderApplication.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; import org.springframework.boot.SpringApplication; @@ -5,7 +21,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; /** * @author xiaojing @@ -21,17 +40,17 @@ public class ProviderApplication { @RestController class EchoController { - @GetMapping(value = "/") + @GetMapping("/") public ResponseEntity index() { return new ResponseEntity("index error", HttpStatus.INTERNAL_SERVER_ERROR); } - @GetMapping(value = "/test") + @GetMapping("/test") public ResponseEntity test() { return new ResponseEntity("error", HttpStatus.INTERNAL_SERVER_ERROR); } - @GetMapping(value = "/sleep") + @GetMapping("/sleep") public String sleep() { try { Thread.sleep(1000L); @@ -42,14 +61,16 @@ public class ProviderApplication { return "ok"; } - @GetMapping(value = "/echo/{string}") + @GetMapping("/echo/{string}") public String echo(@PathVariable String string) { return "hello Nacos Discovery " + string; } - @GetMapping(value = "/divide") + @GetMapping("/divide") public String divide(@RequestParam Integer a, @RequestParam Integer b) { return String.valueOf(a / b); } + } + } diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/resources/application.properties index 66100d79f..dee115b62 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/resources/application.properties +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/resources/application.properties @@ -1,4 +1,4 @@ server.port=18082 spring.application.name=service-provider spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 -management.endpoints.web.exposure.include=* \ No newline at end of file +management.endpoints.web.exposure.include=* diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-spring-cloud-config-client/src/main/java/com/alibaba/cloud/examples/GetConfigController.java b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-spring-cloud-config-client/src/main/java/com/alibaba/cloud/examples/GetConfigController.java index 0fbd29850..32dfcff07 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-spring-cloud-config-client/src/main/java/com/alibaba/cloud/examples/GetConfigController.java +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-spring-cloud-config-client/src/main/java/com/alibaba/cloud/examples/GetConfigController.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,6 @@ package com.alibaba.cloud.examples; 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.RequestMethod; import org.springframework.web.bind.annotation.RestController; @RestController @@ -28,7 +26,7 @@ public class GetConfigController { @Value("${config}") private String config; - @GetMapping(value = "/config") + @GetMapping("/config") public String getConfig() { return config; } diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-spring-cloud-config-client/src/main/java/com/alibaba/cloud/examples/SpringCloudConfigClientApplication.java b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-spring-cloud-config-client/src/main/java/com/alibaba/cloud/examples/SpringCloudConfigClientApplication.java index 4968266c4..05bc6c5bb 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-spring-cloud-config-client/src/main/java/com/alibaba/cloud/examples/SpringCloudConfigClientApplication.java +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-spring-cloud-config-client/src/main/java/com/alibaba/cloud/examples/SpringCloudConfigClientApplication.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,4 +31,4 @@ public class SpringCloudConfigClientApplication { SpringApplication.run(SpringCloudConfigClientApplication.class, args); } -} \ No newline at end of file +} diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-spring-cloud-config-server/src/main/java/com/alibaba/cloud/examples/SpringCloudConfigServerApplication.java b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-spring-cloud-config-server/src/main/java/com/alibaba/cloud/examples/SpringCloudConfigServerApplication.java index 680ab2ec8..a82bad8e8 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-spring-cloud-config-server/src/main/java/com/alibaba/cloud/examples/SpringCloudConfigServerApplication.java +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-spring-cloud-config-server/src/main/java/com/alibaba/cloud/examples/SpringCloudConfigServerApplication.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,4 +33,4 @@ public class SpringCloudConfigServerApplication { SpringApplication.run(SpringCloudConfigServerApplication.class, args); } -} \ No newline at end of file +} diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-gateway-example/nacos-gateway-discovery-example/src/main/java/com/alibaba/cloud/examples/GatewayApplication.java b/spring-cloud-alibaba-examples/nacos-example/nacos-gateway-example/nacos-gateway-discovery-example/src/main/java/com/alibaba/cloud/examples/GatewayApplication.java index a59a4168e..6767357ff 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-gateway-example/nacos-gateway-discovery-example/src/main/java/com/alibaba/cloud/examples/GatewayApplication.java +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-gateway-example/nacos-gateway-discovery-example/src/main/java/com/alibaba/cloud/examples/GatewayApplication.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; import org.springframework.boot.SpringApplication; diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-gateway-example/nacos-gateway-discovery-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/nacos-example/nacos-gateway-example/nacos-gateway-discovery-example/src/main/resources/application.properties index 613948914..276d85d10 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-gateway-example/nacos-gateway-discovery-example/src/main/resources/application.properties +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-gateway-example/nacos-gateway-discovery-example/src/main/resources/application.properties @@ -8,4 +8,4 @@ spring.cloud.gateway.routes[0].id=nacos-route spring.cloud.gateway.routes[0].uri=lb://service-gateway-provider spring.cloud.gateway.routes[0].predicates[0].name=Path spring.cloud.gateway.routes[0].predicates[0].args[pattern]=/nacos/** -spring.cloud.gateway.routes[0].filters[0]=StripPrefix=1 \ No newline at end of file +spring.cloud.gateway.routes[0].filters[0]=StripPrefix=1 diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-gateway-example/nacos-gateway-provider-example/src/main/java/com/alibaba/cloud/examples/ProviderApplication.java b/spring-cloud-alibaba-examples/nacos-example/nacos-gateway-example/nacos-gateway-provider-example/src/main/java/com/alibaba/cloud/examples/ProviderApplication.java index 02a28892c..a28fd9430 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-gateway-example/nacos-gateway-provider-example/src/main/java/com/alibaba/cloud/examples/ProviderApplication.java +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-gateway-example/nacos-gateway-provider-example/src/main/java/com/alibaba/cloud/examples/ProviderApplication.java @@ -1,9 +1,28 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; /** * @author xiaojing @@ -18,14 +37,17 @@ public class ProviderApplication { @RestController class EchoController { - @GetMapping(value = "/echo/{string}") + + @GetMapping("/echo/{string}") public String echo(@PathVariable String string) { return "hello Nacos Discovery " + string; } - @GetMapping(value = "/divide") + @GetMapping("/divide") public String divide(@RequestParam Integer a, @RequestParam Integer b) { return String.valueOf(a / b); } + } + } diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-gateway-example/nacos-gateway-provider-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/nacos-example/nacos-gateway-example/nacos-gateway-provider-example/src/main/resources/application.properties index 9a061092c..ab340ff8c 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-gateway-example/nacos-gateway-provider-example/src/main/resources/application.properties +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-gateway-example/nacos-gateway-provider-example/src/main/resources/application.properties @@ -1,4 +1,4 @@ server.port=18086 spring.application.name=service-gateway-provider spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 -management.endpoints.web.exposure.include=* \ No newline at end of file +management.endpoints.web.exposure.include=* diff --git a/spring-cloud-alibaba-examples/oss-example/src/main/java/com/alibaba/cloud/examples/OssApplication.java b/spring-cloud-alibaba-examples/oss-example/src/main/java/com/alibaba/cloud/examples/OssApplication.java index 9dd6907f6..0e3f7b8a4 100644 --- a/spring-cloud-alibaba-examples/oss-example/src/main/java/com/alibaba/cloud/examples/OssApplication.java +++ b/spring-cloud-alibaba-examples/oss-example/src/main/java/com/alibaba/cloud/examples/OssApplication.java @@ -1,7 +1,25 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; import java.net.URISyntaxException; +import com.aliyun.oss.OSS; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; @@ -9,10 +27,8 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; -import com.aliyun.oss.OSS; - /** - * OSS Application + * OSS Application. * * @author Jim */ @@ -31,6 +47,7 @@ public class OssApplication { } class AppRunner implements ApplicationRunner { + @Autowired private OSS ossClient; @@ -46,6 +63,7 @@ public class OssApplication { System.exit(-1); } } + } } diff --git a/spring-cloud-alibaba-examples/oss-example/src/main/java/com/alibaba/cloud/examples/OssController.java b/spring-cloud-alibaba-examples/oss-example/src/main/java/com/alibaba/cloud/examples/OssController.java index 7dc364cb6..9628f9502 100644 --- a/spring-cloud-alibaba-examples/oss-example/src/main/java/com/alibaba/cloud/examples/OssController.java +++ b/spring-cloud-alibaba-examples/oss-example/src/main/java/com/alibaba/cloud/examples/OssController.java @@ -1,9 +1,30 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.charset.Charset; + import com.aliyun.oss.OSS; import com.aliyun.oss.common.utils.IOUtils; import com.aliyun.oss.model.OSSObject; import org.apache.commons.codec.CharEncoding; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.Resource; @@ -12,12 +33,8 @@ import org.springframework.util.StreamUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.charset.Charset; - /** - * OSS Controller + * OSS Controller. * * @author Jim */ diff --git a/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-consume-example/src/main/java/com/alibaba/cloud/examples/Foo.java b/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-consume-example/src/main/java/com/alibaba/cloud/examples/Foo.java index 78dbf120f..c4127e7b1 100644 --- a/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-consume-example/src/main/java/com/alibaba/cloud/examples/Foo.java +++ b/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-consume-example/src/main/java/com/alibaba/cloud/examples/Foo.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; /** @@ -6,6 +22,7 @@ package com.alibaba.cloud.examples; public class Foo { private int id; + private String bar; public Foo() { @@ -36,4 +53,5 @@ public class Foo { public String toString() { return "Foo{" + "id=" + id + ", bar='" + bar + '\'' + '}'; } + } diff --git a/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-consume-example/src/main/java/com/alibaba/cloud/examples/ReceiveService.java b/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-consume-example/src/main/java/com/alibaba/cloud/examples/ReceiveService.java index 0544f6ae3..0754c91bd 100644 --- a/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-consume-example/src/main/java/com/alibaba/cloud/examples/ReceiveService.java +++ b/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-consume-example/src/main/java/com/alibaba/cloud/examples/ReceiveService.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; import org.springframework.cloud.stream.annotation.StreamListener; diff --git a/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-consume-example/src/main/java/com/alibaba/cloud/examples/RocketMQConsumerApplication.java b/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-consume-example/src/main/java/com/alibaba/cloud/examples/RocketMQConsumerApplication.java index ddfcdbd5c..2bd73880e 100644 --- a/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-consume-example/src/main/java/com/alibaba/cloud/examples/RocketMQConsumerApplication.java +++ b/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-consume-example/src/main/java/com/alibaba/cloud/examples/RocketMQConsumerApplication.java @@ -1,5 +1,23 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; +import com.alibaba.cloud.examples.RocketMQConsumerApplication.MySink; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; @@ -11,8 +29,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.core.ParameterizedTypeReference; import org.springframework.messaging.SubscribableChannel; -import com.alibaba.cloud.examples.RocketMQConsumerApplication.MySink; - /** * @author Jim */ @@ -20,6 +36,15 @@ import com.alibaba.cloud.examples.RocketMQConsumerApplication.MySink; @EnableBinding({ MySink.class }) public class RocketMQConsumerApplication { + public static void main(String[] args) { + SpringApplication.run(RocketMQConsumerApplication.class, args); + } + + @Bean + public ConsumerCustomRunner customRunner() { + return new ConsumerCustomRunner(); + } + public interface MySink { @Input("input1") @@ -36,15 +61,7 @@ public class RocketMQConsumerApplication { @Input("input5") PollableMessageSource input5(); - } - - public static void main(String[] args) { - SpringApplication.run(RocketMQConsumerApplication.class, args); - } - @Bean - public ConsumerCustomRunner customRunner() { - return new ConsumerCustomRunner(); } public static class ConsumerCustomRunner implements CommandLineRunner { @@ -63,6 +80,7 @@ public class RocketMQConsumerApplication { Thread.sleep(2_000); } } + } } diff --git a/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-consume-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-consume-example/src/main/resources/application.properties index dd8bb6ef4..2779db522 100644 --- a/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-consume-example/src/main/resources/application.properties +++ b/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-consume-example/src/main/resources/application.properties @@ -33,4 +33,4 @@ spring.application.name=rocketmq-consume-example server.port=28082 management.endpoints.web.exposure.include=* -management.endpoint.health.show-details=always \ No newline at end of file +management.endpoint.health.show-details=always diff --git a/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-produce-example/src/main/java/com/alibaba/cloud/examples/Foo.java b/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-produce-example/src/main/java/com/alibaba/cloud/examples/Foo.java index 78dbf120f..c4127e7b1 100644 --- a/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-produce-example/src/main/java/com/alibaba/cloud/examples/Foo.java +++ b/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-produce-example/src/main/java/com/alibaba/cloud/examples/Foo.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; /** @@ -6,6 +22,7 @@ package com.alibaba.cloud.examples; public class Foo { private int id; + private String bar; public Foo() { @@ -36,4 +53,5 @@ public class Foo { public String toString() { return "Foo{" + "id=" + id + ", bar='" + bar + '\'' + '}'; } + } diff --git a/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-produce-example/src/main/java/com/alibaba/cloud/examples/RocketMQProduceApplication.java b/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-produce-example/src/main/java/com/alibaba/cloud/examples/RocketMQProduceApplication.java index 6a7ac9d41..eaf4b47ee 100644 --- a/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-produce-example/src/main/java/com/alibaba/cloud/examples/RocketMQProduceApplication.java +++ b/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-produce-example/src/main/java/com/alibaba/cloud/examples/RocketMQProduceApplication.java @@ -1,5 +1,23 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; +import com.alibaba.cloud.examples.RocketMQProduceApplication.MySource; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; @@ -10,8 +28,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.support.MessageBuilder; -import com.alibaba.cloud.examples.RocketMQProduceApplication.MySource; - /** * @author Jim */ @@ -19,17 +35,6 @@ import com.alibaba.cloud.examples.RocketMQProduceApplication.MySource; @EnableBinding({ MySource.class }) public class RocketMQProduceApplication { - public interface MySource { - @Output("output1") - MessageChannel output1(); - - @Output("output2") - MessageChannel output2(); - - @Output("output3") - MessageChannel output3(); - } - public static void main(String[] args) { SpringApplication.run(RocketMQProduceApplication.class, args); } @@ -49,6 +54,19 @@ public class RocketMQProduceApplication { return new CustomRunnerWithTransactional(); } + public interface MySource { + + @Output("output1") + MessageChannel output1(); + + @Output("output2") + MessageChannel output2(); + + @Output("output3") + MessageChannel output3(); + + } + public static class CustomRunner implements CommandLineRunner { private final String bindingName; @@ -90,9 +108,11 @@ public class RocketMQProduceApplication { } } + } public static class CustomRunnerWithTransactional implements CommandLineRunner { + @Autowired private SenderService senderService; @@ -107,6 +127,7 @@ public class RocketMQProduceApplication { // COMMIT_MESSAGE message senderService.sendTransactionalMsg("transactional-msg4", 4); } + } } diff --git a/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-produce-example/src/main/java/com/alibaba/cloud/examples/SenderService.java b/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-produce-example/src/main/java/com/alibaba/cloud/examples/SenderService.java index 79fec70e1..cd9e50939 100644 --- a/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-produce-example/src/main/java/com/alibaba/cloud/examples/SenderService.java +++ b/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-produce-example/src/main/java/com/alibaba/cloud/examples/SenderService.java @@ -1,10 +1,28 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; import java.util.stream.Collectors; import java.util.stream.Stream; +import com.alibaba.cloud.examples.RocketMQProduceApplication.MySource; import org.apache.rocketmq.common.message.MessageConst; import org.apache.rocketmq.spring.support.RocketMQHeaders; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; @@ -12,8 +30,6 @@ import org.springframework.messaging.support.MessageBuilder; import org.springframework.stereotype.Service; import org.springframework.util.MimeTypeUtils; -import com.alibaba.cloud.examples.RocketMQProduceApplication.MySource; - /** * @author Jim */ diff --git a/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-produce-example/src/main/java/com/alibaba/cloud/examples/TransactionListenerImpl.java b/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-produce-example/src/main/java/com/alibaba/cloud/examples/TransactionListenerImpl.java index f2b3b6b6d..e58beb221 100644 --- a/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-produce-example/src/main/java/com/alibaba/cloud/examples/TransactionListenerImpl.java +++ b/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-produce-example/src/main/java/com/alibaba/cloud/examples/TransactionListenerImpl.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,13 +19,16 @@ package com.alibaba.cloud.examples; import org.apache.rocketmq.spring.annotation.RocketMQTransactionListener; import org.apache.rocketmq.spring.core.RocketMQLocalTransactionListener; import org.apache.rocketmq.spring.core.RocketMQLocalTransactionState; + import org.springframework.messaging.Message; /** * @author Jim */ -@RocketMQTransactionListener(txProducerGroup = "myTxProducerGroup", corePoolSize = 5, maximumPoolSize = 10) +@RocketMQTransactionListener(txProducerGroup = "myTxProducerGroup", corePoolSize = 5, + maximumPoolSize = 10) public class TransactionListenerImpl implements RocketMQLocalTransactionListener { + @Override public RocketMQLocalTransactionState executeLocalTransaction(Message msg, Object arg) { @@ -51,4 +54,5 @@ public class TransactionListenerImpl implements RocketMQLocalTransactionListener System.out.println("check: " + new String((byte[]) msg.getPayload())); return RocketMQLocalTransactionState.COMMIT; } -} \ No newline at end of file + +} diff --git a/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-produce-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-produce-example/src/main/resources/application.properties index 562694922..772bf456e 100644 --- a/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-produce-example/src/main/resources/application.properties +++ b/spring-cloud-alibaba-examples/rocketmq-example/rocketmq-produce-example/src/main/resources/application.properties @@ -21,4 +21,4 @@ spring.application.name=rocketmq-produce-example server.port=28081 management.endpoints.web.exposure.include=* -management.endpoint.health.show-details=always \ No newline at end of file +management.endpoint.health.show-details=always diff --git a/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/com/alibaba/cloud/examples/HelloController.java b/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/com/alibaba/cloud/examples/HelloController.java index 564105025..106c23d0d 100644 --- a/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/com/alibaba/cloud/examples/HelloController.java +++ b/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/com/alibaba/cloud/examples/HelloController.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/com/alibaba/cloud/examples/ScxApplication.java b/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/com/alibaba/cloud/examples/ScxApplication.java index fe3d43571..eac0aed11 100644 --- a/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/com/alibaba/cloud/examples/ScxApplication.java +++ b/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/com/alibaba/cloud/examples/ScxApplication.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/com/alibaba/cloud/examples/SimpleTask.java b/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/com/alibaba/cloud/examples/SimpleTask.java index 31d0ffa26..720bb67c4 100644 --- a/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/com/alibaba/cloud/examples/SimpleTask.java +++ b/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/com/alibaba/cloud/examples/SimpleTask.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,12 +16,12 @@ package com.alibaba.cloud.examples; -import org.springframework.beans.factory.annotation.Autowired; - import com.alibaba.edas.schedulerx.ProcessResult; import com.alibaba.edas.schedulerx.ScxSimpleJobContext; import com.alibaba.edas.schedulerx.ScxSimpleJobProcessor; +import org.springframework.beans.factory.annotation.Autowired; + /** * @author xiaolongzuo */ diff --git a/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/com/alibaba/cloud/examples/TestController.java b/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/com/alibaba/cloud/examples/TestController.java index 3230e9b01..7e9291ce8 100644 --- a/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/com/alibaba/cloud/examples/TestController.java +++ b/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/com/alibaba/cloud/examples/TestController.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/com/alibaba/cloud/examples/TestService.java b/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/com/alibaba/cloud/examples/TestService.java index 7681b3ada..78abd7921 100644 --- a/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/com/alibaba/cloud/examples/TestService.java +++ b/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/com/alibaba/cloud/examples/TestService.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,4 +27,5 @@ public class TestService { public void test() { TestController.atomicInteger.incrementAndGet(); } + } diff --git a/spring-cloud-alibaba-examples/seata-example/account-service/src/main/java/com/alibaba/cloud/examples/AccountApplication.java b/spring-cloud-alibaba-examples/seata-example/account-service/src/main/java/com/alibaba/cloud/examples/AccountApplication.java index 7d52d74c8..b573b549d 100644 --- a/spring-cloud-alibaba-examples/seata-example/account-service/src/main/java/com/alibaba/cloud/examples/AccountApplication.java +++ b/spring-cloud-alibaba-examples/seata-example/account-service/src/main/java/com/alibaba/cloud/examples/AccountApplication.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-alibaba-examples/seata-example/account-service/src/main/java/com/alibaba/cloud/examples/AccountController.java b/spring-cloud-alibaba-examples/seata-example/account-service/src/main/java/com/alibaba/cloud/examples/AccountController.java index dda69ec73..903b52f68 100644 --- a/spring-cloud-alibaba-examples/seata-example/account-service/src/main/java/com/alibaba/cloud/examples/AccountController.java +++ b/spring-cloud-alibaba-examples/seata-example/account-service/src/main/java/com/alibaba/cloud/examples/AccountController.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,20 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.examples; import java.util.Random; +import io.seata.core.context.RootContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -import io.seata.core.context.RootContext; - /** * @author xiaojing */ @@ -36,9 +35,11 @@ public class AccountController { private static final Logger LOGGER = LoggerFactory.getLogger(AccountController.class); private static final String SUCCESS = "SUCCESS"; + private static final String FAIL = "FAIL"; private final JdbcTemplate jdbcTemplate; + private Random random; public AccountController(JdbcTemplate jdbcTemplate) { diff --git a/spring-cloud-alibaba-examples/seata-example/account-service/src/main/java/com/alibaba/cloud/examples/DatabaseConfiguration.java b/spring-cloud-alibaba-examples/seata-example/account-service/src/main/java/com/alibaba/cloud/examples/DatabaseConfiguration.java index f22071bbb..624bf47b8 100644 --- a/spring-cloud-alibaba-examples/seata-example/account-service/src/main/java/com/alibaba/cloud/examples/DatabaseConfiguration.java +++ b/spring-cloud-alibaba-examples/seata-example/account-service/src/main/java/com/alibaba/cloud/examples/DatabaseConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,20 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.examples; import java.sql.SQLException; +import com.alibaba.druid.pool.DruidDataSource; +import io.seata.rm.datasource.DataSourceProxy; + import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.jdbc.core.JdbcTemplate; -import com.alibaba.druid.pool.DruidDataSource; - -import io.seata.rm.datasource.DataSourceProxy; - /** * @author xiaojing */ diff --git a/spring-cloud-alibaba-examples/seata-example/account-service/src/main/resources/application.properties b/spring-cloud-alibaba-examples/seata-example/account-service/src/main/resources/application.properties index 68b91d012..8884c924d 100644 --- a/spring-cloud-alibaba-examples/seata-example/account-service/src/main/resources/application.properties +++ b/spring-cloud-alibaba-examples/seata-example/account-service/src/main/resources/application.properties @@ -6,4 +6,4 @@ mysql.server.port=3306 mysql.db.name=demo mysql.user.name=root -mysql.user.password=123456 \ No newline at end of file +mysql.user.password=123456 diff --git a/spring-cloud-alibaba-examples/seata-example/business-service/src/main/java/com/alibaba/cloud/examples/BusinessApplication.java b/spring-cloud-alibaba-examples/seata-example/business-service/src/main/java/com/alibaba/cloud/examples/BusinessApplication.java index b79a530e3..b130d13d5 100644 --- a/spring-cloud-alibaba-examples/seata-example/business-service/src/main/java/com/alibaba/cloud/examples/BusinessApplication.java +++ b/spring-cloud-alibaba-examples/seata-example/business-service/src/main/java/com/alibaba/cloud/examples/BusinessApplication.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,7 +23,6 @@ import org.springframework.cloud.openfeign.FeignClient; import org.springframework.context.annotation.Bean; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.client.RestTemplate; @@ -61,4 +60,5 @@ public class BusinessApplication { @RequestParam("orderCount") int orderCount); } + } diff --git a/spring-cloud-alibaba-examples/seata-example/business-service/src/main/java/com/alibaba/cloud/examples/HomeController.java b/spring-cloud-alibaba-examples/seata-example/business-service/src/main/java/com/alibaba/cloud/examples/HomeController.java index 0aa32fa3a..2b671552a 100644 --- a/spring-cloud-alibaba-examples/seata-example/business-service/src/main/java/com/alibaba/cloud/examples/HomeController.java +++ b/spring-cloud-alibaba-examples/seata-example/business-service/src/main/java/com/alibaba/cloud/examples/HomeController.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,8 +16,12 @@ package com.alibaba.cloud.examples; +import com.alibaba.cloud.examples.BusinessApplication.OrderService; +import com.alibaba.cloud.examples.BusinessApplication.StorageService; +import io.seata.spring.annotation.GlobalTransactional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -25,16 +29,9 @@ import org.springframework.http.ResponseEntity; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; -import com.alibaba.cloud.examples.BusinessApplication.OrderService; -import com.alibaba.cloud.examples.BusinessApplication.StorageService; - -import io.seata.spring.annotation.GlobalTransactional; - /** * @author xiaojing */ @@ -44,13 +41,19 @@ public class HomeController { private static final Logger LOGGER = LoggerFactory.getLogger(HomeController.class); private static final String SUCCESS = "SUCCESS"; + private static final String FAIL = "FAIL"; + private static final String USER_ID = "U100001"; + private static final String COMMODITY_CODE = "C00321"; + private static final int ORDER_COUNT = 2; private final RestTemplate restTemplate; + private final OrderService orderService; + private final StorageService storageService; public HomeController(RestTemplate restTemplate, OrderService orderService, diff --git a/spring-cloud-alibaba-examples/seata-example/business-service/src/main/java/com/alibaba/cloud/examples/Order.java b/spring-cloud-alibaba-examples/seata-example/business-service/src/main/java/com/alibaba/cloud/examples/Order.java index 54ff8a0c1..06ecbde48 100644 --- a/spring-cloud-alibaba-examples/seata-example/business-service/src/main/java/com/alibaba/cloud/examples/Order.java +++ b/spring-cloud-alibaba-examples/seata-example/business-service/src/main/java/com/alibaba/cloud/examples/Order.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,10 +19,15 @@ package com.alibaba.cloud.examples; import java.io.Serializable; public class Order implements Serializable { + public long id; + public String userId; + public String commodityCode; + public int count; + public int money; @Override @@ -30,4 +35,5 @@ public class Order implements Serializable { return "Order{" + "id=" + id + ", userId='" + userId + '\'' + ", commodityCode='" + commodityCode + '\'' + ", count=" + count + ", money=" + money + '}'; } + } diff --git a/spring-cloud-alibaba-examples/seata-example/business-service/src/main/resources/application.properties b/spring-cloud-alibaba-examples/seata-example/business-service/src/main/resources/application.properties index 75ed92904..9ac7ad4d4 100644 --- a/spring-cloud-alibaba-examples/seata-example/business-service/src/main/resources/application.properties +++ b/spring-cloud-alibaba-examples/seata-example/business-service/src/main/resources/application.properties @@ -5,4 +5,4 @@ spring.application.name=business-service #feign.hystrix.enabled=true #feign.sentinel.enabled=true -logging.level.io.seata=debug \ No newline at end of file +logging.level.io.seata=debug diff --git a/spring-cloud-alibaba-examples/seata-example/order-service/src/main/java/com/alibaba/cloud/examples/DatabaseConfiguration.java b/spring-cloud-alibaba-examples/seata-example/order-service/src/main/java/com/alibaba/cloud/examples/DatabaseConfiguration.java index e3a260e26..cd83beec6 100644 --- a/spring-cloud-alibaba-examples/seata-example/order-service/src/main/java/com/alibaba/cloud/examples/DatabaseConfiguration.java +++ b/spring-cloud-alibaba-examples/seata-example/order-service/src/main/java/com/alibaba/cloud/examples/DatabaseConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,20 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.examples; import java.sql.SQLException; +import com.alibaba.druid.pool.DruidDataSource; +import io.seata.rm.datasource.DataSourceProxy; + import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.jdbc.core.JdbcTemplate; -import com.alibaba.druid.pool.DruidDataSource; - -import io.seata.rm.datasource.DataSourceProxy; - /** * @author xiaojing */ diff --git a/spring-cloud-alibaba-examples/seata-example/order-service/src/main/java/com/alibaba/cloud/examples/OderApplication.java b/spring-cloud-alibaba-examples/seata-example/order-service/src/main/java/com/alibaba/cloud/examples/OderApplication.java index 9bd64f514..b1233273f 100644 --- a/spring-cloud-alibaba-examples/seata-example/order-service/src/main/java/com/alibaba/cloud/examples/OderApplication.java +++ b/spring-cloud-alibaba-examples/seata-example/order-service/src/main/java/com/alibaba/cloud/examples/OderApplication.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-alibaba-examples/seata-example/order-service/src/main/java/com/alibaba/cloud/examples/Order.java b/spring-cloud-alibaba-examples/seata-example/order-service/src/main/java/com/alibaba/cloud/examples/Order.java index 54ff8a0c1..06ecbde48 100644 --- a/spring-cloud-alibaba-examples/seata-example/order-service/src/main/java/com/alibaba/cloud/examples/Order.java +++ b/spring-cloud-alibaba-examples/seata-example/order-service/src/main/java/com/alibaba/cloud/examples/Order.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,10 +19,15 @@ package com.alibaba.cloud.examples; import java.io.Serializable; public class Order implements Serializable { + public long id; + public String userId; + public String commodityCode; + public int count; + public int money; @Override @@ -30,4 +35,5 @@ public class Order implements Serializable { return "Order{" + "id=" + id + ", userId='" + userId + '\'' + ", commodityCode='" + commodityCode + '\'' + ", count=" + count + ", money=" + money + '}'; } + } diff --git a/spring-cloud-alibaba-examples/seata-example/order-service/src/main/java/com/alibaba/cloud/examples/OrderController.java b/spring-cloud-alibaba-examples/seata-example/order-service/src/main/java/com/alibaba/cloud/examples/OrderController.java index d2cf5c398..1aba194da 100644 --- a/spring-cloud-alibaba-examples/seata-example/order-service/src/main/java/com/alibaba/cloud/examples/OrderController.java +++ b/spring-cloud-alibaba-examples/seata-example/order-service/src/main/java/com/alibaba/cloud/examples/OrderController.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,8 +21,10 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.Random; +import io.seata.core.context.RootContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -34,13 +36,9 @@ import org.springframework.jdbc.support.KeyHolder; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; -import io.seata.core.context.RootContext; - /** * @author xiaojing */ @@ -48,13 +46,19 @@ import io.seata.core.context.RootContext; public class OrderController { private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class); + private static final String SUCCESS = "SUCCESS"; + private static final String FAIL = "FAIL"; + private static final String USER_ID = "U100001"; + private static final String COMMODITY_CODE = "C00321"; private final JdbcTemplate jdbcTemplate; + private final RestTemplate restTemplate; + private Random random; public OrderController(JdbcTemplate jdbcTemplate, RestTemplate restTemplate) { @@ -129,4 +133,5 @@ public class OrderController { ResponseEntity response = restTemplate.postForEntity(url, request, String.class); } + } diff --git a/spring-cloud-alibaba-examples/seata-example/order-service/src/main/resources/application.properties b/spring-cloud-alibaba-examples/seata-example/order-service/src/main/resources/application.properties index c88342af9..4be899e94 100644 --- a/spring-cloud-alibaba-examples/seata-example/order-service/src/main/resources/application.properties +++ b/spring-cloud-alibaba-examples/seata-example/order-service/src/main/resources/application.properties @@ -6,4 +6,4 @@ mysql.server.port=3306 mysql.db.name=demo mysql.user.name=root -mysql.user.password=123456 \ No newline at end of file +mysql.user.password=123456 diff --git a/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/java/com/alibaba/cloud/examples/DatabaseConfiguration.java b/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/java/com/alibaba/cloud/examples/DatabaseConfiguration.java index b862b26ab..dc8d9a85f 100644 --- a/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/java/com/alibaba/cloud/examples/DatabaseConfiguration.java +++ b/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/java/com/alibaba/cloud/examples/DatabaseConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,16 +18,15 @@ package com.alibaba.cloud.examples; import java.sql.SQLException; +import com.alibaba.druid.pool.DruidDataSource; +import io.seata.rm.datasource.DataSourceProxy; + import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.jdbc.core.JdbcTemplate; -import com.alibaba.druid.pool.DruidDataSource; - -import io.seata.rm.datasource.DataSourceProxy; - /** * @author xiaojing */ diff --git a/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/java/com/alibaba/cloud/examples/StorageApplication.java b/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/java/com/alibaba/cloud/examples/StorageApplication.java index 4e6185b20..91e6c46cd 100644 --- a/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/java/com/alibaba/cloud/examples/StorageApplication.java +++ b/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/java/com/alibaba/cloud/examples/StorageApplication.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/java/com/alibaba/cloud/examples/StorageController.java b/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/java/com/alibaba/cloud/examples/StorageController.java index 84b832316..31bf0607b 100644 --- a/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/java/com/alibaba/cloud/examples/StorageController.java +++ b/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/java/com/alibaba/cloud/examples/StorageController.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,12 +16,14 @@ package com.alibaba.cloud.examples; +import io.seata.core.context.RootContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.web.bind.annotation.*; -import io.seata.core.context.RootContext; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; /** * @author xiaojing @@ -32,6 +34,7 @@ public class StorageController { private static final Logger LOGGER = LoggerFactory.getLogger(StorageController.class); private static final String SUCCESS = "SUCCESS"; + private static final String FAIL = "FAIL"; private final JdbcTemplate jdbcTemplate; @@ -52,4 +55,5 @@ public class StorageController { } return FAIL; } + } diff --git a/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/resources/application.properties b/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/resources/application.properties index b65047c80..08866ced7 100644 --- a/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/resources/application.properties +++ b/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/resources/application.properties @@ -6,4 +6,4 @@ mysql.server.port=3306 mysql.db.name=demo mysql.user.name=root -mysql.user.password=123456 \ No newline at end of file +mysql.user.password=123456 diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/ExceptionUtil.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/ExceptionUtil.java index 1551bedb4..ef41bda9a 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/ExceptionUtil.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/ExceptionUtil.java @@ -1,11 +1,27 @@ -package com.alibaba.cloud.examples; +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ -import org.springframework.http.HttpRequest; -import org.springframework.http.client.ClientHttpRequestExecution; +package com.alibaba.cloud.examples; import com.alibaba.cloud.sentinel.rest.SentinelClientHttpResponse; import com.alibaba.csp.sentinel.slots.block.BlockException; +import org.springframework.http.HttpRequest; +import org.springframework.http.client.ClientHttpRequestExecution; + /** * @author fangjian */ diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/JsonFlowRuleListConverter.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/JsonFlowRuleListConverter.java index aee0fe991..fe90b7187 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/JsonFlowRuleListConverter.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/JsonFlowRuleListConverter.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; import java.util.List; @@ -11,9 +27,11 @@ import com.alibaba.fastjson.TypeReference; * @author fangjian */ public class JsonFlowRuleListConverter implements Converter> { + @Override public List convert(String source) { return JSON.parseObject(source, new TypeReference>() { }); } + } diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/ServiceApplication.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/ServiceApplication.java index 7dea70eef..17121bd9c 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/ServiceApplication.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/ServiceApplication.java @@ -1,13 +1,29 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; +import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate; +import com.alibaba.csp.sentinel.datasource.Converter; + import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.web.client.RestTemplate; -import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate; -import com.alibaba.csp.sentinel.datasource.Converter; - /** * @author xiaojing */ @@ -15,7 +31,8 @@ import com.alibaba.csp.sentinel.datasource.Converter; public class ServiceApplication { @Bean - @SentinelRestTemplate(blockHandler = "handleException", blockHandlerClass = ExceptionUtil.class) + @SentinelRestTemplate(blockHandler = "handleException", + blockHandlerClass = ExceptionUtil.class) public RestTemplate restTemplate() { return new RestTemplate(); } diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/TestController.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/TestController.java index 825fe6c89..1e7a909d9 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/TestController.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/TestController.java @@ -1,14 +1,28 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; +import com.alibaba.csp.sentinel.annotation.SentinelResource; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; -import com.alibaba.csp.sentinel.annotation.SentinelResource; - /** * @author xiaojing */ @@ -18,24 +32,24 @@ public class TestController { @Autowired private RestTemplate restTemplate; - @GetMapping(value = "/hello") + @GetMapping("/hello") @SentinelResource("resource") public String hello() { return "Hello"; } - @GetMapping(value = "/aa") + @GetMapping("/aa") @SentinelResource("aa") public String aa(int b, int a) { return "Hello test"; } - @GetMapping(value = "/test") + @GetMapping("/test") public String test1() { return "Hello test"; } - @GetMapping(value = "/template") + @GetMapping("/template") public String client() { return restTemplate.getForObject("http://www.taobao.com/test", String.class); } diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-api/src/main/java/com/alibaba/cloud/examples/FooService.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-api/src/main/java/com/alibaba/cloud/examples/FooService.java index 65f71bb81..aa9006f6a 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-api/src/main/java/com/alibaba/cloud/examples/FooService.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-api/src/main/java/com/alibaba/cloud/examples/FooService.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; /** diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/src/main/java/com/alibaba/cloud/examples/FooServiceConsumer.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/src/main/java/com/alibaba/cloud/examples/FooServiceConsumer.java index 48c03b86a..c92f0bf10 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/src/main/java/com/alibaba/cloud/examples/FooServiceConsumer.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/src/main/java/com/alibaba/cloud/examples/FooServiceConsumer.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; import org.apache.dubbo.config.annotation.Reference; @@ -7,7 +23,9 @@ import org.apache.dubbo.config.annotation.Reference; */ public class FooServiceConsumer { - @Reference(version = "${foo.service.version}", application = "${dubbo.application.id}", url = "dubbo://localhost:12345?version=1.0.0", timeout = 30000) + @Reference(version = "${foo.service.version}", + application = "${dubbo.application.id}", + url = "dubbo://localhost:12345?version=1.0.0", timeout = 30000) private FooService fooService; public String hello(String name) { diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/src/main/java/com/alibaba/cloud/examples/SentinelDubboConsumerApp.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/src/main/java/com/alibaba/cloud/examples/SentinelDubboConsumerApp.java index bb62527f8..0c6c1932d 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/src/main/java/com/alibaba/cloud/examples/SentinelDubboConsumerApp.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/src/main/java/com/alibaba/cloud/examples/SentinelDubboConsumerApp.java @@ -1,18 +1,34 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; import java.util.Collections; +import com.alibaba.csp.sentinel.slots.block.RuleConstant; +import com.alibaba.csp.sentinel.slots.block.SentinelRpcException; +import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; +import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager; + import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; -import com.alibaba.csp.sentinel.slots.block.RuleConstant; -import com.alibaba.csp.sentinel.slots.block.SentinelRpcException; -import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; -import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager; - /** * @author fangjian */ @@ -27,7 +43,8 @@ public class SentinelDubboConsumerApp { public static void main(String[] args) { FlowRule flowRule = new FlowRule(); - flowRule.setResource("com.alibaba.cloud.examples.FooService:hello(java.lang.String)"); + flowRule.setResource( + "com.alibaba.cloud.examples.FooService:hello(java.lang.String)"); flowRule.setCount(10); flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS); flowRule.setLimitApp("default"); diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/src/main/java/com/alibaba/cloud/examples/FooServiceImpl.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/src/main/java/com/alibaba/cloud/examples/FooServiceImpl.java index 041627d46..0d280ee8b 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/src/main/java/com/alibaba/cloud/examples/FooServiceImpl.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/src/main/java/com/alibaba/cloud/examples/FooServiceImpl.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; import org.apache.dubbo.config.annotation.Service; @@ -5,11 +21,13 @@ import org.apache.dubbo.config.annotation.Service; /** * @author fangjian */ -@Service(version = "${foo.service.version}", application = "${dubbo.application.id}", protocol = "${dubbo.protocol.id}", registry = "${dubbo.registry.id}") +@Service(version = "${foo.service.version}", application = "${dubbo.application.id}", + protocol = "${dubbo.protocol.id}", registry = "${dubbo.registry.id}") public class FooServiceImpl implements FooService { @Override public String hello(String name) { return "hello, " + name; } -} \ No newline at end of file + +} diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/src/main/java/com/alibaba/cloud/examples/SentinelDubboProviderApp.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/src/main/java/com/alibaba/cloud/examples/SentinelDubboProviderApp.java index ac4f78381..a322601d0 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/src/main/java/com/alibaba/cloud/examples/SentinelDubboProviderApp.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/src/main/java/com/alibaba/cloud/examples/SentinelDubboProviderApp.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; import org.springframework.boot.WebApplicationType; diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java index 952c38980..49b5b2950 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/ConsumerApplication.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; import org.springframework.boot.SpringApplication; diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/controller/TestController.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/controller/TestController.java index f90fe1077..209439ab2 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/controller/TestController.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/controller/TestController.java @@ -1,6 +1,23 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples.controller; import com.alibaba.cloud.examples.service.EchoService; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -12,12 +29,12 @@ import org.springframework.web.bind.annotation.RestController; @RestController public class TestController { - @Autowired - private EchoService echoService; + @Autowired + private EchoService echoService; - @GetMapping(value = "/echo-feign/{str}") - public String feign(@PathVariable String str) { - return echoService.echo(str); - } + @GetMapping("/echo-feign/{str}") + public String feign(@PathVariable String str) { + return echoService.echo(str); + } } diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/fallback/EchoServiceFallback.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/fallback/EchoServiceFallback.java index 6d4fd77de..3b3afc007 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/fallback/EchoServiceFallback.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/fallback/EchoServiceFallback.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples.fallback; import com.alibaba.cloud.examples.service.EchoService; @@ -9,20 +25,21 @@ import com.alibaba.cloud.examples.service.EchoService; * sentinel 降级处理 */ public class EchoServiceFallback implements EchoService { - private Throwable throwable; - EchoServiceFallback(Throwable throwable) { - this.throwable = throwable; - } + private Throwable throwable; + + EchoServiceFallback(Throwable throwable) { + this.throwable = throwable; + } + + /** + * 调用服务提供方的输出接口 + * @param str 用户输入 + * @return + */ + @Override + public String echo(String str) { + return "consumer-fallback-default-str" + throwable.getMessage(); + } - /** - * 调用服务提供方的输出接口 - * - * @param str 用户输入 - * @return - */ - @Override - public String echo(String str) { - return "consumer-fallback-default-str" + throwable.getMessage(); - } } diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/fallback/EchoServiceFallbackFactory.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/fallback/EchoServiceFallbackFactory.java index 6d33d7136..94366678f 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/fallback/EchoServiceFallbackFactory.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/fallback/EchoServiceFallbackFactory.java @@ -1,6 +1,23 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples.fallback; import feign.hystrix.FallbackFactory; + import org.springframework.stereotype.Component; /** @@ -9,8 +26,10 @@ import org.springframework.stereotype.Component; */ @Component public class EchoServiceFallbackFactory implements FallbackFactory { - @Override - public EchoServiceFallback create(Throwable throwable) { - return new EchoServiceFallback(throwable); - } + + @Override + public EchoServiceFallback create(Throwable throwable) { + return new EchoServiceFallback(throwable); + } + } diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/service/EchoService.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/service/EchoService.java index 2dcbdc967..120e711cc 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/service/EchoService.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/service/EchoService.java @@ -1,6 +1,23 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples.service; import com.alibaba.cloud.examples.fallback.EchoServiceFallbackFactory; + import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -11,15 +28,16 @@ import org.springframework.web.bind.annotation.PathVariable; *

    * example feign client */ -@FeignClient(name = "service-provider", fallbackFactory = EchoServiceFallbackFactory.class) +@FeignClient(name = "service-provider", + fallbackFactory = EchoServiceFallbackFactory.class) public interface EchoService { - /** - * 调用服务提供方的输出接口 - * - * @param str 用户输入 - * @return - */ - @GetMapping(value = "/echo/{str}") - String echo(@PathVariable("str") String str); + /** + * 调用服务提供方的输出接口 + * @param str 用户输入 + * @return + */ + @GetMapping("/echo/{str}") + String echo(@PathVariable("str") String str); + } diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-provider-example/src/main/java/com/alibaba/cloud/examples/ProviderApplication.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-provider-example/src/main/java/com/alibaba/cloud/examples/ProviderApplication.java index cdc17dd81..e3ac3f96b 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-provider-example/src/main/java/com/alibaba/cloud/examples/ProviderApplication.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-provider-example/src/main/java/com/alibaba/cloud/examples/ProviderApplication.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples; import org.springframework.boot.SpringApplication; @@ -11,7 +27,8 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @SpringBootApplication public class ProviderApplication { - public static void main(String[] args) { - SpringApplication.run(ProviderApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(ProviderApplication.class, args); + } + } diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-provider-example/src/main/java/com/alibaba/cloud/examples/controller/EchoController.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-provider-example/src/main/java/com/alibaba/cloud/examples/controller/EchoController.java index 6d99f33dc..c74f7b48b 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-provider-example/src/main/java/com/alibaba/cloud/examples/controller/EchoController.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-provider-example/src/main/java/com/alibaba/cloud/examples/controller/EchoController.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.examples.controller; import org.springframework.web.bind.annotation.GetMapping; @@ -11,9 +27,9 @@ import org.springframework.web.bind.annotation.RestController; @RestController public class EchoController { - @GetMapping("/echo/{str}") - public String echo(@PathVariable String str) { - return "provider-" + str; - } + @GetMapping("/echo/{str}") + public String echo(@PathVariable String str) { + return "provider-" + str; + } } diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-spring-cloud-gateway-example/src/main/java/com/alibaba/cloud/examples/MySCGConfiguration.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-spring-cloud-gateway-example/src/main/java/com/alibaba/cloud/examples/MySCGConfiguration.java index 6ccf9130b..96a67ae79 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-spring-cloud-gateway-example/src/main/java/com/alibaba/cloud/examples/MySCGConfiguration.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-spring-cloud-gateway-example/src/main/java/com/alibaba/cloud/examples/MySCGConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,8 @@ package com.alibaba.cloud.examples; -import static org.springframework.web.reactive.function.BodyInserters.fromObject; +import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler; +import reactor.core.publisher.Mono; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -24,9 +25,7 @@ import org.springframework.http.MediaType; import org.springframework.web.reactive.function.server.ServerResponse; import org.springframework.web.server.ServerWebExchange; -import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler; - -import reactor.core.publisher.Mono; +import static org.springframework.web.reactive.function.BodyInserters.fromObject; /** * @author Jim diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-spring-cloud-gateway-example/src/main/java/com/alibaba/cloud/examples/RulesWebFluxController.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-spring-cloud-gateway-example/src/main/java/com/alibaba/cloud/examples/RulesWebFluxController.java index 8e2f4efc6..cdf1c8877 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-spring-cloud-gateway-example/src/main/java/com/alibaba/cloud/examples/RulesWebFluxController.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-spring-cloud-gateway-example/src/main/java/com/alibaba/cloud/examples/RulesWebFluxController.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,18 +19,17 @@ package com.alibaba.cloud.examples; import java.util.List; import java.util.Set; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition; import com.alibaba.csp.sentinel.adapter.gateway.common.api.GatewayApiDefinitionManager; import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule; import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager; import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager; - import reactor.core.publisher.Mono; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + /** * @author Jim */ diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-spring-cloud-gateway-example/src/main/java/com/alibaba/cloud/examples/SentinelSpringCloudGatewayApplication.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-spring-cloud-gateway-example/src/main/java/com/alibaba/cloud/examples/SentinelSpringCloudGatewayApplication.java index 137c6e911..7e13e3f4b 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-spring-cloud-gateway-example/src/main/java/com/alibaba/cloud/examples/SentinelSpringCloudGatewayApplication.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-spring-cloud-gateway-example/src/main/java/com/alibaba/cloud/examples/SentinelSpringCloudGatewayApplication.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/MyConfiguration.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/MyConfiguration.java index 4c0225ce5..6a8d271c7 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/MyConfiguration.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/MyConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,8 @@ package com.alibaba.cloud.examples; -import static org.springframework.web.reactive.function.BodyInserters.fromObject; +import com.alibaba.csp.sentinel.adapter.spring.webflux.callback.BlockRequestHandler; +import reactor.core.publisher.Mono; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -25,9 +26,7 @@ import org.springframework.http.MediaType; import org.springframework.web.reactive.function.server.ServerResponse; import org.springframework.web.server.ServerWebExchange; -import com.alibaba.csp.sentinel.adapter.spring.webflux.callback.BlockRequestHandler; - -import reactor.core.publisher.Mono; +import static org.springframework.web.reactive.function.BodyInserters.fromObject; /** * @author Jim diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/SentinelWebFluxApplication.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/SentinelWebFluxApplication.java index 353b8ba09..b933d56a4 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/SentinelWebFluxApplication.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/SentinelWebFluxApplication.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/SentinelWebFluxController.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/SentinelWebFluxController.java index 2ad86f690..5bf963327 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/SentinelWebFluxController.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/SentinelWebFluxController.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,14 +16,13 @@ package com.alibaba.cloud.examples; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - import com.alibaba.csp.sentinel.adapter.reactor.SentinelReactorTransformer; - import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + /** * @author Jim */ @@ -37,12 +36,12 @@ public class SentinelWebFluxController { .transform(new SentinelReactorTransformer<>("mono")); } - @GetMapping("/test") - public Mono test() { - return Mono.just("simple string") - // transform the publisher here. - .transform(new SentinelReactorTransformer<>("test")); - } + @GetMapping("/test") + public Mono test() { + return Mono.just("simple string") + // transform the publisher here. + .transform(new SentinelReactorTransformer<>("test")); + } @GetMapping("/flux") public Flux flux() { diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/resources/application.properties index 3bbd4f370..48bd8f43c 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/resources/application.properties +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/resources/application.properties @@ -3,8 +3,6 @@ server.port=18084 management.endpoints.web.exposure.include=* spring.cloud.sentinel.transport.dashboard=localhost:8080 spring.cloud.sentinel.eager=true - - spring.cloud.sentinel.datasource.ds1.file.file=classpath: flowrule.json spring.cloud.sentinel.datasource.ds1.file.data-type=json -spring.cloud.sentinel.datasource.ds1.file.rule-type=flow \ No newline at end of file +spring.cloud.sentinel.datasource.ds1.file.rule-type=flow diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/RulesController.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/RulesController.java index 73d9ef5a1..5475bcddc 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/RulesController.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/RulesController.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,6 @@ package com.alibaba.cloud.examples; import java.util.List; import java.util.Set; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition; import com.alibaba.csp.sentinel.adapter.gateway.common.api.GatewayApiDefinitionManager; import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule; @@ -29,6 +26,9 @@ import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager; import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + /** * @author Jim */ diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/SentinelZuulApplication.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/SentinelZuulApplication.java index 4c2243c6e..476cbb05d 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/SentinelZuulApplication.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/SentinelZuulApplication.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/ZuulConfiguration.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/ZuulConfiguration.java index 7393707e2..d3e1ffea7 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/ZuulConfiguration.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/ZuulConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,13 +18,13 @@ package com.alibaba.cloud.examples; import javax.servlet.http.HttpServletRequest; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - import com.alibaba.csp.sentinel.adapter.gateway.zuul.callback.RequestOriginParser; import com.alibaba.csp.sentinel.adapter.gateway.zuul.fallback.BlockResponse; import com.alibaba.csp.sentinel.adapter.gateway.zuul.fallback.ZuulBlockFallbackProvider; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + /** * @author Jim */ diff --git a/spring-cloud-alibaba-examples/sms-example/src/main/java/com/alibaba/cloud/example/SmsApplication.java b/spring-cloud-alibaba-examples/sms-example/src/main/java/com/alibaba/cloud/example/SmsApplication.java index 07c0d68f8..16edf32e8 100644 --- a/spring-cloud-alibaba-examples/sms-example/src/main/java/com/alibaba/cloud/example/SmsApplication.java +++ b/spring-cloud-alibaba-examples/sms-example/src/main/java/com/alibaba/cloud/example/SmsApplication.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.example; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** - * + * */ @SpringBootApplication public class SmsApplication { @@ -27,4 +28,5 @@ public class SmsApplication { public static void main(String[] args) throws Exception { SpringApplication.run(SmsApplication.class, args); } -} \ No newline at end of file + +} diff --git a/spring-cloud-alibaba-examples/sms-example/src/main/java/com/alibaba/cloud/example/SmsController.java b/spring-cloud-alibaba-examples/sms-example/src/main/java/com/alibaba/cloud/example/SmsController.java index b34862cef..9a5556fea 100644 --- a/spring-cloud-alibaba-examples/sms-example/src/main/java/com/alibaba/cloud/example/SmsController.java +++ b/spring-cloud-alibaba-examples/sms-example/src/main/java/com/alibaba/cloud/example/SmsController.java @@ -1,16 +1,24 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.example; import java.util.List; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.env.Environment; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - import com.alibaba.alicloud.sms.ISmsService; - import com.aliyun.mns.model.Message; import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsRequest; import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsResponse; @@ -21,6 +29,13 @@ import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.http.MethodType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + @RestController public class SmsController { @@ -39,11 +54,6 @@ public class SmsController { return environment.getProperty("spring.cloud.alicloud.sms.up-queue-name"); } - /** - * 短信发送 Example - * @param code - * @return - */ @RequestMapping("/batch-sms-send.do") public SendBatchSmsResponse batchsendCheckCode( @RequestParam(name = "code") String code) { @@ -74,11 +84,6 @@ public class SmsController { return new SendBatchSmsResponse(); } - /** - * 短信发送 Example - * @param code - * @return - */ @RequestMapping("/sms-send.do") public SendSmsResponse sendCheckCode(@RequestParam(name = "code") String code) { // 组装请求对象-具体描述见控制台-文档部分内容 @@ -107,12 +112,6 @@ public class SmsController { return new SendSmsResponse(); } - /** - * - * 短信查询 Example - * @param telephone - * @return - */ @RequestMapping("/query.do") public QuerySendDetailsResponse querySendDetailsResponse( @RequestParam(name = "tel") String telephone) { @@ -142,4 +141,5 @@ public class SmsController { return smsReportMessageListener.getSmsReportMessageSet(); } -} \ No newline at end of file + +} diff --git a/spring-cloud-alibaba-examples/sms-example/src/main/java/com/alibaba/cloud/example/SmsReportMessageListener.java b/spring-cloud-alibaba-examples/sms-example/src/main/java/com/alibaba/cloud/example/SmsReportMessageListener.java index a94b6bcce..d98554fcc 100644 --- a/spring-cloud-alibaba-examples/sms-example/src/main/java/com/alibaba/cloud/example/SmsReportMessageListener.java +++ b/spring-cloud-alibaba-examples/sms-example/src/main/java/com/alibaba/cloud/example/SmsReportMessageListener.java @@ -1,18 +1,35 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.example; import java.util.LinkedList; import java.util.List; -import org.springframework.stereotype.Component; - import com.aliyun.mns.model.Message; +import org.springframework.stereotype.Component; + /** * @author 如果需要监听短信是否被对方成功接收,只需实现这个接口并初始化一个 Spring Bean 即可。 */ @Component public class SmsReportMessageListener implements com.alibaba.alicloud.sms.SmsReportMessageListener { + private List smsReportMessageSet = new LinkedList<>(); @Override @@ -26,4 +43,5 @@ public class SmsReportMessageListener return smsReportMessageSet; } -} \ No newline at end of file + +} diff --git a/spring-cloud-alibaba-examples/sms-example/src/main/java/com/alibaba/cloud/example/SmsUpMessageListener.java b/spring-cloud-alibaba-examples/sms-example/src/main/java/com/alibaba/cloud/example/SmsUpMessageListener.java index df8e971e5..e6cef0407 100644 --- a/spring-cloud-alibaba-examples/sms-example/src/main/java/com/alibaba/cloud/example/SmsUpMessageListener.java +++ b/spring-cloud-alibaba-examples/sms-example/src/main/java/com/alibaba/cloud/example/SmsUpMessageListener.java @@ -1,9 +1,25 @@ -package com.alibaba.cloud.example; +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ -import org.springframework.stereotype.Component; +package com.alibaba.cloud.example; import com.aliyun.mns.model.Message; +import org.springframework.stereotype.Component; + /** * @author 如果发送的短信需要接收对方回复的状态消息,只需实现该接口并初始化一个 Spring Bean 即可。 */ @@ -16,4 +32,5 @@ public class SmsUpMessageListener System.err.println(this.getClass().getName() + "; " + message.toString()); return true; } -} \ No newline at end of file + +} diff --git a/spring-cloud-alibaba-examples/sms-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/sms-example/src/main/resources/application.properties index 4464cfe94..c5e23fc84 100644 --- a/spring-cloud-alibaba-examples/sms-example/src/main/resources/application.properties +++ b/spring-cloud-alibaba-examples/sms-example/src/main/resources/application.properties @@ -6,4 +6,4 @@ spring.cloud.alicloud.secret-key=****** spring.cloud.alicloud.sms.report-queue-name=***** spring.cloud.alicloud.sms.up-queue-name=***** #config endpoint -management.endpoints.web.exposure.include=* \ No newline at end of file +management.endpoints.web.exposure.include=* diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-client-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudClientBootstrap.java b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-client-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudClientBootstrap.java index a7aadf6e3..e72b805ce 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-client-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudClientBootstrap.java +++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-client-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudClientBootstrap.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,17 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.bootstrap; +import com.alibaba.cloud.dubbo.service.EchoService; + import org.apache.dubbo.config.annotation.Reference; + import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; -import com.alibaba.cloud.dubbo.service.EchoService; - /** * Dubbo Spring Cloud Client Bootstrap */ diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-consumer-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudConsumerBootstrap.java b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-consumer-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudConsumerBootstrap.java index ce569695f..7fcc7d49f 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-consumer-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudConsumerBootstrap.java +++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-consumer-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudConsumerBootstrap.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,14 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.bootstrap; -import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE; +package com.alibaba.cloud.dubbo.bootstrap; import java.util.HashMap; import java.util.Map; +import com.alibaba.cloud.dubbo.annotation.DubboTransported; +import com.alibaba.cloud.dubbo.service.RestService; +import com.alibaba.cloud.dubbo.service.User; +import com.alibaba.cloud.dubbo.service.UserService; + import org.apache.dubbo.config.annotation.Reference; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.ApplicationRunner; @@ -43,13 +48,10 @@ import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.client.RestTemplate; -import com.alibaba.cloud.dubbo.annotation.DubboTransported; -import com.alibaba.cloud.dubbo.service.RestService; -import com.alibaba.cloud.dubbo.service.User; -import com.alibaba.cloud.dubbo.service.UserService; +import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE; /** - * Dubbo Spring Cloud Consumer Bootstrap + * Dubbo Spring Cloud Consumer Bootstrap. */ @EnableDiscoveryClient @EnableAutoConfiguration diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudProviderBootstrap.java b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudProviderBootstrap.java index 1424019c6..b8ef9fd1a 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudProviderBootstrap.java +++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudProviderBootstrap.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.bootstrap; import org.springframework.boot.WebApplicationType; @@ -21,7 +22,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; /** - * Dubbo Spring Cloud Provider Bootstrap + * Dubbo Spring Cloud Provider Bootstrap. */ @EnableDiscoveryClient @EnableAutoConfiguration diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-sample/src/main/java/com/alibaba/cloud/dubbo/service/InMemoryUserService.java b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-sample/src/main/java/com/alibaba/cloud/dubbo/service/InMemoryUserService.java index 2a9c30dec..8f5eed069 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-sample/src/main/java/com/alibaba/cloud/dubbo/service/InMemoryUserService.java +++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-sample/src/main/java/com/alibaba/cloud/dubbo/service/InMemoryUserService.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.service; import java.util.Collection; @@ -22,7 +23,7 @@ import java.util.Map; import org.apache.dubbo.config.annotation.Service; /** - * In-Memory {@link UserService} implementation + * In-Memory {@link UserService} implementation. */ @Service(protocol = "dubbo") public class InMemoryUserService implements UserService { diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-sample/src/main/java/com/alibaba/cloud/dubbo/service/StandardRestService.java b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-sample/src/main/java/com/alibaba/cloud/dubbo/service/StandardRestService.java index 9721d2588..c53d9999a 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-sample/src/main/java/com/alibaba/cloud/dubbo/service/StandardRestService.java +++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-sample/src/main/java/com/alibaba/cloud/dubbo/service/StandardRestService.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.service; -import static com.alibaba.cloud.dubbo.util.LoggerUtils.log; -import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON_VALUE; +package com.alibaba.cloud.dubbo.service; import java.util.HashMap; import java.util.Map; @@ -36,8 +34,11 @@ import org.apache.dubbo.config.annotation.Service; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static com.alibaba.cloud.dubbo.util.LoggerUtils.log; +import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON_VALUE; + /** - * Default {@link RestService} + * Default {@link RestService}. * * @author Mercy */ diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-web-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudWebProviderBootstrap.java b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-web-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudWebProviderBootstrap.java index 55c40c4d3..f3b8dc8bd 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-web-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudWebProviderBootstrap.java +++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-web-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudWebProviderBootstrap.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.bootstrap; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -20,7 +21,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; /** - * Dubbo Spring Cloud Provider Bootstrap + * Dubbo Spring Cloud Provider Bootstrap. */ @EnableDiscoveryClient @EnableAutoConfiguration diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-web-sample/src/main/java/com/alibaba/cloud/dubbo/service/InMemoryUserService.java b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-web-sample/src/main/java/com/alibaba/cloud/dubbo/service/InMemoryUserService.java index 2a9c30dec..8f5eed069 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-web-sample/src/main/java/com/alibaba/cloud/dubbo/service/InMemoryUserService.java +++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-web-sample/src/main/java/com/alibaba/cloud/dubbo/service/InMemoryUserService.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.service; import java.util.Collection; @@ -22,7 +23,7 @@ import java.util.Map; import org.apache.dubbo.config.annotation.Service; /** - * In-Memory {@link UserService} implementation + * In-Memory {@link UserService} implementation. */ @Service(protocol = "dubbo") public class InMemoryUserService implements UserService { diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-web-sample/src/main/java/com/alibaba/cloud/dubbo/service/SpringRestService.java b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-web-sample/src/main/java/com/alibaba/cloud/dubbo/service/SpringRestService.java index 1b1d7f241..37d89b4c9 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-web-sample/src/main/java/com/alibaba/cloud/dubbo/service/SpringRestService.java +++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-web-sample/src/main/java/com/alibaba/cloud/dubbo/service/SpringRestService.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.dubbo.service; -import static com.alibaba.cloud.dubbo.util.LoggerUtils.log; +package com.alibaba.cloud.dubbo.service; import java.util.HashMap; import java.util.Map; @@ -23,6 +22,7 @@ import java.util.Map; import org.apache.dubbo.config.annotation.Service; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -32,8 +32,10 @@ import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import static com.alibaba.cloud.dubbo.util.LoggerUtils.log; + /** - * Spring MVC {@link RestService} + * Spring MVC {@link RestService}. * * @author Mercy */ diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-sample-api/src/main/java/com/alibaba/cloud/dubbo/service/EchoService.java b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-sample-api/src/main/java/com/alibaba/cloud/dubbo/service/EchoService.java index c11d3176b..852930686 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-sample-api/src/main/java/com/alibaba/cloud/dubbo/service/EchoService.java +++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-sample-api/src/main/java/com/alibaba/cloud/dubbo/service/EchoService.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.service; /** - * Echo Service + * Echo Service. */ public interface EchoService { diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-sample-api/src/main/java/com/alibaba/cloud/dubbo/service/RestService.java b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-sample-api/src/main/java/com/alibaba/cloud/dubbo/service/RestService.java index d916e473c..1a021f4f9 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-sample-api/src/main/java/com/alibaba/cloud/dubbo/service/RestService.java +++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-sample-api/src/main/java/com/alibaba/cloud/dubbo/service/RestService.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.service; import java.util.Map; /** - * Rest Service + * Rest Service. * * @author Mercy */ diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-sample-api/src/main/java/com/alibaba/cloud/dubbo/service/User.java b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-sample-api/src/main/java/com/alibaba/cloud/dubbo/service/User.java index 5349356ce..f22769332 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-sample-api/src/main/java/com/alibaba/cloud/dubbo/service/User.java +++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-sample-api/src/main/java/com/alibaba/cloud/dubbo/service/User.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.service; import java.io.Serializable; /** - * User Entity + * User Entity. * * @author Mercy */ diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-sample-api/src/main/java/com/alibaba/cloud/dubbo/service/UserService.java b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-sample-api/src/main/java/com/alibaba/cloud/dubbo/service/UserService.java index 1798f5f2c..c170b463c 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-sample-api/src/main/java/com/alibaba/cloud/dubbo/service/UserService.java +++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-sample-api/src/main/java/com/alibaba/cloud/dubbo/service/UserService.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.service; import java.util.Collection; /** - * {@link User} Service + * {@link User} Service. * * @author Mercy */ diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-sample-api/src/main/java/com/alibaba/cloud/dubbo/util/LoggerUtils.java b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-sample-api/src/main/java/com/alibaba/cloud/dubbo/util/LoggerUtils.java index b09577fc2..5c01d0a5e 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-sample-api/src/main/java/com/alibaba/cloud/dubbo/util/LoggerUtils.java +++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-sample-api/src/main/java/com/alibaba/cloud/dubbo/util/LoggerUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.util; import org.apache.dubbo.rpc.RpcContext; @@ -20,7 +21,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Logger Utilities + * Logger Utilities. */ public abstract class LoggerUtils { diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-server-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudServerBootstrap.java b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-server-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudServerBootstrap.java index 19e5bdb39..f29f89521 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-server-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudServerBootstrap.java +++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-server-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudServerBootstrap.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,17 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.dubbo.bootstrap; +import com.alibaba.cloud.dubbo.service.EchoService; + import org.apache.dubbo.config.annotation.Service; + import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import com.alibaba.cloud.dubbo.service.EchoService; - /** - * Dubbo Spring Cloud Server Bootstrap + * Dubbo Spring Cloud Server Bootstrap. */ @EnableDiscoveryClient @EnableAutoConfiguration diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-servlet-gateway-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudServletGatewayBootstrap.java b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-servlet-gateway-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudServletGatewayBootstrap.java index 6eecaf1a4..35884f231 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-servlet-gateway-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudServletGatewayBootstrap.java +++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-servlet-gateway-sample/src/main/java/com/alibaba/cloud/dubbo/bootstrap/DubboSpringCloudServletGatewayBootstrap.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.dubbo.bootstrap; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -7,7 +23,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.openfeign.EnableFeignClients; /** - * Dubbo Spring Cloud Servlet Gateway Bootstrap + * Dubbo Spring Cloud Servlet Gateway Bootstrap. */ @EnableDiscoveryClient @EnableAutoConfiguration diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-servlet-gateway-sample/src/main/java/com/alibaba/cloud/dubbo/gateway/DubboGatewayServlet.java b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-servlet-gateway-sample/src/main/java/com/alibaba/cloud/dubbo/gateway/DubboGatewayServlet.java index be73c115c..f23cf3966 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-servlet-gateway-sample/src/main/java/com/alibaba/cloud/dubbo/gateway/DubboGatewayServlet.java +++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-servlet-gateway-sample/src/main/java/com/alibaba/cloud/dubbo/gateway/DubboGatewayServlet.java @@ -1,7 +1,37 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.dubbo.gateway; -import org.apache.dubbo.rpc.service.GenericException; -import org.apache.dubbo.rpc.service.GenericService; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Arrays; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.ServletInputStream; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import com.alibaba.cloud.dubbo.http.MutableHttpServerRequest; import com.alibaba.cloud.dubbo.metadata.DubboRestServiceMetadata; @@ -11,6 +41,10 @@ import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepositor import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContext; import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContextFactory; import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory; + +import org.apache.dubbo.rpc.service.GenericException; +import org.apache.dubbo.rpc.service.GenericService; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpRequest; import org.springframework.util.AntPathMatcher; @@ -19,22 +53,6 @@ import org.springframework.util.StreamUtils; import org.springframework.web.servlet.HttpServletBean; import org.springframework.web.util.UriComponents; -import javax.servlet.ServletException; -import javax.servlet.ServletInputStream; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Arrays; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - import static org.apache.commons.lang3.StringUtils.substringAfter; import static org.apache.commons.lang3.StringUtils.substringBetween; import static org.springframework.web.util.UriComponentsBuilder.fromUriString; diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-sidecar-examples/spring-cloud-alibaba-sidecar-consul-example/src/main/java/com/alibaba/cloud/sidecar/DemoApplication.java b/spring-cloud-alibaba-examples/spring-cloud-alibaba-sidecar-examples/spring-cloud-alibaba-sidecar-consul-example/src/main/java/com/alibaba/cloud/sidecar/DemoApplication.java index d97b18070..f61c6013c 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-sidecar-examples/spring-cloud-alibaba-sidecar-consul-example/src/main/java/com/alibaba/cloud/sidecar/DemoApplication.java +++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-sidecar-examples/spring-cloud-alibaba-sidecar-consul-example/src/main/java/com/alibaba/cloud/sidecar/DemoApplication.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,7 +21,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class DemoApplication { - public static void main(String[] args) { - SpringApplication.run(DemoApplication.class, args); - } + + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } + } diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-sidecar-examples/spring-cloud-alibaba-sidecar-nacos-example/src/main/java/com/alibaba/cloud/sidecar/DemoApplication.java b/spring-cloud-alibaba-examples/spring-cloud-alibaba-sidecar-examples/spring-cloud-alibaba-sidecar-nacos-example/src/main/java/com/alibaba/cloud/sidecar/DemoApplication.java index d449ac26a..f61c6013c 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-sidecar-examples/spring-cloud-alibaba-sidecar-nacos-example/src/main/java/com/alibaba/cloud/sidecar/DemoApplication.java +++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-sidecar-examples/spring-cloud-alibaba-sidecar-nacos-example/src/main/java/com/alibaba/cloud/sidecar/DemoApplication.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,8 +22,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class DemoApplication { - public static void main(String[] args) { - SpringApplication.run(DemoApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } } diff --git a/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/com/alibaba/cloud/examples/rocketmq/RocketMQBusApplication.java b/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/com/alibaba/cloud/examples/rocketmq/RocketMQBusApplication.java index 678af12f4..eff0e4fb8 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/com/alibaba/cloud/examples/rocketmq/RocketMQBusApplication.java +++ b/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/com/alibaba/cloud/examples/rocketmq/RocketMQBusApplication.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,8 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.examples.rocketmq; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -27,11 +31,8 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; - /** - * RocketMQ Bus Spring Application + * RocketMQ Bus Spring Application. * * @author Mercy * @since 0.2.1 @@ -65,7 +66,6 @@ public class RocketMQBusApplication { /** * Publish the {@link UserRemoteApplicationEvent} - * * @param name the user name * @param destination the destination * @return If published @@ -83,7 +83,6 @@ public class RocketMQBusApplication { /** * Listener on the {@link UserRemoteApplicationEvent} - * * @param event {@link UserRemoteApplicationEvent} */ @EventListener @@ -98,4 +97,5 @@ public class RocketMQBusApplication { System.out.printf("Server [port : %d] listeners on %s\n", localServerPort, objectMapper.writeValueAsString(event)); } + } diff --git a/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/com/alibaba/cloud/examples/rocketmq/User.java b/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/com/alibaba/cloud/examples/rocketmq/User.java index 3805094e3..40b3e7d7e 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/com/alibaba/cloud/examples/rocketmq/User.java +++ b/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/com/alibaba/cloud/examples/rocketmq/User.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.examples.rocketmq; /** - * User Domain + * User Domain. * * @author Mercy * @since 0.2.1 @@ -47,4 +48,5 @@ public class User { public String toString() { return "User{" + "id=" + id + ", name='" + name + '\'' + '}'; } + } diff --git a/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/com/alibaba/cloud/examples/rocketmq/UserRemoteApplicationEvent.java b/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/com/alibaba/cloud/examples/rocketmq/UserRemoteApplicationEvent.java index d5fb804dd..e7d56ffca 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/com/alibaba/cloud/examples/rocketmq/UserRemoteApplicationEvent.java +++ b/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/com/alibaba/cloud/examples/rocketmq/UserRemoteApplicationEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.examples.rocketmq; import org.springframework.cloud.bus.event.RemoteApplicationEvent; /** - * {@link User} {@link RemoteApplicationEvent} + * {@link User} {@link RemoteApplicationEvent}. * * @author Mercy * @since 0.2.1 @@ -43,4 +44,5 @@ public class UserRemoteApplicationEvent extends RemoteApplicationEvent { public User getUser() { return user; } + } diff --git a/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/resources/bootstrap.properties b/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/resources/bootstrap.properties index 9e36d301b..d2265b76f 100644 --- a/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/resources/bootstrap.properties +++ b/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/resources/bootstrap.properties @@ -1,4 +1,4 @@ spring.application.name=spring-cloud-bus-rocketmq-example spring.cloud.stream.rocketmq.binder.name-server=127.0.0.1:9876 server.port=8080 -spring.cloud.bus.id=${spring.application.name}:${server.port} \ No newline at end of file +spring.cloud.bus.id=${spring.application.name}:${server.port} diff --git a/spring-cloud-alibaba-nacos-config-server/src/main/java/com/alibaba/cloud/nacos/config/server/NacosConfigServerAutoConfiguration.java b/spring-cloud-alibaba-nacos-config-server/src/main/java/com/alibaba/cloud/nacos/config/server/NacosConfigServerAutoConfiguration.java index 9e00214af..a1c1b250e 100644 --- a/spring-cloud-alibaba-nacos-config-server/src/main/java/com/alibaba/cloud/nacos/config/server/NacosConfigServerAutoConfiguration.java +++ b/spring-cloud-alibaba-nacos-config-server/src/main/java/com/alibaba/cloud/nacos/config/server/NacosConfigServerAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,8 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.nacos.config.server; +import com.alibaba.cloud.nacos.config.server.environment.NacosEnvironmentRepository; + import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.cloud.config.server.EnableConfigServer; @@ -23,17 +26,15 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import com.alibaba.cloud.nacos.config.server.environment.NacosEnvironmentRepository; - /** - * Nacos Config Server Auto-Configuration + * Nacos Config Server Auto-Configuration. * * @author Mercy * @since 0.2.0 */ @ConditionalOnClass(EnableConfigServer.class) // If class of @EnableConfigServer is // present in class-path -@ComponentScan(basePackages = { "com.alibaba.nacos.config.server", }) +@ComponentScan(basePackages = { "com.alibaba.nacos.config.server" }) @AutoConfigureBefore(ConfigServerAutoConfiguration.class) @Configuration public class NacosConfigServerAutoConfiguration { diff --git a/spring-cloud-alibaba-nacos-config-server/src/main/java/com/alibaba/cloud/nacos/config/server/environment/NacosEnvironmentRepository.java b/spring-cloud-alibaba-nacos-config-server/src/main/java/com/alibaba/cloud/nacos/config/server/environment/NacosEnvironmentRepository.java index ced3cbd29..66fb2dfd8 100644 --- a/spring-cloud-alibaba-nacos-config-server/src/main/java/com/alibaba/cloud/nacos/config/server/environment/NacosEnvironmentRepository.java +++ b/spring-cloud-alibaba-nacos-config-server/src/main/java/com/alibaba/cloud/nacos/config/server/environment/NacosEnvironmentRepository.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,25 +13,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.nacos.config.server.environment; -import static com.alibaba.nacos.config.server.constant.Constants.DEFAULT_GROUP; +package com.alibaba.cloud.nacos.config.server.environment; import java.io.IOException; import java.io.StringReader; import java.util.Properties; +import com.alibaba.nacos.config.server.model.ConfigInfo; +import com.alibaba.nacos.config.server.service.PersistService; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; import org.springframework.cloud.config.server.environment.EnvironmentRepository; import org.springframework.util.StringUtils; -import com.alibaba.nacos.config.server.model.ConfigInfo; -import com.alibaba.nacos.config.server.service.PersistService; +import static com.alibaba.nacos.config.server.constant.Constants.DEFAULT_GROUP; /** - * Nacos {@link EnvironmentRepository} + * Nacos {@link EnvironmentRepository}. * * @author Mercy * @since 0.2.0 @@ -87,4 +88,5 @@ public class NacosEnvironmentRepository implements EnvironmentRepository { private static String[] of(String... values) { return values; } + } diff --git a/spring-cloud-alibaba-nacos-config-server/src/test/java/com/alibaba/cloud/nacos/config/server/bootstrap/NacosConfigServerBootstrap.java b/spring-cloud-alibaba-nacos-config-server/src/test/java/com/alibaba/cloud/nacos/config/server/bootstrap/NacosConfigServerBootstrap.java index a1222f39a..2ff7dc1c2 100644 --- a/spring-cloud-alibaba-nacos-config-server/src/test/java/com/alibaba/cloud/nacos/config/server/bootstrap/NacosConfigServerBootstrap.java +++ b/spring-cloud-alibaba-nacos-config-server/src/test/java/com/alibaba/cloud/nacos/config/server/bootstrap/NacosConfigServerBootstrap.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.nacos.config.server.bootstrap; import org.springframework.boot.ApplicationRunner; @@ -43,4 +44,5 @@ public class NacosConfigServerBootstrap { System.out.println("Running..."); }; } + } diff --git a/spring-cloud-alibaba-nacos-config-server/src/test/resources/application.properties b/spring-cloud-alibaba-nacos-config-server/src/test/resources/application.properties index dcecabe77..7121d6310 100644 --- a/spring-cloud-alibaba-nacos-config-server/src/test/resources/application.properties +++ b/spring-cloud-alibaba-nacos-config-server/src/test/resources/application.properties @@ -1,2 +1,2 @@ spring.application.name=nacos-config-server -management.endpoints.web.exposure.include=* \ No newline at end of file +management.endpoints.web.exposure.include=* diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigAutoConfiguration.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigAutoConfiguration.java index bdc0b2d39..7bd23ce4f 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigAutoConfiguration.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,16 +16,16 @@ package com.alibaba.cloud.nacos; +import com.alibaba.cloud.nacos.refresh.NacosContextRefresher; +import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory; +import com.alibaba.cloud.nacos.refresh.NacosRefreshProperties; + import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.alibaba.cloud.nacos.refresh.NacosContextRefresher; -import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory; -import com.alibaba.cloud.nacos.refresh.NacosRefreshProperties; - /** * @author juven.xuxb */ @@ -67,4 +67,5 @@ public class NacosConfigAutoConfiguration { return new NacosContextRefresher(nacosRefreshProperties, refreshHistory, nacosConfigManager.getConfigService()); } + } diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigBootstrapConfiguration.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigBootstrapConfiguration.java index 0a5712e16..5850ac504 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigBootstrapConfiguration.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigBootstrapConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,13 @@ package com.alibaba.cloud.nacos; +import com.alibaba.cloud.nacos.client.NacosPropertySourceLocator; + import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.alibaba.cloud.nacos.client.NacosPropertySourceLocator; - /** * @author xiaojing */ diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigManager.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigManager.java index 91f4759dd..df5469d36 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigManager.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigManager.java @@ -1,12 +1,11 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Copyright 2013-2018 the original author or authors. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -14,16 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.nacos; +import java.util.Objects; + import com.alibaba.nacos.api.NacosFactory; import com.alibaba.nacos.api.config.ConfigService; import com.alibaba.nacos.api.exception.NacosException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import java.util.Objects; +import org.springframework.beans.factory.annotation.Autowired; /** * @author liaochuntao diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigProperties.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigProperties.java index 1537002ca..a5ce70a70 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigProperties.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,38 +16,37 @@ package com.alibaba.cloud.nacos; -import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY; -import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME; -import static com.alibaba.nacos.api.PropertyKeyConst.CONTEXT_PATH; -import static com.alibaba.nacos.api.PropertyKeyConst.ENCODE; -import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT; -import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT_PORT; -import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE; -import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY; -import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR; -import static com.alibaba.nacos.api.PropertyKeyConst.MAX_RETRY; -import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT; -import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_RETRY_TIME; -import static com.alibaba.nacos.api.PropertyKeyConst.ENABLE_REMOTE_SYNC_CONFIG; - import java.util.List; import java.util.Objects; import java.util.Properties; import javax.annotation.PostConstruct; +import com.alibaba.nacos.api.config.ConfigService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.core.env.Environment; import org.springframework.util.StringUtils; -import com.alibaba.nacos.api.NacosFactory; -import com.alibaba.nacos.api.config.ConfigService; +import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY; +import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME; +import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT; +import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_RETRY_TIME; +import static com.alibaba.nacos.api.PropertyKeyConst.CONTEXT_PATH; +import static com.alibaba.nacos.api.PropertyKeyConst.ENABLE_REMOTE_SYNC_CONFIG; +import static com.alibaba.nacos.api.PropertyKeyConst.ENCODE; +import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT; +import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT_PORT; +import static com.alibaba.nacos.api.PropertyKeyConst.MAX_RETRY; +import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE; +import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY; +import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR; /** - * nacos properties + * Nacos properties. * * @author leijuan * @author xiaojing @@ -57,6 +56,9 @@ import com.alibaba.nacos.api.config.ConfigService; @ConfigurationProperties(NacosConfigProperties.PREFIX) public class NacosConfigProperties { + /** + * Prefix of {@link NacosConfigProperties}. + */ public static final String PREFIX = "spring.cloud.nacos.config"; private static final Logger log = LoggerFactory @@ -101,6 +103,7 @@ public class NacosConfigProperties { * nacos config dataId prefix. */ private String prefix; + /** * the suffix of nacos config dataId, also the file extension of config content. */ @@ -351,60 +354,9 @@ public class NacosConfigProperties { this.name = name; } - public static class Config { - /** - * the data id of extended configuration - */ - private String dataId; - /** - * the group of extended configuration, the default value is DEFAULT_GROUP - */ - private String group = "DEFAULT_GROUP"; - /** - * whether to support dynamic refresh, the default does not support . - */ - private boolean refresh = false; - - public String getDataId() { - return dataId; - } - - public void setDataId(String dataId) { - this.dataId = dataId; - } - - public String getGroup() { - return group; - } - - public void setGroup(String group) { - this.group = group; - } - - public boolean isRefresh() { - return refresh; - } - - public void setRefresh(boolean refresh) { - this.refresh = refresh; - } - } - - @Override - public String toString() { - return "NacosConfigProperties{" + "serverAddr='" + serverAddr + '\'' - + ", encode='" + encode + '\'' + ", group='" + group + '\'' + ", prefix='" - + prefix + '\'' + ", fileExtension='" + fileExtension + '\'' - + ", timeout=" + timeout + ", endpoint='" + endpoint + '\'' - + ", namespace='" + namespace + '\'' + ", accessKey='" + accessKey + '\'' - + ", secretKey='" + secretKey + '\'' + ", contextPath='" + contextPath - + '\'' + ", clusterName='" + clusterName + '\'' + ", name='" + name + '\'' - + ", sharedDataids='" + sharedDataids + '\'' + ", refreshableDataids='" - + refreshableDataids + '\'' + ", extConfig=" + extConfig + '}'; - } - /** - * @see NacosConfigManager#getConfigService() + * @see NacosConfigManager#getConfigService() . + * @return ConfigService */ @Deprecated public ConfigService configServiceInstance() { @@ -442,4 +394,60 @@ public class NacosConfigProperties { return properties; } + @Override + public String toString() { + return "NacosConfigProperties{" + "serverAddr='" + serverAddr + '\'' + + ", encode='" + encode + '\'' + ", group='" + group + '\'' + ", prefix='" + + prefix + '\'' + ", fileExtension='" + fileExtension + '\'' + + ", timeout=" + timeout + ", endpoint='" + endpoint + '\'' + + ", namespace='" + namespace + '\'' + ", accessKey='" + accessKey + '\'' + + ", secretKey='" + secretKey + '\'' + ", contextPath='" + contextPath + + '\'' + ", clusterName='" + clusterName + '\'' + ", name='" + name + '\'' + + ", sharedDataids='" + sharedDataids + '\'' + ", refreshableDataids='" + + refreshableDataids + '\'' + ", extConfig=" + extConfig + '}'; + } + + public static class Config { + + /** + * the data id of extended configuration. + */ + private String dataId; + + /** + * the group of extended configuration, the default value is DEFAULT_GROUP. + */ + private String group = "DEFAULT_GROUP"; + + /** + * whether to support dynamic refresh, the default does not support . + */ + private boolean refresh = false; + + public String getDataId() { + return dataId; + } + + public void setDataId(String dataId) { + this.dataId = dataId; + } + + public String getGroup() { + return group; + } + + public void setGroup(String group) { + this.group = group; + } + + public boolean isRefresh() { + return refresh; + } + + public void setRefresh(boolean refresh) { + this.refresh = refresh; + } + + } + } diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosPropertySourceRepository.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosPropertySourceRepository.java index f7937336a..470646215 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosPropertySourceRepository.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosPropertySourceRepository.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,25 +16,29 @@ package com.alibaba.cloud.nacos; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.ConcurrentHashMap; import com.alibaba.cloud.nacos.client.NacosPropertySource; -import com.google.common.collect.Lists; /** * @author xiaojing * @author pbting */ -public class NacosPropertySourceRepository { +public final class NacosPropertySourceRepository { private final static ConcurrentHashMap NACOS_PROPERTY_SOURCE_REPOSITORY = new ConcurrentHashMap<>(); + private NacosPropertySourceRepository() { + + } + /** - * @return all nacos properties from application context + * @return all nacos properties from application context. */ public static List getAll() { - return Lists.newArrayList(NACOS_PROPERTY_SOURCE_REPOSITORY.values()); + return new ArrayList<>(NACOS_PROPERTY_SOURCE_REPOSITORY.values()); } public static void collectNacosPropertySources( @@ -44,7 +48,7 @@ public class NacosPropertySourceRepository { } public static NacosPropertySource getNacosPropertySource(String dataId) { - return NACOS_PROPERTY_SOURCE_REPOSITORY.get(dataId); } + } diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/client/NacosPropertySource.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/client/NacosPropertySource.java index d932f2b3d..82c93f5ba 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/client/NacosPropertySource.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/client/NacosPropertySource.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -28,22 +28,22 @@ import org.springframework.core.env.MapPropertySource; public class NacosPropertySource extends MapPropertySource { /** - * Nacos Group + * Nacos Group. */ private final String group; /** - * Nacos dataID + * Nacos dataID. */ private final String dataId; /** - * timestamp the property get + * timestamp the property get. */ private final Date timestamp; /** - * Whether to support dynamic refresh for this Property Source + * Whether to support dynamic refresh for this Property Source. */ private final boolean isRefreshable; @@ -71,4 +71,5 @@ public class NacosPropertySource extends MapPropertySource { public boolean isRefreshable() { return isRefreshable; } + } diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/client/NacosPropertySourceBuilder.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/client/NacosPropertySourceBuilder.java index 1b615d700..acd2a49d4 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/client/NacosPropertySourceBuilder.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/client/NacosPropertySourceBuilder.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,25 +22,28 @@ import java.util.HashMap; import java.util.Map; import java.util.Properties; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.util.StringUtils; - import com.alibaba.cloud.nacos.NacosPropertySourceRepository; import com.alibaba.cloud.nacos.parser.NacosDataParserHandler; import com.alibaba.nacos.api.config.ConfigService; import com.alibaba.nacos.api.exception.NacosException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.util.StringUtils; /** * @author xiaojing * @author pbting */ public class NacosPropertySourceBuilder { + private static final Logger log = LoggerFactory .getLogger(NacosPropertySourceBuilder.class); + private static final Properties EMPTY_PROPERTIES = new Properties(); private ConfigService configService; + private long timeout; public NacosPropertySourceBuilder(ConfigService configService, long timeout) { diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/client/NacosPropertySourceLocator.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/client/NacosPropertySourceLocator.java index 6a7dc6ccd..165e8cb0c 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/client/NacosPropertySourceLocator.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/client/NacosPropertySourceLocator.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,8 +19,14 @@ package com.alibaba.cloud.nacos.client; import java.util.List; import com.alibaba.cloud.nacos.NacosConfigManager; +import com.alibaba.cloud.nacos.NacosConfigProperties; +import com.alibaba.cloud.nacos.NacosPropertySourceRepository; +import com.alibaba.cloud.nacos.parser.NacosDataParserHandler; +import com.alibaba.cloud.nacos.refresh.NacosContextRefresher; +import com.alibaba.nacos.api.config.ConfigService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.cloud.bootstrap.config.PropertySourceLocator; import org.springframework.core.annotation.Order; import org.springframework.core.env.CompositePropertySource; @@ -29,12 +35,6 @@ import org.springframework.core.env.PropertySource; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; -import com.alibaba.cloud.nacos.NacosConfigProperties; -import com.alibaba.cloud.nacos.NacosPropertySourceRepository; -import com.alibaba.cloud.nacos.parser.NacosDataParserHandler; -import com.alibaba.cloud.nacos.refresh.NacosContextRefresher; -import com.alibaba.nacos.api.config.ConfigService; - /** * @author xiaojing * @author pbting @@ -44,9 +44,13 @@ public class NacosPropertySourceLocator implements PropertySourceLocator { private static final Logger log = LoggerFactory .getLogger(NacosPropertySourceLocator.class); + private static final String NACOS_PROPERTY_SOURCE_NAME = "NACOS"; + private static final String SEP1 = "-"; + private static final String DOT = "."; + private static final String SHARED_CONFIG_SEPARATOR_CHAR = "[,]"; private NacosPropertySourceBuilder nacosPropertySourceBuilder; @@ -197,7 +201,7 @@ public class NacosPropertySourceLocator implements PropertySourceLocator { /** * Add the nacos configuration to the first place and maybe ignore the empty - * configuration + * configuration. */ private void addFirstPropertySource(final CompositePropertySource composite, NacosPropertySource nacosPropertySource, boolean ignoreEmpty) { diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/diagnostics/analyzer/NacosConnectionFailureAnalyzer.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/diagnostics/analyzer/NacosConnectionFailureAnalyzer.java index b8109b89f..611ac534e 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/diagnostics/analyzer/NacosConnectionFailureAnalyzer.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/diagnostics/analyzer/NacosConnectionFailureAnalyzer.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -34,4 +34,5 @@ public class NacosConnectionFailureAnalyzer return new FailureAnalysis("Application failed to connect to Nacos server", "check your Nacos server config", cause); } + } diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/diagnostics/analyzer/NacosConnectionFailureException.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/diagnostics/analyzer/NacosConnectionFailureException.java index f01458d46..2935fc291 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/diagnostics/analyzer/NacosConnectionFailureException.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/diagnostics/analyzer/NacosConnectionFailureException.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/endpoint/NacosConfigEndpoint.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/endpoint/NacosConfigEndpoint.java index 2594ae923..d5b516601 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/endpoint/NacosConfigEndpoint.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/endpoint/NacosConfigEndpoint.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,16 +23,17 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.springframework.boot.actuate.endpoint.annotation.Endpoint; -import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; - import com.alibaba.cloud.nacos.NacosConfigProperties; import com.alibaba.cloud.nacos.NacosPropertySourceRepository; import com.alibaba.cloud.nacos.client.NacosPropertySource; import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory; +import org.springframework.boot.actuate.endpoint.annotation.Endpoint; +import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; + /** - * Endpoint for Nacos, contains config data and refresh history + * Endpoint for Nacos, contains config data and refresh history. + * * @author xiaojing */ @Endpoint(id = "nacos-config") @@ -70,4 +71,5 @@ public class NacosConfigEndpoint { return result; } + } diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/endpoint/NacosConfigEndpointAutoConfiguration.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/endpoint/NacosConfigEndpointAutoConfiguration.java index 920b510d7..ff3b91f74 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/endpoint/NacosConfigEndpointAutoConfiguration.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/endpoint/NacosConfigEndpointAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,6 +17,9 @@ package com.alibaba.cloud.nacos.endpoint; import com.alibaba.cloud.nacos.NacosConfigManager; +import com.alibaba.cloud.nacos.NacosConfigProperties; +import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; @@ -26,14 +29,11 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.context.annotation.Bean; -import com.alibaba.cloud.nacos.NacosConfigProperties; -import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory; - /** * @author xiaojing */ @ConditionalOnWebApplication -@ConditionalOnClass(value = Endpoint.class) +@ConditionalOnClass(Endpoint.class) @ConditionalOnProperty(name = "spring.cloud.nacos.config.enabled", matchIfMissing = true) public class NacosConfigEndpointAutoConfiguration { @@ -57,4 +57,5 @@ public class NacosConfigEndpointAutoConfiguration { public NacosConfigHealthIndicator nacosConfigHealthIndicator() { return new NacosConfigHealthIndicator(nacosConfigManager.getConfigService()); } + } diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/endpoint/NacosConfigHealthIndicator.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/endpoint/NacosConfigHealthIndicator.java index 7fe5a1895..7becf481a 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/endpoint/NacosConfigHealthIndicator.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/endpoint/NacosConfigHealthIndicator.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,11 +16,11 @@ package com.alibaba.cloud.nacos.endpoint; +import com.alibaba.nacos.api.config.ConfigService; + import org.springframework.boot.actuate.health.AbstractHealthIndicator; import org.springframework.boot.actuate.health.Health; -import com.alibaba.nacos.api.config.ConfigService; - /** * @author xiaojing */ @@ -39,4 +39,5 @@ public class NacosConfigHealthIndicator extends AbstractHealthIndicator { String status = configService.getServerStatus(); builder.status(status); } + } diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/AbstractNacosDataParser.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/AbstractNacosDataParser.java index 42f49bbb0..5f83c0b2d 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/AbstractNacosDataParser.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/AbstractNacosDataParser.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -29,9 +29,11 @@ import com.alibaba.nacos.client.utils.StringUtils; public abstract class AbstractNacosDataParser { protected static final String DOT = "."; + protected static final String VALUE = "value"; private String extension; + private AbstractNacosDataParser nextParser; protected AbstractNacosDataParser(String extension) { @@ -41,7 +43,11 @@ public abstract class AbstractNacosDataParser { this.extension = extension.toLowerCase(); } - /** Verify file extensions */ + /** + * Verify dataId extensions. + * @param extension file extension. json or xml or yml or yaml or properties + * @return valid or not + */ public final boolean checkFileExtension(String extension) { if (this.isLegal(extension.toLowerCase())) { return true; @@ -53,7 +59,13 @@ public abstract class AbstractNacosDataParser { } - /** Parsing nacos configuration content */ + /** + * Parsing nacos configuration content. + * @param data config data from Nacos + * @param extension file extension. json or xml or yml or yaml or properties + * @return result of Properties + * @throws IOException thrown if there is a problem parsing config. + */ public final Properties parseNacosData(String data, String extension) throws IOException { if (extension == null || extension.length() < 1) { @@ -68,7 +80,12 @@ public abstract class AbstractNacosDataParser { return this.nextParser.parseNacosData(data, extension); } - /** Core logic for parsing */ + /** + * Core logic for parsing. + * @param data config from Nacos + * @return result of Properties + * @throws IOException thrown if there is a problem parsing config. + */ protected abstract Properties doParse(String data) throws IOException; protected AbstractNacosDataParser setNextParser(AbstractNacosDataParser nextParser) { @@ -76,7 +93,6 @@ public abstract class AbstractNacosDataParser { return this; } - /** add the next parser */ public AbstractNacosDataParser addNextParser(AbstractNacosDataParser nextParser) { if (this.nextParser == null) { this.nextParser = nextParser; @@ -93,7 +109,7 @@ public abstract class AbstractNacosDataParser { } /** - * Generate key-value pairs from the map + * Generate key-value pairs from the map. */ protected Properties generateProperties(Map map) { if (null == map || map.isEmpty()) { @@ -112,7 +128,7 @@ public abstract class AbstractNacosDataParser { } /** - * Reload the key ending in `value`,if you need + * Reload the key ending in `value` if need. */ protected Map reloadMap(Map map) { if (map == null || map.isEmpty()) { diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosDataJsonParser.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosDataJsonParser.java index 8e500e33f..891379924 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosDataJsonParser.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosDataJsonParser.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -30,6 +30,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; * @author zkz */ public class NacosDataJsonParser extends AbstractNacosDataParser { + protected NacosDataJsonParser() { super("json"); } @@ -44,7 +45,10 @@ public class NacosDataJsonParser extends AbstractNacosDataParser { } /** - * JSON to Map + * JSON to Map. + * @param json json data + * @return the map convert by json string + * @throws IOException thrown if there is a problem parsing config. */ public static Map parseJSON2Map(String json) throws IOException { Map map = new HashMap<>(32); diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosDataParserHandler.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosDataParserHandler.java index cc41bd363..5aabf8042 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosDataParserHandler.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosDataParserHandler.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,7 +22,7 @@ import java.util.Properties; /** * @author zkz */ -public class NacosDataParserHandler { +public final class NacosDataParserHandler { private AbstractNacosDataParser parser; @@ -30,7 +30,13 @@ public class NacosDataParserHandler { parser = this.createParser(); } - /** Parsing nacos configuration content */ + /** + * Parsing nacos configuration content. + * @param data config from Nacos + * @param extension file extension. json or xml or yml or yaml or properties + * @return result of properties + * @throws IOException thrown if there is a problem parsing config. + */ public Properties parseNacosData(String data, String extension) throws IOException { if (null == parser) { parser = this.createParser(); @@ -38,7 +44,11 @@ public class NacosDataParserHandler { return parser.parseNacosData(data, extension); } - /** check the validity of file extensions in dataid */ + /** + * check the validity of file extensions in dataid. + * @param dataIdAry array of dataId + * @return dataId handle success or not + */ public boolean checkDataId(String... dataIdAry) { StringBuilder stringBuilder = new StringBuilder(); for (String dataId : dataIdAry) { @@ -70,6 +80,9 @@ public class NacosDataParserHandler { } private static class ParserHandler { + private static final NacosDataParserHandler HANDLER = new NacosDataParserHandler(); + } + } diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosDataPropertiesParser.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosDataPropertiesParser.java index f0599bd20..a560648cf 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosDataPropertiesParser.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosDataPropertiesParser.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -35,4 +35,5 @@ public class NacosDataPropertiesParser extends AbstractNacosDataParser { properties.load(new StringReader(data)); return properties; } + } diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosDataXmlParser.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosDataXmlParser.java index e9431ba48..5e2987187 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosDataXmlParser.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosDataXmlParser.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,17 +25,16 @@ import java.util.Properties; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; +import com.alibaba.nacos.client.utils.StringUtils; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; -import com.alibaba.nacos.client.utils.StringUtils; - /** * With relatively few usage scenarios, only simple parsing is performed to reduce jar - * dependencies + * dependencies. * * @author zkz */ @@ -55,9 +54,7 @@ public class NacosDataXmlParser extends AbstractNacosDataParser { } private Map parseXml2Map(String xml) throws IOException { - xml = xml.replaceAll("\\r", "") - .replaceAll("\\n", "") - .replaceAll("\\t", ""); + xml = xml.replaceAll("\\r", "").replaceAll("\\n", "").replaceAll("\\t", ""); Map map = new HashMap<>(32); try { DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance() diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosDataYamlParser.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosDataYamlParser.java index 748980276..c96105f39 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosDataYamlParser.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosDataYamlParser.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -36,4 +36,5 @@ public class NacosDataYamlParser extends AbstractNacosDataParser { yamlFactory.setResources(new ByteArrayResource(data.getBytes())); return yamlFactory.getObject(); } + } diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/refresh/NacosContextRefresher.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/refresh/NacosContextRefresher.java index 7512b283e..d6a0458ad 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/refresh/NacosContextRefresher.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/refresh/NacosContextRefresher.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -26,8 +26,14 @@ import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; +import com.alibaba.cloud.nacos.NacosPropertySourceRepository; +import com.alibaba.cloud.nacos.client.NacosPropertySource; +import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.nacos.api.config.listener.Listener; +import com.alibaba.nacos.api.exception.NacosException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.cloud.endpoint.event.RefreshEvent; import org.springframework.context.ApplicationContext; @@ -35,12 +41,6 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationListener; import org.springframework.util.StringUtils; -import com.alibaba.cloud.nacos.NacosPropertySourceRepository; -import com.alibaba.cloud.nacos.client.NacosPropertySource; -import com.alibaba.nacos.api.config.ConfigService; -import com.alibaba.nacos.api.config.listener.Listener; -import com.alibaba.nacos.api.exception.NacosException; - /** * On application start up, NacosContextRefresher add nacos listeners to all application * level dataIds, when there is a change in the data, listeners will refresh @@ -150,4 +150,5 @@ public class NacosContextRefresher public static void refreshCountIncrement() { REFRESH_COUNT.incrementAndGet(); } + } diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/refresh/NacosRefreshHistory.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/refresh/NacosRefreshHistory.java index 0778fb344..1297061c9 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/refresh/NacosRefreshHistory.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/refresh/NacosRefreshHistory.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -44,6 +44,7 @@ public class NacosRefreshHistory { public LinkedList getRecords() { return records; } + } class Record { @@ -54,7 +55,7 @@ class Record { private final String md5; - public Record(String timestamp, String dataId, String md5) { + Record(String timestamp, String dataId, String md5) { this.timestamp = timestamp; this.dataId = dataId; this.md5 = md5; @@ -71,4 +72,5 @@ class Record { public String getMd5() { return md5; } + } diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/refresh/NacosRefreshProperties.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/refresh/NacosRefreshProperties.java index 6d07e7946..9874eebd7 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/refresh/NacosRefreshProperties.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/refresh/NacosRefreshProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -35,4 +35,5 @@ public class NacosRefreshProperties { public void setEnabled(boolean enabled) { this.enabled = enabled; } + } diff --git a/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigPropertiesServerAddressBothLevelTests.java b/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigPropertiesServerAddressBothLevelTests.java index 15e573512..d0e134892 100644 --- a/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigPropertiesServerAddressBothLevelTests.java +++ b/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigPropertiesServerAddressBothLevelTests.java @@ -1,10 +1,25 @@ -package com.alibaba.cloud.nacos; +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ -import static org.junit.Assert.assertEquals; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; +package com.alibaba.cloud.nacos; +import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -12,15 +27,18 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; /** * @author lyuzb */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = NacosConfigPropertiesServerAddressBothLevelTests.TestConfig.class, properties = { - "spring.cloud.nacos.config.server-addr=321,321,321,321:8848", - "spring.cloud.nacos.server-addr=123.123.123.123:8848" }, webEnvironment = RANDOM_PORT) +@SpringBootTest( + classes = NacosConfigPropertiesServerAddressBothLevelTests.TestConfig.class, + properties = { "spring.cloud.nacos.config.server-addr=321,321,321,321:8848", + "spring.cloud.nacos.server-addr=123.123.123.123:8848" }, + webEnvironment = RANDOM_PORT) public class NacosConfigPropertiesServerAddressBothLevelTests { @Autowired @@ -28,8 +46,7 @@ public class NacosConfigPropertiesServerAddressBothLevelTests { @Test public void testGetServerAddr() { - assertEquals("NacosConfigProperties server address was wrong", - "321,321,321,321:8848", properties.getServerAddr()); + assertThat(properties.getServerAddr()).isEqualTo("321,321,321,321:8848"); } @Configuration @@ -37,5 +54,7 @@ public class NacosConfigPropertiesServerAddressBothLevelTests { @ImportAutoConfiguration({ NacosConfigEndpointAutoConfiguration.class, NacosConfigAutoConfiguration.class, NacosConfigBootstrapConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigPropertiesServerAddressTopLevelTests.java b/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigPropertiesServerAddressTopLevelTests.java index 62ce114c2..c080fe6bd 100644 --- a/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigPropertiesServerAddressTopLevelTests.java +++ b/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigPropertiesServerAddressTopLevelTests.java @@ -1,10 +1,25 @@ -package com.alibaba.cloud.nacos; +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ -import static org.junit.Assert.assertEquals; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; +package com.alibaba.cloud.nacos; +import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -12,14 +27,17 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; /** * @author lyuzb */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = NacosConfigPropertiesServerAddressTopLevelTests.TestConfig.class, properties = { - "spring.cloud.nacos.server-addr=123.123.123.123:8848" }, webEnvironment = RANDOM_PORT) +@SpringBootTest( + classes = NacosConfigPropertiesServerAddressTopLevelTests.TestConfig.class, + properties = { "spring.cloud.nacos.server-addr=123.123.123.123:8848" }, + webEnvironment = RANDOM_PORT) public class NacosConfigPropertiesServerAddressTopLevelTests { @Autowired @@ -27,8 +45,7 @@ public class NacosConfigPropertiesServerAddressTopLevelTests { @Test public void testGetServerAddr() { - assertEquals("NacosConfigProperties server address was wrong", - "123.123.123.123:8848", properties.getServerAddr()); + assertThat(properties.getServerAddr()).isEqualTo("123.123.123.123:8848"); } @Configuration @@ -36,5 +53,7 @@ public class NacosConfigPropertiesServerAddressTopLevelTests { @ImportAutoConfiguration({ NacosConfigEndpointAutoConfiguration.class, NacosConfigAutoConfiguration.class, NacosConfigBootstrapConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigurationExtConfigTests.java b/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigurationExtConfigTests.java index 467603210..73f8b80f4 100644 --- a/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigurationExtConfigTests.java +++ b/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigurationExtConfigTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,12 @@ package com.alibaba.cloud.nacos; -import static org.junit.Assert.assertNotNull; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; - import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; -import org.junit.Assert; +import com.alibaba.cloud.nacos.client.NacosPropertySourceLocator; +import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration; +import com.alibaba.nacos.client.config.NacosConfigService; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; @@ -31,6 +30,7 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -39,9 +39,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.cloud.nacos.client.NacosPropertySourceLocator; -import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration; -import com.alibaba.nacos.client.config.NacosConfigService; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; /** * @author xiaojing @@ -51,18 +50,20 @@ import com.alibaba.nacos.client.config.NacosConfigService; @PowerMockIgnore("javax.management.*") @PowerMockRunnerDelegate(SpringRunner.class) @PrepareForTest({ NacosConfigService.class }) -@SpringBootTest(classes = NacosConfigurationExtConfigTests.TestConfig.class, properties = { - "spring.application.name=myTestService1", "spring.profiles.active=dev,test", - "spring.cloud.nacos.config.server-addr=127.0.0.1:8848", - "spring.cloud.nacos.config.encode=utf-8", - "spring.cloud.nacos.config.timeout=1000", - "spring.cloud.nacos.config.file-extension=properties", - "spring.cloud.nacos.config.ext-config[0].data-id=ext-config-common01.properties", - "spring.cloud.nacos.config.ext-config[1].data-id=ext-config-common02.properties", - "spring.cloud.nacos.config.ext-config[1].group=GLOBAL_GROUP", - "spring.cloud.nacos.config.shared-dataids=common1.properties,common2.properties", - "spring.cloud.nacos.config.accessKey=test-accessKey", - "spring.cloud.nacos.config.secretKey=test-secretKey" }, webEnvironment = NONE) +@SpringBootTest(classes = NacosConfigurationExtConfigTests.TestConfig.class, + properties = { "spring.application.name=myTestService1", + "spring.profiles.active=dev,test", + "spring.cloud.nacos.config.server-addr=127.0.0.1:8848", + "spring.cloud.nacos.config.encode=utf-8", + "spring.cloud.nacos.config.timeout=1000", + "spring.cloud.nacos.config.file-extension=properties", + "spring.cloud.nacos.config.ext-config[0].data-id=ext-config-common01.properties", + "spring.cloud.nacos.config.ext-config[1].data-id=ext-config-common02.properties", + "spring.cloud.nacos.config.ext-config[1].group=GLOBAL_GROUP", + "spring.cloud.nacos.config.shared-dataids=common1.properties,common2.properties", + "spring.cloud.nacos.config.accessKey=test-accessKey", + "spring.cloud.nacos.config.secretKey=test-secretKey" }, + webEnvironment = NONE) public class NacosConfigurationExtConfigTests { static { @@ -130,14 +131,13 @@ public class NacosConfigurationExtConfigTests { @Test public void contextLoads() throws Exception { - assertNotNull("NacosPropertySourceLocator was not created", locator); - assertNotNull("NacosConfigProperties was not created", properties); - - Assert.assertEquals(environment.getProperty("test-ext-config1"), "config1"); - Assert.assertEquals(environment.getProperty("test-ext-config2"), "config2"); - Assert.assertEquals(environment.getProperty("test-common1"), "common1"); - Assert.assertEquals(environment.getProperty("test-common2"), "common2"); + assertThat(locator).isNotNull(); + assertThat(properties).isNotNull(); + assertThat("config1").isEqualTo(environment.getProperty("test-ext-config1")); + assertThat("config2").isEqualTo(environment.getProperty("test-ext-config2")); + assertThat("common1").isEqualTo(environment.getProperty("test-common1")); + assertThat("common2").isEqualTo(environment.getProperty("test-common2")); } @Configuration @@ -145,5 +145,7 @@ public class NacosConfigurationExtConfigTests { @ImportAutoConfiguration({ NacosConfigEndpointAutoConfiguration.class, NacosConfigAutoConfiguration.class, NacosConfigBootstrapConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigurationNoSuffixTest.java b/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigurationNoSuffixTest.java index 5edb7a9dd..a5c992ef2 100644 --- a/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigurationNoSuffixTest.java +++ b/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigurationNoSuffixTest.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,15 +16,15 @@ package com.alibaba.cloud.nacos; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; - import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.util.Map; +import com.alibaba.cloud.nacos.client.NacosPropertySourceLocator; +import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpoint; +import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration; +import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory; +import com.alibaba.nacos.client.config.NacosConfigService; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; @@ -33,21 +33,17 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.EnvironmentAware; import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.Environment; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.cloud.nacos.client.NacosPropertySourceLocator; -import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpoint; -import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration; -import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory; -import com.alibaba.nacos.client.config.NacosConfigService; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; /** * @author zkz @@ -163,14 +159,15 @@ public class NacosConfigurationNoSuffixTest { @Autowired private NacosRefreshHistory refreshHistory; + @Autowired private Environment environment; @Test public void contextLoads() throws Exception { - assertNotNull("NacosPropertySourceLocator was not created", locator); - assertNotNull("NacosConfigProperties was not created", properties); + assertThat(locator).isNotNull(); + assertThat(properties).isNotNull(); checkoutNacosConfigServerAddr(); checkoutNacosConfigNamespace(); @@ -189,77 +186,61 @@ public class NacosConfigurationNoSuffixTest { } private void checkEnvironmentProperties() { - assertNull( - "The configuration of `spring.cloud.nacos.config.name` must be used first", - environment.getProperty("test-no-suffix")); - assertEquals( - "Priority of configuration is wrong , should be in this order : `profile->hasSuffix->noSuffix`", - "assign-dev-value-no-suffix-333", - environment.getProperty("test-no-suffix-assign")); - + assertThat(environment.getProperty("test-no-suffix")).isNull(); + assertThat(environment.getProperty("test-no-suffix-assign")) + .isEqualTo("assign-dev-value-no-suffix-333"); } private void checkoutNacosConfigServerAddr() { - assertEquals("NacosConfigProperties server address is wrong", "127.0.0.1:8848", - properties.getServerAddr()); + assertThat(properties.getServerAddr()).isEqualTo("127.0.0.1:8848"); } private void checkoutNacosConfigNamespace() { - assertEquals("NacosConfigProperties namespace is wrong", "test-namespace", - properties.getNamespace()); + assertThat(properties.getNamespace()).isEqualTo("test-namespace"); } private void checkoutNacosConfigClusterName() { - assertEquals("NacosConfigProperties' cluster is wrong", "test-cluster", - properties.getClusterName()); + assertThat(properties.getClusterName()).isEqualTo("test-cluster"); } private void checkoutNacosConfigAccessKey() { - assertEquals("NacosConfigProperties' is access key is wrong", "test-accessKey", - properties.getAccessKey()); + assertThat(properties.getAccessKey()).isEqualTo("test-accessKey"); } private void checkoutNacosConfigSecrectKey() { - assertEquals("NacosConfigProperties' is secret key is wrong", "test-secretKey", - properties.getSecretKey()); + assertThat(properties.getSecretKey()).isEqualTo("test-secretKey"); } private void checkoutNacosConfigContextPath() { - assertEquals("NacosConfigProperties' context path is wrong", "test-contextpath", - properties.getContextPath()); + assertThat(properties.getContextPath()).isEqualTo("test-contextpath"); } private void checkoutNacosConfigName() { - assertEquals("NacosConfigProperties' name is wrong", "test-no-suffix-name", - properties.getName()); + assertThat(properties.getName()).isEqualTo("test-no-suffix-name"); } private void checkoutNacosConfigGroup() { - assertEquals("NacosConfigProperties' group is wrong", "test-group", - properties.getGroup()); + assertThat(properties.getGroup()).isEqualTo("test-group"); } private void checkoutNacosConfigFileExtension() { - assertEquals("NacosConfigProperties' file extension is wrong", "properties", - properties.getFileExtension()); + assertThat(properties.getFileExtension()).isEqualTo("properties"); } private void checkoutNacosConfigTimeout() { - assertEquals("NacosConfigProperties' timeout is wrong", 1000, - properties.getTimeout()); + assertThat(properties.getTimeout()).isEqualTo(1000); } private void checkoutNacosConfigEncode() { - assertEquals("NacosConfigProperties' encode is wrong", "utf-8", - properties.getEncode()); + assertThat(properties.getEncode()).isEqualTo("utf-8"); } private void checkoutEndpoint() throws Exception { NacosConfigEndpoint nacosConfigEndpoint = new NacosConfigEndpoint(properties, refreshHistory); Map map = nacosConfigEndpoint.invoke(); - assertEquals(map.get("NacosConfigProperties"), properties); - assertEquals(map.get("RefreshHistory"), refreshHistory.getRecords()); + assertThat(properties).isEqualTo(map.get("NacosConfigProperties")); + assertThat(refreshHistory.getRecords()).isEqualTo(map.get("RefreshHistory")); } @Configuration @@ -267,5 +248,7 @@ public class NacosConfigurationNoSuffixTest { @ImportAutoConfiguration({ NacosConfigEndpointAutoConfiguration.class, NacosConfigAutoConfiguration.class, NacosConfigBootstrapConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigurationTests.java b/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigurationTests.java index 1f80136c1..102e31858 100644 --- a/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigurationTests.java +++ b/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigurationTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,15 +16,15 @@ package com.alibaba.cloud.nacos; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; - import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.util.Map; -import org.junit.Assert; +import com.alibaba.cloud.nacos.client.NacosPropertySourceLocator; +import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpoint; +import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration; +import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory; +import com.alibaba.nacos.client.config.NacosConfigService; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; @@ -33,6 +33,7 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -41,16 +42,12 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.cloud.nacos.client.NacosPropertySourceLocator; -import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpoint; -import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration; -import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory; -import com.alibaba.nacos.client.config.NacosConfigService; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; /** * @author xiaojing */ - @RunWith(PowerMockRunner.class) @PowerMockIgnore("javax.management.*") @PowerMockRunnerDelegate(SpringRunner.class) @@ -140,8 +137,8 @@ public class NacosConfigurationTests { @Test public void contextLoads() throws Exception { - assertNotNull("NacosPropertySourceLocator was not created", locator); - assertNotNull("NacosConfigProperties was not created", properties); + assertThat(locator).isNotNull(); + assertThat(properties).isNotNull(); checkoutNacosConfigServerAddr(); checkoutNacosConfigNamespace(); @@ -161,72 +158,60 @@ public class NacosConfigurationTests { } private void checkoutNacosConfigServerAddr() { - assertEquals("NacosConfigProperties server address is wrong", "127.0.0.1:8848", - properties.getServerAddr()); + assertThat(properties.getServerAddr()).isEqualTo("127.0.0.1:8848"); } private void checkoutNacosConfigNamespace() { - assertEquals("NacosConfigProperties namespace is wrong", "test-namespace", - properties.getNamespace()); + assertThat(properties.getNamespace()).isEqualTo("test-namespace"); } private void checkoutNacosConfigClusterName() { - assertEquals("NacosConfigProperties' cluster is wrong", "test-cluster", - properties.getClusterName()); + assertThat(properties.getClusterName()).isEqualTo("test-cluster"); } private void checkoutNacosConfigAccessKey() { - assertEquals("NacosConfigProperties' is access key is wrong", "test-accessKey", - properties.getAccessKey()); + assertThat(properties.getAccessKey()).isEqualTo("test-accessKey"); } private void checkoutNacosConfigSecrectKey() { - assertEquals("NacosConfigProperties' is secret key is wrong", "test-secretKey", - properties.getSecretKey()); + assertThat(properties.getSecretKey()).isEqualTo("test-secretKey"); } private void checkoutNacosConfigContextPath() { - assertEquals("NacosConfigProperties' context path is wrong", "test-contextpath", - properties.getContextPath()); + assertThat(properties.getContextPath()).isEqualTo("test-contextpath"); } private void checkoutNacosConfigName() { - assertEquals("NacosConfigProperties' name is wrong", "test-name", - properties.getName()); + assertThat(properties.getName()).isEqualTo("test-name"); } private void checkoutNacosConfigGroup() { - assertEquals("NacosConfigProperties' group is wrong", "test-group", - properties.getGroup()); + assertThat(properties.getGroup()).isEqualTo("test-group"); } private void checkoutNacosConfigFileExtension() { - assertEquals("NacosConfigProperties' file extension is wrong", "properties", - properties.getFileExtension()); + assertThat(properties.getFileExtension()).isEqualTo("properties"); } private void checkoutNacosConfigTimeout() { - assertEquals("NacosConfigProperties' timeout is wrong", 1000, - properties.getTimeout()); + assertThat(properties.getTimeout()).isEqualTo(1000); } private void checkoutNacosConfigEncode() { - assertEquals("NacosConfigProperties' encode is wrong", "utf-8", - properties.getEncode()); + assertThat(properties.getEncode()).isEqualTo("utf-8"); } private void checkoutDataLoad() { - - Assert.assertEquals("dev", environment.getProperty("user.name")); - Assert.assertEquals("12", environment.getProperty("user.age")); + assertThat(environment.getProperty("user.name")).isEqualTo("dev"); + assertThat(environment.getProperty("user.age")).isEqualTo("12"); } private void checkoutEndpoint() throws Exception { NacosConfigEndpoint nacosConfigEndpoint = new NacosConfigEndpoint(properties, refreshHistory); Map map = nacosConfigEndpoint.invoke(); - assertEquals(map.get("NacosConfigProperties"), properties); - assertEquals(map.get("RefreshHistory"), refreshHistory.getRecords()); + assertThat(map.get("NacosConfigProperties")).isEqualTo(properties); + assertThat(map.get("RefreshHistory")).isEqualTo(refreshHistory.getRecords()); } @Configuration @@ -234,5 +219,7 @@ public class NacosConfigurationTests { @ImportAutoConfiguration({ NacosConfigEndpointAutoConfiguration.class, NacosConfigAutoConfiguration.class, NacosConfigBootstrapConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigurationXmlJsonTest.java b/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigurationXmlJsonTest.java index 019ebd7e1..da1380c2f 100644 --- a/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigurationXmlJsonTest.java +++ b/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosConfigurationXmlJsonTest.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,12 +16,15 @@ package com.alibaba.cloud.nacos; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.util.Map; + import com.alibaba.cloud.nacos.client.NacosPropertySourceLocator; import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpoint; import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration; import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory; import com.alibaba.nacos.client.config.NacosConfigService; -import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; @@ -30,48 +33,42 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.Environment; import org.springframework.test.context.junit4.SpringRunner; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; /** * @author zkz */ - @RunWith(PowerMockRunner.class) @PowerMockIgnore("javax.management.*") @PowerMockRunnerDelegate(SpringRunner.class) @PrepareForTest({ NacosConfigService.class }) -@SpringBootTest(classes = NacosConfigurationXmlJsonTest.TestConfig.class, properties = { - "spring.application.name=xmlApp", "spring.profiles.active=dev" - ,"spring.cloud.nacos.config.server-addr=127.0.0.1:8848" - ,"spring.cloud.nacos.config.namespace=test-namespace" - ,"spring.cloud.nacos.config.encode=utf-8" - ,"spring.cloud.nacos.config.timeout=1000" - ,"spring.cloud.nacos.config.group=test-group" - ,"spring.cloud.nacos.config.name=test-name" - ,"spring.cloud.nacos.config.cluster-name=test-cluster" - ,"spring.cloud.nacos.config.file-extension=xml" - ,"spring.cloud.nacos.config.contextPath=test-contextpath" - ,"spring.cloud.nacos.config.ext-config[0].data-id=ext-json-test.json" - ,"spring.cloud.nacos.config.ext-config[1].data-id=ext-common02.properties" - ,"spring.cloud.nacos.config.ext-config[1].group=GLOBAL_GROUP" - ,"spring.cloud.nacos.config.shared-dataids=shared-data1.properties" - ,"spring.cloud.nacos.config.accessKey=test-accessKey" - ,"spring.cloud.nacos.config.secretKey=test-secretKey" -}, webEnvironment = NONE) +@SpringBootTest(classes = NacosConfigurationXmlJsonTest.TestConfig.class, + properties = { "spring.application.name=xmlApp", "spring.profiles.active=dev", + "spring.cloud.nacos.config.server-addr=127.0.0.1:8848", + "spring.cloud.nacos.config.namespace=test-namespace", + "spring.cloud.nacos.config.encode=utf-8", + "spring.cloud.nacos.config.timeout=1000", + "spring.cloud.nacos.config.group=test-group", + "spring.cloud.nacos.config.name=test-name", + "spring.cloud.nacos.config.cluster-name=test-cluster", + "spring.cloud.nacos.config.file-extension=xml", + "spring.cloud.nacos.config.contextPath=test-contextpath", + "spring.cloud.nacos.config.ext-config[0].data-id=ext-json-test.json", + "spring.cloud.nacos.config.ext-config[1].data-id=ext-common02.properties", + "spring.cloud.nacos.config.ext-config[1].group=GLOBAL_GROUP", + "spring.cloud.nacos.config.shared-dataids=shared-data1.properties", + "spring.cloud.nacos.config.accessKey=test-accessKey", + "spring.cloud.nacos.config.secretKey=test-secretKey" }, + webEnvironment = NONE) public class NacosConfigurationXmlJsonTest { static { @@ -82,64 +79,60 @@ public class NacosConfigurationXmlJsonTest { String.class, String.class, long.class); MethodProxy.proxy(method, new InvocationHandler() { @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public Object invoke(Object proxy, Method method, Object[] args) + throws Throwable { if ("xmlApp.xml".equals(args[0]) && "test-group".equals(args[1])) { - return "\n" + - " one\n" + - " \n" + - " three\n" + - " \n" + - ""; + return "\n" + " one\n" + + " \n" + + " three\n" + " \n" + + ""; } if ("test-name.xml".equals(args[0]) && "test-group".equals(args[1])) { - return " \n" + - " \n" + - " \n" + - " 开启服务 \n" + - " 初始化一下 \n" + - " \n" + - " \n" + - " one\n" + - " \n" + - " three\n" + - " \n" + - " \n" + - " \n" + - " 销毁一下 \n" + - " 关闭服务 \n" + - " \n" + - " \n" + - " "; + return " \n" + + " \n" + + " \n" + + " 开启服务 \n" + + " 初始化一下 \n" + + " \n" + " \n" + + " one\n" + + " \n" + + " three\n" + + " \n" + + " \n" + " \n" + + " 销毁一下 \n" + + " 关闭服务 \n" + + " \n" + " \n" + + " "; } - if ("test-name-dev.xml".equals(args[0]) && "test-group".equals(args[1])) { - return "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - ""; + if ("test-name-dev.xml".equals(args[0]) + && "test-group".equals(args[1])) { + return "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + " \n" + + ""; } - if ("ext-json-test.json".equals(args[0]) && "DEFAULT_GROUP".equals(args[1])) { - return "{\n" + - " \"people\":{\n" + - " \"firstName\":\"Brett\",\n" + - " \"lastName\":\"McLaughlin\"\n" + - " }\n" + - "}"; + if ("ext-json-test.json".equals(args[0]) + && "DEFAULT_GROUP".equals(args[1])) { + return "{\n" + " \"people\":{\n" + + " \"firstName\":\"Brett\",\n" + + " \"lastName\":\"McLaughlin\"\n" + " }\n" + + "}"; } - if ("ext-config-common02.properties".equals(args[0]) && "GLOBAL_GROUP".equals(args[1])) { + if ("ext-config-common02.properties".equals(args[0]) + && "GLOBAL_GROUP".equals(args[1])) { return "global-ext-config=global-config-value-2"; } - - if ("shared-data1.properties".equals(args[0]) && "DEFAULT_GROUP".equals(args[1])) { + if ("shared-data1.properties".equals(args[0]) + && "DEFAULT_GROUP".equals(args[1])) { return "shared-name=shared-value-1"; } @@ -166,8 +159,8 @@ public class NacosConfigurationXmlJsonTest { @Test public void contextLoads() throws Exception { - assertNotNull("NacosPropertySourceLocator was not created", locator); - assertNotNull("NacosConfigProperties was not created", properties); + assertThat(locator).isNotNull(); + assertThat(properties).isNotNull(); checkoutNacosConfigServerAddr(); checkoutNacosConfigNamespace(); @@ -186,67 +179,55 @@ public class NacosConfigurationXmlJsonTest { } private void checkoutNacosConfigServerAddr() { - assertEquals("NacosConfigProperties server address is wrong", "127.0.0.1:8848", - properties.getServerAddr()); + assertThat(properties.getServerAddr()).isEqualTo("127.0.0.1:8848"); } private void checkoutNacosConfigNamespace() { - assertEquals("NacosConfigProperties namespace is wrong", "test-namespace", - properties.getNamespace()); + assertThat(properties.getNamespace()).isEqualTo("test-namespace"); } private void checkoutNacosConfigClusterName() { - assertEquals("NacosConfigProperties' cluster is wrong", "test-cluster", - properties.getClusterName()); + assertThat(properties.getClusterName()).isEqualTo("test-cluster"); } private void checkoutNacosConfigAccessKey() { - assertEquals("NacosConfigProperties' is access key is wrong", "test-accessKey", - properties.getAccessKey()); + assertThat(properties.getAccessKey()).isEqualTo("test-accessKey"); } private void checkoutNacosConfigSecrectKey() { - assertEquals("NacosConfigProperties' is secret key is wrong", "test-secretKey", - properties.getSecretKey()); + assertThat(properties.getSecretKey()).isEqualTo("test-secretKey"); } private void checkoutNacosConfigContextPath() { - assertEquals("NacosConfigProperties' context path is wrong", "test-contextpath", - properties.getContextPath()); + assertThat(properties.getContextPath()).isEqualTo("test-contextpath"); } private void checkoutNacosConfigName() { - assertEquals("NacosConfigProperties' name is wrong", "test-name", - properties.getName()); + assertThat(properties.getName()).isEqualTo("test-name"); } private void checkoutNacosConfigGroup() { - assertEquals("NacosConfigProperties' group is wrong", "test-group", - properties.getGroup()); + assertThat(properties.getGroup()).isEqualTo("test-group"); } private void checkoutNacosConfigFileExtension() { - assertEquals("NacosConfigProperties' file extension is wrong", "xml", - properties.getFileExtension()); + assertThat(properties.getFileExtension()).isEqualTo("xml"); } private void checkoutNacosConfigTimeout() { - assertEquals("NacosConfigProperties' timeout is wrong", 1000, - properties.getTimeout()); + assertThat(properties.getTimeout()).isEqualTo(1000); } private void checkoutNacosConfigEncode() { - assertEquals("NacosConfigProperties' encode is wrong", "utf-8", - properties.getEncode()); + assertThat(properties.getEncode()).isEqualTo("utf-8"); } - private void checkoutEndpoint() throws Exception { NacosConfigEndpoint nacosConfigEndpoint = new NacosConfigEndpoint(properties, refreshHistory); Map map = nacosConfigEndpoint.invoke(); - assertEquals(map.get("NacosConfigProperties"), properties); - assertEquals(map.get("RefreshHistory"), refreshHistory.getRecords()); + assertThat(properties).isEqualTo(map.get("NacosConfigProperties")); + assertThat(refreshHistory.getRecords()).isEqualTo(map.get("RefreshHistory")); } @Configuration @@ -254,5 +235,7 @@ public class NacosConfigurationXmlJsonTest { @ImportAutoConfiguration({ NacosConfigEndpointAutoConfiguration.class, NacosConfigAutoConfiguration.class, NacosConfigBootstrapConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosFileExtensionTest.java b/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosFileExtensionTest.java index e4806e665..229610514 100644 --- a/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosFileExtensionTest.java +++ b/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/NacosFileExtensionTest.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,11 +16,11 @@ package com.alibaba.cloud.nacos; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; - import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; +import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration; +import com.alibaba.nacos.client.config.NacosConfigService; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -30,6 +30,7 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -38,8 +39,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration; -import com.alibaba.nacos.client.config.NacosConfigService; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; /** * @author xiaojing @@ -49,10 +49,11 @@ import com.alibaba.nacos.client.config.NacosConfigService; @PowerMockIgnore("javax.management.*") @PowerMockRunnerDelegate(SpringRunner.class) @PrepareForTest({ NacosConfigService.class }) -@SpringBootTest(classes = NacosFileExtensionTest.TestConfig.class, properties = { - "spring.application.name=test-name", - "spring.cloud.nacos.config.server-addr=127.0.0.1:8848", - "spring.cloud.nacos.config.file-extension=yaml" }, webEnvironment = NONE) +@SpringBootTest(classes = NacosFileExtensionTest.TestConfig.class, + properties = { "spring.application.name=test-name", + "spring.cloud.nacos.config.server-addr=127.0.0.1:8848", + "spring.cloud.nacos.config.file-extension=yaml" }, + webEnvironment = NONE) public class NacosFileExtensionTest { static { @@ -94,5 +95,7 @@ public class NacosFileExtensionTest { @ImportAutoConfiguration({ NacosConfigEndpointAutoConfiguration.class, NacosConfigAutoConfiguration.class, NacosConfigBootstrapConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/endpoint/NacosConfigEndpointTests.java b/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/endpoint/NacosConfigEndpointTests.java index 86f2468a0..175345acc 100644 --- a/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/endpoint/NacosConfigEndpointTests.java +++ b/spring-cloud-alibaba-nacos-config/src/test/java/com/alibaba/cloud/nacos/endpoint/NacosConfigEndpointTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,15 @@ package com.alibaba.cloud.nacos.endpoint; -import static org.junit.Assert.assertEquals; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; - import java.lang.reflect.Method; import java.util.Map; +import com.alibaba.cloud.nacos.NacosConfigAutoConfiguration; +import com.alibaba.cloud.nacos.NacosConfigBootstrapConfiguration; import com.alibaba.cloud.nacos.NacosConfigManager; +import com.alibaba.cloud.nacos.NacosConfigProperties; +import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory; +import com.alibaba.nacos.client.config.NacosConfigService; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; @@ -31,6 +33,7 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.health.Health.Builder; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -39,31 +42,29 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.cloud.nacos.NacosConfigAutoConfiguration; -import com.alibaba.cloud.nacos.NacosConfigBootstrapConfiguration; -import com.alibaba.cloud.nacos.NacosConfigProperties; -import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory; -import com.alibaba.nacos.client.config.NacosConfigService; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; /** * @author xiaojing */ - @RunWith(PowerMockRunner.class) @PowerMockIgnore("javax.management.*") @PowerMockRunnerDelegate(SpringRunner.class) @PrepareForTest({ NacosConfigService.class }) -@SpringBootTest(classes = NacosConfigEndpointTests.TestConfig.class, properties = { - "spring.application.name=test-name", - "spring.cloud.nacos.config.server-addr=127.0.0.1:8848", - "spring.cloud.nacos.config.file-extension=properties" }, webEnvironment = NONE) +@SpringBootTest(classes = NacosConfigEndpointTests.TestConfig.class, + properties = { "spring.application.name=test-name", + "spring.cloud.nacos.config.server-addr=127.0.0.1:8848", + "spring.cloud.nacos.config.file-extension=properties" }, + webEnvironment = NONE) public class NacosConfigEndpointTests { static { try { - Method method = PowerMockito.method(NacosConfigService.class, "getServerStatus"); + Method method = PowerMockito.method(NacosConfigService.class, + "getServerStatus"); MethodProxy.proxy(method, (proxy, method1, args) -> "UP"); } @@ -101,8 +102,7 @@ public class NacosConfigEndpointTests { Builder builder1 = new Builder(); builder1.up(); - assertEquals(builder1.build(), builder.build()); - + assertThat(builder.build()).isEqualTo(builder1.build()); } catch (Exception ignore) { @@ -114,8 +114,9 @@ public class NacosConfigEndpointTests { NacosConfigEndpoint endpoint = new NacosConfigEndpoint(properties, refreshHistory); Map map = endpoint.invoke(); - assertEquals(map.get("NacosConfigProperties"), properties); - assertEquals(map.get("RefreshHistory"), refreshHistory.getRecords()); + + assertThat(properties).isEqualTo(map.get("NacosConfigProperties")); + assertThat(refreshHistory.getRecords()).isEqualTo(map.get("RefreshHistory")); } @Configuration @@ -123,5 +124,7 @@ public class NacosConfigEndpointTests { @ImportAutoConfiguration({ NacosConfigEndpointAutoConfiguration.class, NacosConfigAutoConfiguration.class, NacosConfigBootstrapConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ConditionalOnNacosDiscoveryEnabled.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ConditionalOnNacosDiscoveryEnabled.java index d576b8791..18c4db132 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ConditionalOnNacosDiscoveryEnabled.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ConditionalOnNacosDiscoveryEnabled.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,7 +25,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.TYPE, ElementType.METHOD }) -@ConditionalOnProperty(value = "spring.cloud.nacos.discovery.enabled", matchIfMissing = true) +@ConditionalOnProperty(value = "spring.cloud.nacos.discovery.enabled", + matchIfMissing = true) public @interface ConditionalOnNacosDiscoveryEnabled { } diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryAutoConfiguration.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryAutoConfiguration.java index 455853c7b..2e6c08589 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryAutoConfiguration.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,10 @@ package com.alibaba.cloud.nacos; +import com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration; +import com.alibaba.cloud.nacos.registry.NacosRegistration; +import com.alibaba.cloud.nacos.registry.NacosServiceRegistry; + import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -27,10 +31,6 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration; -import com.alibaba.cloud.nacos.registry.NacosRegistration; -import com.alibaba.cloud.nacos.registry.NacosServiceRegistry; - /** * @author xiaojing * @author Mercy @@ -38,7 +38,8 @@ import com.alibaba.cloud.nacos.registry.NacosServiceRegistry; @Configuration @EnableConfigurationProperties @ConditionalOnNacosDiscoveryEnabled -@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true) +@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", + matchIfMissing = true) @AutoConfigureAfter({ AutoServiceRegistrationConfiguration.class, AutoServiceRegistrationAutoConfiguration.class }) public class NacosDiscoveryAutoConfiguration { @@ -73,4 +74,5 @@ public class NacosDiscoveryAutoConfiguration { return new NacosAutoServiceRegistration(registry, autoServiceRegistrationProperties, registration); } -} \ No newline at end of file + +} diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java index 85e633044..632ee7e9c 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,15 +16,6 @@ package com.alibaba.cloud.nacos; -import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY; -import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME; -import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT; -import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT_PORT; -import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE; -import static com.alibaba.nacos.api.PropertyKeyConst.NAMING_LOAD_CACHE_AT_START; -import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY; -import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR; - import java.net.Inet4Address; import java.net.InetAddress; import java.net.NetworkInterface; @@ -37,8 +28,15 @@ import java.util.Properties; import javax.annotation.PostConstruct; +import com.alibaba.nacos.api.NacosFactory; +import com.alibaba.nacos.api.naming.NamingMaintainFactory; +import com.alibaba.nacos.api.naming.NamingMaintainService; +import com.alibaba.nacos.api.naming.NamingService; +import com.alibaba.nacos.api.naming.PreservedMetadataKeys; +import com.alibaba.nacos.client.naming.utils.UtilAndComs; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -46,12 +44,14 @@ import org.springframework.cloud.commons.util.InetUtils; import org.springframework.core.env.Environment; import org.springframework.util.StringUtils; -import com.alibaba.nacos.api.NacosFactory; -import com.alibaba.nacos.api.naming.NamingMaintainFactory; -import com.alibaba.nacos.api.naming.NamingMaintainService; -import com.alibaba.nacos.api.naming.NamingService; -import com.alibaba.nacos.api.naming.PreservedMetadataKeys; -import com.alibaba.nacos.client.naming.utils.UtilAndComs; +import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY; +import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME; +import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT; +import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT_PORT; +import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE; +import static com.alibaba.nacos.api.PropertyKeyConst.NAMING_LOAD_CACHE_AT_START; +import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY; +import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR; /** * @author dungu.zpf @@ -109,7 +109,7 @@ public class NacosDiscoveryProperties { private String clusterName = "DEFAULT"; /** - * group name for nacos + * group name for nacos. */ private String group = "DEFAULT_GROUP"; diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosNamingManager.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosNamingManager.java index 46968b52f..aec598866 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosNamingManager.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosNamingManager.java @@ -1,12 +1,11 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Copyright 2013-2018 the original author or authors. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -14,24 +13,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.nacos; +import java.util.Objects; + import com.alibaba.nacos.api.naming.NamingMaintainService; import com.alibaba.nacos.api.naming.NamingService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import java.util.Objects; +import org.springframework.beans.factory.annotation.Autowired; /** * @author liaochuntao */ public class NacosNamingManager { - private static final Logger log = LoggerFactory.getLogger(NacosNamingManager.class); + private static final Logger log = LoggerFactory.getLogger(NacosNamingManager.class); private static NamingService namingService = null; + private static NamingMaintainService namingMaintainService = null; @Autowired diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosServiceInstance.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosServiceInstance.java index 407a1560d..1db224499 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosServiceInstance.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosServiceInstance.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -26,10 +26,15 @@ import org.springframework.cloud.client.ServiceInstance; * @author xiaojing */ public class NacosServiceInstance implements ServiceInstance { + private String serviceId; + private String host; + private int port; + private boolean secure; + private Map metadata; @Override diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/NacosDiscoveryClient.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/NacosDiscoveryClient.java index 60c287f98..852cc07b1 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/NacosDiscoveryClient.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/NacosDiscoveryClient.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,12 @@ package com.alibaba.cloud.nacos.discovery; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import com.alibaba.cloud.nacos.NacosDiscoveryProperties; import com.alibaba.cloud.nacos.NacosNamingManager; import com.alibaba.cloud.nacos.NacosServiceInstance; @@ -23,15 +29,10 @@ import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.pojo.ListView; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.DiscoveryClient; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - /** * @author xiaojing * @author renhaojun @@ -39,9 +40,14 @@ import java.util.Map; public class NacosDiscoveryClient implements DiscoveryClient { private static final Logger log = LoggerFactory.getLogger(NacosDiscoveryClient.class); + + /** + * Nacos Discovery Client Description. + */ public static final String DESCRIPTION = "Spring Cloud Nacos Discovery Client"; private NacosNamingManager nacosNamingManager; + private NacosDiscoveryProperties discoveryProperties; public NacosDiscoveryClient(NacosNamingManager nacosNamingManager, @@ -120,4 +126,5 @@ public class NacosDiscoveryClient implements DiscoveryClient { return Collections.emptyList(); } } + } diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/NacosDiscoveryClientAutoConfiguration.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/NacosDiscoveryClientAutoConfiguration.java index 2edc84bef..da0411390 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/NacosDiscoveryClientAutoConfiguration.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/NacosDiscoveryClientAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ package com.alibaba.cloud.nacos.discovery; +import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled; +import com.alibaba.cloud.nacos.NacosDiscoveryProperties; import com.alibaba.cloud.nacos.NacosNamingManager; + import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -26,9 +29,6 @@ import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAu import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled; -import com.alibaba.cloud.nacos.NacosDiscoveryProperties; - /** * @author xiaojing */ @@ -52,8 +52,10 @@ public class NacosDiscoveryClientAutoConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnProperty(value = "spring.cloud.nacos.discovery.watch.enabled", matchIfMissing = true) + @ConditionalOnProperty(value = "spring.cloud.nacos.discovery.watch.enabled", + matchIfMissing = true) public NacosWatch nacosWatch(NacosDiscoveryProperties nacosDiscoveryProperties) { return new NacosWatch(nacosDiscoveryProperties); } + } diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/NacosWatch.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/NacosWatch.java index d0c45a76b..36761d479 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/NacosWatch.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/NacosWatch.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,8 +23,11 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; +import com.alibaba.cloud.nacos.NacosDiscoveryProperties; +import com.alibaba.nacos.api.naming.listener.EventListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.cloud.client.discovery.event.HeartbeatEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; @@ -32,9 +35,6 @@ import org.springframework.context.SmartLifecycle; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; -import com.alibaba.cloud.nacos.NacosDiscoveryProperties; -import com.alibaba.nacos.api.naming.listener.EventListener; - /** * @author xiaojing */ @@ -121,4 +121,5 @@ public class NacosWatch implements ApplicationEventPublisherAware, SmartLifecycl new HeartbeatEvent(this, nacosWatchIndex.getAndIncrement())); } + } diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/configclient/NacosConfigServerAutoConfiguration.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/configclient/NacosConfigServerAutoConfiguration.java index 0cccdcfd3..56785ed4b 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/configclient/NacosConfigServerAutoConfiguration.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/configclient/NacosConfigServerAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,6 +18,8 @@ package com.alibaba.cloud.nacos.discovery.configclient; import javax.annotation.PostConstruct; +import com.alibaba.cloud.nacos.NacosDiscoveryProperties; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -25,8 +27,6 @@ import org.springframework.cloud.config.server.config.ConfigServerProperties; import org.springframework.context.annotation.Configuration; import org.springframework.util.StringUtils; -import com.alibaba.cloud.nacos.NacosDiscoveryProperties; - /** * Extra configuration for config server if it happens to be registered with Nacos. * diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/configclient/NacosDiscoveryClientConfigServiceBootstrapConfiguration.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/configclient/NacosDiscoveryClientConfigServiceBootstrapConfiguration.java index 309439ae1..ac4671821 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/configclient/NacosDiscoveryClientConfigServiceBootstrapConfiguration.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/configclient/NacosDiscoveryClientConfigServiceBootstrapConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,22 +16,23 @@ package com.alibaba.cloud.nacos.discovery.configclient; +import com.alibaba.cloud.nacos.NacosDiscoveryAutoConfiguration; +import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientAutoConfiguration; + import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.cloud.config.client.ConfigServicePropertySourceLocator; import org.springframework.context.annotation.Configuration; -import com.alibaba.cloud.nacos.NacosDiscoveryAutoConfiguration; -import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientAutoConfiguration; - /** * Helper for config client that wants to lookup the config server via discovery. * * @author JevonYang */ @ConditionalOnClass(ConfigServicePropertySourceLocator.class) -@ConditionalOnProperty(value = "spring.cloud.config.discovery.enabled", matchIfMissing = false) +@ConditionalOnProperty(value = "spring.cloud.config.discovery.enabled", + matchIfMissing = false) @Configuration @ImportAutoConfiguration({ NacosDiscoveryClientAutoConfiguration.class, NacosDiscoveryAutoConfiguration.class }) diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/endpoint/NacosDiscoveryEndpoint.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/endpoint/NacosDiscoveryEndpoint.java index 6d38c0051..06012198d 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/endpoint/NacosDiscoveryEndpoint.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/endpoint/NacosDiscoveryEndpoint.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,18 +21,19 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import com.alibaba.cloud.nacos.NacosDiscoveryProperties; import com.alibaba.cloud.nacos.NacosNamingManager; +import com.alibaba.nacos.api.naming.NamingService; +import com.alibaba.nacos.api.naming.pojo.ServiceInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; -import com.alibaba.cloud.nacos.NacosDiscoveryProperties; -import com.alibaba.nacos.api.naming.NamingService; -import com.alibaba.nacos.api.naming.pojo.ServiceInfo; - /** - * Endpoint for nacos discovery, get nacos properties and subscribed services + * Endpoint for nacos discovery, get nacos properties and subscribed services. + * * @author xiaojing */ @Endpoint(id = "nacos-discovery") @@ -42,6 +43,7 @@ public class NacosDiscoveryEndpoint { .getLogger(NacosDiscoveryEndpoint.class); private NacosNamingManager nacosNamingManager; + private NacosDiscoveryProperties nacosDiscoveryProperties; public NacosDiscoveryEndpoint(NacosNamingManager nacosNamingManager, @@ -70,4 +72,5 @@ public class NacosDiscoveryEndpoint { result.put("subscribe", subscribe); return result; } -} \ No newline at end of file + +} diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/endpoint/NacosDiscoveryEndpointAutoConfiguration.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/endpoint/NacosDiscoveryEndpointAutoConfiguration.java index 895313269..3fdc1422a 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/endpoint/NacosDiscoveryEndpointAutoConfiguration.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/endpoint/NacosDiscoveryEndpointAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ package com.alibaba.cloud.nacos.endpoint; +import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled; +import com.alibaba.cloud.nacos.NacosDiscoveryProperties; import com.alibaba.cloud.nacos.NacosNamingManager; + import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -24,9 +27,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled; -import com.alibaba.cloud.nacos.NacosDiscoveryProperties; - /** * @author xiaojing */ diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistration.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistration.java index 3dbf37c22..649ddd678 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistration.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,6 +18,7 @@ package com.alibaba.cloud.nacos.registry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration; import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties; import org.springframework.cloud.client.serviceregistry.Registration; @@ -31,6 +32,7 @@ import org.springframework.util.StringUtils; */ public class NacosAutoServiceRegistration extends AbstractAutoServiceRegistration { + private static final Logger log = LoggerFactory .getLogger(NacosAutoServiceRegistration.class); diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/registry/NacosRegistration.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/registry/NacosRegistration.java index 968f8e59f..14d2b1109 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/registry/NacosRegistration.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/registry/NacosRegistration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,7 +21,11 @@ import java.util.Map; import javax.annotation.PostConstruct; +import com.alibaba.cloud.nacos.NacosDiscoveryProperties; import com.alibaba.cloud.nacos.NacosNamingManager; +import com.alibaba.nacos.api.naming.NamingService; +import com.alibaba.nacos.api.naming.PreservedMetadataKeys; + import org.springframework.cloud.client.DefaultServiceInstance; import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.ManagementServerPortUtils; @@ -30,21 +34,33 @@ import org.springframework.context.ApplicationContext; import org.springframework.core.env.Environment; import org.springframework.util.StringUtils; -import com.alibaba.cloud.nacos.NacosDiscoveryProperties; -import com.alibaba.nacos.api.naming.NamingService; -import com.alibaba.nacos.api.naming.PreservedMetadataKeys; - /** * @author xiaojing */ public class NacosRegistration implements Registration, ServiceInstance { + /** + * The metadata key of management port. + */ public static final String MANAGEMENT_PORT = "management.port"; + + /** + * The metadata key of management context-path. + */ public static final String MANAGEMENT_CONTEXT_PATH = "management.context-path"; + + /** + * The metadata key of management address. + */ public static final String MANAGEMENT_ADDRESS = "management.address"; + + /** + * The metadata key of management endpoints web base path. + */ public static final String MANAGEMENT_ENDPOINT_BASE_PATH = "management.endpoints.web.base-path"; private NacosNamingManager nacosNamingManager; + private NacosDiscoveryProperties nacosDiscoveryProperties; private ApplicationContext context; @@ -155,4 +171,5 @@ public class NacosRegistration implements Registration, ServiceInstance { return "NacosRegistration{" + "nacosDiscoveryProperties=" + nacosDiscoveryProperties + '}'; } + } diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/registry/NacosServiceRegistry.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/registry/NacosServiceRegistry.java index 2e27a158e..3dd0e3d39 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/registry/NacosServiceRegistry.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/registry/NacosServiceRegistry.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,17 +18,17 @@ package com.alibaba.cloud.nacos.registry; import java.util.List; +import com.alibaba.cloud.nacos.NacosDiscoveryProperties; import com.alibaba.cloud.nacos.NacosNamingManager; +import com.alibaba.nacos.api.naming.NamingService; +import com.alibaba.nacos.api.naming.pojo.Instance; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.cloud.client.serviceregistry.Registration; import org.springframework.cloud.client.serviceregistry.ServiceRegistry; import org.springframework.util.StringUtils; -import com.alibaba.cloud.nacos.NacosDiscoveryProperties; -import com.alibaba.nacos.api.naming.NamingService; -import com.alibaba.nacos.api.naming.pojo.Instance; - /** * @author xiaojing * @author Mercy @@ -38,6 +38,7 @@ public class NacosServiceRegistry implements ServiceRegistry { private static final Logger log = LoggerFactory.getLogger(NacosServiceRegistry.class); private final NacosNamingManager nacosNamingManager; + private final NacosDiscoveryProperties nacosDiscoveryProperties; private final NamingService namingService; @@ -142,8 +143,9 @@ public class NacosServiceRegistry implements ServiceRegistry { .getAllInstances(serviceName); for (Instance instance : instances) { if (instance.getIp().equalsIgnoreCase(nacosDiscoveryProperties.getIp()) - && instance.getPort() == nacosDiscoveryProperties.getPort()) + && instance.getPort() == nacosDiscoveryProperties.getPort()) { return instance.isEnabled() ? "UP" : "DOWN"; + } } } catch (Exception e) { diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/ConditionalOnRibbonNacos.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/ConditionalOnRibbonNacos.java index 1e25ec470..1cbdb6591 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/ConditionalOnRibbonNacos.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/ConditionalOnRibbonNacos.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/ExtendBalancer.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/ExtendBalancer.java index 061112639..e52278cb8 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/ExtendBalancer.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/ExtendBalancer.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.nacos.ribbon; import java.util.List; @@ -9,13 +25,14 @@ import com.alibaba.nacos.client.naming.core.Balancer; * @author itmuch.com */ public class ExtendBalancer extends Balancer { + /** - * 根据权重,随机选择实例 - * - * @param instances 实例列表 - * @return 选择的实例 + * Choose instance by weight. + * @param instances Instance List + * @return the chosen instance */ public static Instance getHostByRandomWeight2(List instances) { return getHostByRandomWeight(instances); } + } diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosRibbonClientConfiguration.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosRibbonClientConfiguration.java index 0fe4ef17b..f8168eeab 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosRibbonClientConfiguration.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosRibbonClientConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,18 +16,18 @@ package com.alibaba.cloud.nacos.ribbon; +import com.alibaba.cloud.nacos.NacosDiscoveryProperties; import com.alibaba.cloud.nacos.NacosNamingManager; +import com.netflix.client.config.IClientConfig; +import com.netflix.loadbalancer.ServerList; + import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.alibaba.cloud.nacos.NacosDiscoveryProperties; - -import com.netflix.client.config.IClientConfig; -import com.netflix.loadbalancer.ServerList; - /** - * integrated Ribbon by default + * integrated Ribbon by default. + * * @author xiaojing */ @Configuration @@ -50,4 +50,5 @@ public class NacosRibbonClientConfiguration { public NacosServerIntrospector nacosServerIntrospector() { return new NacosServerIntrospector(); } + } diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosRule.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosRule.java index f0c5fcdab..50ad73b04 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosRule.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosRule.java @@ -1,24 +1,39 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.nacos.ribbon; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; -import com.alibaba.cloud.nacos.NacosNamingManager; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; - import com.alibaba.cloud.nacos.NacosDiscoveryProperties; +import com.alibaba.cloud.nacos.NacosNamingManager; import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.pojo.Instance; - import com.netflix.client.config.IClientConfig; import com.netflix.loadbalancer.AbstractLoadBalancerRule; import com.netflix.loadbalancer.DynamicServerListLoadBalancer; import com.netflix.loadbalancer.Server; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.CollectionUtils; /** * Supports preferentially calling the ribbon load balancing rules of the same cluster @@ -27,6 +42,7 @@ import com.netflix.loadbalancer.Server; * @author itmuch.com */ public class NacosRule extends AbstractLoadBalancerRule { + private static final Logger LOGGER = LoggerFactory.getLogger(NacosRule.class); @Autowired @@ -78,4 +94,5 @@ public class NacosRule extends AbstractLoadBalancerRule { @Override public void initWithNiwsConfig(IClientConfig iClientConfig) { } + } diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServer.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServer.java index 73d9579e2..9c292a9a6 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServer.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServer.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,7 +19,6 @@ package com.alibaba.cloud.nacos.ribbon; import java.util.Map; import com.alibaba.nacos.api.naming.pojo.Instance; - import com.netflix.loadbalancer.Server; /** @@ -29,7 +28,9 @@ import com.netflix.loadbalancer.Server; public class NacosServer extends Server { private final MetaInfo metaInfo; + private final Instance instance; + private final Map metadata; public NacosServer(final Instance instance) { @@ -71,4 +72,5 @@ public class NacosServer extends Server { public Map getMetadata() { return metadata; } + } diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServerIntrospector.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServerIntrospector.java index 481c2d4a3..d186446dc 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServerIntrospector.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServerIntrospector.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,10 +18,10 @@ package com.alibaba.cloud.nacos.ribbon; import java.util.Map; -import org.springframework.cloud.netflix.ribbon.DefaultServerIntrospector; - import com.netflix.loadbalancer.Server; +import org.springframework.cloud.netflix.ribbon.DefaultServerIntrospector; + /** * @author xiaojing */ @@ -43,4 +43,5 @@ public class NacosServerIntrospector extends DefaultServerIntrospector { return super.isSecure(server); } + } diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServerList.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServerList.java index 1e88744e9..34ec5ff9d 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServerList.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServerList.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,7 +22,6 @@ import java.util.List; import com.alibaba.cloud.nacos.NacosDiscoveryProperties; import com.alibaba.cloud.nacos.NacosNamingManager; import com.alibaba.nacos.api.naming.pojo.Instance; - import com.alibaba.nacos.client.naming.utils.CollectionUtils; import com.netflix.client.config.IClientConfig; import com.netflix.loadbalancer.AbstractServerList; @@ -34,6 +33,7 @@ import com.netflix.loadbalancer.AbstractServerList; public class NacosServerList extends AbstractServerList { private NacosNamingManager nacosNamingManager; + private NacosDiscoveryProperties discoveryProperties; private String serviceId; @@ -88,4 +88,5 @@ public class NacosServerList extends AbstractServerList { public void initWithNiwsConfig(IClientConfig iClientConfig) { this.serviceId = iClientConfig.getClientName(); } -} \ No newline at end of file + +} diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/RibbonNacosAutoConfiguration.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/RibbonNacosAutoConfiguration.java index 64a301670..77410e56f 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/RibbonNacosAutoConfiguration.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/RibbonNacosAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,8 @@ package com.alibaba.cloud.nacos.ribbon; +import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled; + import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -24,8 +26,6 @@ import org.springframework.cloud.netflix.ribbon.RibbonClients; import org.springframework.cloud.netflix.ribbon.SpringClientFactory; import org.springframework.context.annotation.Configuration; -import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled; - /** * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration * Auto-configuration} that sets up Ribbon for Nacos. @@ -38,4 +38,5 @@ import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled; @AutoConfigureAfter(RibbonAutoConfiguration.class) @RibbonClients(defaultConfiguration = NacosRibbonClientConfiguration.class) public class RibbonNacosAutoConfiguration { -} \ No newline at end of file + +} diff --git a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/NacosDiscoveryClientTests.java b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/NacosDiscoveryClientTests.java index 100ac15a3..3c24f5e7b 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/NacosDiscoveryClientTests.java +++ b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/NacosDiscoveryClientTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,17 +16,18 @@ package com.alibaba.cloud.nacos; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; + import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClient; import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.pojo.ListView; import org.junit.Test; -import org.springframework.cloud.client.ServiceInstance; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; +import org.springframework.cloud.client.ServiceInstance; import static com.alibaba.cloud.nacos.test.NacosMockTest.serviceInstance; import static org.assertj.core.api.Assertions.assertThat; @@ -40,7 +41,9 @@ import static org.mockito.Mockito.when; public class NacosDiscoveryClientTests { private String host = "123.123.123.123"; + private int port = 8888; + private String serviceName = "test-service"; @Test @@ -127,4 +130,5 @@ public class NacosDiscoveryClientTests { return "http://" + host + ":" + port; } + } diff --git a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/NacosDiscoveryPropertiesServerAddressBothLevelTests.java b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/NacosDiscoveryPropertiesServerAddressBothLevelTests.java index 6c1af0151..8cbc831a1 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/NacosDiscoveryPropertiesServerAddressBothLevelTests.java +++ b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/NacosDiscoveryPropertiesServerAddressBothLevelTests.java @@ -1,10 +1,25 @@ -package com.alibaba.cloud.nacos; +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ -import static org.junit.Assert.assertEquals; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; +package com.alibaba.cloud.nacos; +import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientAutoConfiguration; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -13,17 +28,18 @@ import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationC import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.cloud.nacos.NacosDiscoveryAutoConfiguration; -import com.alibaba.cloud.nacos.NacosDiscoveryProperties; -import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientAutoConfiguration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; /** * @author lyuzb */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = NacosDiscoveryPropertiesServerAddressBothLevelTests.TestConfig.class, properties = { - "spring.cloud.nacos.discovery.server-addr=321.321.321.321:8848", - "spring.cloud.nacos.server-addr=123.123.123.123:8848" }, webEnvironment = RANDOM_PORT) +@SpringBootTest( + classes = NacosDiscoveryPropertiesServerAddressBothLevelTests.TestConfig.class, + properties = { "spring.cloud.nacos.discovery.server-addr=321.321.321.321:8848", + "spring.cloud.nacos.server-addr=123.123.123.123:8848" }, + webEnvironment = RANDOM_PORT) public class NacosDiscoveryPropertiesServerAddressBothLevelTests { @Autowired @@ -31,8 +47,7 @@ public class NacosDiscoveryPropertiesServerAddressBothLevelTests { @Test public void testGetServerAddr() { - assertEquals("NacosDiscoveryProperties server address was wrong", - "321.321.321.321:8848", properties.getServerAddr()); + assertThat(properties.getServerAddr()).isEqualTo("321.321.321.321:8848"); } @Configuration @@ -41,5 +56,7 @@ public class NacosDiscoveryPropertiesServerAddressBothLevelTests { NacosDiscoveryClientAutoConfiguration.class, NacosDiscoveryAutoConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/NacosDiscoveryPropertiesServerAddressTopLevelTests.java b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/NacosDiscoveryPropertiesServerAddressTopLevelTests.java index 7e3a065dc..6bc146820 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/NacosDiscoveryPropertiesServerAddressTopLevelTests.java +++ b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/NacosDiscoveryPropertiesServerAddressTopLevelTests.java @@ -1,10 +1,25 @@ -package com.alibaba.cloud.nacos; +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ -import static org.junit.Assert.assertEquals; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; +package com.alibaba.cloud.nacos; +import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientAutoConfiguration; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -13,18 +28,18 @@ import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationC import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.cloud.nacos.NacosDiscoveryAutoConfiguration; -import com.alibaba.cloud.nacos.NacosDiscoveryProperties; -import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientAutoConfiguration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; /** - * * @author lyuzb * */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = NacosDiscoveryPropertiesServerAddressTopLevelTests.TestConfig.class, properties = { - "spring.cloud.nacos.server-addr=123.123.123.123:8848" }, webEnvironment = RANDOM_PORT) +@SpringBootTest( + classes = NacosDiscoveryPropertiesServerAddressTopLevelTests.TestConfig.class, + properties = { "spring.cloud.nacos.server-addr=123.123.123.123:8848" }, + webEnvironment = RANDOM_PORT) public class NacosDiscoveryPropertiesServerAddressTopLevelTests { @@ -33,8 +48,7 @@ public class NacosDiscoveryPropertiesServerAddressTopLevelTests { @Test public void testGetServerAddr() { - assertEquals("NacosDiscoveryProperties server address was wrong", - "123.123.123.123:8848", properties.getServerAddr()); + assertThat(properties.getServerAddr()).isEqualTo("123.123.123.123:8848"); } @Configuration @@ -43,5 +57,7 @@ public class NacosDiscoveryPropertiesServerAddressTopLevelTests { NacosDiscoveryClientAutoConfiguration.class, NacosDiscoveryAutoConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistrationIpNetworkInterfaceTests.java b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistrationIpNetworkInterfaceTests.java index 0486b8519..a71b2c84b 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistrationIpNetworkInterfaceTests.java +++ b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistrationIpNetworkInterfaceTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,17 +16,17 @@ package com.alibaba.cloud.nacos.registry; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - import java.net.Inet4Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.util.Enumeration; +import com.alibaba.cloud.nacos.NacosDiscoveryAutoConfiguration; +import com.alibaba.cloud.nacos.NacosDiscoveryProperties; +import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientAutoConfiguration; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -36,18 +36,19 @@ import org.springframework.cloud.commons.util.InetUtils; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.cloud.nacos.NacosDiscoveryAutoConfiguration; -import com.alibaba.cloud.nacos.NacosDiscoveryProperties; -import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientAutoConfiguration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; /** * @author xiaojing */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = NacosAutoServiceRegistrationIpNetworkInterfaceTests.TestConfig.class, properties = { - "spring.application.name=myTestService1", - "spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848" }, webEnvironment = RANDOM_PORT) +@SpringBootTest( + classes = NacosAutoServiceRegistrationIpNetworkInterfaceTests.TestConfig.class, + properties = { "spring.application.name=myTestService1", + "spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848" }, + webEnvironment = RANDOM_PORT) public class NacosAutoServiceRegistrationIpNetworkInterfaceTests { @Autowired @@ -64,21 +65,16 @@ public class NacosAutoServiceRegistrationIpNetworkInterfaceTests { @Test public void contextLoads() throws Exception { - - assertNotNull("NacosRegistration was not created", registration); - assertNotNull("NacosDiscoveryProperties was not created", properties); - assertNotNull("NacosAutoServiceRegistration was not created", - nacosAutoServiceRegistration); + assertThat(registration).isNotNull(); + assertThat(properties).isNotNull(); + assertThat(nacosAutoServiceRegistration).isNotNull(); checkoutNacosDiscoveryServiceIP(); - } private void checkoutNacosDiscoveryServiceIP() { - assertEquals("NacosDiscoveryProperties service IP was wrong", - getIPFromNetworkInterface(TestConfig.netWorkInterfaceName), - registration.getHost()); - + assertThat(registration.getHost()) + .isEqualTo(getIPFromNetworkInterface(TestConfig.netWorkInterfaceName)); } private String getIPFromNetworkInterface(String networkInterface) { @@ -143,6 +139,7 @@ public class NacosAutoServiceRegistrationIpNetworkInterfaceTests { } } + } } diff --git a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistrationIpTests.java b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistrationIpTests.java index 2f0944eb5..e364c7a12 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistrationIpTests.java +++ b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistrationIpTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,12 +16,12 @@ package com.alibaba.cloud.nacos.registry; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - +import com.alibaba.cloud.nacos.NacosDiscoveryAutoConfiguration; +import com.alibaba.cloud.nacos.NacosDiscoveryProperties; +import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientAutoConfiguration; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -30,19 +30,19 @@ import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationC import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.cloud.nacos.NacosDiscoveryAutoConfiguration; -import com.alibaba.cloud.nacos.NacosDiscoveryProperties; -import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientAutoConfiguration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; /** * @author xiaojing */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = NacosAutoServiceRegistrationIpTests.TestConfig.class, properties = { - "spring.application.name=myTestService1", - "spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848", - "spring.cloud.nacos.discovery.ip=123.123.123.123" }, webEnvironment = RANDOM_PORT) +@SpringBootTest(classes = NacosAutoServiceRegistrationIpTests.TestConfig.class, + properties = { "spring.application.name=myTestService1", + "spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848", + "spring.cloud.nacos.discovery.ip=123.123.123.123" }, + webEnvironment = RANDOM_PORT) public class NacosAutoServiceRegistrationIpTests { @Autowired @@ -56,20 +56,15 @@ public class NacosAutoServiceRegistrationIpTests { @Test public void contextLoads() throws Exception { - - assertNotNull("NacosRegistration was not created", registration); - assertNotNull("NacosDiscoveryProperties was not created", properties); - assertNotNull("NacosAutoServiceRegistration was not created", - nacosAutoServiceRegistration); + assertThat(registration).isNotNull(); + assertThat(properties).isNotNull(); + assertThat(nacosAutoServiceRegistration).isNotNull(); checkoutNacosDiscoveryServiceIP(); - } private void checkoutNacosDiscoveryServiceIP() { - assertEquals("NacosDiscoveryProperties service IP was wrong", "123.123.123.123", - registration.getHost()); - + assertThat(registration.getHost()).isEqualTo("123.123.123.123"); } @Configuration @@ -78,5 +73,7 @@ public class NacosAutoServiceRegistrationIpTests { NacosDiscoveryClientAutoConfiguration.class, NacosDiscoveryAutoConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistrationManagementPortTests.java b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistrationManagementPortTests.java index 6fca25f8b..4e2e8830a 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistrationManagementPortTests.java +++ b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistrationManagementPortTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,12 +16,12 @@ package com.alibaba.cloud.nacos.registry; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - +import com.alibaba.cloud.nacos.NacosDiscoveryAutoConfiguration; +import com.alibaba.cloud.nacos.NacosDiscoveryProperties; +import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientAutoConfiguration; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -30,20 +30,22 @@ import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationC import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.cloud.nacos.NacosDiscoveryAutoConfiguration; -import com.alibaba.cloud.nacos.NacosDiscoveryProperties; -import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientAutoConfiguration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; /** * @author xiaojing */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = NacosAutoServiceRegistrationManagementPortTests.TestConfig.class, properties = { - "spring.application.name=myTestService1", "management.server.port=8888", - "management.server.servlet.context-path=/test-context-path", - "spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848", - "spring.cloud.nacos.discovery.port=8888" }, webEnvironment = RANDOM_PORT) +@SpringBootTest( + classes = NacosAutoServiceRegistrationManagementPortTests.TestConfig.class, + properties = { "spring.application.name=myTestService1", + "management.server.port=8888", + "management.server.servlet.context-path=/test-context-path", + "spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848", + "spring.cloud.nacos.discovery.port=8888" }, + webEnvironment = RANDOM_PORT) public class NacosAutoServiceRegistrationManagementPortTests { @Autowired @@ -57,24 +59,19 @@ public class NacosAutoServiceRegistrationManagementPortTests { @Test public void contextLoads() throws Exception { - - assertNotNull("NacosRegistration was not created", registration); - assertNotNull("NacosDiscoveryProperties was not created", properties); - assertNotNull("NacosAutoServiceRegistration was not created", - nacosAutoServiceRegistration); + assertThat(registration).isNotNull(); + assertThat(properties).isNotNull(); + assertThat(nacosAutoServiceRegistration).isNotNull(); checkoutNacosDiscoveryManagementData(); - } private void checkoutNacosDiscoveryManagementData() { - assertEquals("NacosDiscoveryProperties management port was wrong", "8888", - properties.getMetadata().get(NacosRegistration.MANAGEMENT_PORT)); - - assertEquals("NacosDiscoveryProperties management context path was wrong", - "/test-context-path", - properties.getMetadata().get(NacosRegistration.MANAGEMENT_CONTEXT_PATH)); - + assertThat(properties.getMetadata().get(NacosRegistration.MANAGEMENT_PORT)) + .isEqualTo("8888"); + assertThat( + properties.getMetadata().get(NacosRegistration.MANAGEMENT_CONTEXT_PATH)) + .isEqualTo("/test-context-path"); } @Configuration @@ -83,5 +80,7 @@ public class NacosAutoServiceRegistrationManagementPortTests { NacosDiscoveryClientAutoConfiguration.class, NacosDiscoveryAutoConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistrationPortTests.java b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistrationPortTests.java index 25483a82a..c3da41066 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistrationPortTests.java +++ b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistrationPortTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,12 +16,12 @@ package com.alibaba.cloud.nacos.registry; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - +import com.alibaba.cloud.nacos.NacosDiscoveryAutoConfiguration; +import com.alibaba.cloud.nacos.NacosDiscoveryProperties; +import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientAutoConfiguration; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -30,19 +30,19 @@ import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationC import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.cloud.nacos.NacosDiscoveryAutoConfiguration; -import com.alibaba.cloud.nacos.NacosDiscoveryProperties; -import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientAutoConfiguration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; /** * @author xiaojing */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = NacosAutoServiceRegistrationPortTests.TestConfig.class, properties = { - "spring.application.name=myTestService1", - "spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848", - "spring.cloud.nacos.discovery.port=8888" }, webEnvironment = RANDOM_PORT) +@SpringBootTest(classes = NacosAutoServiceRegistrationPortTests.TestConfig.class, + properties = { "spring.application.name=myTestService1", + "spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848", + "spring.cloud.nacos.discovery.port=8888" }, + webEnvironment = RANDOM_PORT) public class NacosAutoServiceRegistrationPortTests { @Autowired @@ -56,20 +56,15 @@ public class NacosAutoServiceRegistrationPortTests { @Test public void contextLoads() throws Exception { - - assertNotNull("NacosRegistration was not created", registration); - assertNotNull("NacosDiscoveryProperties was not created", properties); - assertNotNull("NacosAutoServiceRegistration was not created", - nacosAutoServiceRegistration); + assertThat(registration).isNotNull(); + assertThat(properties).isNotNull(); + assertThat(nacosAutoServiceRegistration).isNotNull(); checkoutNacosDiscoveryServicePort(); - } private void checkoutNacosDiscoveryServicePort() { - assertEquals("NacosDiscoveryProperties service Port was wrong", 8888, - registration.getPort()); - + assertThat(registration.getPort()).isEqualTo(8888); } @Configuration @@ -78,5 +73,7 @@ public class NacosAutoServiceRegistrationPortTests { NacosDiscoveryClientAutoConfiguration.class, NacosDiscoveryAutoConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistrationTests.java b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistrationTests.java index b2fd7f477..8519c4cd4 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistrationTests.java +++ b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/registry/NacosAutoServiceRegistrationTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,16 +16,16 @@ package com.alibaba.cloud.nacos.registry; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - import java.util.Map; +import com.alibaba.cloud.nacos.NacosDiscoveryAutoConfiguration; +import com.alibaba.cloud.nacos.NacosDiscoveryProperties; import com.alibaba.cloud.nacos.NacosNamingManager; +import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientAutoConfiguration; +import com.alibaba.cloud.nacos.endpoint.NacosDiscoveryEndpoint; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -36,31 +36,30 @@ import org.springframework.cloud.commons.util.InetUtils; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.cloud.nacos.NacosDiscoveryAutoConfiguration; -import com.alibaba.cloud.nacos.NacosDiscoveryProperties; -import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientAutoConfiguration; -import com.alibaba.cloud.nacos.endpoint.NacosDiscoveryEndpoint; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; /** * @author xiaojing */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = NacosAutoServiceRegistrationTests.TestConfig.class, properties = { - "spring.application.name=myTestService1", - "spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848", - "spring.cloud.nacos.discovery.endpoint=test-endpoint", - "spring.cloud.nacos.discovery.namespace=test-namespace", - "spring.cloud.nacos.discovery.log-name=test-logName", - "spring.cloud.nacos.discovery.weight=2", - "spring.cloud.nacos.discovery.clusterName=test-cluster", - "spring.cloud.nacos.discovery.namingLoadCacheAtStart=true", - "spring.cloud.nacos.discovery.secure=true", - "spring.cloud.nacos.discovery.accessKey=test-accessKey", - "spring.cloud.nacos.discovery.secretKey=test-secretKey", - "spring.cloud.nacos.discovery.heart-beat-interval=3", - "spring.cloud.nacos.discovery.heart-beat-timeout=6", - "spring.cloud.nacos.discovery.ip-delete-timeout=9", }, webEnvironment = RANDOM_PORT) +@SpringBootTest(classes = NacosAutoServiceRegistrationTests.TestConfig.class, + properties = { "spring.application.name=myTestService1", + "spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848", + "spring.cloud.nacos.discovery.endpoint=test-endpoint", + "spring.cloud.nacos.discovery.namespace=test-namespace", + "spring.cloud.nacos.discovery.log-name=test-logName", + "spring.cloud.nacos.discovery.weight=2", + "spring.cloud.nacos.discovery.clusterName=test-cluster", + "spring.cloud.nacos.discovery.namingLoadCacheAtStart=true", + "spring.cloud.nacos.discovery.secure=true", + "spring.cloud.nacos.discovery.accessKey=test-accessKey", + "spring.cloud.nacos.discovery.secretKey=test-secretKey", + "spring.cloud.nacos.discovery.heart-beat-interval=3", + "spring.cloud.nacos.discovery.heart-beat-timeout=6", + "spring.cloud.nacos.discovery.ip-delete-timeout=9" }, + webEnvironment = RANDOM_PORT) public class NacosAutoServiceRegistrationTests { @Autowired @@ -83,11 +82,9 @@ public class NacosAutoServiceRegistrationTests { @Test public void contextLoads() throws Exception { - - assertNotNull("NacosRegistration was not created", registration); - assertNotNull("NacosDiscoveryProperties was not created", properties); - assertNotNull("NacosAutoServiceRegistration was not created", - nacosAutoServiceRegistration); + assertThat(registration).isNotNull(); + assertThat(properties).isNotNull(); + assertThat(nacosAutoServiceRegistration).isNotNull(); checkoutNacosDiscoveryServerAddr(); checkoutNacosDiscoveryEndpoint(); @@ -114,105 +111,84 @@ public class NacosAutoServiceRegistrationTests { } private void checkAutoRegister() { - assertTrue("Nacos Auto Registration was not start", - nacosAutoServiceRegistration.isRunning()); + assertThat(nacosAutoServiceRegistration.isRunning()).isEqualTo(Boolean.TRUE); } private void checkoutNacosDiscoveryServerAddr() { - assertEquals("NacosDiscoveryProperties server address was wrong", - "127.0.0.1:8848", properties.getServerAddr()); - + assertThat(properties.getServerAddr()).isEqualTo("127.0.0.1:8848"); } private void checkoutNacosDiscoveryEndpoint() { - assertEquals("NacosDiscoveryProperties endpoint was wrong", "test-endpoint", - properties.getEndpoint()); - + assertThat(properties.getEndpoint()).isEqualTo("test-endpoint"); } private void checkoutNacosDiscoveryNamespace() { - assertEquals("NacosDiscoveryProperties namespace was wrong", "test-namespace", - properties.getNamespace()); - + assertThat(properties.getNamespace()).isEqualTo("test-namespace"); } private void checkoutNacosDiscoveryLogName() { - assertEquals("NacosDiscoveryProperties logName was wrong", "test-logName", - properties.getLogName()); + assertThat(properties.getLogName()).isEqualTo("test-logName"); } private void checkoutNacosDiscoveryWeight() { - assertEquals(2, properties.getWeight(), 0.00000001); + assertThat(properties.getWeight()).isEqualTo(2); } private void checkoutNacosDiscoveryClusterName() { - assertEquals("NacosDiscoveryProperties cluster was wrong", "test-cluster", - properties.getClusterName()); + assertThat(properties.getClusterName()).isEqualTo("test-cluster"); } private void checkoutNacosDiscoveryCache() { - assertEquals("NacosDiscoveryProperties naming load cache was wrong", "true", - properties.getNamingLoadCacheAtStart()); + assertThat(properties.getNamingLoadCacheAtStart()).isEqualTo("true"); } private void checkoutNacosDiscoverySecure() { - assertEquals("NacosDiscoveryProperties is secure was wrong", true, - properties.isSecure()); - assertEquals("NacosDiscoveryProperties is secure was wrong", "true", - properties.getMetadata().get("secure")); + assertThat(properties.isSecure()).isEqualTo(true); + assertThat(properties.getMetadata().get("secure")).isEqualTo("true"); } private void checkoutNacosDiscoveryAccessKey() { - assertEquals("NacosDiscoveryProperties is access key was wrong", "test-accessKey", - properties.getAccessKey()); + assertThat(properties.getAccessKey()).isEqualTo("test-accessKey"); } private void checkoutNacosDiscoverySecrectKey() { - assertEquals("NacosDiscoveryProperties is secret key was wrong", "test-secretKey", - properties.getSecretKey()); + assertThat(properties.getSecretKey()).isEqualTo("test-secretKey"); } private void checkoutNacosDiscoveryHeartBeatInterval() { - assertEquals("NacosDiscoveryProperties heart beat interval was wrong", - Integer.valueOf(3), properties.getHeartBeatInterval()); + assertThat(properties.getHeartBeatInterval()).isEqualTo(Integer.valueOf(3)); } private void checkoutNacosDiscoveryHeartBeatTimeout() { - assertEquals("NacosDiscoveryProperties heart beat timeout was wrong", - Integer.valueOf(6), properties.getHeartBeatTimeout()); + assertThat(properties.getHeartBeatTimeout()).isEqualTo(Integer.valueOf(6)); } private void checkoutNacosDiscoveryIpDeleteTimeout() { - assertEquals("NacosDiscoveryProperties ip delete timeout was wrong", - Integer.valueOf(9), properties.getIpDeleteTimeout()); + assertThat(properties.getIpDeleteTimeout()).isEqualTo(Integer.valueOf(9)); } private void checkoutNacosDiscoveryServiceName() { - assertEquals("NacosDiscoveryProperties service name was wrong", "myTestService1", - properties.getService()); - + assertThat(properties.getService()).isEqualTo("myTestService1"); } private void checkoutNacosDiscoveryServiceIP() { - assertEquals("NacosDiscoveryProperties service IP was wrong", - inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(), - registration.getHost()); - + assertThat(registration.getHost()) + .isEqualTo(inetUtils.findFirstNonLoopbackHostInfo().getIpAddress()); } private void checkoutNacosDiscoveryServicePort() { - assertEquals("NacosDiscoveryProperties service Port was wrong", port, - registration.getPort()); - + assertThat(registration.getPort()).isEqualTo(port); } private void checkoutEndpoint() throws Exception { NacosDiscoveryEndpoint nacosDiscoveryEndpoint = new NacosDiscoveryEndpoint( nacosNamingManager, properties); Map map = nacosDiscoveryEndpoint.nacosDiscovery(); - assertEquals(map.get("NacosDiscoveryProperties"), properties); - assertEquals(map.get("subscribe").toString(), - nacosNamingManager.getNamingService().getSubscribeServices().toString()); + + assertThat(properties).isEqualTo(map.get("NacosDiscoveryProperties")); + assertThat( + nacosNamingManager.getNamingService().getSubscribeServices().toString()) + .isEqualTo(map.get("subscribe").toString()); } @Configuration @@ -221,5 +197,7 @@ public class NacosAutoServiceRegistrationTests { NacosDiscoveryClientAutoConfiguration.class, NacosDiscoveryAutoConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/ribbon/NacosRibbonClientConfigurationTests.java b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/ribbon/NacosRibbonClientConfigurationTests.java index 2dd70b040..958a29f1b 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/ribbon/NacosRibbonClientConfigurationTests.java +++ b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/ribbon/NacosRibbonClientConfigurationTests.java @@ -1,8 +1,26 @@ -package com.alibaba.cloud.nacos.ribbon; +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ -import static org.assertj.core.api.Assertions.assertThat; +package com.alibaba.cloud.nacos.ribbon; +import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientAutoConfiguration; +import com.netflix.client.config.DefaultClientConfigImpl; +import com.netflix.client.config.IClientConfig; import org.junit.Test; + import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; @@ -12,10 +30,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.client.RestTemplate; -import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientAutoConfiguration; - -import com.netflix.client.config.DefaultClientConfigImpl; -import com.netflix.client.config.IClientConfig; +import static org.assertj.core.api.Assertions.assertThat; /** * @author xiaojing diff --git a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/ribbon/NacosServerListTests.java b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/ribbon/NacosServerListTests.java index 17161df00..85b111122 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/ribbon/NacosServerListTests.java +++ b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/ribbon/NacosServerListTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,27 +16,25 @@ package com.alibaba.cloud.nacos.ribbon; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.stream.Collectors; -import com.alibaba.cloud.nacos.NacosNamingManager; -import org.junit.Test; - import com.alibaba.cloud.nacos.NacosDiscoveryProperties; +import com.alibaba.cloud.nacos.NacosNamingManager; import com.alibaba.cloud.nacos.test.NacosMockTest; import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.pojo.Instance; - import com.netflix.client.config.IClientConfig; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * @author xiaojing @@ -172,4 +170,5 @@ public class NacosServerListTests { assertThat(servers.get(0).getInstance().getMetadata().get("instanceNum")) .isEqualTo("1"); } -} \ No newline at end of file + +} diff --git a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/test/CommonTestConfig.java b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/test/CommonTestConfig.java index 7e7b51ab2..f4c5ee85f 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/test/CommonTestConfig.java +++ b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/test/CommonTestConfig.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -33,4 +33,5 @@ public class CommonTestConfig { RestTemplate loadBalancedRestTemplate() { return new RestTemplate(); } -} \ No newline at end of file + +} diff --git a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/test/NacosMockTest.java b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/test/NacosMockTest.java index f97870ded..684ab749d 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/test/NacosMockTest.java +++ b/spring-cloud-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/test/NacosMockTest.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -46,4 +46,5 @@ public class NacosMockTest { instance.setMetadata(metadata); return instance; } + } diff --git a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/GlobalTransactionAutoConfiguration.java b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/GlobalTransactionAutoConfiguration.java index dad69eda3..b7aaa7a0a 100644 --- a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/GlobalTransactionAutoConfiguration.java +++ b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/GlobalTransactionAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,14 +16,14 @@ package com.alibaba.cloud.seata; +import io.seata.spring.annotation.GlobalTransactionScanner; + import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.util.StringUtils; -import io.seata.spring.annotation.GlobalTransactionScanner; - /** * @author xiaojing */ @@ -57,4 +57,5 @@ public class GlobalTransactionAutoConfiguration { return new GlobalTransactionScanner(applicationName, txServiceGroup); } + } diff --git a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/SeataProperties.java b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/SeataProperties.java index c95314340..6c369ac6c 100644 --- a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/SeataProperties.java +++ b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/SeataProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataBeanPostProcessor.java b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataBeanPostProcessor.java index 4218c7676..e815a9ec8 100644 --- a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataBeanPostProcessor.java +++ b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataBeanPostProcessor.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -41,4 +41,5 @@ final class SeataBeanPostProcessor implements BeanPostProcessor { throws BeansException { return bean; } -} \ No newline at end of file + +} diff --git a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataContextBeanPostProcessor.java b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataContextBeanPostProcessor.java index e214bdddc..37c35c261 100644 --- a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataContextBeanPostProcessor.java +++ b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataContextBeanPostProcessor.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,6 +27,7 @@ import org.springframework.cloud.openfeign.FeignContext; public class SeataContextBeanPostProcessor implements BeanPostProcessor { private final BeanFactory beanFactory; + private SeataFeignObjectWrapper seataFeignObjectWrapper; SeataContextBeanPostProcessor(BeanFactory beanFactory) { @@ -56,4 +57,5 @@ public class SeataContextBeanPostProcessor implements BeanPostProcessor { } return this.seataFeignObjectWrapper; } + } diff --git a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBuilder.java b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBuilder.java index 0855e3586..73e1dbed6 100644 --- a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBuilder.java +++ b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBuilder.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,10 +16,10 @@ package com.alibaba.cloud.seata.feign; -import org.springframework.beans.factory.BeanFactory; - import feign.Feign; +import org.springframework.beans.factory.BeanFactory; + /** * @author xiaojing */ @@ -31,4 +31,5 @@ final class SeataFeignBuilder { static Feign.Builder builder(BeanFactory beanFactory) { return Feign.builder().client(new SeataFeignClient(beanFactory)); } + } diff --git a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClient.java b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClient.java index c13b4cbc6..5bcaebca5 100644 --- a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClient.java +++ b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClient.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,21 +23,23 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.springframework.beans.factory.BeanFactory; -import org.springframework.util.StringUtils; - import feign.Client; import feign.Request; import feign.Response; import io.seata.core.context.RootContext; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.util.StringUtils; + /** * @author xiaojing */ public class SeataFeignClient implements Client { private final Client delegate; + private final BeanFactory beanFactory; + private static final int MAP_SIZE = 16; SeataFeignClient(BeanFactory beanFactory) { @@ -76,4 +78,4 @@ public class SeataFeignClient implements Client { request.charset()); } -} \ No newline at end of file +} diff --git a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClientAutoConfiguration.java b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClientAutoConfiguration.java index 3602e23d6..98f670ea1 100644 --- a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClientAutoConfiguration.java +++ b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClientAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,9 @@ package com.alibaba.cloud.seata.feign; +import feign.Client; +import feign.Feign; + import org.springframework.beans.factory.BeanFactory; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -26,9 +29,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; -import feign.Client; -import feign.Feign; - /** * @author xiaojing */ @@ -80,6 +80,7 @@ public class SeataFeignClientAutoConfiguration { SeataFeignObjectWrapper seataFeignObjectWrapper(BeanFactory beanFactory) { return new SeataFeignObjectWrapper(beanFactory); } + } -} \ No newline at end of file +} diff --git a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignContext.java b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignContext.java index 86b017f68..b0723f5ac 100644 --- a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignContext.java +++ b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignContext.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,17 +19,17 @@ package com.alibaba.cloud.seata.feign; import java.util.HashMap; import java.util.Map; -import org.springframework.cloud.openfeign.FeignContext; - import feign.Client; +import org.springframework.cloud.openfeign.FeignContext; + /** - * * @author xiaojing */ public class SeataFeignContext extends FeignContext { private final SeataFeignObjectWrapper seataFeignObjectWrapper; + private final FeignContext delegate; SeataFeignContext(SeataFeignObjectWrapper seataFeignObjectWrapper, @@ -65,4 +65,5 @@ public class SeataFeignContext extends FeignContext { } return convertedInstances; } + } diff --git a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignObjectWrapper.java b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignObjectWrapper.java index 374b83674..95c2a3f8e 100644 --- a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignObjectWrapper.java +++ b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignObjectWrapper.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,13 @@ package com.alibaba.cloud.seata.feign; +import feign.Client; + import org.springframework.beans.factory.BeanFactory; import org.springframework.cloud.netflix.ribbon.SpringClientFactory; import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory; import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient; -import feign.Client; - /** * @author xiaojing */ @@ -31,6 +31,7 @@ public class SeataFeignObjectWrapper { private final BeanFactory beanFactory; private CachingSpringLoadBalancerFactory cachingSpringLoadBalancerFactory; + private SpringClientFactory springClientFactory; SeataFeignObjectWrapper(BeanFactory beanFactory) { @@ -64,4 +65,5 @@ public class SeataFeignObjectWrapper { } return this.springClientFactory; } + } diff --git a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataHystrixFeignBuilder.java b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataHystrixFeignBuilder.java index f226244a9..98fb605f7 100644 --- a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataHystrixFeignBuilder.java +++ b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataHystrixFeignBuilder.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,12 +16,12 @@ package com.alibaba.cloud.seata.feign; -import org.springframework.beans.factory.BeanFactory; - import feign.Feign; import feign.Retryer; import feign.hystrix.HystrixFeign; +import org.springframework.beans.factory.BeanFactory; + /** * @author xiaojing */ @@ -34,4 +34,5 @@ final class SeataHystrixFeignBuilder { return HystrixFeign.builder().retryer(Retryer.NEVER_RETRY) .client(new SeataFeignClient(beanFactory)); } + } diff --git a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataLoadBalancerFeignClient.java b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataLoadBalancerFeignClient.java index fd0a9ebc5..bc93c3db0 100644 --- a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataLoadBalancerFeignClient.java +++ b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataLoadBalancerFeignClient.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,17 +23,17 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import feign.Client; +import feign.Request; +import feign.Response; +import io.seata.core.context.RootContext; + import org.springframework.beans.factory.BeanFactory; import org.springframework.cloud.netflix.ribbon.SpringClientFactory; import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory; import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient; import org.springframework.util.StringUtils; -import feign.Client; -import feign.Request; -import feign.Response; -import io.seata.core.context.RootContext; - /** * @author xiaojing */ @@ -78,4 +78,5 @@ public class SeataLoadBalancerFeignClient extends LoadBalancerFeignClient { return Request.create(request.method(), request.url(), headers, request.body(), request.charset()); } + } diff --git a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataSentinelFeignBuilder.java b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataSentinelFeignBuilder.java index 0f185c2ab..f7ef15ed3 100644 --- a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataSentinelFeignBuilder.java +++ b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataSentinelFeignBuilder.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,12 @@ package com.alibaba.cloud.seata.feign; -import org.springframework.beans.factory.BeanFactory; - import com.alibaba.cloud.sentinel.feign.SentinelFeign; - import feign.Feign; import feign.Retryer; +import org.springframework.beans.factory.BeanFactory; + /** * @author xiaojing */ @@ -35,4 +34,5 @@ final class SeataSentinelFeignBuilder { return SentinelFeign.builder().retryer(Retryer.NEVER_RETRY) .client(new SeataFeignClient(beanFactory)); } + } diff --git a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/hystrix/SeataHystrixAutoConfiguration.java b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/hystrix/SeataHystrixAutoConfiguration.java index 465ca3e65..e3295ed14 100644 --- a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/hystrix/SeataHystrixAutoConfiguration.java +++ b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/hystrix/SeataHystrixAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,18 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.seata.feign.hystrix; +import com.netflix.hystrix.HystrixCommand; + import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.netflix.hystrix.HystrixCommand; - /** * @author xiaojing */ - @Configuration @ConditionalOnClass(HystrixCommand.class) public class SeataHystrixAutoConfiguration { @@ -34,4 +34,4 @@ public class SeataHystrixAutoConfiguration { return new SeataHystrixConcurrencyStrategy(); } -} \ No newline at end of file +} diff --git a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/hystrix/SeataHystrixConcurrencyStrategy.java b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/hystrix/SeataHystrixConcurrencyStrategy.java index 0bff8173f..59253059c 100644 --- a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/hystrix/SeataHystrixConcurrencyStrategy.java +++ b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/hystrix/SeataHystrixConcurrencyStrategy.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.cloud.seata.feign.hystrix; import java.util.concurrent.Callable; import com.netflix.hystrix.strategy.HystrixPlugins; import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy; - import io.seata.core.context.RootContext; /** @@ -58,6 +58,7 @@ public class SeataHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy private static class SeataContextCallable implements Callable { private final Callable actual; + private final String xid; SeataContextCallable(Callable actual) { @@ -77,4 +78,5 @@ public class SeataHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy } } + } diff --git a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/rest/SeataRestTemplateAutoConfiguration.java b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/rest/SeataRestTemplateAutoConfiguration.java index 7dc05fdea..40c37af37 100644 --- a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/rest/SeataRestTemplateAutoConfiguration.java +++ b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/rest/SeataRestTemplateAutoConfiguration.java @@ -1,26 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - */ -/* - * Copyright (C) 2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/rest/SeataRestTemplateInterceptor.java b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/rest/SeataRestTemplateInterceptor.java index d90f1255b..829ef0797 100644 --- a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/rest/SeataRestTemplateInterceptor.java +++ b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/rest/SeataRestTemplateInterceptor.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,6 +18,8 @@ package com.alibaba.cloud.seata.rest; import java.io.IOException; +import io.seata.core.context.RootContext; + import org.springframework.http.HttpRequest; import org.springframework.http.client.ClientHttpRequestExecution; import org.springframework.http.client.ClientHttpRequestInterceptor; @@ -25,12 +27,11 @@ import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.support.HttpRequestWrapper; import org.springframework.util.StringUtils; -import io.seata.core.context.RootContext; - /** * @author xiaojing */ public class SeataRestTemplateInterceptor implements ClientHttpRequestInterceptor { + @Override public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, ClientHttpRequestExecution clientHttpRequestExecution) throws IOException { @@ -43,4 +44,5 @@ public class SeataRestTemplateInterceptor implements ClientHttpRequestIntercepto } return clientHttpRequestExecution.execute(requestWrapper, bytes); } + } diff --git a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/web/SeataHandlerInterceptor.java b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/web/SeataHandlerInterceptor.java index 9f50352aa..dcc0b28c0 100644 --- a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/web/SeataHandlerInterceptor.java +++ b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/web/SeataHandlerInterceptor.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,13 +19,13 @@ package com.alibaba.cloud.seata.web; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import io.seata.core.context.RootContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.util.StringUtils; import org.springframework.web.servlet.HandlerInterceptor; -import io.seata.core.context.RootContext; - /** * @author xiaojing * diff --git a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/web/SeataHandlerInterceptorConfiguration.java b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/web/SeataHandlerInterceptorConfiguration.java index 51757bf49..347b0de56 100644 --- a/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/web/SeataHandlerInterceptorConfiguration.java +++ b/spring-cloud-alibaba-seata/src/main/java/com/alibaba/cloud/seata/web/SeataHandlerInterceptorConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -28,4 +28,5 @@ public class SeataHandlerInterceptorConfiguration implements WebMvcConfigurer { public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new SeataHandlerInterceptor()).addPathPatterns("/**"); } + } diff --git a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/RuleType.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/RuleType.java index 4a376fd2b..12229a4e6 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/RuleType.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/RuleType.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,8 +19,6 @@ package com.alibaba.cloud.sentinel.datasource; import java.util.Arrays; import java.util.Optional; -import org.springframework.util.StringUtils; - import com.alibaba.cloud.sentinel.datasource.config.AbstractDataSourceProperties; import com.alibaba.csp.sentinel.slots.block.AbstractRule; import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule; @@ -29,57 +27,59 @@ import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule; import com.alibaba.csp.sentinel.slots.system.SystemRule; +import org.springframework.util.StringUtils; + /** * Enum for {@link AbstractRule} class, using in - * {@link AbstractDataSourceProperties#ruleType} + * {@link AbstractDataSourceProperties#ruleType}. * * @author Jim */ public enum RuleType { /** - * flow + * flow. */ FLOW("flow", FlowRule.class), /** - * degrade + * degrade. */ DEGRADE("degrade", DegradeRule.class), /** - * param flow + * param flow. */ PARAM_FLOW("param-flow", ParamFlowRule.class), /** - * system + * system. */ SYSTEM("system", SystemRule.class), /** - * authority + * authority. */ AUTHORITY("authority", AuthorityRule.class), /** - * gateway flow + * gateway flow. */ GW_FLOW("gw-flow", "com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule"), /** - * api + * api. */ GW_API_GROUP("gw-api-group", "com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition"); /** - * alias for {@link AbstractRule} + * alias for {@link AbstractRule}. */ private final String name; /** - * concrete {@link AbstractRule} class + * concrete {@link AbstractRule} class. */ private Class clazz; /** - * concrete {@link AbstractRule} class name + * concrete {@link AbstractRule} class name. */ private String clazzName; diff --git a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/SentinelDataSourceConstants.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/SentinelDataSourceConstants.java deleted file mode 100644 index 5240ba267..000000000 --- a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/SentinelDataSourceConstants.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.alibaba.cloud.sentinel.datasource; - -/** - * @author Jim - */ -public interface SentinelDataSourceConstants { - - String PROPERTY_PREFIX = "spring.cloud.sentinel"; - -} diff --git a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/AbstractDataSourceProperties.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/AbstractDataSourceProperties.java index df89dbd9e..a3f16fe0b 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/AbstractDataSourceProperties.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/AbstractDataSourceProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,8 +19,6 @@ package com.alibaba.cloud.sentinel.datasource.config; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; -import org.springframework.core.env.Environment; - import com.alibaba.cloud.sentinel.datasource.RuleType; import com.alibaba.csp.sentinel.adapter.gateway.common.api.GatewayApiDefinitionManager; import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager; @@ -30,11 +28,12 @@ import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager; import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager; import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRuleManager; import com.alibaba.csp.sentinel.slots.system.SystemRuleManager; - import com.fasterxml.jackson.annotation.JsonIgnore; +import org.springframework.core.env.Environment; + /** - * Abstract class Using by {@link DataSourcePropertiesConfiguration} + * Abstract class Using by {@link DataSourcePropertiesConfiguration}. * * @author Jim */ @@ -42,11 +41,15 @@ public class AbstractDataSourceProperties { @NotEmpty private String dataType = "json"; + @NotNull private RuleType ruleType; + private String converterClass; + @JsonIgnore private final String factoryBeanName; + @JsonIgnore private Environment env; @@ -121,4 +124,5 @@ public class AbstractDataSourceProperties { break; } } + } diff --git a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/ApolloDataSourceProperties.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/ApolloDataSourceProperties.java index d67baf049..7f1f9078e 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/ApolloDataSourceProperties.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/ApolloDataSourceProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,7 +22,7 @@ import com.alibaba.cloud.sentinel.datasource.factorybean.ApolloDataSourceFactory /** * Apollo Properties class Using by {@link DataSourcePropertiesConfiguration} and - * {@link ApolloDataSourceFactoryBean} + * {@link ApolloDataSourceFactoryBean}. * * @author Jim */ @@ -30,8 +30,10 @@ public class ApolloDataSourceProperties extends AbstractDataSourceProperties { @NotEmpty private String namespaceName; + @NotEmpty private String flowRulesKey; + private String defaultFlowRuleValue; public ApolloDataSourceProperties() { @@ -61,4 +63,5 @@ public class ApolloDataSourceProperties extends AbstractDataSourceProperties { public void setDefaultFlowRuleValue(String defaultFlowRuleValue) { this.defaultFlowRuleValue = defaultFlowRuleValue; } + } diff --git a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/DataSourcePropertiesConfiguration.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/DataSourcePropertiesConfiguration.java index 9726668f2..2c4f1d7b0 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/DataSourcePropertiesConfiguration.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/DataSourcePropertiesConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,10 +21,10 @@ import java.util.List; import java.util.Objects; import java.util.stream.Collectors; -import org.springframework.util.ObjectUtils; - import com.fasterxml.jackson.annotation.JsonIgnore; +import org.springframework.util.ObjectUtils; + /** * Using By ConfigurationProperties. * @@ -66,11 +66,11 @@ public class DataSourcePropertiesConfiguration { this.apollo = apollo; } - public DataSourcePropertiesConfiguration(RedisDataSourceProperties redis) { - this.redis = redis; - } + public DataSourcePropertiesConfiguration(RedisDataSourceProperties redis) { + this.redis = redis; + } - public FileDataSourceProperties getFile() { + public FileDataSourceProperties getFile() { return file; } diff --git a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/FileDataSourceProperties.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/FileDataSourceProperties.java index c8551c24c..318523fdf 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/FileDataSourceProperties.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/FileDataSourceProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,14 +20,14 @@ import java.io.IOException; import javax.validation.constraints.NotEmpty; +import com.alibaba.cloud.sentinel.datasource.factorybean.FileRefreshableDataSourceFactoryBean; + import org.springframework.util.ResourceUtils; import org.springframework.util.StringUtils; -import com.alibaba.cloud.sentinel.datasource.factorybean.FileRefreshableDataSourceFactoryBean; - /** * File Properties class Using by {@link DataSourcePropertiesConfiguration} and - * {@link FileRefreshableDataSourceFactoryBean} + * {@link FileRefreshableDataSourceFactoryBean}. * * @author Jim */ @@ -35,8 +35,11 @@ public class FileDataSourceProperties extends AbstractDataSourceProperties { @NotEmpty private String file; + private String charset = "utf-8"; + private long recommendRefreshMs = 3000L; + private int bufSize = 1024 * 1024; public FileDataSourceProperties() { @@ -90,4 +93,5 @@ public class FileDataSourceProperties extends AbstractDataSourceProperties { } } + } diff --git a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/NacosDataSourceProperties.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/NacosDataSourceProperties.java index f8673d0bf..cbb63e8ea 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/NacosDataSourceProperties.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/NacosDataSourceProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,13 +18,13 @@ package com.alibaba.cloud.sentinel.datasource.config; import javax.validation.constraints.NotEmpty; -import org.springframework.util.StringUtils; - import com.alibaba.cloud.sentinel.datasource.factorybean.NacosDataSourceFactoryBean; +import org.springframework.util.StringUtils; + /** * Nacos Properties class Using by {@link DataSourcePropertiesConfiguration} and - * {@link NacosDataSourceFactoryBean} + * {@link NacosDataSourceFactoryBean}. * * @author Jim */ @@ -39,8 +39,11 @@ public class NacosDataSourceProperties extends AbstractDataSourceProperties { private String dataId; private String endpoint; + private String namespace; + private String accessKey; + private String secretKey; public NacosDataSourceProperties() { diff --git a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/RedisDataSourceProperties.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/RedisDataSourceProperties.java index 8bea76251..984b6e2cd 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/RedisDataSourceProperties.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/RedisDataSourceProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -14,160 +14,161 @@ * limitations under the License. */ - package com.alibaba.cloud.sentinel.datasource.config; -import com.alibaba.cloud.sentinel.datasource.factorybean.RedisDataSourceFactoryBean; -import org.springframework.util.StringUtils; - import java.time.Duration; import java.util.List; +import com.alibaba.cloud.sentinel.datasource.factorybean.RedisDataSourceFactoryBean; + +import org.springframework.util.StringUtils; + /** * Zookeeper Properties class Using by {@link DataSourcePropertiesConfiguration} and - * {@link RedisDataSourceFactoryBean} + * {@link RedisDataSourceFactoryBean}. * * @author lengleng */ public class RedisDataSourceProperties extends AbstractDataSourceProperties { - public RedisDataSourceProperties() { - super(RedisDataSourceFactoryBean.class.getName()); - } - - /** - * redis server host - */ - private String host = "localhost"; - - /** - * redis server port - */ - private int port = 6379; - - /** - * redis server password - */ - private String password; - - /** - * redis server default select database - */ - private int database; - - /** - * redis server timeout - */ - private Duration timeout; - - /** - * Comma-separated list of "host:port" pairs. - */ - private List nodes; - - /** - * data key in Redis - */ - private String ruleKey; - - /** - * channel to subscribe in Redis - */ - private String channel; - - /** - * redis sentinel model - */ - private String masterId; - - @Override - public void preCheck(String dataSourceName) { - super.preCheck(dataSourceName); - if (StringUtils.isEmpty(ruleKey)) { - throw new IllegalArgumentException( - "RedisDataSource ruleKey can not be empty"); - } - - if (StringUtils.isEmpty(channel)) { - throw new IllegalArgumentException( - "RedisDataSource channel can not be empty"); - } - - if (!StringUtils.isEmpty(masterId) && StringUtils.isEmpty(masterId)) { - throw new IllegalArgumentException( - "RedisDataSource sentinel model,masterId can not be empty"); - } - } - - public String getHost() { - return host; - } - - public void setHost(String host) { - this.host = host; - } - - public int getPort() { - return port; - } - - public void setPort(int port) { - this.port = port; - } - - public String getRuleKey() { - return ruleKey; - } - - public void setRuleKey(String ruleKey) { - this.ruleKey = ruleKey; - } - - public String getChannel() { - return channel; - } - - public void setChannel(String channel) { - this.channel = channel; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public int getDatabase() { - return database; - } - - public void setDatabase(int database) { - this.database = database; - } - - public Duration getTimeout() { - return timeout; - } - - public void setTimeout(Duration timeout) { - this.timeout = timeout; - } - - public List getNodes() { - return nodes; - } - - public void setNodes(List nodes) { - this.nodes = nodes; - } - - public String getMasterId() { - return masterId; - } - - public void setMasterId(String masterId) { - this.masterId = masterId; - } + public RedisDataSourceProperties() { + super(RedisDataSourceFactoryBean.class.getName()); + } + + /** + * redis server host. + */ + private String host = "localhost"; + + /** + * redis server port. + */ + private int port = 6379; + + /** + * redis server password. + */ + private String password; + + /** + * redis server default select database. + */ + private int database; + + /** + * redis server timeout. + */ + private Duration timeout; + + /** + * Comma-separated list of "host:port" pairs. + */ + private List nodes; + + /** + * data key in Redis. + */ + private String ruleKey; + + /** + * channel to subscribe in Redis. + */ + private String channel; + + /** + * redis sentinel model. + */ + private String masterId; + + @Override + public void preCheck(String dataSourceName) { + super.preCheck(dataSourceName); + if (StringUtils.isEmpty(ruleKey)) { + throw new IllegalArgumentException( + "RedisDataSource ruleKey can not be empty"); + } + + if (StringUtils.isEmpty(channel)) { + throw new IllegalArgumentException( + "RedisDataSource channel can not be empty"); + } + + if (!StringUtils.isEmpty(masterId) && StringUtils.isEmpty(masterId)) { + throw new IllegalArgumentException( + "RedisDataSource sentinel model,masterId can not be empty"); + } + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getRuleKey() { + return ruleKey; + } + + public void setRuleKey(String ruleKey) { + this.ruleKey = ruleKey; + } + + public String getChannel() { + return channel; + } + + public void setChannel(String channel) { + this.channel = channel; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public int getDatabase() { + return database; + } + + public void setDatabase(int database) { + this.database = database; + } + + public Duration getTimeout() { + return timeout; + } + + public void setTimeout(Duration timeout) { + this.timeout = timeout; + } + + public List getNodes() { + return nodes; + } + + public void setNodes(List nodes) { + this.nodes = nodes; + } + + public String getMasterId() { + return masterId; + } + + public void setMasterId(String masterId) { + this.masterId = masterId; + } + } diff --git a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/ZookeeperDataSourceProperties.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/ZookeeperDataSourceProperties.java index 3de046bc4..d0d7b8b83 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/ZookeeperDataSourceProperties.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/ZookeeperDataSourceProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,13 @@ package com.alibaba.cloud.sentinel.datasource.config; -import org.springframework.util.StringUtils; - import com.alibaba.cloud.sentinel.datasource.factorybean.ZookeeperDataSourceFactoryBean; +import org.springframework.util.StringUtils; + /** * Zookeeper Properties class Using by {@link DataSourcePropertiesConfiguration} and - * {@link ZookeeperDataSourceFactoryBean} + * {@link ZookeeperDataSourceFactoryBean}. * * @author Jim */ @@ -83,4 +83,5 @@ public class ZookeeperDataSourceProperties extends AbstractDataSourceProperties public void setDataId(String dataId) { this.dataId = dataId; } + } diff --git a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/converter/JsonConverter.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/converter/JsonConverter.java index 7ffd4ef71..298ce492b 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/converter/JsonConverter.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/converter/JsonConverter.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,11 +21,10 @@ import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule; import com.alibaba.csp.sentinel.slots.system.SystemRule; - import com.fasterxml.jackson.databind.ObjectMapper; /** - * Convert sentinel rules for json array Using strict mode to parse json + * Convert sentinel rules for json array Using strict mode to parse json. * * @author Jim * @see FlowRule diff --git a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/converter/SentinelConverter.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/converter/SentinelConverter.java index cf2645cda..306dd1a0b 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/converter/SentinelConverter.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/converter/SentinelConverter.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,22 +24,21 @@ import java.util.HashSet; import java.util.List; import java.util.Optional; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.util.StringUtils; - import com.alibaba.csp.sentinel.datasource.Converter; import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule; import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule; import com.alibaba.csp.sentinel.slots.system.SystemRule; - import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.util.StringUtils; /** - * Convert sentinel rules for json or xml array Using strict mode to parse json or xml + * Convert sentinel rules for json or xml array Using strict mode to parse json or xml. * * @author Jim * @see FlowRule diff --git a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/converter/XmlConverter.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/converter/XmlConverter.java index 770413c1d..91ec15600 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/converter/XmlConverter.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/converter/XmlConverter.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,12 +21,11 @@ import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule; import com.alibaba.csp.sentinel.slots.system.SystemRule; - import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.xml.XmlMapper; /** - * Convert sentinel rules for xml array Using strict mode to parse xml + * Convert sentinel rules for xml array Using strict mode to parse xml. * * @author Jim * @see FlowRule diff --git a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/factorybean/ApolloDataSourceFactoryBean.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/factorybean/ApolloDataSourceFactoryBean.java index 47843e5c4..4272db5c2 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/factorybean/ApolloDataSourceFactoryBean.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/factorybean/ApolloDataSourceFactoryBean.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,11 +16,11 @@ package com.alibaba.cloud.sentinel.datasource.factorybean; -import org.springframework.beans.factory.FactoryBean; - import com.alibaba.csp.sentinel.datasource.Converter; import com.alibaba.csp.sentinel.datasource.apollo.ApolloDataSource; +import org.springframework.beans.factory.FactoryBean; + /** * A {@link FactoryBean} for creating {@link ApolloDataSource} instance. * @@ -30,8 +30,11 @@ import com.alibaba.csp.sentinel.datasource.apollo.ApolloDataSource; public class ApolloDataSourceFactoryBean implements FactoryBean { private String namespaceName; + private String flowRulesKey; + private String defaultFlowRuleValue; + private Converter converter; @Override @@ -76,4 +79,5 @@ public class ApolloDataSourceFactoryBean implements FactoryBean { private String file; + private String charset; + private long recommendRefreshMs; + private int bufSize; + private Converter converter; @Override @@ -89,4 +93,5 @@ public class FileRefreshableDataSourceFactoryBean public void setConverter(Converter converter) { this.converter = converter; } + } diff --git a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/factorybean/NacosDataSourceFactoryBean.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/factorybean/NacosDataSourceFactoryBean.java index da640f8e5..f94c5fc6a 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/factorybean/NacosDataSourceFactoryBean.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/factorybean/NacosDataSourceFactoryBean.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,13 +18,13 @@ package com.alibaba.cloud.sentinel.datasource.factorybean; import java.util.Properties; -import org.springframework.beans.factory.FactoryBean; -import org.springframework.util.StringUtils; - import com.alibaba.csp.sentinel.datasource.Converter; import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource; import com.alibaba.nacos.api.PropertyKeyConst; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.util.StringUtils; + /** * A {@link FactoryBean} for creating {@link NacosDataSource} instance. * @@ -34,13 +34,19 @@ import com.alibaba.nacos.api.PropertyKeyConst; public class NacosDataSourceFactoryBean implements FactoryBean { private String serverAddr; + private String groupId; + private String dataId; + private Converter converter; private String endpoint; + private String namespace; + private String accessKey; + private String secretKey; @Override @@ -128,4 +134,5 @@ public class NacosDataSourceFactoryBean implements FactoryBean public void setSecretKey(String secretKey) { this.secretKey = secretKey; } + } diff --git a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/factorybean/RedisDataSourceFactoryBean.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/factorybean/RedisDataSourceFactoryBean.java index bbf8435bc..98967fa15 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/factorybean/RedisDataSourceFactoryBean.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/factorybean/RedisDataSourceFactoryBean.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,17 +16,18 @@ package com.alibaba.cloud.sentinel.datasource.factorybean; +import java.time.Duration; +import java.util.List; + import com.alibaba.csp.sentinel.datasource.Converter; import com.alibaba.csp.sentinel.datasource.redis.RedisDataSource; import com.alibaba.csp.sentinel.datasource.redis.config.RedisConnectionConfig; import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; + import org.springframework.beans.factory.FactoryBean; import org.springframework.util.Assert; import org.springframework.util.StringUtils; -import java.time.Duration; -import java.util.List; - /** * A {@link FactoryBean} for creating {@link RedisDataSource} instance. * @@ -35,152 +36,155 @@ import java.util.List; */ public class RedisDataSourceFactoryBean implements FactoryBean { - private String host; - - private int port; - - private int database; - - private Duration timeout; - - /** - * Comma-separated list of "host:port" pairs. - */ - private List nodes; - - private Converter converter; - - /** - * data key in Redis - */ - private String ruleKey; - - /** - * channel to subscribe in Redis - */ - private String channel; - - /** - * redis server password - */ - private String password; + private String host; + + private int port; + + private int database; + + private Duration timeout; + + /** + * Comma-separated list of "host:port" pairs. + */ + private List nodes; + + private Converter converter; + + /** + * data key in Redis. + */ + private String ruleKey; + + /** + * channel to subscribe in Redis. + */ + private String channel; + + /** + * redis server password. + */ + private String password; + + private String masterId; + + @Override + public RedisDataSource getObject() { + RedisConnectionConfig.Builder builder = RedisConnectionConfig.builder(); + + if (nodes == null || nodes.isEmpty()) { + builder.withHost(host).withPort(port).withDatabase(database); + } + else { + nodes.forEach(node -> { + try { + String[] parts = StringUtils.split(node, ":"); + Assert.state(parts.length == 2, "Must be defined as 'host:port'"); + builder.withRedisSentinel(parts[0], Integer.parseInt(parts[1])); + } + catch (RuntimeException ex) { + throw new IllegalStateException( + "Invalid redis sentinel property " + node, ex); + } + }); + builder.withSentinelMasterId(masterId); + } + + if (timeout != null) { + builder.withTimeout(timeout.toMillis()); + } + + if (StringUtils.hasText(password)) { + builder.withPassword(password); + } + + return new RedisDataSource>(builder.build(), ruleKey, channel, + converter); + } + + @Override + public Class getObjectType() { + return RedisDataSource.class; + } + + public Converter getConverter() { + return converter; + } + + public void setConverter(Converter converter) { + this.converter = converter; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getRuleKey() { + return ruleKey; + } + + public void setRuleKey(String ruleKey) { + this.ruleKey = ruleKey; + } + + public String getChannel() { + return channel; + } + + public void setChannel(String channel) { + this.channel = channel; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public int getDatabase() { + return database; + } + + public void setDatabase(int database) { + this.database = database; + } + + public Duration getTimeout() { + return timeout; + } + + public void setTimeout(Duration timeout) { + this.timeout = timeout; + } + + public List getNodes() { + return nodes; + } + + public void setNodes(List nodes) { + this.nodes = nodes; + } + + public String getMasterId() { + return masterId; + } + + public void setMasterId(String masterId) { + this.masterId = masterId; + } - private String masterId; - - @Override - public RedisDataSource getObject() { - RedisConnectionConfig.Builder builder = RedisConnectionConfig.builder(); - - if (nodes == null || nodes.isEmpty()) { - builder.withHost(host) - .withPort(port) - .withDatabase(database); - } else { - nodes.forEach(node -> { - try { - String[] parts = StringUtils.split(node, ":"); - Assert.state(parts.length == 2, "Must be defined as 'host:port'"); - builder.withRedisSentinel(parts[0], Integer.parseInt(parts[1])); - } catch (RuntimeException ex) { - throw new IllegalStateException("Invalid redis sentinel property " + node, ex); - } - }); - builder.withSentinelMasterId(masterId); - } - - if (timeout != null) { - builder.withTimeout(timeout.toMillis()); - } - - if (StringUtils.hasText(password)) { - builder.withPassword(password); - } - - return new RedisDataSource>(builder.build(), ruleKey, channel, converter); - } - - @Override - public Class getObjectType() { - return RedisDataSource.class; - } - - public Converter getConverter() { - return converter; - } - - public void setConverter(Converter converter) { - this.converter = converter; - } - - public String getHost() { - return host; - } - - public void setHost(String host) { - this.host = host; - } - - public int getPort() { - return port; - } - - public void setPort(int port) { - this.port = port; - } - - public String getRuleKey() { - return ruleKey; - } - - public void setRuleKey(String ruleKey) { - this.ruleKey = ruleKey; - } - - public String getChannel() { - return channel; - } - - public void setChannel(String channel) { - this.channel = channel; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public int getDatabase() { - return database; - } - - public void setDatabase(int database) { - this.database = database; - } - - public Duration getTimeout() { - return timeout; - } - - public void setTimeout(Duration timeout) { - this.timeout = timeout; - } - - public List getNodes() { - return nodes; - } - - public void setNodes(List nodes) { - this.nodes = nodes; - } - - public String getMasterId() { - return masterId; - } - - public void setMasterId(String masterId) { - this.masterId = masterId; - } } diff --git a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/factorybean/ZookeeperDataSourceFactoryBean.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/factorybean/ZookeeperDataSourceFactoryBean.java index 5731d8f12..d9b514038 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/factorybean/ZookeeperDataSourceFactoryBean.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/factorybean/ZookeeperDataSourceFactoryBean.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,11 +16,11 @@ package com.alibaba.cloud.sentinel.datasource.factorybean; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.FactoryBean; - import com.alibaba.csp.sentinel.datasource.Converter; import com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource; +import org.apache.commons.lang3.StringUtils; + +import org.springframework.beans.factory.FactoryBean; /** * A {@link FactoryBean} for creating {@link ZookeeperDataSource} instance. @@ -35,6 +35,7 @@ public class ZookeeperDataSourceFactoryBean implements FactoryBeanJim @@ -35,7 +34,9 @@ import com.alibaba.csp.sentinel.datasource.apollo.ApolloDataSource; public class ApolloDataSourceFactoryBeanTests { private String flowRuleKey = "sentinel"; + private String namespace = "namespace"; + private String defaultFlowValue = "{}"; @Test @@ -54,18 +55,12 @@ public class ApolloDataSourceFactoryBeanTests { when(apolloDataSource.readSource()).thenReturn("{}"); doReturn(apolloDataSource).when(factoryBean).getObject(); - assertEquals("ApolloDataSourceFactoryBean getObject error", apolloDataSource, - factoryBean.getObject()); - assertEquals("ApolloDataSource read source value was wrong", "{}", - factoryBean.getObject().readSource()); - assertEquals("ApolloDataSource converter was wrong", converter, - factoryBean.getConverter()); - assertEquals("ApolloDataSourceFactoryBean flowRuleKey was wrong", flowRuleKey, - factoryBean.getFlowRulesKey()); - assertEquals("ApolloDataSourceFactoryBean namespace was wrong", namespace, - factoryBean.getNamespaceName()); - assertEquals("ApolloDataSourceFactoryBean defaultFlowValue was wrong", - defaultFlowValue, factoryBean.getDefaultFlowRuleValue()); + assertThat(factoryBean.getObject()).isEqualTo(apolloDataSource); + assertThat(factoryBean.getObject().readSource()).isEqualTo("{}"); + assertThat(factoryBean.getConverter()).isEqualTo(converter); + assertThat(factoryBean.getFlowRulesKey()).isEqualTo(flowRuleKey); + assertThat(factoryBean.getNamespaceName()).isEqualTo(namespace); + assertThat(factoryBean.getDefaultFlowRuleValue()).isEqualTo(defaultFlowValue); } } diff --git a/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/DataSourcePropertiesConfigurationTests.java b/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/DataSourcePropertiesConfigurationTests.java deleted file mode 100644 index 903bb3779..000000000 --- a/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/DataSourcePropertiesConfigurationTests.java +++ /dev/null @@ -1,250 +0,0 @@ -/// * -// * Copyright (C) 2018 the original author or authors. -// * -// * Licensed under the Apache License, Version 2.0 (the "License"); -// * you may not use this file except in compliance with the License. -// * You may obtain a copy of the License at -// * -// * http://www.apache.org/licenses/LICENSE-2.0 -// * -// * 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.alibaba.cloud.sentinel.datasource; -// -// import static org.junit.Assert.assertEquals; -// import static org.junit.Assert.assertNotNull; -// import static org.junit.Assert.assertNull; -// -// import org.junit.Test; -// import ApolloDataSourceProperties; -// import DataSourcePropertiesConfiguration; -// import FileDataSourceProperties; -// import NacosDataSourceProperties; -// import ZookeeperDataSourceProperties; -// -/// ** -// * @author Jim -// */ -// public class DataSourcePropertiesConfigurationTests { -// -// @Test -// public void testFileAttr() { -// DataSourcePropertiesConfiguration dataSourcePropertiesConfiguration = new -/// DataSourcePropertiesConfiguration(); -// assertEquals("DataSourcePropertiesConfiguration valid field size was wrong", 0, -// dataSourcePropertiesConfiguration.getValidField().size()); -// assertNull("DataSourcePropertiesConfiguration valid properties was not null", -// dataSourcePropertiesConfiguration.getValidDataSourceProperties()); -// -// FileDataSourceProperties fileDataSourceProperties = buildFileProperties(); -// -// dataSourcePropertiesConfiguration.setFile(fileDataSourceProperties); -// -// assertEquals( -// "DataSourcePropertiesConfiguration valid field size was wrong after set file -/// attribute", -// 1, dataSourcePropertiesConfiguration.getValidField().size()); -// assertNotNull( -// "DataSourcePropertiesConfiguration file properties was null after set file attribute", -// dataSourcePropertiesConfiguration.getFile()); -// assertNotNull( -// "DataSourcePropertiesConfiguration valid properties was null after set file attribute", -// dataSourcePropertiesConfiguration.getValidDataSourceProperties()); -// } -// -// @Test -// public void testNacosAttr() { -// DataSourcePropertiesConfiguration dataSourcePropertiesConfiguration = new -/// DataSourcePropertiesConfiguration(); -// assertEquals("DataSourcePropertiesConfiguration valid field size was wrong", 0, -// dataSourcePropertiesConfiguration.getValidField().size()); -// assertNull("DataSourcePropertiesConfiguration valid properties was not null", -// dataSourcePropertiesConfiguration.getValidDataSourceProperties()); -// -// NacosDataSourceProperties nacosDataSourceProperties = buildNacosProperties(); -// -// dataSourcePropertiesConfiguration.setNacos(nacosDataSourceProperties); -// -// assertEquals( -// "DataSourcePropertiesConfiguration valid field size was wrong after set nacos -/// attribute", -// 1, dataSourcePropertiesConfiguration.getValidField().size()); -// assertNotNull( -// "DataSourcePropertiesConfiguration nacos properties was null after set nacos -/// attribute", -// dataSourcePropertiesConfiguration.getNacos()); -// assertNotNull( -// "DataSourcePropertiesConfiguration valid properties was null after set nacos -/// attribute", -// dataSourcePropertiesConfiguration.getValidDataSourceProperties()); -// } -// -// @Test -// public void testZKAttr() { -// DataSourcePropertiesConfiguration dataSourcePropertiesConfiguration = new -/// DataSourcePropertiesConfiguration(); -// assertEquals("DataSourcePropertiesConfiguration valid field size was wrong", 0, -// dataSourcePropertiesConfiguration.getValidField().size()); -// assertNull("DataSourcePropertiesConfiguration valid properties was not null", -// dataSourcePropertiesConfiguration.getValidDataSourceProperties()); -// -// ZookeeperDataSourceProperties zookeeperDataSourceProperties = buildZKProperties(); -// -// dataSourcePropertiesConfiguration.setZk(zookeeperDataSourceProperties); -// -// assertEquals( -// "DataSourcePropertiesConfiguration valid field size was wrong after set zk attribute", -// 1, dataSourcePropertiesConfiguration.getValidField().size()); -// assertNotNull( -// "DataSourcePropertiesConfiguration zk properties was null after set zk attribute", -// dataSourcePropertiesConfiguration.getZk()); -// assertNotNull( -// "DataSourcePropertiesConfiguration valid properties was null after set zk attribute", -// dataSourcePropertiesConfiguration.getValidDataSourceProperties()); -// } -// -// @Test -// public void testApolloAttr() { -// DataSourcePropertiesConfiguration dataSourcePropertiesConfiguration = new -/// DataSourcePropertiesConfiguration(); -// assertEquals("DataSourcePropertiesConfiguration valid field size was wrong", 0, -// dataSourcePropertiesConfiguration.getValidField().size()); -// assertNull("DataSourcePropertiesConfiguration valid properties was not null", -// dataSourcePropertiesConfiguration.getValidDataSourceProperties()); -// -// ApolloDataSourceProperties apolloDataSourceProperties = buildApolloProperties(); -// -// dataSourcePropertiesConfiguration.setApollo(apolloDataSourceProperties); -// -// assertEquals( -// "DataSourcePropertiesConfiguration valid field size was wrong after set apollo -/// attribute", -// 1, dataSourcePropertiesConfiguration.getValidField().size()); -// assertNotNull( -// "DataSourcePropertiesConfiguration apollo properties was null after set apollo -/// attribute", -// dataSourcePropertiesConfiguration.getApollo()); -// assertNotNull( -// "DataSourcePropertiesConfiguration valid properties was null after set apollo -/// attribute", -// dataSourcePropertiesConfiguration.getValidDataSourceProperties()); -// } -// -// @Test -// public void testMultiAttr() { -// DataSourcePropertiesConfiguration dataSourcePropertiesConfiguration = new -/// DataSourcePropertiesConfiguration(); -// assertEquals("DataSourcePropertiesConfiguration valid field size was wrong", 0, -// dataSourcePropertiesConfiguration.getValidField().size()); -// assertNull("DataSourcePropertiesConfiguration valid properties was not null", -// dataSourcePropertiesConfiguration.getValidDataSourceProperties()); -// -// FileDataSourceProperties fileDataSourceProperties = buildFileProperties(); -// NacosDataSourceProperties nacosDataSourceProperties = buildNacosProperties(); -// -// dataSourcePropertiesConfiguration.setFile(fileDataSourceProperties); -// dataSourcePropertiesConfiguration.setNacos(nacosDataSourceProperties); -// -// assertEquals( -// "DataSourcePropertiesConfiguration valid field size was wrong after set file and nacos -/// attribute", -// 2, dataSourcePropertiesConfiguration.getValidField().size()); -// assertNull( -// "DataSourcePropertiesConfiguration valid properties was not null after set file and -/// nacos attribute", -// dataSourcePropertiesConfiguration.getValidDataSourceProperties()); -// } -// -// @Test -// public void testFileConstructor() { -// DataSourcePropertiesConfiguration dataSourcePropertiesConfiguration = new -/// DataSourcePropertiesConfiguration( -// buildFileProperties()); -// assertEquals( -// "DataSourcePropertiesConfiguration file constructor valid field size was wrong", -// 1, dataSourcePropertiesConfiguration.getValidField().size()); -// assertNotNull( -// "DataSourcePropertiesConfiguration file constructor valid properties was null", -// dataSourcePropertiesConfiguration.getValidDataSourceProperties()); -// } -// -// @Test -// public void testNacosConstructor() { -// DataSourcePropertiesConfiguration dataSourcePropertiesConfiguration = new -/// DataSourcePropertiesConfiguration( -// buildNacosProperties()); -// assertEquals( -// "DataSourcePropertiesConfiguration nacos constructor valid field size was wrong", -// 1, dataSourcePropertiesConfiguration.getValidField().size()); -// assertNotNull( -// "DataSourcePropertiesConfiguration nacos constructor valid properties was null", -// dataSourcePropertiesConfiguration.getValidDataSourceProperties()); -// } -// -// @Test -// public void testApolloConstructor() { -// DataSourcePropertiesConfiguration dataSourcePropertiesConfiguration = new -/// DataSourcePropertiesConfiguration( -// buildApolloProperties()); -// assertEquals( -// "DataSourcePropertiesConfiguration apollo constructor valid field size was wrong", -// 1, dataSourcePropertiesConfiguration.getValidField().size()); -// assertNotNull( -// "DataSourcePropertiesConfiguration apollo constructor valid properties was null", -// dataSourcePropertiesConfiguration.getValidDataSourceProperties()); -// } -// -// @Test -// public void testZKConstructor() { -// DataSourcePropertiesConfiguration dataSourcePropertiesConfiguration = new -/// DataSourcePropertiesConfiguration( -// buildZKProperties()); -// assertEquals( -// "DataSourcePropertiesConfiguration zk constructor valid field size was wrong", -// 1, dataSourcePropertiesConfiguration.getValidField().size()); -// assertNotNull( -// "DataSourcePropertiesConfiguration zk constructor valid properties was null", -// dataSourcePropertiesConfiguration.getValidDataSourceProperties()); -// } -// -// private FileDataSourceProperties buildFileProperties() { -// FileDataSourceProperties fileDataSourceProperties = new FileDataSourceProperties(); -// -// fileDataSourceProperties.setFile("/tmp/test.json"); -// fileDataSourceProperties.setBufSize(1024); -// fileDataSourceProperties.setRecommendRefreshMs(2000); -// return fileDataSourceProperties; -// } -// -// private NacosDataSourceProperties buildNacosProperties() { -// NacosDataSourceProperties nacosDataSourceProperties = new NacosDataSourceProperties(); -// nacosDataSourceProperties.setServerAddr("127.0.0.1:8848"); -// nacosDataSourceProperties.setDataId("sentinel"); -// nacosDataSourceProperties.setGroupId("custom-group"); -// return nacosDataSourceProperties; -// } -// -// private ApolloDataSourceProperties buildApolloProperties() { -// ApolloDataSourceProperties apolloDataSourceProperties = new -/// ApolloDataSourceProperties(); -// apolloDataSourceProperties.setFlowRulesKey("test-key"); -// apolloDataSourceProperties.setDefaultFlowRuleValue("dft-val"); -// apolloDataSourceProperties.setNamespaceName("namespace"); -// return apolloDataSourceProperties; -// } -// -// private ZookeeperDataSourceProperties buildZKProperties() { -// ZookeeperDataSourceProperties zookeeperDataSourceProperties = new -/// ZookeeperDataSourceProperties(); -// -// zookeeperDataSourceProperties.setServerAddr("localhost:2181"); -// zookeeperDataSourceProperties.setPath("/path"); -// return zookeeperDataSourceProperties; -// } -// -// } diff --git a/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/DataSourcePropertiesTests.java b/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/DataSourcePropertiesTests.java index 86384e6ab..3b4ebc993 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/DataSourcePropertiesTests.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/DataSourcePropertiesTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,17 +16,9 @@ package com.alibaba.cloud.sentinel.datasource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - import java.io.IOException; import java.util.List; -import org.junit.Assert; -import org.junit.Test; -import org.springframework.util.ResourceUtils; -import org.springframework.util.StringUtils; - import com.alibaba.cloud.sentinel.datasource.config.ApolloDataSourceProperties; import com.alibaba.cloud.sentinel.datasource.config.FileDataSourceProperties; import com.alibaba.cloud.sentinel.datasource.config.ZookeeperDataSourceProperties; @@ -37,9 +29,14 @@ import com.alibaba.csp.sentinel.datasource.Converter; import com.alibaba.csp.sentinel.datasource.FileRefreshableDataSource; import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager; - import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Test; + +import org.springframework.util.ResourceUtils; +import org.springframework.util.StringUtils; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Jim @@ -53,21 +50,16 @@ public class DataSourcePropertiesTests { apolloDataSourceProperties.setDefaultFlowRuleValue("dft-val"); apolloDataSourceProperties.setNamespaceName("namespace"); apolloDataSourceProperties.setRuleType(RuleType.DEGRADE); - assertEquals("Apollo flow rule key was wrong", "test-key", - apolloDataSourceProperties.getFlowRulesKey()); - assertEquals("Apollo namespace was wrong", "namespace", - apolloDataSourceProperties.getNamespaceName()); - assertEquals("Apollo default data type was wrong", "json", - apolloDataSourceProperties.getDataType()); - Assert.assertEquals("Apollo rule type was wrong", RuleType.DEGRADE, - apolloDataSourceProperties.getRuleType()); - assertEquals("Apollo default flow value was wrong", "dft-val", - apolloDataSourceProperties.getDefaultFlowRuleValue()); - assertEquals("Apollo factory bean was wrong", - ApolloDataSourceFactoryBean.class.getName(), - apolloDataSourceProperties.getFactoryBeanName()); - assertNull("Apollo converterClass was not null", - apolloDataSourceProperties.getConverterClass()); + + assertThat(apolloDataSourceProperties.getFlowRulesKey()).isEqualTo("test-key"); + assertThat(apolloDataSourceProperties.getNamespaceName()).isEqualTo("namespace"); + assertThat(apolloDataSourceProperties.getDataType()).isEqualTo("json"); + assertThat(apolloDataSourceProperties.getRuleType()).isEqualTo(RuleType.DEGRADE); + assertThat(apolloDataSourceProperties.getDefaultFlowRuleValue()) + .isEqualTo("dft-val"); + assertThat(apolloDataSourceProperties.getFactoryBeanName()) + .isEqualTo(ApolloDataSourceFactoryBean.class.getName()); + assertThat(apolloDataSourceProperties.getConverterClass()).isNull(); } @Test @@ -81,21 +73,17 @@ public class DataSourcePropertiesTests { zookeeperDataSourceProperties.setConverterClass("test.ConverterClass"); zookeeperDataSourceProperties.setRuleType(RuleType.AUTHORITY); - assertEquals("ZK serverAddr was wrong", "localhost:2181", - zookeeperDataSourceProperties.getServerAddr()); - assertEquals("ZK groupId was wrong", "groupId", - zookeeperDataSourceProperties.getGroupId()); - assertEquals("ZK dataId was wrong", "dataId", - zookeeperDataSourceProperties.getDataId()); - assertEquals("ZK path was wrong", "/path", - zookeeperDataSourceProperties.getPath()); - assertEquals("ZK factory bean was wrong", - ZookeeperDataSourceFactoryBean.class.getName(), - zookeeperDataSourceProperties.getFactoryBeanName()); - assertEquals("ZK custom converter class was wrong", "test.ConverterClass", - zookeeperDataSourceProperties.getConverterClass()); - Assert.assertEquals("ZK rule type was wrong", RuleType.AUTHORITY, - zookeeperDataSourceProperties.getRuleType()); + assertThat(zookeeperDataSourceProperties.getServerAddr()) + .isEqualTo("localhost:2181"); + assertThat(zookeeperDataSourceProperties.getGroupId()).isEqualTo("groupId"); + assertThat(zookeeperDataSourceProperties.getDataId()).isEqualTo("dataId"); + assertThat(zookeeperDataSourceProperties.getPath()).isEqualTo("/path"); + assertThat(zookeeperDataSourceProperties.getFactoryBeanName()) + .isEqualTo(ZookeeperDataSourceFactoryBean.class.getName()); + assertThat(zookeeperDataSourceProperties.getConverterClass()) + .isEqualTo("test.ConverterClass"); + assertThat(zookeeperDataSourceProperties.getRuleType()) + .isEqualTo(RuleType.AUTHORITY); } @Test @@ -105,19 +93,13 @@ public class DataSourcePropertiesTests { fileDataSourceProperties.setFile("/tmp/test.json"); fileDataSourceProperties.setRuleType(RuleType.PARAM_FLOW); - assertEquals("File path was wrong", "/tmp/test.json", - fileDataSourceProperties.getFile()); - assertEquals("File charset was wrong", "utf-8", - fileDataSourceProperties.getCharset()); - assertEquals("File refresh time was wrong", 3000L, - fileDataSourceProperties.getRecommendRefreshMs()); - assertEquals("File buf size was wrong", 1024 * 1024, - fileDataSourceProperties.getBufSize()); - assertEquals("File factory bean was wrong", - FileRefreshableDataSourceFactoryBean.class.getName(), - fileDataSourceProperties.getFactoryBeanName()); - Assert.assertEquals("File rule type was wrong", RuleType.PARAM_FLOW, - fileDataSourceProperties.getRuleType()); + assertThat(fileDataSourceProperties.getFile()).isEqualTo("/tmp/test.json"); + assertThat(fileDataSourceProperties.getCharset()).isEqualTo("utf-8"); + assertThat(fileDataSourceProperties.getRecommendRefreshMs()).isEqualTo(3000L); + assertThat(fileDataSourceProperties.getBufSize()).isEqualTo(1024 * 1024); + assertThat(fileDataSourceProperties.getFactoryBeanName()) + .isEqualTo(FileRefreshableDataSourceFactoryBean.class.getName()); + assertThat(fileDataSourceProperties.getRuleType()).isEqualTo(RuleType.PARAM_FLOW); } @Test @@ -129,14 +111,10 @@ public class DataSourcePropertiesTests { fileDataSourceProperties.setRecommendRefreshMs(2000); fileDataSourceProperties.setCharset("ISO8859-1"); - assertEquals("File path was wrong", "/tmp/test.json", - fileDataSourceProperties.getFile()); - assertEquals("File charset was wrong", "ISO8859-1", - fileDataSourceProperties.getCharset()); - assertEquals("File refresh time was wrong", 2000L, - fileDataSourceProperties.getRecommendRefreshMs()); - assertEquals("File buf size was wrong", 1024, - fileDataSourceProperties.getBufSize()); + assertThat(fileDataSourceProperties.getFile()).isEqualTo("/tmp/test.json"); + assertThat(fileDataSourceProperties.getCharset()).isEqualTo("ISO8859-1"); + assertThat(fileDataSourceProperties.getRecommendRefreshMs()).isEqualTo(2000L); + assertThat(fileDataSourceProperties.getBufSize()).isEqualTo(1024); } @Test(expected = RuntimeException.class) @@ -175,8 +153,8 @@ public class DataSourcePropertiesTests { } }); fileDataSourceProperties.postRegister(fileRefreshableDataSource); - assertEquals("DataSourceProperties postRegister error", - fileRefreshableDataSource.loadConfig(), FlowRuleManager.getRules()); + assertThat(FlowRuleManager.getRules()) + .isEqualTo(fileRefreshableDataSource.loadConfig()); } } diff --git a/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/FileRefreshableDataSourceFactoryBeanTests.java b/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/FileRefreshableDataSourceFactoryBeanTests.java index 5e49678ef..25bad0449 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/FileRefreshableDataSourceFactoryBeanTests.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/FileRefreshableDataSourceFactoryBeanTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,26 +16,24 @@ package com.alibaba.cloud.sentinel.datasource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - import java.io.FileNotFoundException; import java.io.IOException; import java.util.List; -import org.junit.Test; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.util.ResourceUtils; - import com.alibaba.cloud.sentinel.datasource.factorybean.FileRefreshableDataSourceFactoryBean; import com.alibaba.csp.sentinel.datasource.Converter; import com.alibaba.csp.sentinel.datasource.FileRefreshableDataSource; import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; - import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Test; + +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.util.ResourceUtils; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Jim @@ -46,24 +44,18 @@ public class FileRefreshableDataSourceFactoryBeanTests { public void testFile() throws Exception { AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext( TestConfig.class); - assertNotNull("FileRefreshableDataSourceFactoryBean was not created", - annotationConfigApplicationContext.getBean("fileBean")); + assertThat(annotationConfigApplicationContext.getBean("fileBean")).isNotNull(); FileRefreshableDataSource fileRefreshableDataSource = annotationConfigApplicationContext .getBean("fileBean", FileRefreshableDataSource.class); - assertEquals("FileRefreshableDataSourceFactoryBean flow rule size was wrong", 1, - ((List) fileRefreshableDataSource.loadConfig()).size()); + assertThat(((List) fileRefreshableDataSource.loadConfig()).size()) + .isEqualTo(1); FileRefreshableDataSourceFactoryBean factoryBean = annotationConfigApplicationContext .getBean("&fileBean", FileRefreshableDataSourceFactoryBean.class); - assertEquals("FileRefreshableDataSourceFactoryBean buf size was wrong", 1024, - factoryBean.getBufSize()); - assertEquals("FileRefreshableDataSourceFactoryBean charset was wrong", "utf-8", - factoryBean.getCharset()); - assertEquals("FileRefreshableDataSourceFactoryBean recommendRefreshMs was wrong", - 2000, factoryBean.getRecommendRefreshMs()); - assertNotNull("FileRefreshableDataSourceFactoryBean file was null", - factoryBean.getFile()); - assertNotNull("FileRefreshableDataSourceFactoryBean converter was null", - factoryBean.getConverter()); + assertThat(factoryBean.getBufSize()).isEqualTo(1024); + assertThat(factoryBean.getCharset()).isEqualTo("utf-8"); + assertThat(factoryBean.getRecommendRefreshMs()).isEqualTo(2000); + assertThat(factoryBean.getFile()).isNotNull(); + assertThat(factoryBean.getConverter()).isNotNull(); } @Configuration diff --git a/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/NacosDataSourceFactoryBeanTests.java b/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/NacosDataSourceFactoryBeanTests.java index 3fbf10605..ca364f30e 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/NacosDataSourceFactoryBeanTests.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/NacosDataSourceFactoryBeanTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,18 +16,17 @@ package com.alibaba.cloud.sentinel.datasource; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - -import org.junit.Test; - import com.alibaba.cloud.sentinel.datasource.converter.SentinelConverter; import com.alibaba.cloud.sentinel.datasource.factorybean.NacosDataSourceFactoryBean; import com.alibaba.csp.sentinel.datasource.Converter; import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; /** * @author Jim @@ -35,11 +34,17 @@ import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource; public class NacosDataSourceFactoryBeanTests { private String dataId = "sentinel"; + private String groupId = "DEFAULT_GROUP"; + private String serverAddr = "localhost:8848"; + private String accessKey = "ak"; + private String secretKey = "sk"; + private String endpoint = "endpoint"; + private String namespace = "namespace"; @Test @@ -58,18 +63,12 @@ public class NacosDataSourceFactoryBeanTests { doReturn(nacosDataSource).when(factoryBean).getObject(); when(nacosDataSource.readSource()).thenReturn("{}"); - assertEquals("NacosDataSourceFactoryBean getObject was wrong", nacosDataSource, - factoryBean.getObject()); - assertEquals("NacosDataSource read source value was wrong", "{}", - factoryBean.getObject().readSource()); - assertEquals("NacosDataSource converter was wrong", converter, - factoryBean.getConverter()); - assertEquals("NacosDataSourceFactoryBean dataId was wrong", dataId, - factoryBean.getDataId()); - assertEquals("NacosDataSourceFactoryBean groupId was wrong", groupId, - factoryBean.getGroupId()); - assertEquals("NacosDataSourceFactoryBean serverAddr was wrong", serverAddr, - factoryBean.getServerAddr()); + assertThat(factoryBean.getObject()).isEqualTo(nacosDataSource); + assertThat(factoryBean.getObject().readSource()).isEqualTo("{}"); + assertThat(factoryBean.getConverter()).isEqualTo(converter); + assertThat(factoryBean.getDataId()).isEqualTo(dataId); + assertThat(factoryBean.getGroupId()).isEqualTo(groupId); + assertThat(factoryBean.getServerAddr()).isEqualTo(serverAddr); } @Test @@ -91,25 +90,15 @@ public class NacosDataSourceFactoryBeanTests { doReturn(nacosDataSource).when(factoryBean).getObject(); when(nacosDataSource.readSource()).thenReturn("{}"); - assertEquals("NacosDataSourceFactoryBean getObject was wrong", nacosDataSource, - factoryBean.getObject()); - assertEquals("NacosDataSource read source value was wrong", "{}", - factoryBean.getObject().readSource()); - assertEquals("NacosDataSource converter was wrong", converter, - factoryBean.getConverter()); - assertEquals("NacosDataSourceFactoryBean dataId was wrong", dataId, - factoryBean.getDataId()); - assertEquals("NacosDataSourceFactoryBean groupId was wrong", groupId, - factoryBean.getGroupId()); - assertEquals("NacosDataSourceFactoryBean namespace was wrong", namespace, - factoryBean.getNamespace()); - assertEquals("NacosDataSourceFactoryBean endpoint was wrong", endpoint, - factoryBean.getEndpoint()); - assertEquals("NacosDataSourceFactoryBean ak was wrong", accessKey, - factoryBean.getAccessKey()); - assertEquals("NacosDataSourceFactoryBean sk was wrong", secretKey, - factoryBean.getSecretKey()); - + assertThat(factoryBean.getObject()).isEqualTo(nacosDataSource); + assertThat(factoryBean.getObject().readSource()).isEqualTo("{}"); + assertThat(factoryBean.getConverter()).isEqualTo(converter); + assertThat(factoryBean.getDataId()).isEqualTo(dataId); + assertThat(factoryBean.getGroupId()).isEqualTo(groupId); + assertThat(factoryBean.getNamespace()).isEqualTo(namespace); + assertThat(factoryBean.getEndpoint()).isEqualTo(endpoint); + assertThat(factoryBean.getAccessKey()).isEqualTo(accessKey); + assertThat(factoryBean.getSecretKey()).isEqualTo(secretKey); } } diff --git a/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/NacosDataSourcePropertiesTests.java b/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/NacosDataSourcePropertiesTests.java index 6b3471f1c..f897d6ed8 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/NacosDataSourcePropertiesTests.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/NacosDataSourcePropertiesTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,11 @@ package com.alibaba.cloud.sentinel.datasource; -import static org.junit.Assert.assertEquals; - -import org.junit.Assert; -import org.junit.Test; - import com.alibaba.cloud.sentinel.datasource.config.NacosDataSourceProperties; import com.alibaba.cloud.sentinel.datasource.factorybean.NacosDataSourceFactoryBean; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Jim @@ -38,17 +36,12 @@ public class NacosDataSourcePropertiesTests { nacosDataSourceProperties.setGroupId("custom-group"); nacosDataSourceProperties.setDataType("xml"); - assertEquals("Nacos groupId was wrong", "custom-group", - nacosDataSourceProperties.getGroupId()); - assertEquals("Nacos dataId was wrong", "sentinel", - nacosDataSourceProperties.getDataId()); - assertEquals("Nacos default data type was wrong", "xml", - nacosDataSourceProperties.getDataType()); - Assert.assertEquals("Nacos rule type was wrong", RuleType.FLOW, - nacosDataSourceProperties.getRuleType()); - assertEquals("Nacos default factory bean was wrong", - NacosDataSourceFactoryBean.class.getName(), - nacosDataSourceProperties.getFactoryBeanName()); + assertThat(nacosDataSourceProperties.getGroupId()).isEqualTo("custom-group"); + assertThat(nacosDataSourceProperties.getDataId()).isEqualTo("sentinel"); + assertThat(nacosDataSourceProperties.getDataType()).isEqualTo("xml"); + assertThat(nacosDataSourceProperties.getRuleType()).isEqualTo(RuleType.FLOW); + assertThat(nacosDataSourceProperties.getFactoryBeanName()) + .isEqualTo(NacosDataSourceFactoryBean.class.getName()); } @Test @@ -60,16 +53,11 @@ public class NacosDataSourcePropertiesTests { nacosDataSourceProperties.setNamespace("namespace"); nacosDataSourceProperties.setRuleType(RuleType.SYSTEM); - assertEquals("Nacos ak was wrong", "ak", - nacosDataSourceProperties.getAccessKey()); - assertEquals("Nacos sk was wrong", "sk", - nacosDataSourceProperties.getSecretKey()); - assertEquals("Nacos endpoint was wrong", "endpoint", - nacosDataSourceProperties.getEndpoint()); - assertEquals("Nacos namespace was wrong", "namespace", - nacosDataSourceProperties.getNamespace()); - Assert.assertEquals("Nacos rule type was wrong", RuleType.SYSTEM, - nacosDataSourceProperties.getRuleType()); + assertThat(nacosDataSourceProperties.getAccessKey()).isEqualTo("ak"); + assertThat(nacosDataSourceProperties.getSecretKey()).isEqualTo("sk"); + assertThat(nacosDataSourceProperties.getEndpoint()).isEqualTo("endpoint"); + assertThat(nacosDataSourceProperties.getNamespace()).isEqualTo("namespace"); + assertThat(nacosDataSourceProperties.getRuleType()).isEqualTo(RuleType.SYSTEM); } } diff --git a/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/RuleTypeTests.java b/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/RuleTypeTests.java index 4eea620a7..c8a03b883 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/RuleTypeTests.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/RuleTypeTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,18 +16,15 @@ package com.alibaba.cloud.sentinel.datasource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - import com.alibaba.csp.sentinel.slots.block.AbstractRule; import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule; import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule; import com.alibaba.csp.sentinel.slots.system.SystemRule; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Jim @@ -36,52 +33,39 @@ public class RuleTypeTests { @Test public void testGetByName() { - assertFalse("empty str rule name was not null", - RuleType.getByName("").isPresent()); - assertFalse("test rule name was not null", - RuleType.getByName("test").isPresent()); - assertFalse("param_flow rule name was not null", - RuleType.getByName("param_flow").isPresent()); - assertFalse("param rule name was not null", - RuleType.getByName("param").isPresent()); - assertFalse("FLOW rule name was not null", - RuleType.getByName("FLOW").isPresent()); - assertTrue("flow rule name was null", RuleType.getByName("flow").isPresent()); - assertTrue("degrade rule name was null", - RuleType.getByName("degrade").isPresent()); - assertTrue("param-flow rule name was null", - RuleType.getByName("param-flow").isPresent()); - assertTrue("system rule name was null", RuleType.getByName("system").isPresent()); - assertTrue("authority rule name was null", - RuleType.getByName("authority").isPresent()); - assertEquals("flow rule name was not equals RuleType.FLOW", RuleType.FLOW, - RuleType.getByName("flow").get()); - assertEquals("flow rule name was not equals RuleType.DEGRADE", RuleType.DEGRADE, - RuleType.getByName("degrade").get()); - assertEquals("flow rule name was not equals RuleType.PARAM_FLOW", - RuleType.PARAM_FLOW, RuleType.getByName("param-flow").get()); - assertEquals("flow rule name was not equals RuleType.SYSTEM", RuleType.SYSTEM, - RuleType.getByName("system").get()); - assertEquals("flow rule name was not equals RuleType.AUTHORITY", - RuleType.AUTHORITY, RuleType.getByName("authority").get()); + assertThat(RuleType.getByName("").isPresent()).isEqualTo(Boolean.FALSE); + assertThat(RuleType.getByName("test").isPresent()).isEqualTo(Boolean.FALSE); + assertThat(RuleType.getByName("param_flow").isPresent()).isEqualTo(Boolean.FALSE); + assertThat(RuleType.getByName("param").isPresent()).isEqualTo(Boolean.FALSE); + assertThat(RuleType.getByName("FLOW").isPresent()).isEqualTo(Boolean.FALSE); + assertThat(RuleType.getByName("flow").isPresent()).isEqualTo(Boolean.TRUE); + assertThat(RuleType.getByName("degrade").isPresent()).isEqualTo(Boolean.TRUE); + assertThat(RuleType.getByName("param-flow").isPresent()).isEqualTo(Boolean.TRUE); + assertThat(RuleType.getByName("system").isPresent()).isEqualTo(Boolean.TRUE); + assertThat(RuleType.getByName("authority").isPresent()).isEqualTo(Boolean.TRUE); + assertThat(RuleType.getByName("flow").get()).isEqualTo(RuleType.FLOW); + assertThat(RuleType.getByName("degrade").get()).isEqualTo(RuleType.DEGRADE); + assertThat(RuleType.getByName("param-flow").get()).isEqualTo(RuleType.PARAM_FLOW); + assertThat(RuleType.getByName("system").get()).isEqualTo(RuleType.SYSTEM); + assertThat(RuleType.getByName("authority").get()).isEqualTo(RuleType.AUTHORITY); } @Test public void testGetByClass() { - assertFalse("Object.class type type was not null", - RuleType.getByClass(Object.class).isPresent()); - assertFalse("AbstractRule.class rule type was not null", - RuleType.getByClass(AbstractRule.class).isPresent()); - assertTrue("FlowRule.class rule type was null", - RuleType.getByClass(FlowRule.class).isPresent()); - assertTrue("DegradeRule.class rule type was null", - RuleType.getByClass(DegradeRule.class).isPresent()); - assertTrue("ParamFlowRule.class rule type was null", - RuleType.getByClass(ParamFlowRule.class).isPresent()); - assertTrue("SystemRule.class rule type was null", - RuleType.getByClass(SystemRule.class).isPresent()); - assertTrue("AuthorityRule.class rule type was null", - RuleType.getByClass(AuthorityRule.class).isPresent()); + assertThat(RuleType.getByClass(Object.class).isPresent()) + .isEqualTo(Boolean.FALSE); + assertThat(RuleType.getByClass(AbstractRule.class).isPresent()) + .isEqualTo(Boolean.FALSE); + assertThat(RuleType.getByClass(FlowRule.class).isPresent()) + .isEqualTo(Boolean.TRUE); + assertThat(RuleType.getByClass(DegradeRule.class).isPresent()) + .isEqualTo(Boolean.TRUE); + assertThat(RuleType.getByClass(ParamFlowRule.class).isPresent()) + .isEqualTo(Boolean.TRUE); + assertThat(RuleType.getByClass(SystemRule.class).isPresent()) + .isEqualTo(Boolean.TRUE); + assertThat(RuleType.getByClass(AuthorityRule.class).isPresent()) + .isEqualTo(Boolean.TRUE); } } diff --git a/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/SentinelConverterTests.java b/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/SentinelConverterTests.java index e909b7518..1053c3679 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/SentinelConverterTests.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/SentinelConverterTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,23 +16,22 @@ package com.alibaba.cloud.sentinel.datasource; -import static org.junit.Assert.assertEquals; - import java.io.IOException; import java.util.List; -import org.apache.commons.io.FileUtils; -import org.junit.Test; -import org.springframework.util.ResourceUtils; -import org.springframework.util.StringUtils; - import com.alibaba.cloud.sentinel.datasource.converter.JsonConverter; import com.alibaba.cloud.sentinel.datasource.converter.XmlConverter; import com.alibaba.csp.sentinel.slots.block.RuleConstant; import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; - import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import org.apache.commons.io.FileUtils; +import org.junit.Test; + +import org.springframework.util.ResourceUtils; +import org.springframework.util.StringUtils; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Jim @@ -48,27 +47,23 @@ public class SentinelConverterTests { JsonConverter jsonConverter = new JsonConverter(objectMapper, FlowRule.class); List flowRules = (List) jsonConverter .convert(readFileContent("classpath: flowrule.json")); - assertEquals("json converter flow rule size was wrong", 1, flowRules.size()); - assertEquals("json converter flow rule resource name was wrong", "resource", - flowRules.get(0).getResource()); - assertEquals("json converter flow rule limit app was wrong", "default", - flowRules.get(0).getLimitApp()); - assertEquals("json converter flow rule count was wrong", "1.0", - String.valueOf(flowRules.get(0).getCount())); - assertEquals("json converter flow rule control behavior was wrong", - RuleConstant.CONTROL_BEHAVIOR_DEFAULT, - flowRules.get(0).getControlBehavior()); - assertEquals("json converter flow rule strategy was wrong", - RuleConstant.STRATEGY_DIRECT, flowRules.get(0).getStrategy()); - assertEquals("json converter flow rule grade was wrong", - RuleConstant.FLOW_GRADE_QPS, flowRules.get(0).getGrade()); + + assertThat(flowRules.size()).isEqualTo(1); + assertThat(flowRules.get(0).getResource()).isEqualTo("resource"); + assertThat(flowRules.get(0).getLimitApp()).isEqualTo("default"); + assertThat(String.valueOf(flowRules.get(0).getCount())).isEqualTo("1.0"); + assertThat(flowRules.get(0).getControlBehavior()) + .isEqualTo(RuleConstant.CONTROL_BEHAVIOR_DEFAULT); + assertThat(flowRules.get(0).getStrategy()) + .isEqualTo(RuleConstant.STRATEGY_DIRECT); + assertThat(flowRules.get(0).getGrade()).isEqualTo(RuleConstant.FLOW_GRADE_QPS); } @Test public void testConverterEmptyContent() { JsonConverter jsonConverter = new JsonConverter(objectMapper, FlowRule.class); List flowRules = (List) jsonConverter.convert(""); - assertEquals("json converter flow rule size was not empty", 0, flowRules.size()); + assertThat(flowRules.size()).isEqualTo(0); } @Test(expected = RuntimeException.class) @@ -88,34 +83,25 @@ public class SentinelConverterTests { XmlConverter jsonConverter = new XmlConverter(xmlMapper, FlowRule.class); List flowRules = (List) jsonConverter .convert(readFileContent("classpath: flowrule.xml")); - assertEquals("xml converter flow rule size was wrong", 2, flowRules.size()); - assertEquals("xml converter flow rule1 resource name was wrong", "resource", - flowRules.get(0).getResource()); - assertEquals("xml converter flow rule2 limit app was wrong", "default", - flowRules.get(0).getLimitApp()); - assertEquals("xml converter flow rule1 count was wrong", "1.0", - String.valueOf(flowRules.get(0).getCount())); - assertEquals("xml converter flow rule1 control behavior was wrong", - RuleConstant.CONTROL_BEHAVIOR_DEFAULT, - flowRules.get(0).getControlBehavior()); - assertEquals("xml converter flow rule1 strategy was wrong", - RuleConstant.STRATEGY_DIRECT, flowRules.get(0).getStrategy()); - assertEquals("xml converter flow rule1 grade was wrong", - RuleConstant.FLOW_GRADE_QPS, flowRules.get(0).getGrade()); - - assertEquals("xml converter flow rule2 resource name was wrong", "test", - flowRules.get(1).getResource()); - assertEquals("xml converter flow rule2 limit app was wrong", "default", - flowRules.get(1).getLimitApp()); - assertEquals("xml converter flow rule2 count was wrong", "1.0", - String.valueOf(flowRules.get(1).getCount())); - assertEquals("xml converter flow rule2 control behavior was wrong", - RuleConstant.CONTROL_BEHAVIOR_DEFAULT, - flowRules.get(1).getControlBehavior()); - assertEquals("xml converter flow rule2 strategy was wrong", - RuleConstant.STRATEGY_DIRECT, flowRules.get(1).getStrategy()); - assertEquals("xml converter flow rule2 grade was wrong", - RuleConstant.FLOW_GRADE_QPS, flowRules.get(1).getGrade()); + + assertThat(flowRules.size()).isEqualTo(2); + assertThat(flowRules.get(0).getResource()).isEqualTo("resource"); + assertThat(flowRules.get(0).getLimitApp()).isEqualTo("default"); + assertThat(String.valueOf(flowRules.get(0).getCount())).isEqualTo("1.0"); + assertThat(flowRules.get(0).getControlBehavior()) + .isEqualTo(RuleConstant.CONTROL_BEHAVIOR_DEFAULT); + assertThat(flowRules.get(0).getStrategy()) + .isEqualTo(RuleConstant.STRATEGY_DIRECT); + assertThat(flowRules.get(0).getGrade()).isEqualTo(RuleConstant.FLOW_GRADE_QPS); + + assertThat(flowRules.get(1).getResource()).isEqualTo("test"); + assertThat(flowRules.get(1).getLimitApp()).isEqualTo("default"); + assertThat(String.valueOf(flowRules.get(1).getCount())).isEqualTo("1.0"); + assertThat(flowRules.get(1).getControlBehavior()) + .isEqualTo(RuleConstant.CONTROL_BEHAVIOR_DEFAULT); + assertThat(flowRules.get(1).getStrategy()) + .isEqualTo(RuleConstant.STRATEGY_DIRECT); + assertThat(flowRules.get(1).getGrade()).isEqualTo(RuleConstant.FLOW_GRADE_QPS); } private String readFileContent(String file) { diff --git a/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/ZookeeperDataSourceFactoryBeanTests.java b/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/ZookeeperDataSourceFactoryBeanTests.java index 813b4053f..fb7a23d9b 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/ZookeeperDataSourceFactoryBeanTests.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/test/java/com/alibaba/cloud/sentinel/datasource/ZookeeperDataSourceFactoryBeanTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,18 +16,17 @@ package com.alibaba.cloud.sentinel.datasource; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - -import org.junit.Test; - import com.alibaba.cloud.sentinel.datasource.converter.XmlConverter; import com.alibaba.cloud.sentinel.datasource.factorybean.ZookeeperDataSourceFactoryBean; import com.alibaba.csp.sentinel.datasource.Converter; import com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; /** * @author Jim @@ -35,7 +34,9 @@ import com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource; public class ZookeeperDataSourceFactoryBeanTests { private String dataId = "dataId"; + private String groupId = "groupId"; + private String serverAddr = "localhost:2181"; private String path = "/sentinel"; @@ -57,18 +58,12 @@ public class ZookeeperDataSourceFactoryBeanTests { when(zookeeperDataSource.readSource()).thenReturn("{}"); doReturn(zookeeperDataSource).when(factoryBean).getObject(); - assertEquals("ZookeeperDataSource getObject was wrong", zookeeperDataSource, - factoryBean.getObject()); - assertEquals("ZookeeperDataSource read source value was wrong", "{}", - factoryBean.getObject().readSource()); - assertEquals("ZookeeperDataSourceFactoryBean dataId was wrong", dataId, - factoryBean.getDataId()); - assertEquals("ZookeeperDataSourceFactoryBean converter was wrong", converter, - factoryBean.getConverter()); - assertEquals("ZookeeperDataSourceFactoryBean groupId was wrong", groupId, - factoryBean.getGroupId()); - assertEquals("ZookeeperDataSourceFactoryBean serverAddr was wrong", serverAddr, - factoryBean.getServerAddr()); + assertThat(factoryBean.getObject()).isEqualTo(zookeeperDataSource); + assertThat(factoryBean.getObject().readSource()).isEqualTo("{}"); + assertThat(factoryBean.getDataId()).isEqualTo(dataId); + assertThat(factoryBean.getConverter()).isEqualTo(converter); + assertThat(factoryBean.getGroupId()).isEqualTo(groupId); + assertThat(factoryBean.getServerAddr()).isEqualTo(serverAddr); } @Test @@ -87,16 +82,11 @@ public class ZookeeperDataSourceFactoryBeanTests { when(zookeeperDataSource.readSource()).thenReturn("{}"); doReturn(zookeeperDataSource).when(factoryBean).getObject(); - assertEquals("ZookeeperDataSource value was wrong", zookeeperDataSource, - factoryBean.getObject()); - assertEquals("ZookeeperDataSource read source value was wrong", "{}", - factoryBean.getObject().readSource()); - assertEquals("ZookeeperDataSourceFactoryBean converter was wrong", converter, - factoryBean.getConverter()); - assertEquals("ZookeeperDataSourceFactoryBean path was wrong", path, - factoryBean.getPath()); - assertEquals("ZookeeperDataSourceFactoryBean serverAddr was wrong", serverAddr, - factoryBean.getServerAddr()); + assertThat(factoryBean.getObject()).isEqualTo(zookeeperDataSource); + assertThat(factoryBean.getObject().readSource()).isEqualTo("{}"); + assertThat(factoryBean.getConverter()).isEqualTo(converter); + assertThat(factoryBean.getPath()).isEqualTo(path); + assertThat(factoryBean.getServerAddr()).isEqualTo(serverAddr); } } diff --git a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/ConfigConstants.java b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/ConfigConstants.java index 89ae04538..9cf273319 100644 --- a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/ConfigConstants.java +++ b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/ConfigConstants.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,19 +16,46 @@ package com.alibaba.cloud.sentinel.gateway; +import com.alibaba.cloud.sentinel.gateway.scg.SentinelGatewayProperties; +import com.alibaba.cloud.sentinel.gateway.zuul.SentinelZuulProperties; + /** * @author Jim */ -public interface ConfigConstants { +public final class ConfigConstants { + + /** + * Netflix Zuul type. + */ + public static final String APP_TYPE_ZUUL_GATEWAY = "12"; + + /** + * Spring Cloud Gateway type. + */ + public static final String APP_TYPE_SCG_GATEWAY = "11"; + + /** + * ConfigurationProperties for {@link SentinelZuulProperties}. + */ + public static final String ZUUl_PREFIX = "spring.cloud.sentinel.zuul"; - String APP_TYPE_ZUUL_GATEWAY = "12"; - String APP_TYPE_SCG_GATEWAY = "11"; + /** + * ConfigurationProperties for {@link SentinelGatewayProperties}. + */ + public static final String GATEWAY_PREFIX = "spring.cloud.sentinel.scg"; - String ZUUl_PREFIX = "spring.cloud.sentinel.zuul"; + /** + * Response type for Spring Cloud Gateway fallback. + */ + public static final String FALLBACK_MSG_RESPONSE = "response"; - String GATEWAY_PREFIX = "spring.cloud.sentinel.scg"; + /** + * Redirect type for Spring Cloud Gateway fallback. + */ + public static final String FALLBACK_REDIRECT = "redirect"; - String FALLBACK_MSG_RESPONSE = "response"; - String FALLBACK_REDIRECT = "redirect"; + private ConfigConstants() { + throw new AssertionError("Must not instantiate constant utility class"); + } } diff --git a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/FallbackProperties.java b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/FallbackProperties.java index 9d910a0ad..5d4d6ee81 100644 --- a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/FallbackProperties.java +++ b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/FallbackProperties.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,18 +29,22 @@ public class FallbackProperties { * `response`. */ private String mode; + /** * Redirect Url for `redirect` mode. */ private String redirect; + /** * Response Body for `response` mode. */ private String responseBody; + /** * Response Status for `response` mode. */ private Integer responseStatus = HttpStatus.TOO_MANY_REQUESTS.value(); + /** * Content-Type for `response` mode. */ @@ -90,4 +94,5 @@ public class FallbackProperties { this.contentType = contentType; return this; } + } diff --git a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/GatewayEnvironmentPostProcessor.java b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/GatewayEnvironmentPostProcessor.java index 3a2546133..c02bb78d2 100644 --- a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/GatewayEnvironmentPostProcessor.java +++ b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/GatewayEnvironmentPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,62 +13,68 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.sentinel.gateway; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.env.EnvironmentPostProcessor; -import org.springframework.core.env.*; +package com.alibaba.cloud.sentinel.gateway; import java.util.HashMap; import java.util.Map; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.env.EnvironmentPostProcessor; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; +import org.springframework.core.env.MutablePropertySources; +import org.springframework.core.env.PropertySource; + /** * @author zhuhonghan */ public class GatewayEnvironmentPostProcessor implements EnvironmentPostProcessor { - private final static String SENTINEL_FILTER_ENABLED = "spring.cloud.sentinel.filter.enabled"; - private final static String PROPERTY_SOURCE_NAME = "defaultProperties"; - @Override - public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication springApplication) { - addDefaultPropertySource(environment); - } + private final static String SENTINEL_FILTER_ENABLED = "spring.cloud.sentinel.filter.enabled"; + + private final static String PROPERTY_SOURCE_NAME = "defaultProperties"; - private void addDefaultPropertySource(ConfigurableEnvironment environment) { + @Override + public void postProcessEnvironment(ConfigurableEnvironment environment, + SpringApplication springApplication) { + addDefaultPropertySource(environment); + } - Map map = new HashMap(); + private void addDefaultPropertySource(ConfigurableEnvironment environment) { - configureDefaultProperties(map); + Map map = new HashMap(); - addOrReplace(environment.getPropertySources(), map); - } + configureDefaultProperties(map); - private void configureDefaultProperties(Map source) { - // Required Properties - source.put(SENTINEL_FILTER_ENABLED, "false"); - } + addOrReplace(environment.getPropertySources(), map); + } - private void addOrReplace(MutablePropertySources propertySources, - Map map) { - MapPropertySource target = null; - if (propertySources.contains(PROPERTY_SOURCE_NAME)) { - PropertySource source = propertySources.get(PROPERTY_SOURCE_NAME); - if (source instanceof MapPropertySource) { - target = (MapPropertySource) source; - for (String key : map.keySet()) { - if (!target.containsProperty(key)) { - target.getSource().put(key, map.get(key)); - } - } - } - } - if (target == null) { - target = new MapPropertySource(PROPERTY_SOURCE_NAME, map); - } - if (!propertySources.contains(PROPERTY_SOURCE_NAME)) { - propertySources.addLast(target); - } - } + private void configureDefaultProperties(Map source) { + // Required Properties + source.put(SENTINEL_FILTER_ENABLED, "false"); + } + private void addOrReplace(MutablePropertySources propertySources, + Map map) { + MapPropertySource target = null; + if (propertySources.contains(PROPERTY_SOURCE_NAME)) { + PropertySource source = propertySources.get(PROPERTY_SOURCE_NAME); + if (source instanceof MapPropertySource) { + target = (MapPropertySource) source; + for (String key : map.keySet()) { + if (!target.containsProperty(key)) { + target.getSource().put(key, map.get(key)); + } + } + } + } + if (target == null) { + target = new MapPropertySource(PROPERTY_SOURCE_NAME, map); + } + if (!propertySources.contains(PROPERTY_SOURCE_NAME)) { + propertySources.addLast(target); + } + } } diff --git a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/SentinelGatewayAutoConfiguration.java b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/SentinelGatewayAutoConfiguration.java index 3efd42abb..d7871c2f0 100644 --- a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/SentinelGatewayAutoConfiguration.java +++ b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/SentinelGatewayAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,11 +22,6 @@ import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - import com.alibaba.cloud.sentinel.datasource.converter.JsonConverter; import com.alibaba.cloud.sentinel.datasource.converter.XmlConverter; import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition; @@ -34,7 +29,6 @@ import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPathPredicateItem; import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPredicateGroupItem; import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPredicateItem; import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule; - import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.Version; import com.fasterxml.jackson.databind.DeserializationContext; @@ -46,6 +40,11 @@ import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + /** * @author Jim */ @@ -59,6 +58,7 @@ public class SentinelGatewayAutoConfiguration { static class ApiPredicateItemDeserializer extends StdDeserializer { + private Map> registry = new HashMap>(); ApiPredicateItemDeserializer() { @@ -90,6 +90,7 @@ public class SentinelGatewayAutoConfiguration { } return mapper.readValue(root.toString(), apiPredicateItemClass); } + } @Configuration @@ -122,6 +123,7 @@ public class SentinelGatewayAutoConfiguration { public JsonConverter jsonApiConverter() { return new JsonConverter(objectMapper, ApiDefinition.class); } + } @ConditionalOnClass(XmlMapper.class) @@ -156,6 +158,7 @@ public class SentinelGatewayAutoConfiguration { } } + } } diff --git a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/scg/SentinelGatewayProperties.java b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/scg/SentinelGatewayProperties.java index 86e3996b2..a0d93ce6e 100644 --- a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/scg/SentinelGatewayProperties.java +++ b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/scg/SentinelGatewayProperties.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,13 +16,13 @@ package com.alibaba.cloud.sentinel.gateway.scg; +import com.alibaba.cloud.sentinel.gateway.ConfigConstants; +import com.alibaba.cloud.sentinel.gateway.FallbackProperties; + import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; import org.springframework.core.Ordered; -import com.alibaba.cloud.sentinel.gateway.ConfigConstants; -import com.alibaba.cloud.sentinel.gateway.FallbackProperties; - /** * @author Jim */ @@ -50,4 +50,5 @@ public class SentinelGatewayProperties { public void setOrder(Integer order) { this.order = order; } + } diff --git a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/scg/SentinelSCGAutoConfiguration.java b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/scg/SentinelSCGAutoConfiguration.java index b7693f385..cd397158a 100644 --- a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/scg/SentinelSCGAutoConfiguration.java +++ b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/scg/SentinelSCGAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,16 +16,25 @@ package com.alibaba.cloud.sentinel.gateway.scg; -import static org.springframework.web.reactive.function.BodyInserters.fromObject; - import java.util.Collections; import java.util.List; import java.util.Optional; import javax.annotation.PostConstruct; +import com.alibaba.cloud.sentinel.gateway.ConfigConstants; +import com.alibaba.cloud.sentinel.gateway.FallbackProperties; +import com.alibaba.csp.sentinel.adapter.gateway.sc.SentinelGatewayFilter; +import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler; +import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager; +import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.RedirectBlockRequestHandler; +import com.alibaba.csp.sentinel.adapter.gateway.sc.exception.SentinelGatewayBlockExceptionHandler; +import com.alibaba.csp.sentinel.config.SentinelConfig; +import com.alibaba.csp.sentinel.util.StringUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import reactor.core.publisher.Mono; + import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -43,24 +52,15 @@ import org.springframework.web.reactive.function.server.ServerResponse; import org.springframework.web.reactive.result.view.ViewResolver; import org.springframework.web.server.ServerWebExchange; -import com.alibaba.cloud.sentinel.gateway.ConfigConstants; -import com.alibaba.cloud.sentinel.gateway.FallbackProperties; -import com.alibaba.csp.sentinel.adapter.gateway.sc.SentinelGatewayFilter; -import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler; -import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager; -import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.RedirectBlockRequestHandler; -import com.alibaba.csp.sentinel.adapter.gateway.sc.exception.SentinelGatewayBlockExceptionHandler; -import com.alibaba.csp.sentinel.config.SentinelConfig; -import com.alibaba.csp.sentinel.util.StringUtil; - -import reactor.core.publisher.Mono; +import static org.springframework.web.reactive.function.BodyInserters.fromObject; /** * @author Jim */ @Configuration @ConditionalOnClass(GlobalFilter.class) -@ConditionalOnProperty(prefix = ConfigConstants.GATEWAY_PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true) +@ConditionalOnProperty(prefix = ConfigConstants.GATEWAY_PREFIX, name = "enabled", + havingValue = "true", matchIfMissing = true) @EnableConfigurationProperties(SentinelGatewayProperties.class) public class SentinelSCGAutoConfiguration { @@ -68,6 +68,7 @@ public class SentinelSCGAutoConfiguration { .getLogger(SentinelSCGAutoConfiguration.class); private final List viewResolvers; + private final ServerCodecConfigurer serverCodecConfigurer; @Autowired diff --git a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/FallBackProviderHandler.java b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/FallBackProviderHandler.java index 9f9074e62..dd08bd24a 100644 --- a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/FallBackProviderHandler.java +++ b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/FallBackProviderHandler.java @@ -1,17 +1,33 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.sentinel.gateway.zuul; import java.util.Map; +import com.alibaba.csp.sentinel.adapter.gateway.zuul.fallback.DefaultBlockFallbackProvider; +import com.alibaba.csp.sentinel.adapter.gateway.zuul.fallback.ZuulBlockFallbackManager; +import com.alibaba.csp.sentinel.adapter.gateway.zuul.fallback.ZuulBlockFallbackProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.SmartInitializingSingleton; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.util.CollectionUtils; -import com.alibaba.csp.sentinel.adapter.gateway.zuul.fallback.DefaultBlockFallbackProvider; -import com.alibaba.csp.sentinel.adapter.gateway.zuul.fallback.ZuulBlockFallbackManager; -import com.alibaba.csp.sentinel.adapter.gateway.zuul.fallback.ZuulBlockFallbackProvider; - /** * @author tiger */ @@ -42,4 +58,5 @@ public class FallBackProviderHandler implements SmartInitializingSingleton { ZuulBlockFallbackManager.registerProvider(new DefaultBlockFallbackProvider()); } } + } diff --git a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/SentinelZuulAutoConfiguration.java b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/SentinelZuulAutoConfiguration.java index 12a866b4d..6b2a26535 100644 --- a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/SentinelZuulAutoConfiguration.java +++ b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/SentinelZuulAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,8 +20,17 @@ import java.util.Optional; import javax.annotation.PostConstruct; +import com.alibaba.cloud.sentinel.gateway.ConfigConstants; +import com.alibaba.csp.sentinel.adapter.gateway.zuul.callback.RequestOriginParser; +import com.alibaba.csp.sentinel.adapter.gateway.zuul.callback.ZuulGatewayCallbackManager; +import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulErrorFilter; +import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulPostFilter; +import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulPreFilter; +import com.alibaba.csp.sentinel.config.SentinelConfig; +import com.netflix.zuul.http.ZuulServlet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -31,24 +40,15 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.alibaba.cloud.sentinel.gateway.ConfigConstants; -import com.alibaba.csp.sentinel.adapter.gateway.zuul.callback.RequestOriginParser; -import com.alibaba.csp.sentinel.adapter.gateway.zuul.callback.ZuulGatewayCallbackManager; -import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulErrorFilter; -import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulPostFilter; -import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulPreFilter; -import com.alibaba.csp.sentinel.config.SentinelConfig; - -import com.netflix.zuul.http.ZuulServlet; - /** - * Sentinel Spring Cloud Zuul AutoConfiguration + * Sentinel Spring Cloud Zuul AutoConfiguration. * * @author tiger */ @Configuration @ConditionalOnClass(ZuulServlet.class) -@ConditionalOnProperty(prefix = ConfigConstants.ZUUl_PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true) +@ConditionalOnProperty(prefix = ConfigConstants.ZUUl_PREFIX, name = "enabled", + havingValue = "true", matchIfMissing = true) @EnableConfigurationProperties(SentinelZuulProperties.class) public class SentinelZuulAutoConfiguration { diff --git a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/SentinelZuulProperties.java b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/SentinelZuulProperties.java index d690c252a..300766dc5 100644 --- a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/SentinelZuulProperties.java +++ b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/SentinelZuulProperties.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,15 +16,15 @@ package com.alibaba.cloud.sentinel.gateway.zuul; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.NestedConfigurationProperty; - import com.alibaba.cloud.sentinel.gateway.ConfigConstants; import com.alibaba.csp.sentinel.adapter.gateway.zuul.constants.ZuulConstant; import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulErrorFilter; import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulPostFilter; import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulPreFilter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.NestedConfigurationProperty; + /** * @author Jim */ @@ -83,6 +83,7 @@ public class SentinelZuulProperties { public void setError(int error) { this.error = error; } + } } diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/SentinelConstants.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/SentinelConstants.java index 7501ee49b..ca008a047 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/SentinelConstants.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/SentinelConstants.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,17 +19,30 @@ package com.alibaba.cloud.sentinel; /** * @author fangjian */ -public interface SentinelConstants { +public final class SentinelConstants { - String PROPERTY_PREFIX = "spring.cloud.sentinel"; + /** + * Prefix of {@link SentinelProperties}. + */ + public static final String PROPERTY_PREFIX = "spring.cloud.sentinel"; - String BLOCK_TYPE = "block"; - String FALLBACK_TYPE = "fallback"; - String URLCLEANER_TYPE = "urlCleaner"; + /** + * Block type. + */ + public static final String BLOCK_TYPE = "block"; - // commercialization + /** + * Fallback type. + */ + public static final String FALLBACK_TYPE = "fallback"; - String FLOW_DATASOURCE_NAME = "edas-flow"; - String DEGRADE_DATASOURCE_NAME = "edas-degrade"; + /** + * UrlCleaner type. + */ + public static final String URLCLEANER_TYPE = "urlCleaner"; + + private SentinelConstants() { + throw new AssertionError("Must not instantiate constant utility class"); + } } diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/SentinelProperties.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/SentinelProperties.java index 72dcfa992..8bef50ad1 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/SentinelProperties.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/SentinelProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,15 +20,15 @@ import java.util.List; import java.util.Map; import java.util.TreeMap; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.core.Ordered; -import org.springframework.validation.annotation.Validated; - import com.alibaba.cloud.sentinel.datasource.config.DataSourcePropertiesConfiguration; import com.alibaba.csp.sentinel.config.SentinelConfig; import com.alibaba.csp.sentinel.log.LogBase; import com.alibaba.csp.sentinel.transport.config.TransportConfig; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.core.Ordered; +import org.springframework.validation.annotation.Validated; + /** * {@link ConfigurationProperties} for Sentinel. * @@ -89,9 +89,9 @@ public class SentinelProperties { */ private Log log = new Log(); - /** - * Add HTTP method prefix for Sentinel Resource. - */ + /** + * Add HTTP method prefix for Sentinel Resource. + */ private Boolean httpMethodSpecify = false; public boolean isEager() { @@ -166,15 +166,15 @@ public class SentinelProperties { this.log = log; } - public Boolean getHttpMethodSpecify() { - return httpMethodSpecify; - } + public Boolean getHttpMethodSpecify() { + return httpMethodSpecify; + } - public void setHttpMethodSpecify(Boolean httpMethodSpecify) { - this.httpMethodSpecify = httpMethodSpecify; - } + public void setHttpMethodSpecify(Boolean httpMethodSpecify) { + this.httpMethodSpecify = httpMethodSpecify; + } - public static class Flow { + public static class Flow { /** * The cold factor {@link SentinelConfig#COLD_FACTOR}. @@ -205,6 +205,7 @@ public class SentinelProperties { public void setBlockPage(String blockPage) { this.blockPage = blockPage; } + } public static class Metric { @@ -248,6 +249,7 @@ public class SentinelProperties { public void setCharset(String charset) { this.charset = charset; } + } public static class Transport { @@ -306,6 +308,7 @@ public class SentinelProperties { public void setClientIp(String clientIp) { this.clientIp = clientIp; } + } public static class Filter { @@ -316,7 +319,7 @@ public class SentinelProperties { private int order = Ordered.HIGHEST_PRECEDENCE; /** - * URL pattern for sentinel filter, default is /* + * URL pattern for sentinel filter, default is /*. */ private List urlPatterns; @@ -349,6 +352,7 @@ public class SentinelProperties { public void setEnabled(boolean enabled) { this.enabled = enabled; } + } public static class Log { diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/SentinelWebAutoConfiguration.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/SentinelWebAutoConfiguration.java index 5dfe68842..b8531ebfe 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/SentinelWebAutoConfiguration.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/SentinelWebAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,8 +23,14 @@ import java.util.Optional; import javax.annotation.PostConstruct; import javax.servlet.Filter; +import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter; +import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser; +import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlBlockHandler; +import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlCleaner; +import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -35,12 +41,6 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter; -import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser; -import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlBlockHandler; -import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlCleaner; -import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager; - /** * @author xiaojing */ @@ -74,7 +74,8 @@ public class SentinelWebAutoConfiguration { } @Bean - @ConditionalOnProperty(name = "spring.cloud.sentinel.filter.enabled", matchIfMissing = true) + @ConditionalOnProperty(name = "spring.cloud.sentinel.filter.enabled", + matchIfMissing = true) public FilterRegistrationBean sentinelFilter() { FilterRegistrationBean registration = new FilterRegistrationBean<>(); @@ -100,4 +101,4 @@ public class SentinelWebAutoConfiguration { } -} \ No newline at end of file +} diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/SentinelWebFluxAutoConfiguration.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/SentinelWebFluxAutoConfiguration.java index 86a6bcbca..e42133c3c 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/SentinelWebFluxAutoConfiguration.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/SentinelWebFluxAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,8 +22,14 @@ import java.util.Optional; import javax.annotation.PostConstruct; +import com.alibaba.csp.sentinel.adapter.reactor.SentinelReactorTransformer; +import com.alibaba.csp.sentinel.adapter.spring.webflux.SentinelWebFluxFilter; +import com.alibaba.csp.sentinel.adapter.spring.webflux.callback.BlockRequestHandler; +import com.alibaba.csp.sentinel.adapter.spring.webflux.callback.WebFluxCallbackManager; +import com.alibaba.csp.sentinel.adapter.spring.webflux.exception.SentinelBlockExceptionHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -37,12 +43,6 @@ import org.springframework.core.annotation.Order; import org.springframework.http.codec.ServerCodecConfigurer; import org.springframework.web.reactive.result.view.ViewResolver; -import com.alibaba.csp.sentinel.adapter.reactor.SentinelReactorTransformer; -import com.alibaba.csp.sentinel.adapter.spring.webflux.SentinelWebFluxFilter; -import com.alibaba.csp.sentinel.adapter.spring.webflux.callback.BlockRequestHandler; -import com.alibaba.csp.sentinel.adapter.spring.webflux.callback.WebFluxCallbackManager; -import com.alibaba.csp.sentinel.adapter.spring.webflux.exception.SentinelBlockExceptionHandler; - /** * @author Jim */ @@ -57,6 +57,7 @@ public class SentinelWebFluxAutoConfiguration { .getLogger(SentinelWebFluxAutoConfiguration.class); private final List viewResolvers; + private final ServerCodecConfigurer serverCodecConfigurer; @Autowired @@ -76,17 +77,19 @@ public class SentinelWebFluxAutoConfiguration { @Bean @Order(-2) - @ConditionalOnProperty(name = "spring.cloud.sentinel.filter.enabled", matchIfMissing = true) + @ConditionalOnProperty(name = "spring.cloud.sentinel.filter.enabled", + matchIfMissing = true) public SentinelBlockExceptionHandler sentinelBlockExceptionHandler() { return new SentinelBlockExceptionHandler(viewResolvers, serverCodecConfigurer); } @Bean @Order(-1) - @ConditionalOnProperty(name = "spring.cloud.sentinel.filter.enabled", matchIfMissing = true) + @ConditionalOnProperty(name = "spring.cloud.sentinel.filter.enabled", + matchIfMissing = true) public SentinelWebFluxFilter sentinelWebFluxFilter() { log.info("[Sentinel Starter] register Sentinel SentinelWebFluxFilter"); return new SentinelWebFluxFilter(); } -} \ No newline at end of file +} diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/annotation/SentinelRestTemplate.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/annotation/SentinelRestTemplate.java index 039c9b169..d7d00965a 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/annotation/SentinelRestTemplate.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/annotation/SentinelRestTemplate.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -41,4 +41,5 @@ public @interface SentinelRestTemplate { String urlCleaner() default ""; Class urlCleanerClass() default void.class; + } diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/BlockClassRegistry.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/BlockClassRegistry.java index f1092018b..7bb1bf4d4 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/BlockClassRegistry.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/BlockClassRegistry.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,15 +21,20 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import com.alibaba.csp.sentinel.util.StringUtil; -import org.springframework.util.StringUtils; /** * @author fangjian */ final class BlockClassRegistry { + private BlockClassRegistry() { + + } + private static final Map FALLBACK_MAP = new ConcurrentHashMap<>(); + private static final Map BLOCK_HANDLER_MAP = new ConcurrentHashMap<>(); + private static final Map URL_CLEANER_MAP = new ConcurrentHashMap<>(); static Method lookupFallback(Class clazz, String name) { diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelAutoConfiguration.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelAutoConfiguration.java index a3b435bdd..2ec5ac171 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelAutoConfiguration.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,19 +18,6 @@ package com.alibaba.cloud.sentinel.custom; import javax.annotation.PostConstruct; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.Environment; -import org.springframework.util.StringUtils; - import com.alibaba.cloud.sentinel.SentinelProperties; import com.alibaba.cloud.sentinel.datasource.converter.JsonConverter; import com.alibaba.cloud.sentinel.datasource.converter.XmlConverter; @@ -46,11 +33,23 @@ import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule; import com.alibaba.csp.sentinel.slots.system.SystemRule; import com.alibaba.csp.sentinel.transport.config.TransportConfig; import com.alibaba.csp.sentinel.util.AppNameUtil; - import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import org.springframework.util.StringUtils; + /** * @author xiaojing * @author jiashuai.xie @@ -145,7 +144,8 @@ public class SentinelAutoConfiguration { @Bean @ConditionalOnMissingBean @ConditionalOnClass(name = "org.springframework.web.client.RestTemplate") - @ConditionalOnProperty(name = "resttemplate.sentinel.enabled", havingValue = "true", matchIfMissing = true) + @ConditionalOnProperty(name = "resttemplate.sentinel.enabled", havingValue = "true", + matchIfMissing = true) public SentinelBeanPostProcessor sentinelBeanPostProcessor( ApplicationContext applicationContext) { return new SentinelBeanPostProcessor(applicationContext); @@ -237,6 +237,7 @@ public class SentinelAutoConfiguration { } } + } } diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelBeanPostProcessor.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelBeanPostProcessor.java index 474c8bcd8..0a0fcd238 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelBeanPostProcessor.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelBeanPostProcessor.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,8 +20,12 @@ import java.lang.reflect.Method; import java.util.Arrays; import java.util.concurrent.ConcurrentHashMap; +import com.alibaba.cloud.sentinel.SentinelConstants; +import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate; +import com.alibaba.csp.sentinel.slots.block.BlockException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; @@ -38,12 +42,9 @@ import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; import org.springframework.web.client.RestTemplate; -import com.alibaba.cloud.sentinel.SentinelConstants; -import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate; -import com.alibaba.csp.sentinel.slots.block.BlockException; - /** - * PostProcessor handle @SentinelRestTemplate Annotation, add interceptor for RestTemplate + * PostProcessor handle @SentinelRestTemplate Annotation, add interceptor for + * RestTemplate. * * @author Jim * @see SentinelRestTemplate @@ -219,4 +220,4 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces interceptorBeanDefinition); } -} \ No newline at end of file +} diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelCircuitBreakerConfiguration.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelCircuitBreakerConfiguration.java index 526719bc1..7642d9e8b 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelCircuitBreakerConfiguration.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelCircuitBreakerConfiguration.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.sentinel.custom; import org.springframework.context.annotation.Configuration; @@ -9,4 +25,5 @@ import org.springframework.context.annotation.Configuration; */ @Configuration public class SentinelCircuitBreakerConfiguration { + } diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelDataSourceHandler.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelDataSourceHandler.java index 6c7d3f1d9..2de7727cd 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelDataSourceHandler.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelDataSourceHandler.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.sentinel.custom; import java.lang.reflect.Field; @@ -7,8 +23,15 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import com.alibaba.cloud.sentinel.SentinelProperties; +import com.alibaba.cloud.sentinel.datasource.config.AbstractDataSourceProperties; +import com.alibaba.cloud.sentinel.datasource.converter.JsonConverter; +import com.alibaba.cloud.sentinel.datasource.converter.XmlConverter; +import com.alibaba.csp.sentinel.datasource.AbstractDataSource; +import com.alibaba.csp.sentinel.datasource.ReadableDataSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.SmartInitializingSingleton; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.DefaultListableBeanFactory; @@ -16,16 +39,9 @@ import org.springframework.core.env.Environment; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; -import com.alibaba.cloud.sentinel.SentinelProperties; -import com.alibaba.cloud.sentinel.datasource.config.AbstractDataSourceProperties; -import com.alibaba.cloud.sentinel.datasource.converter.JsonConverter; -import com.alibaba.cloud.sentinel.datasource.converter.XmlConverter; -import com.alibaba.csp.sentinel.datasource.AbstractDataSource; -import com.alibaba.csp.sentinel.datasource.ReadableDataSource; - /** * Sentinel {@link ReadableDataSource} Handler Handle the configurations of - * 'spring.cloud.sentinel.datasource' + * 'spring.cloud.sentinel.datasource'. * * @author Jim * @see SentinelProperties#datasource @@ -40,7 +56,9 @@ public class SentinelDataSourceHandler implements SmartInitializingSingleton { private List dataTypeList = Arrays.asList("json", "xml"); private final String DATA_TYPE_FIELD = "dataType"; + private final String CUSTOM_DATA_TYPE = "custom"; + private final String CONVERTER_CLASS_FIELD = "converterClass"; private final DefaultListableBeanFactory beanFactory; diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelProtectInterceptor.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelProtectInterceptor.java index 7b3702644..fbd468b26 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelProtectInterceptor.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelProtectInterceptor.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,12 +21,6 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URI; -import org.springframework.http.HttpRequest; -import org.springframework.http.client.ClientHttpRequestExecution; -import org.springframework.http.client.ClientHttpRequestInterceptor; -import org.springframework.http.client.ClientHttpResponse; -import org.springframework.web.client.RestTemplate; - import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate; import com.alibaba.cloud.sentinel.rest.SentinelClientHttpResponse; import com.alibaba.csp.sentinel.Entry; @@ -36,8 +30,14 @@ import com.alibaba.csp.sentinel.Tracer; import com.alibaba.csp.sentinel.slots.block.BlockException; import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException; +import org.springframework.http.HttpRequest; +import org.springframework.http.client.ClientHttpRequestExecution; +import org.springframework.http.client.ClientHttpRequestInterceptor; +import org.springframework.http.client.ClientHttpResponse; +import org.springframework.web.client.RestTemplate; + /** - * Interceptor using by SentinelRestTemplate + * Interceptor using by SentinelRestTemplate. * * @author Jim */ @@ -73,7 +73,8 @@ public class SentinelProtectInterceptor implements ClientHttpRequestInterceptor hostWithPathResource); } - Entry hostEntry = null, hostWithPathEntry = null; + Entry hostEntry = null; + Entry hostWithPathEntry = null; ClientHttpResponse response = null; try { hostEntry = SphU.entry(hostResource, EntryType.OUT); diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/endpoint/SentinelEndpoint.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/endpoint/SentinelEndpoint.java index 3d523ebb4..98aace362 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/endpoint/SentinelEndpoint.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/endpoint/SentinelEndpoint.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,9 +19,6 @@ package com.alibaba.cloud.sentinel.endpoint; import java.util.HashMap; import java.util.Map; -import org.springframework.boot.actuate.endpoint.annotation.Endpoint; -import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; - import com.alibaba.cloud.sentinel.SentinelProperties; import com.alibaba.csp.sentinel.adapter.servlet.config.WebServletConfig; import com.alibaba.csp.sentinel.config.SentinelConfig; @@ -34,8 +31,12 @@ import com.alibaba.csp.sentinel.slots.system.SystemRuleManager; import com.alibaba.csp.sentinel.transport.config.TransportConfig; import com.alibaba.csp.sentinel.util.AppNameUtil; +import org.springframework.boot.actuate.endpoint.annotation.Endpoint; +import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; + /** - * Endpoint for Sentinel, contains ans properties and rules + * Endpoint for Sentinel, contains ans properties and rules. + * * @author xiaojing */ @Endpoint(id = "sentinel") diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/endpoint/SentinelEndpointAutoConfiguration.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/endpoint/SentinelEndpointAutoConfiguration.java index ded2f47c4..caa5afd2f 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/endpoint/SentinelEndpointAutoConfiguration.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/endpoint/SentinelEndpointAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,8 @@ package com.alibaba.cloud.sentinel.endpoint; +import com.alibaba.cloud.sentinel.SentinelProperties; + import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; @@ -25,8 +27,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; -import com.alibaba.cloud.sentinel.SentinelProperties; - /** * @author hengyunabc */ @@ -49,4 +49,5 @@ public class SentinelEndpointAutoConfiguration { SentinelProperties sentinelProperties) { return new SentinelHealthIndicator(beanFactory, sentinelProperties); } + } diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/endpoint/SentinelHealthIndicator.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/endpoint/SentinelHealthIndicator.java index 08864b8bd..2d9466b32 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/endpoint/SentinelHealthIndicator.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/endpoint/SentinelHealthIndicator.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,6 +19,12 @@ package com.alibaba.cloud.sentinel.endpoint; import java.util.HashMap; import java.util.Map; +import com.alibaba.cloud.sentinel.SentinelProperties; +import com.alibaba.csp.sentinel.datasource.AbstractDataSource; +import com.alibaba.csp.sentinel.heartbeat.HeartbeatSenderProvider; +import com.alibaba.csp.sentinel.transport.HeartbeatSender; +import com.alibaba.csp.sentinel.transport.config.TransportConfig; + import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.boot.actuate.health.AbstractHealthIndicator; import org.springframework.boot.actuate.health.Health; @@ -26,12 +32,6 @@ import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.actuate.health.Status; import org.springframework.util.StringUtils; -import com.alibaba.cloud.sentinel.SentinelProperties; -import com.alibaba.csp.sentinel.datasource.AbstractDataSource; -import com.alibaba.csp.sentinel.heartbeat.HeartbeatSenderProvider; -import com.alibaba.csp.sentinel.transport.HeartbeatSender; -import com.alibaba.csp.sentinel.transport.config.TransportConfig; - /** * A {@link HealthIndicator} for Sentinel, which checks the status of Sentinel Dashboard * and DataSource. @@ -145,4 +145,5 @@ public class SentinelHealthIndicator extends AbstractHealthIndicator { builder.down().withDetails(detailMap); } } + } diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelContractHolder.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelContractHolder.java index b83fbfd9c..9a5acfd31 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelContractHolder.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelContractHolder.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -26,7 +26,7 @@ import feign.MethodMetadata; /** * * Using static field {@link SentinelContractHolder#METADATA_MAP} to hold - * {@link MethodMetadata} data + * {@link MethodMetadata} data. * * @author Jim */ diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelFeign.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelFeign.java index 3dbc00adb..5b2f89d85 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelFeign.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelFeign.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,13 +21,6 @@ import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.util.Map; -import org.springframework.beans.BeansException; -import org.springframework.cloud.openfeign.FeignContext; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.util.ReflectionUtils; -import org.springframework.util.StringUtils; - import feign.Contract; import feign.Feign; import feign.InvocationHandlerFactory; @@ -35,12 +28,23 @@ import feign.Target; import feign.hystrix.FallbackFactory; import feign.hystrix.HystrixFeign; +import org.springframework.beans.BeansException; +import org.springframework.cloud.openfeign.FeignContext; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.util.ReflectionUtils; +import org.springframework.util.StringUtils; + /** - * {@link Feign.Builder} like {@link HystrixFeign.Builder} + * {@link Feign.Builder} like {@link HystrixFeign.Builder}. * * @author Jim */ -public class SentinelFeign { +public final class SentinelFeign { + + private SentinelFeign() { + + } public static Builder builder() { return new Builder(); @@ -149,6 +153,7 @@ public class SentinelFeign { this.applicationContext = applicationContext; feignContext = this.applicationContext.getBean(FeignContext.class); } + } } diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelFeignAutoConfiguration.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelFeignAutoConfiguration.java index 9989c9964..a3e2831d7 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelFeignAutoConfiguration.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelFeignAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,9 @@ package com.alibaba.cloud.sentinel.feign; +import com.alibaba.csp.sentinel.SphU; +import feign.Feign; + import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -23,10 +26,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; -import com.alibaba.csp.sentinel.SphU; - -import feign.Feign; - /** * @author Jim */ diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelInvocationHandler.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelInvocationHandler.java index 5564ca019..e5f80a62b 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelInvocationHandler.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelInvocationHandler.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,8 +16,6 @@ package com.alibaba.cloud.sentinel.feign; -import static feign.Util.checkNotNull; - import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -31,24 +29,27 @@ import com.alibaba.csp.sentinel.SphU; import com.alibaba.csp.sentinel.Tracer; import com.alibaba.csp.sentinel.context.ContextUtil; import com.alibaba.csp.sentinel.slots.block.BlockException; - import feign.Feign; import feign.InvocationHandlerFactory.MethodHandler; import feign.MethodMetadata; import feign.Target; import feign.hystrix.FallbackFactory; +import static feign.Util.checkNotNull; + /** - * {@link InvocationHandler} handle invocation that protected by Sentinel + * {@link InvocationHandler} handle invocation that protected by Sentinel. * * @author Jim */ public class SentinelInvocationHandler implements InvocationHandler { private final Target target; + private final Map dispatch; private FallbackFactory fallbackFactory; + private Map fallbackMethodMap; SentinelInvocationHandler(Target target, Map dispatch, @@ -70,8 +71,7 @@ public class SentinelInvocationHandler implements InvocationHandler { if ("equals".equals(method.getName())) { try { Object otherHandler = args.length > 0 && args[0] != null - ? Proxy.getInvocationHandler(args[0]) - : null; + ? Proxy.getInvocationHandler(args[0]) : null; return equals(otherHandler); } catch (IllegalArgumentException e) { diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/rest/SentinelClientHttpResponse.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/rest/SentinelClientHttpResponse.java index a38084e3b..3822d46a3 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/rest/SentinelClientHttpResponse.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/rest/SentinelClientHttpResponse.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,16 +24,16 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate; +import com.alibaba.cloud.sentinel.custom.SentinelProtectInterceptor; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.client.AbstractClientHttpResponse; -import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate; -import com.alibaba.cloud.sentinel.custom.SentinelProtectInterceptor; - /** - * Using by {@link SentinelRestTemplate} and {@link SentinelProtectInterceptor} + * Using by {@link SentinelRestTemplate} and {@link SentinelProtectInterceptor}. * * @author Jim */ @@ -77,4 +77,5 @@ public class SentinelClientHttpResponse extends AbstractClientHttpResponse { httpHeaders.putAll(headers); return httpHeaders; } + } diff --git a/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/ContextIdSentinelFeignTests.java b/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/ContextIdSentinelFeignTests.java index e6c581de1..f6996fdbc 100644 --- a/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/ContextIdSentinelFeignTests.java +++ b/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/ContextIdSentinelFeignTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,10 @@ package com.alibaba.cloud.sentinel; -import static org.junit.Assert.*; - -import java.util.Arrays; - -import org.junit.Before; +import com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -37,19 +34,16 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration; -import com.alibaba.csp.sentinel.slots.block.RuleConstant; -import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; -import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager; +import static org.assertj.core.api.Assertions.assertThat; /** * Add this unit test to verify https://github.com/alibaba/spring-cloud-alibaba/pull/838 - * + * * @author Jim */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = { ContextIdSentinelFeignTests.TestConfig.class }, properties = { - "feign.sentinel.enabled=true" }) +@SpringBootTest(classes = { ContextIdSentinelFeignTests.TestConfig.class }, + properties = { "feign.sentinel.enabled=true" }) public class ContextIdSentinelFeignTests { @Autowired @@ -60,16 +54,11 @@ public class ContextIdSentinelFeignTests { @Test public void testFeignClient() { - assertEquals("Sentinel Feign Client fallback success", "echo fallback", - echoService.echo("test")); - assertEquals("Sentinel Feign Client fallbackFactory success", "foo fallback", - fooService.echo("test")); - assertNotEquals("ToString method invoke was not in SentinelInvocationHandler", - echoService.toString(), fooService.toString()); - assertNotEquals("HashCode method invoke was not in SentinelInvocationHandler", - echoService.hashCode(), fooService.hashCode()); - assertFalse("Equals method invoke was not in SentinelInvocationHandler", - echoService.equals(fooService)); + assertThat(echoService.echo("test")).isEqualTo("echo fallback"); + assertThat(fooService.echo("test")).isEqualTo("foo fallback"); + assertThat(fooService.toString()).isNotEqualTo(echoService.toString()); + assertThat(fooService.hashCode()).isNotEqualTo(echoService.hashCode()); + assertThat(echoService.equals(fooService)).isEqualTo(Boolean.FALSE); } @Configuration @@ -80,16 +69,24 @@ public class ContextIdSentinelFeignTests { } - @FeignClient(contextId = "echoService", name = "service-provider", fallback = EchoServiceFallback.class, configuration = FeignConfiguration.class) + @FeignClient(contextId = "echoService", name = "service-provider", + fallback = EchoServiceFallback.class, + configuration = FeignConfiguration.class) public interface EchoService { - @GetMapping(value = "/echo/{str}") + + @GetMapping("/echo/{str}") String echo(@PathVariable("str") String str); + } - @FeignClient(contextId = "fooService", value = "foo-service", fallbackFactory = CustomFallbackFactory.class, configuration = FeignConfiguration.class) + @FeignClient(contextId = "fooService", value = "foo-service", + fallbackFactory = CustomFallbackFactory.class, + configuration = FeignConfiguration.class) public interface FooService { + @RequestMapping(path = "echo/{str}") String echo(@RequestParam("str") String param); + } public static class FeignConfiguration { @@ -121,6 +118,7 @@ public class ContextIdSentinelFeignTests { public String echo(@RequestParam("str") String param) { return "foo fallback"; } + } public static class CustomFallbackFactory @@ -132,6 +130,7 @@ public class ContextIdSentinelFeignTests { public FooService create(Throwable throwable) { return fooService; } + } } diff --git a/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelAutoConfigurationTests.java b/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelAutoConfigurationTests.java index bc60fa988..045ab8b74 100644 --- a/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelAutoConfigurationTests.java +++ b/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelAutoConfigurationTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,18 +16,28 @@ package com.alibaba.cloud.sentinel; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.mock; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - import java.util.Arrays; import java.util.Map; +import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate; +import com.alibaba.cloud.sentinel.custom.SentinelAutoConfiguration; +import com.alibaba.cloud.sentinel.custom.SentinelBeanPostProcessor; +import com.alibaba.cloud.sentinel.endpoint.SentinelEndpoint; +import com.alibaba.cloud.sentinel.rest.SentinelClientHttpResponse; +import com.alibaba.csp.sentinel.adapter.servlet.config.WebServletConfig; +import com.alibaba.csp.sentinel.config.SentinelConfig; +import com.alibaba.csp.sentinel.log.LogBase; +import com.alibaba.csp.sentinel.slots.block.BlockException; +import com.alibaba.csp.sentinel.slots.block.RuleConstant; +import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; +import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager; +import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; +import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager; +import com.alibaba.csp.sentinel.transport.config.TransportConfig; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -45,30 +55,18 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; -import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate; -import com.alibaba.cloud.sentinel.custom.SentinelAutoConfiguration; -import com.alibaba.cloud.sentinel.custom.SentinelBeanPostProcessor; -import com.alibaba.cloud.sentinel.endpoint.SentinelEndpoint; -import com.alibaba.cloud.sentinel.rest.SentinelClientHttpResponse; -import com.alibaba.csp.sentinel.adapter.servlet.config.WebServletConfig; -import com.alibaba.csp.sentinel.config.SentinelConfig; -import com.alibaba.csp.sentinel.log.LogBase; -import com.alibaba.csp.sentinel.slots.block.BlockException; -import com.alibaba.csp.sentinel.slots.block.RuleConstant; -import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; -import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager; -import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; -import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager; -import com.alibaba.csp.sentinel.transport.config.TransportConfig; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.mock; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; /** * @author Jim * @author jiashuai.xie */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = { - SentinelAutoConfigurationTests.TestConfig.class }, properties = { - "spring.cloud.sentinel.filter.order=123", +@SpringBootTest(classes = { SentinelAutoConfigurationTests.TestConfig.class }, + properties = { "spring.cloud.sentinel.filter.order=123", "spring.cloud.sentinel.filter.urlPatterns=/*,/test", "spring.cloud.sentinel.metric.fileSingleSize=9999", "spring.cloud.sentinel.metric.fileTotalCount=100", @@ -79,7 +77,8 @@ import com.alibaba.csp.sentinel.transport.config.TransportConfig; "spring.cloud.sentinel.transport.dashboard=http://localhost:8080", "spring.cloud.sentinel.transport.port=9999", "spring.cloud.sentinel.transport.clientIp=1.1.1.1", - "spring.cloud.sentinel.transport.heartbeatIntervalMs=20000" }, webEnvironment = RANDOM_PORT) + "spring.cloud.sentinel.transport.heartbeatIntervalMs=20000" }, + webEnvironment = RANDOM_PORT) public class SentinelAutoConfigurationTests { @Autowired @@ -131,10 +130,10 @@ public class SentinelAutoConfigurationTests { @Test public void contextLoads() throws Exception { - assertNotNull("FilterRegistrationBean was not created", filterRegistrationBean); - assertNotNull("SentinelProperties was not created", sentinelProperties); - assertNotNull("SentinelBeanPostProcessor was not created", - sentinelBeanPostProcessor); + + assertThat(filterRegistrationBean).isNotNull(); + assertThat(filterRegistrationBean).isNotNull(); + assertThat(sentinelBeanPostProcessor).isNotNull(); checkSentinelLog(); checkSentinelEager(); @@ -148,139 +147,110 @@ public class SentinelAutoConfigurationTests { private void checkEndpoint() { SentinelEndpoint sentinelEndpoint = new SentinelEndpoint(sentinelProperties); Map map = sentinelEndpoint.invoke(); - assertEquals("Endpoint Sentinel log pid was wrong", true, map.get("logUsePid")); - assertEquals("Endpoint Sentinel transport console server was wrong", - "http://localhost:8080", map.get("consoleServer")); - assertEquals("Endpoint Sentinel transport port was wrong", "9999", - map.get("clientPort")); - assertEquals("Endpoint Sentinel transport heartbeatIntervalMs was wrong", 20000l, - map.get("heartbeatIntervalMs")); - assertEquals("Endpoint Sentinel transport clientIp was wrong", "1.1.1.1", - map.get("clientIp")); - assertEquals("Endpoint Sentinel metric file size was wrong", 9999l, - map.get("metricsFileSize")); - assertEquals("Endpoint Sentinel metric file count was wrong", 100, - map.get("totalMetricsFileCount")); - assertEquals("Endpoint Sentinel metric file charset was wrong", "UTF-8", - map.get("metricsFileCharset")); - assertEquals("Endpoint Sentinel block page was wrong", "/error", - map.get("blockPage")); + + assertThat(map.get("logUsePid")).isEqualTo(Boolean.TRUE); + assertThat(map.get("consoleServer")).isEqualTo("http://localhost:8080"); + assertThat(map.get("clientPort")).isEqualTo("9999"); + assertThat(map.get("heartbeatIntervalMs")).isEqualTo(20000L); + assertThat(map.get("clientIp")).isEqualTo("1.1.1.1"); + assertThat(map.get("metricsFileSize")).isEqualTo(9999L); + assertThat(map.get("totalMetricsFileCount")).isEqualTo(100); + assertThat(map.get("metricsFileCharset")).isEqualTo("UTF-8"); + assertThat(map.get("blockPage")).isEqualTo("/error"); } private void checkSentinelFilter() { - assertEquals("SentinelProperties filter order was wrong", 123, - sentinelProperties.getFilter().getOrder()); - assertEquals("SentinelProperties filter url pattern size was wrong", 2, - sentinelProperties.getFilter().getUrlPatterns().size()); - assertEquals("SentinelProperties filter url pattern item was wrong", "/*", - sentinelProperties.getFilter().getUrlPatterns().get(0)); - assertEquals("SentinelProperties filter url pattern item was wrong", "/test", - sentinelProperties.getFilter().getUrlPatterns().get(1)); + assertThat(sentinelProperties.getFilter().getOrder()).isEqualTo(123); + assertThat(sentinelProperties.getFilter().getUrlPatterns().size()).isEqualTo(2); + assertThat(sentinelProperties.getFilter().getUrlPatterns().get(0)) + .isEqualTo("/*"); + assertThat(sentinelProperties.getFilter().getUrlPatterns().get(1)) + .isEqualTo("/test"); } private void checkSentinelMetric() { - assertEquals("SentinelProperties metric charset was wrong", "UTF-8", - sentinelProperties.getMetric().getCharset()); - assertEquals("SentinelProperties metric file single size was wrong", "9999", - sentinelProperties.getMetric().getFileSingleSize()); - assertEquals("SentinelProperties metric file total count was wrong", "100", - sentinelProperties.getMetric().getFileTotalCount()); + assertThat(sentinelProperties.getMetric().getCharset()).isEqualTo("UTF-8"); + assertThat(sentinelProperties.getMetric().getFileSingleSize()).isEqualTo("9999"); + assertThat(sentinelProperties.getMetric().getFileTotalCount()).isEqualTo("100"); } private void checkSentinelColdFactor() { - assertEquals("SentinelProperties coldFactor was wrong", "3", - sentinelProperties.getFlow().getColdFactor()); + assertThat(sentinelProperties.getFlow().getColdFactor()).isEqualTo("3"); } private void checkSentinelTransport() { - assertEquals("SentinelProperties transport port was wrong", "9999", - sentinelProperties.getTransport().getPort()); - assertEquals("SentinelProperties transport dashboard was wrong", - "http://localhost:8080", - sentinelProperties.getTransport().getDashboard()); - assertEquals("SentinelProperties transport clientIp was wrong", "1.1.1.1", - sentinelProperties.getTransport().getClientIp()); - assertEquals("SentinelProperties transport heartbeatIntervalMs was wrong", - "20000", sentinelProperties.getTransport().getHeartbeatIntervalMs()); + assertThat(sentinelProperties.getTransport().getPort()).isEqualTo("9999"); + assertThat(sentinelProperties.getTransport().getDashboard()) + .isEqualTo("http://localhost:8080"); + assertThat(sentinelProperties.getTransport().getClientIp()).isEqualTo("1.1.1.1"); + assertThat(sentinelProperties.getTransport().getHeartbeatIntervalMs()) + .isEqualTo("20000"); } private void checkSentinelEager() { - assertEquals("SentinelProperties eager was wrong", true, - sentinelProperties.isEager()); + assertThat(sentinelProperties.isEager()).isEqualTo(true); } private void checkSentinelLog() { - assertEquals("SentinelProperties log file pid was wrong", true, - sentinelProperties.getLog().isSwitchPid()); + assertThat(sentinelProperties.getLog().isSwitchPid()).isEqualTo(true); } @Test public void testFilter() { - assertEquals("Sentinel Filter order was wrong", filterRegistrationBean.getOrder(), - 123); - assertEquals("Sentinel Filter url-pattern was wrong", - filterRegistrationBean.getUrlPatterns().size(), 2); + assertThat(123).isEqualTo(filterRegistrationBean.getOrder()); + assertThat(2).isEqualTo(filterRegistrationBean.getUrlPatterns().size()); } @Test public void testSentinelSystemProperties() { - assertEquals("Sentinel log pid was wrong", true, LogBase.isLogNameUsePid()); - assertEquals("Sentinel transport console server was wrong", - "http://localhost:8080", TransportConfig.getConsoleServer()); - assertEquals("Sentinel transport port was wrong", "9999", - TransportConfig.getPort()); - assertEquals("Sentinel transport heartbeatIntervalMs was wrong", 20000l, - TransportConfig.getHeartbeatIntervalMs().longValue()); - assertEquals("Sentinel transport clientIp was wrong", "1.1.1.1", - TransportConfig.getHeartbeatClientIp()); - assertEquals("Sentinel metric file size was wrong", 9999, - SentinelConfig.singleMetricFileSize()); - assertEquals("Sentinel metric file count was wrong", 100, - SentinelConfig.totalMetricFileCount()); - assertEquals("Sentinel metric file charset was wrong", "UTF-8", - SentinelConfig.charset()); - assertEquals("Sentinel block page was wrong", "/error", - WebServletConfig.getBlockPage()); + assertThat(LogBase.isLogNameUsePid()).isEqualTo(true); + assertThat(TransportConfig.getConsoleServer()).isEqualTo("http://localhost:8080"); + assertThat(TransportConfig.getPort()).isEqualTo("9999"); + assertThat(TransportConfig.getHeartbeatIntervalMs().longValue()) + .isEqualTo(20000L); + assertThat(TransportConfig.getHeartbeatClientIp()).isEqualTo("1.1.1.1"); + assertThat(SentinelConfig.singleMetricFileSize()).isEqualTo(9999); + assertThat(SentinelConfig.totalMetricFileCount()).isEqualTo(100); + assertThat(SentinelConfig.charset()).isEqualTo("UTF-8"); + assertThat(WebServletConfig.getBlockPage()).isEqualTo("/error"); } @Test public void testFlowRestTemplate() { - assertEquals("RestTemplate interceptors size was wrong", 2, - restTemplate.getInterceptors().size()); - assertEquals("RestTemplateWithBlockClass interceptors size was wrong", 1, - restTemplateWithBlockClass.getInterceptors().size()); + + assertThat(restTemplate.getInterceptors().size()).isEqualTo(2); + assertThat(restTemplateWithBlockClass.getInterceptors().size()).isEqualTo(1); + ResponseEntity responseEntityBlock = restTemplateWithBlockClass .getForEntity(flowUrl, String.class); - assertEquals("RestTemplateWithBlockClass Sentinel Block Message was wrong", - "Oops", responseEntityBlock.getBody()); - assertEquals( - "RestTemplateWithBlockClass Sentinel Block Http Status Code was wrong", - HttpStatus.OK, responseEntityBlock.getStatusCode()); + + assertThat(responseEntityBlock.getBody()).isEqualTo("Oops"); + assertThat(responseEntityBlock.getStatusCode()).isEqualTo(HttpStatus.OK); + ResponseEntity responseEntityRaw = restTemplate.getForEntity(flowUrl, String.class); - assertEquals("RestTemplate Sentinel Block Message was wrong", - "RestTemplate request block by sentinel", responseEntityRaw.getBody()); - assertEquals("RestTemplate Sentinel Block Http Status Code was wrong", - HttpStatus.OK, responseEntityRaw.getStatusCode()); + + assertThat(responseEntityRaw.getBody()) + .isEqualTo("RestTemplate request block by sentinel"); + assertThat(responseEntityRaw.getStatusCode()).isEqualTo(HttpStatus.OK); } @Test public void testNormalRestTemplate() { - assertEquals("RestTemplateWithoutBlockClass interceptors size was wrong", 0, - restTemplateWithoutBlockClass.getInterceptors().size()); - assertThatExceptionOfType(RestClientException.class).isThrownBy(() -> { + assertThat(restTemplateWithoutBlockClass.getInterceptors().size()).isEqualTo(0); + + assertThatThrownBy(() -> { restTemplateWithoutBlockClass.getForEntity(flowUrl, String.class); - }); + }).isInstanceOf(RestClientException.class); } @Test public void testFallbackRestTemplate() { ResponseEntity responseEntity = restTemplateWithFallbackClass .getForEntity(degradeUrl, String.class); - assertEquals("RestTemplateWithFallbackClass Sentinel Message was wrong", - "Oops fallback", responseEntity.getBody()); - assertEquals("RestTemplateWithFallbackClass Sentinel Http Status Code was wrong", - HttpStatus.OK, responseEntity.getStatusCode()); + + assertThat(responseEntity.getBody()).isEqualTo("Oops fallback"); + assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK); } @Configuration @@ -295,13 +265,15 @@ public class SentinelAutoConfigurationTests { } @Bean - @SentinelRestTemplate(blockHandlerClass = ExceptionUtil.class, blockHandler = "handleException") + @SentinelRestTemplate(blockHandlerClass = ExceptionUtil.class, + blockHandler = "handleException") RestTemplate restTemplateWithBlockClass() { return new RestTemplate(); } @Bean - @SentinelRestTemplate(fallbackClass = ExceptionUtil.class, fallback = "fallbackException") + @SentinelRestTemplate(fallbackClass = ExceptionUtil.class, + fallback = "fallbackException") RestTemplate restTemplateWithFallbackClass() { return new RestTemplate(); } @@ -314,6 +286,7 @@ public class SentinelAutoConfigurationTests { } public static class ExceptionUtil { + public static SentinelClientHttpResponse handleException(HttpRequest request, byte[] body, ClientHttpRequestExecution execution, BlockException ex) { System.out.println("Oops: " + ex.getClass().getCanonicalName()); @@ -325,6 +298,7 @@ public class SentinelAutoConfigurationTests { System.out.println("Oops: " + ex.getClass().getCanonicalName()); return new SentinelClientHttpResponse("Oops fallback"); } + } @Configuration @@ -332,6 +306,7 @@ public class SentinelAutoConfigurationTests { @ImportAutoConfiguration({ SentinelAutoConfiguration.class, SentinelWebAutoConfiguration.class, SentinelTestConfiguration.class }) public static class TestConfig { + } } diff --git a/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelBeanAutowiredTests.java b/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelBeanAutowiredTests.java index ef8c67e33..cfb671148 100644 --- a/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelBeanAutowiredTests.java +++ b/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelBeanAutowiredTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,16 +16,21 @@ package com.alibaba.cloud.sentinel; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - import java.io.IOException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import com.alibaba.cloud.sentinel.custom.SentinelAutoConfiguration; +import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser; +import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlBlockHandler; +import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlCleaner; +import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager; +import com.alibaba.csp.sentinel.adapter.servlet.util.FilterUtil; +import com.alibaba.csp.sentinel.slots.block.BlockException; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -34,20 +39,14 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.cloud.sentinel.custom.SentinelAutoConfiguration; -import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser; -import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlBlockHandler; -import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlCleaner; -import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager; -import com.alibaba.csp.sentinel.adapter.servlet.util.FilterUtil; -import com.alibaba.csp.sentinel.slots.block.BlockException; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Jim */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = { SentinelBeanAutowiredTests.TestConfig.class }, properties = { - "spring.cloud.sentinel.filter.order=111" }) +@SpringBootTest(classes = { SentinelBeanAutowiredTests.TestConfig.class }, + properties = { "spring.cloud.sentinel.filter.order=111" }) public class SentinelBeanAutowiredTests { @Autowired @@ -64,31 +63,27 @@ public class SentinelBeanAutowiredTests { @Test public void contextLoads() throws Exception { - assertNotNull("UrlCleaner was not created", urlCleaner); - assertNotNull("UrlBlockHandler was not created", urlBlockHandler); - assertNotNull("RequestOriginParser was not created", requestOriginParser); - assertNotNull("SentinelProperties was not created", sentinelProperties); + assertThat(urlCleaner).isNotNull(); + assertThat(urlBlockHandler).isNotNull(); + assertThat(requestOriginParser).isNotNull(); + assertThat(sentinelProperties).isNotNull(); checkUrlPattern(); } private void checkUrlPattern() { - assertEquals("SentinelProperties filter order was wrong", 111, - sentinelProperties.getFilter().getOrder()); - assertEquals("SentinelProperties filter url pattern size was wrong", 1, - sentinelProperties.getFilter().getUrlPatterns().size()); - assertEquals("SentinelProperties filter url pattern was wrong", "/*", - sentinelProperties.getFilter().getUrlPatterns().get(0)); + assertThat(sentinelProperties.getFilter().getOrder()).isEqualTo(111); + assertThat(sentinelProperties.getFilter().getUrlPatterns().size()).isEqualTo(1); + assertThat(sentinelProperties.getFilter().getUrlPatterns().get(0)) + .isEqualTo("/*"); } @Test public void testBeanAutowired() { - assertEquals("UrlCleaner was not autowired", urlCleaner, - WebCallbackManager.getUrlCleaner()); - assertEquals("UrlBlockHandler was not autowired", urlBlockHandler, - WebCallbackManager.getUrlBlockHandler()); - assertEquals("RequestOriginParser was not autowired", requestOriginParser, - WebCallbackManager.getRequestOriginParser()); + assertThat(WebCallbackManager.getUrlCleaner()).isEqualTo(urlCleaner); + assertThat(WebCallbackManager.getUrlBlockHandler()).isEqualTo(urlBlockHandler); + assertThat(WebCallbackManager.getRequestOriginParser()) + .isEqualTo(requestOriginParser); } @Configuration diff --git a/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelDataSourceTests.java b/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelDataSourceTests.java index 40446485e..189d52228 100644 --- a/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelDataSourceTests.java +++ b/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelDataSourceTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,12 +16,11 @@ package com.alibaba.cloud.sentinel; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - +import com.alibaba.cloud.sentinel.custom.SentinelAutoConfiguration; +import com.alibaba.cloud.sentinel.datasource.RuleType; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -29,8 +28,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.cloud.sentinel.custom.SentinelAutoConfiguration; -import com.alibaba.cloud.sentinel.datasource.RuleType; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Jim @@ -62,38 +60,31 @@ public class SentinelDataSourceTests { @Test public void contextLoads() throws Exception { - assertNotNull("SentinelProperties was not created", sentinelProperties); + assertThat(sentinelProperties).isNotNull(); checkUrlPattern(); } private void checkUrlPattern() { - assertEquals("SentinelProperties filter order was wrong", Integer.MIN_VALUE, - sentinelProperties.getFilter().getOrder()); - assertEquals("SentinelProperties filter url pattern size was wrong", 1, - sentinelProperties.getFilter().getUrlPatterns().size()); - assertEquals("SentinelProperties filter url pattern was wrong", "/*", - sentinelProperties.getFilter().getUrlPatterns().get(0)); + assertThat(sentinelProperties.getFilter().getOrder()) + .isEqualTo(Integer.MIN_VALUE); + assertThat(sentinelProperties.getFilter().getUrlPatterns().size()).isEqualTo(1); + assertThat(sentinelProperties.getFilter().getUrlPatterns().get(0)) + .isEqualTo("/*"); } @Test public void testDataSource() { - assertEquals("DataSource size was wrong", 5, - sentinelProperties.getDatasource().size()); - assertNull("DataSource ds1 apollo is not null", - sentinelProperties.getDatasource().get("ds1").getApollo()); - assertNull("DataSource ds1 nacos is not null", - sentinelProperties.getDatasource().get("ds1").getNacos()); - assertNull("DataSource ds1 zk is not null", - sentinelProperties.getDatasource().get("ds1").getZk()); - assertNotNull("DataSource ds1 file is null", - sentinelProperties.getDatasource().get("ds1").getFile()); - - assertEquals("DataSource ds1 file dataType was wrong", "json", - sentinelProperties.getDatasource().get("ds1").getFile().getDataType()); - assertEquals("DataSource ds1 file ruleType was wrong", RuleType.FLOW, - sentinelProperties.getDatasource().get("ds1").getFile().getRuleType()); - + assertThat(sentinelProperties.getDatasource().size()).isEqualTo(5); + assertThat(sentinelProperties.getDatasource().get("ds1").getApollo()).isNull(); + assertThat(sentinelProperties.getDatasource().get("ds1").getNacos()).isNull(); + assertThat(sentinelProperties.getDatasource().get("ds1").getZk()).isNull(); + assertThat(sentinelProperties.getDatasource().get("ds1").getFile()).isNotNull(); + + assertThat(sentinelProperties.getDatasource().get("ds1").getFile().getDataType()) + .isEqualTo("json"); + assertThat(sentinelProperties.getDatasource().get("ds1").getFile().getRuleType()) + .isEqualTo(RuleType.FLOW); } @Configuration diff --git a/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelFeignTests.java b/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelFeignTests.java index 92e17beab..0939bf0ba 100644 --- a/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelFeignTests.java +++ b/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelFeignTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,17 +16,16 @@ package com.alibaba.cloud.sentinel; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; - import java.util.Arrays; +import com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration; +import com.alibaba.csp.sentinel.slots.block.RuleConstant; +import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; +import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -39,17 +38,15 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration; -import com.alibaba.csp.sentinel.slots.block.RuleConstant; -import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; -import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * @author Jim */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = { SentinelFeignTests.TestConfig.class }, properties = { - "feign.sentinel.enabled=true" }) +@SpringBootTest(classes = { SentinelFeignTests.TestConfig.class }, + properties = { "feign.sentinel.enabled=true" }) public class SentinelFeignTests { @Autowired @@ -99,29 +96,26 @@ public class SentinelFeignTests { @Test public void contextLoads() throws Exception { - assertNotNull("EchoService was not created", echoService); - assertNotNull("FooService was not created", fooService); + assertThat(echoService).isNotNull(); + assertThat(fooService).isNotNull(); } @Test public void testFeignClient() { - assertEquals("Sentinel Feign Client fallback success", "echo fallback", - echoService.echo("test")); - assertEquals("Sentinel Feign Client fallbackFactory success", "foo fallback", - fooService.echo("test")); - assertThatExceptionOfType(Exception.class).isThrownBy(() -> { + assertThat(echoService.echo("test")).isEqualTo("echo fallback"); + assertThat(fooService.echo("test")).isEqualTo("foo fallback"); + + assertThatThrownBy(() -> { barService.bar(); - }); - assertThatExceptionOfType(Exception.class).isThrownBy(() -> { + }).isInstanceOf(Exception.class); + + assertThatThrownBy(() -> { bazService.baz(); - }); - - assertNotEquals("ToString method invoke was not in SentinelInvocationHandler", - echoService.toString(), fooService.toString()); - assertNotEquals("HashCode method invoke was not in SentinelInvocationHandler", - echoService.hashCode(), fooService.hashCode()); - assertFalse("Equals method invoke was not in SentinelInvocationHandler", - echoService.equals(fooService)); + }).isInstanceOf(Exception.class); + + assertThat(fooService.toString()).isNotEqualTo(echoService.toString()); + assertThat(fooService.hashCode()).isNotEqualTo(echoService.hashCode()); + assertThat(echoService.equals(fooService)).isEqualTo(Boolean.FALSE); } @Configuration @@ -144,29 +138,38 @@ public class SentinelFeignTests { @FeignClient(value = "test-service", fallback = EchoServiceFallback.class) public interface EchoService { + @RequestMapping(path = "echo/{str}") String echo(@RequestParam("str") String param); + } @FeignClient(value = "foo-service", fallbackFactory = CustomFallbackFactory.class) public interface FooService { + @RequestMapping(path = "echo/{str}") String echo(@RequestParam("str") String param); + } - @FeignClient(value = "bar-service") + @FeignClient("bar-service") public interface BarService { + @RequestMapping(path = "bar") String bar(); + } public interface BazService { + @RequestMapping(path = "baz") String baz(); + } - @FeignClient(value = "baz-service") + @FeignClient("baz-service") public interface BazClient extends BazService { + } public static class EchoServiceFallback implements EchoService { @@ -184,6 +187,7 @@ public class SentinelFeignTests { public String echo(@RequestParam("str") String param) { return "foo fallback"; } + } public static class CustomFallbackFactory @@ -195,6 +199,7 @@ public class SentinelFeignTests { public FooService create(Throwable throwable) { return fooService; } + } } diff --git a/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelRestTemplateTests.java b/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelRestTemplateTests.java index 299673782..5fb912dde 100644 --- a/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelRestTemplateTests.java +++ b/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelRestTemplateTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,9 +16,12 @@ package com.alibaba.cloud.sentinel; -import static org.junit.Assert.assertEquals; - +import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate; +import com.alibaba.cloud.sentinel.custom.SentinelBeanPostProcessor; +import com.alibaba.cloud.sentinel.rest.SentinelClientHttpResponse; +import com.alibaba.csp.sentinel.slots.block.BlockException; import org.junit.Test; + import org.springframework.beans.factory.BeanCreationException; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -28,10 +31,7 @@ import org.springframework.http.HttpRequest; import org.springframework.http.client.ClientHttpRequestExecution; import org.springframework.web.client.RestTemplate; -import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate; -import com.alibaba.cloud.sentinel.custom.SentinelBeanPostProcessor; -import com.alibaba.cloud.sentinel.rest.SentinelClientHttpResponse; -import com.alibaba.csp.sentinel.slots.block.BlockException; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Jim @@ -62,8 +62,7 @@ public class SentinelRestTemplateTests { public void testNormal() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( TestConfig5.class); - assertEquals("RestTemplate size was wrong", 1, - context.getBeansOfType(RestTemplate.class).size()); + assertThat(context.getBeansOfType(RestTemplate.class).size()).isEqualTo(1); } @Test(expected = BeanCreationException.class) @@ -113,6 +112,7 @@ public class SentinelRestTemplateTests { @Configuration public static class TestConfig1 { + @Bean SentinelBeanPostProcessor sentinelBeanPostProcessor( ApplicationContext applicationContext) { @@ -124,10 +124,12 @@ public class SentinelRestTemplateTests { RestTemplate restTemplate() { return new RestTemplate(); } + } @Configuration public static class TestConfig2 { + @Bean SentinelBeanPostProcessor sentinelBeanPostProcessor( ApplicationContext applicationContext) { @@ -139,10 +141,12 @@ public class SentinelRestTemplateTests { RestTemplate restTemplate() { return new RestTemplate(); } + } @Configuration public static class TestConfig3 { + @Bean SentinelBeanPostProcessor sentinelBeanPostProcessor( ApplicationContext applicationContext) { @@ -154,10 +158,12 @@ public class SentinelRestTemplateTests { RestTemplate restTemplate() { return new RestTemplate(); } + } @Configuration public static class TestConfig4 { + @Bean SentinelBeanPostProcessor sentinelBeanPostProcessor( ApplicationContext applicationContext) { @@ -169,10 +175,12 @@ public class SentinelRestTemplateTests { RestTemplate restTemplate() { return new RestTemplate(); } + } @Configuration public static class TestConfig5 { + @Bean SentinelBeanPostProcessor sentinelBeanPostProcessor( ApplicationContext applicationContext) { @@ -180,14 +188,22 @@ public class SentinelRestTemplateTests { } @Bean - @SentinelRestTemplate(blockHandlerClass = SentinelRestTemplateTests.ExceptionUtil.class, blockHandler = "handleException", fallbackClass = SentinelRestTemplateTests.ExceptionUtil.class, fallback = "fallbackException", urlCleanerClass = SentinelRestTemplateTests.UrlCleanUtil.class, urlCleaner = "clean") + @SentinelRestTemplate( + blockHandlerClass = SentinelRestTemplateTests.ExceptionUtil.class, + blockHandler = "handleException", + fallbackClass = SentinelRestTemplateTests.ExceptionUtil.class, + fallback = "fallbackException", + urlCleanerClass = SentinelRestTemplateTests.UrlCleanUtil.class, + urlCleaner = "clean") RestTemplate restTemplate() { return new RestTemplate(); } + } @Configuration public static class TestConfig6 { + @Bean SentinelBeanPostProcessor sentinelBeanPostProcessor( ApplicationContext applicationContext) { @@ -195,14 +211,18 @@ public class SentinelRestTemplateTests { } @Bean - @SentinelRestTemplate(blockHandlerClass = SentinelRestTemplateTests.ExceptionUtil.class, blockHandler = "handleException1") + @SentinelRestTemplate( + blockHandlerClass = SentinelRestTemplateTests.ExceptionUtil.class, + blockHandler = "handleException1") RestTemplate restTemplate() { return new RestTemplate(); } + } @Configuration public static class TestConfig7 { + @Bean SentinelBeanPostProcessor sentinelBeanPostProcessor( ApplicationContext applicationContext) { @@ -210,14 +230,18 @@ public class SentinelRestTemplateTests { } @Bean - @SentinelRestTemplate(fallbackClass = SentinelRestTemplateTests.ExceptionUtil.class, fallback = "fallbackException1") + @SentinelRestTemplate( + fallbackClass = SentinelRestTemplateTests.ExceptionUtil.class, + fallback = "fallbackException1") RestTemplate restTemplate() { return new RestTemplate(); } + } @Configuration public static class TestConfig8 { + @Bean SentinelBeanPostProcessor sentinelBeanPostProcessor( ApplicationContext applicationContext) { @@ -225,14 +249,18 @@ public class SentinelRestTemplateTests { } @Bean - @SentinelRestTemplate(blockHandlerClass = SentinelRestTemplateTests.ExceptionUtil.class, blockHandler = "handleException2") + @SentinelRestTemplate( + blockHandlerClass = SentinelRestTemplateTests.ExceptionUtil.class, + blockHandler = "handleException2") RestTemplate restTemplate() { return new RestTemplate(); } + } @Configuration public static class TestConfig9 { + @Bean SentinelBeanPostProcessor sentinelBeanPostProcessor( ApplicationContext applicationContext) { @@ -240,14 +268,18 @@ public class SentinelRestTemplateTests { } @Bean - @SentinelRestTemplate(fallbackClass = SentinelRestTemplateTests.ExceptionUtil.class, fallback = "fallbackException2") + @SentinelRestTemplate( + fallbackClass = SentinelRestTemplateTests.ExceptionUtil.class, + fallback = "fallbackException2") RestTemplate restTemplate() { return new RestTemplate(); } + } @Configuration public static class TestConfig10 { + @Bean SentinelBeanPostProcessor sentinelBeanPostProcessor( ApplicationContext applicationContext) { @@ -265,10 +297,12 @@ public class SentinelRestTemplateTests { RestTemplate restTemplate2() { return new RestTemplate(); } + } @Configuration public static class TestConfig11 { + @Bean SentinelBeanPostProcessor sentinelBeanPostProcessor( ApplicationContext applicationContext) { @@ -280,10 +314,12 @@ public class SentinelRestTemplateTests { RestTemplate restTemplate() { return new RestTemplate(); } + } @Configuration public static class TestConfig12 { + @Bean SentinelBeanPostProcessor sentinelBeanPostProcessor( ApplicationContext applicationContext) { @@ -295,10 +331,12 @@ public class SentinelRestTemplateTests { RestTemplate restTemplate() { return new RestTemplate(); } + } @Configuration public static class TestConfig13 { + @Bean SentinelBeanPostProcessor sentinelBeanPostProcessor( ApplicationContext applicationContext) { @@ -306,14 +344,18 @@ public class SentinelRestTemplateTests { } @Bean - @SentinelRestTemplate(urlCleanerClass = SentinelRestTemplateTests.UrlCleanUtil.class, urlCleaner = "clean1") + @SentinelRestTemplate( + urlCleanerClass = SentinelRestTemplateTests.UrlCleanUtil.class, + urlCleaner = "clean1") RestTemplate restTemplate() { return new RestTemplate(); } + } @Configuration public static class TestConfig14 { + @Bean SentinelBeanPostProcessor sentinelBeanPostProcessor( ApplicationContext applicationContext) { @@ -321,13 +363,17 @@ public class SentinelRestTemplateTests { } @Bean - @SentinelRestTemplate(urlCleanerClass = SentinelRestTemplateTests.UrlCleanUtil.class, urlCleaner = "clean2") + @SentinelRestTemplate( + urlCleanerClass = SentinelRestTemplateTests.UrlCleanUtil.class, + urlCleaner = "clean2") RestTemplate restTemplate() { return new RestTemplate(); } + } public static class ExceptionUtil { + public static SentinelClientHttpResponse handleException(HttpRequest request, byte[] body, ClientHttpRequestExecution execution, BlockException ex) { System.out.println("Oops: " + ex.getClass().getCanonicalName()); @@ -349,15 +395,18 @@ public class SentinelRestTemplateTests { ClientHttpRequestExecution execution, BlockException ex) { System.out.println("Oops: " + ex.getClass().getCanonicalName()); } + } public static class UrlCleanUtil { + public static String clean(String url) { return url; } public static void clean2(String url) { } + } } diff --git a/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/TestConverter.java b/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/TestConverter.java index b17f45ae5..95e967cb7 100644 --- a/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/TestConverter.java +++ b/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/TestConverter.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,7 +21,6 @@ import java.util.List; import com.alibaba.csp.sentinel.datasource.Converter; import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule; - import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; @@ -29,6 +28,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; * @author Jim */ public class TestConverter implements Converter> { + private ObjectMapper objectMapper = new ObjectMapper(); @Override @@ -42,4 +42,5 @@ public class TestConverter implements Converter> { } return null; } + } diff --git a/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/endpoint/SentinelHealthIndicatorTests.java b/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/endpoint/SentinelHealthIndicatorTests.java index b5586ce00..b8d68d522 100644 --- a/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/endpoint/SentinelHealthIndicatorTests.java +++ b/spring-cloud-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/endpoint/SentinelHealthIndicatorTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,21 +16,10 @@ package com.alibaba.cloud.sentinel.endpoint; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.boot.actuate.health.Health; -import org.springframework.boot.actuate.health.Status; -import org.springframework.util.ReflectionUtils; - import com.alibaba.cloud.sentinel.SentinelProperties; import com.alibaba.csp.sentinel.config.SentinelConfig; import com.alibaba.csp.sentinel.datasource.AbstractDataSource; @@ -38,6 +27,17 @@ import com.alibaba.csp.sentinel.datasource.FileRefreshableDataSource; import com.alibaba.csp.sentinel.heartbeat.HeartbeatSenderProvider; import com.alibaba.csp.sentinel.transport.HeartbeatSender; import com.alibaba.csp.sentinel.transport.config.TransportConfig; +import org.junit.Before; +import org.junit.Test; + +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.Status; +import org.springframework.util.ReflectionUtils; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * Test cases for {@link SentinelHealthIndicator}. @@ -171,4 +171,5 @@ public class SentinelHealthIndicatorTests { assertThat(dataSourceDetailMap.get("ds2-sentinel-file-datasource")) .isEqualTo(new Status(Status.DOWN.getCode(), "fileDataSource2 error")); } + } diff --git a/spring-cloud-alibaba-sidecar/pom.xml b/spring-cloud-alibaba-sidecar/pom.xml index f7833b4d9..ea5595e9f 100644 --- a/spring-cloud-alibaba-sidecar/pom.xml +++ b/spring-cloud-alibaba-sidecar/pom.xml @@ -34,12 +34,6 @@ true - - org.projectlombok - lombok - true - - org.springframework.boot spring-boot-configuration-processor diff --git a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/SidecarAutoConfiguration.java b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/SidecarAutoConfiguration.java index ee2a5d785..d31e5320a 100644 --- a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/SidecarAutoConfiguration.java +++ b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/SidecarAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,28 +23,34 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.web.client.RestTemplate; - /** * @author www.itmuch.com */ @Configuration @EnableConfigurationProperties(SidecarProperties.class) public class SidecarAutoConfiguration { - @Bean - @ConditionalOnMissingBean - public RestTemplate restTemplate() { - return new RestTemplate(); - } - @Bean - public SidecarHealthIndicator sidecarHealthIndicator(SidecarProperties sidecarProperties, RestTemplate restTemplate) { - return new SidecarHealthIndicator(sidecarProperties, restTemplate); - } + @Bean + @ConditionalOnMissingBean + public RestTemplate restTemplate() { + return new RestTemplate(); + } + + @Bean + public SidecarHealthIndicator sidecarHealthIndicator( + SidecarProperties sidecarProperties, RestTemplate restTemplate) { + return new SidecarHealthIndicator(sidecarProperties, restTemplate); + } + + @Bean + public SidecarHealthChecker sidecarHealthChecker( + SidecarDiscoveryClient sidecarDiscoveryClient, + SidecarHealthIndicator sidecarHealthIndicator, + SidecarProperties sidecarProperties, ConfigurableEnvironment environment) { + SidecarHealthChecker cleaner = new SidecarHealthChecker(sidecarDiscoveryClient, + sidecarHealthIndicator, sidecarProperties, environment); + cleaner.check(); + return cleaner; + } - @Bean - public SidecarHealthChecker sidecarHealthChecker(SidecarDiscoveryClient sidecarDiscoveryClient, SidecarHealthIndicator sidecarHealthIndicator, SidecarProperties sidecarProperties, ConfigurableEnvironment environment) { - SidecarHealthChecker cleaner = new SidecarHealthChecker(sidecarDiscoveryClient, sidecarHealthIndicator, sidecarProperties, environment); - cleaner.check(); - return cleaner; - } -} \ No newline at end of file +} diff --git a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/SidecarDiscoveryClient.java b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/SidecarDiscoveryClient.java index d492e1424..8a67c5753 100644 --- a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/SidecarDiscoveryClient.java +++ b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/SidecarDiscoveryClient.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,21 +20,21 @@ package com.alibaba.cloud.sidecar; * @author www.itmuch.com */ public interface SidecarDiscoveryClient { - /** - * register instance - * - * @param applicationName applicationName - * @param ip ip - * @param port port - */ - void registerInstance(String applicationName, String ip, Integer port); - /** - * deregister instance - * - * @param applicationName applicationName - * @param ip ip - * @param port port - */ - void deregisterInstance(String applicationName, String ip, Integer port); + /** + * register instance. + * @param applicationName applicationName + * @param ip ip + * @param port port + */ + void registerInstance(String applicationName, String ip, Integer port); + + /** + * deregister instance. + * @param applicationName applicationName + * @param ip ip + * @param port port + */ + void deregisterInstance(String applicationName, String ip, Integer port); + } diff --git a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/SidecarHealthChecker.java b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/SidecarHealthChecker.java index a302a1e20..66deeb6e1 100644 --- a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/SidecarHealthChecker.java +++ b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/SidecarHealthChecker.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,53 +16,62 @@ package com.alibaba.cloud.sidecar; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; +import java.util.concurrent.TimeUnit; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import reactor.core.scheduler.Schedulers; + import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.actuate.health.Status; import org.springframework.core.env.ConfigurableEnvironment; -import reactor.core.scheduler.Schedulers; - -import java.util.concurrent.TimeUnit; /** * @author www.itmuch.com */ -@Slf4j -@RequiredArgsConstructor(onConstructor = @__(@Autowired)) public class SidecarHealthChecker { - private final SidecarDiscoveryClient sidecarDiscoveryClient; - private final HealthIndicator healthIndicator; - private final SidecarProperties sidecarProperties; - private final ConfigurableEnvironment environment; - - public void check() { - Schedulers.single() - .schedulePeriodically( - () -> { - String ip = sidecarProperties.getIp(); - Integer port = sidecarProperties.getPort(); - - Status status = healthIndicator.health().getStatus(); - String applicationName = environment.getProperty("spring.application.name"); - - if (status.equals(Status.UP)) { - this.sidecarDiscoveryClient.registerInstance(applicationName, ip, port); - log.debug("Health check success. register this instance. applicationName = {}, ip = {}, port = {}, status = {}", - applicationName, ip, port, status - ); - } else { - log.warn("Health check failed. unregister this instance. applicationName = {}, ip = {}, port = {}, status = {}", - applicationName, ip, port, status - ); - this.sidecarDiscoveryClient.deregisterInstance(applicationName, ip, port); - } - - }, - 0, - 30, - TimeUnit.SECONDS - ); - } + + private static final Logger log = LoggerFactory.getLogger(SidecarHealthChecker.class); + + private final SidecarDiscoveryClient sidecarDiscoveryClient; + + private final HealthIndicator healthIndicator; + + private final SidecarProperties sidecarProperties; + + private final ConfigurableEnvironment environment; + + public SidecarHealthChecker(SidecarDiscoveryClient sidecarDiscoveryClient, + HealthIndicator healthIndicator, SidecarProperties sidecarProperties, + ConfigurableEnvironment environment) { + this.sidecarDiscoveryClient = sidecarDiscoveryClient; + this.healthIndicator = healthIndicator; + this.sidecarProperties = sidecarProperties; + this.environment = environment; + } + + public void check() { + Schedulers.single().schedulePeriodically(() -> { + String ip = sidecarProperties.getIp(); + Integer port = sidecarProperties.getPort(); + + Status status = healthIndicator.health().getStatus(); + String applicationName = environment.getProperty("spring.application.name"); + + if (status.equals(Status.UP)) { + this.sidecarDiscoveryClient.registerInstance(applicationName, ip, port); + log.debug( + "Health check success. register this instance. applicationName = {}, ip = {}, port = {}, status = {}", + applicationName, ip, port, status); + } + else { + log.warn( + "Health check failed. unregister this instance. applicationName = {}, ip = {}, port = {}, status = {}", + applicationName, ip, port, status); + this.sidecarDiscoveryClient.deregisterInstance(applicationName, ip, port); + } + + }, 0, 30, TimeUnit.SECONDS); + } + } diff --git a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/SidecarHealthIndicator.java b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/SidecarHealthIndicator.java index 6a2b5eb8d..4d07a380c 100644 --- a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/SidecarHealthIndicator.java +++ b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/SidecarHealthIndicator.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,8 +16,9 @@ package com.alibaba.cloud.sidecar; -import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Autowired; +import java.net.URI; +import java.util.Map; + import org.springframework.boot.actuate.health.AbstractHealthIndicator; import org.springframework.boot.actuate.health.Health; import org.springframework.core.ParameterizedTypeReference; @@ -25,52 +26,56 @@ import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; -import java.net.URI; -import java.util.Map; - /** * @author www.itmuch.com */ -@RequiredArgsConstructor(onConstructor = @__(@Autowired)) public class SidecarHealthIndicator extends AbstractHealthIndicator { - private final SidecarProperties sidecarProperties; - private final RestTemplate restTemplate; - @Override - protected void doHealthCheck(Health.Builder builder) throws Exception { - try { - URI uri = this.sidecarProperties.getHealthCheckUrl(); - if (uri == null) { - builder.up(); - return; - } + private final SidecarProperties sidecarProperties; + + private final RestTemplate restTemplate; + + public SidecarHealthIndicator(SidecarProperties sidecarProperties, + RestTemplate restTemplate) { + this.sidecarProperties = sidecarProperties; + this.restTemplate = restTemplate; + } + + @Override + protected void doHealthCheck(Health.Builder builder) throws Exception { + try { + URI uri = this.sidecarProperties.getHealthCheckUrl(); + if (uri == null) { + builder.up(); + return; + } + + ResponseEntity> exchange = this.restTemplate.exchange(uri, + HttpMethod.GET, null, + new ParameterizedTypeReference>() { + }); - ResponseEntity> exchange = this.restTemplate.exchange( - uri, - HttpMethod.GET, - null, - new ParameterizedTypeReference>() { - } - ); + Map map = exchange.getBody(); - Map map = exchange.getBody(); + if (map == null) { + this.getWarning(builder); + return; + } + Object status = map.get("status"); + if (status instanceof String) { + builder.status(status.toString()); + } + else { + this.getWarning(builder); + } + } + catch (Exception e) { + builder.down().withDetail("error", e.getMessage()); + } + } - if (map == null) { - this.getWarning(builder); - return; - } - Object status = map.get("status"); - if (status instanceof String) { - builder.status(status.toString()); - } else { - this.getWarning(builder); - } - } catch (Exception e) { - builder.down().withDetail("error", e.getMessage()); - } - } + private void getWarning(Health.Builder builder) { + builder.unknown().withDetail("warning", "no status field in response"); + } - private void getWarning(Health.Builder builder) { - builder.unknown().withDetail("warning", "no status field in response"); - } } diff --git a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/SidecarProperties.java b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/SidecarProperties.java index 075db5dbc..50f91692c 100644 --- a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/SidecarProperties.java +++ b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/SidecarProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,39 +16,63 @@ package com.alibaba.cloud.sidecar; -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.validation.annotation.Validated; +import java.net.URI; import javax.validation.constraints.Max; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; -import java.net.URI; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.validation.annotation.Validated; /** * @author www.itmuch.com */ @ConfigurationProperties("sidecar") -@Data @Validated public class SidecarProperties { - /** - * polyglot service's ip - */ - private String ip; - - /** - * polyglot service's port - */ - @NotNull - @Max(65535) - @Min(1) - private Integer port; - - /** - * polyglot service's health check url. - * this endpoint must return json and the format must follow spring boot actuator's health endpoint. - * eg. {"status": "UP"} - */ - private URI healthCheckUrl; + + /** + * polyglot service's ip. + */ + private String ip; + + /** + * polyglot service's port. + */ + @NotNull + @Max(65535) + @Min(1) + private Integer port; + + /** + * polyglot service's health check url. this endpoint must return json and the format + * must follow spring boot actuator's health endpoint. eg. {"status": "UP"}. + */ + private URI healthCheckUrl; + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public Integer getPort() { + return port; + } + + public void setPort(Integer port) { + this.port = port; + } + + public URI getHealthCheckUrl() { + return healthCheckUrl; + } + + public void setHealthCheckUrl(URI healthCheckUrl) { + this.healthCheckUrl = healthCheckUrl; + } + } diff --git a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/consul/SidecarConsulAutoConfiguration.java b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/consul/SidecarConsulAutoConfiguration.java index 777dd5090..d3f40929c 100644 --- a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/consul/SidecarConsulAutoConfiguration.java +++ b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/consul/SidecarConsulAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,48 +16,58 @@ package com.alibaba.cloud.sidecar.consul; +import java.util.List; + import com.alibaba.cloud.sidecar.SidecarAutoConfiguration; import com.alibaba.cloud.sidecar.SidecarDiscoveryClient; import com.alibaba.cloud.sidecar.SidecarProperties; + import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties; import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties; import org.springframework.cloud.consul.discovery.HeartbeatProperties; -import org.springframework.cloud.consul.serviceregistry.*; +import org.springframework.cloud.consul.serviceregistry.ConsulAutoRegistration; +import org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistrationAutoConfiguration; +import org.springframework.cloud.consul.serviceregistry.ConsulManagementRegistrationCustomizer; +import org.springframework.cloud.consul.serviceregistry.ConsulRegistrationCustomizer; +import org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistry; +import org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistryAutoConfiguration; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import java.util.List; - /** * @author www.itmuch.com */ @Configuration @ConditionalOnClass(ConsulServiceRegistryAutoConfiguration.class) -@AutoConfigureBefore({ConsulAutoServiceRegistrationAutoConfiguration.class, SidecarAutoConfiguration.class}) +@AutoConfigureBefore({ ConsulAutoServiceRegistrationAutoConfiguration.class, + SidecarAutoConfiguration.class }) public class SidecarConsulAutoConfiguration { - @Bean - public ConsulAutoRegistration consulRegistration( - AutoServiceRegistrationProperties autoServiceRegistrationProperties, - ConsulDiscoveryProperties properties, - ApplicationContext applicationContext, - ObjectProvider> registrationCustomizers, - ObjectProvider> managementRegistrationCustomizers, - HeartbeatProperties heartbeatProperties, - SidecarProperties sidecarProperties) { - return SidecarConsulAutoRegistration.registration(autoServiceRegistrationProperties, - properties, applicationContext, registrationCustomizers.getIfAvailable(), - managementRegistrationCustomizers.getIfAvailable(), heartbeatProperties, sidecarProperties); - } - - @Bean - public SidecarDiscoveryClient sidecarDiscoveryClient( - ConsulDiscoveryProperties properties, - ConsulServiceRegistry serviceRegistry, - ConsulAutoRegistration registration) { - return new SidecarConsulDiscoveryClient(properties, serviceRegistry, registration); - } + + @Bean + public ConsulAutoRegistration consulRegistration( + AutoServiceRegistrationProperties autoServiceRegistrationProperties, + ConsulDiscoveryProperties properties, ApplicationContext applicationContext, + ObjectProvider> registrationCustomizers, + ObjectProvider> managementRegistrationCustomizers, + HeartbeatProperties heartbeatProperties, + SidecarProperties sidecarProperties) { + return SidecarConsulAutoRegistration.registration( + autoServiceRegistrationProperties, properties, applicationContext, + registrationCustomizers.getIfAvailable(), + managementRegistrationCustomizers.getIfAvailable(), heartbeatProperties, + sidecarProperties); + } + + @Bean + public SidecarDiscoveryClient sidecarDiscoveryClient( + ConsulDiscoveryProperties properties, ConsulServiceRegistry serviceRegistry, + ConsulAutoRegistration registration) { + return new SidecarConsulDiscoveryClient(properties, serviceRegistry, + registration); + } + } diff --git a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/consul/SidecarConsulAutoRegistration.java b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/consul/SidecarConsulAutoRegistration.java index 49e64ab0c..f53a0a1d3 100644 --- a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/consul/SidecarConsulAutoRegistration.java +++ b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/consul/SidecarConsulAutoRegistration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,8 +16,11 @@ package com.alibaba.cloud.sidecar.consul; -import com.ecwid.consul.v1.agent.model.NewService; +import java.util.List; + import com.alibaba.cloud.sidecar.SidecarProperties; +import com.ecwid.consul.v1.agent.model.NewService; + import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties; import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties; import org.springframework.cloud.consul.discovery.HeartbeatProperties; @@ -27,52 +30,58 @@ import org.springframework.cloud.consul.serviceregistry.ConsulRegistrationCustom import org.springframework.context.ApplicationContext; import org.springframework.core.env.Environment; -import java.util.List; - /** * @author www.itmuch.com */ public class SidecarConsulAutoRegistration extends ConsulAutoRegistration { - public SidecarConsulAutoRegistration(NewService service, AutoServiceRegistrationProperties autoServiceRegistrationProperties, ConsulDiscoveryProperties properties, ApplicationContext context, HeartbeatProperties heartbeatProperties, List managementRegistrationCustomizers) { - super(service, autoServiceRegistrationProperties, properties, context, heartbeatProperties, managementRegistrationCustomizers); - } - public static ConsulAutoRegistration registration( - AutoServiceRegistrationProperties autoServiceRegistrationProperties, - ConsulDiscoveryProperties properties, ApplicationContext context, - List registrationCustomizers, - List managementRegistrationCustomizers, - HeartbeatProperties heartbeatProperties, - SidecarProperties sidecarProperties) { + public SidecarConsulAutoRegistration(NewService service, + AutoServiceRegistrationProperties autoServiceRegistrationProperties, + ConsulDiscoveryProperties properties, ApplicationContext context, + HeartbeatProperties heartbeatProperties, + List managementRegistrationCustomizers) { + super(service, autoServiceRegistrationProperties, properties, context, + heartbeatProperties, managementRegistrationCustomizers); + } + + public static ConsulAutoRegistration registration( + AutoServiceRegistrationProperties autoServiceRegistrationProperties, + ConsulDiscoveryProperties properties, ApplicationContext context, + List registrationCustomizers, + List managementRegistrationCustomizers, + HeartbeatProperties heartbeatProperties, + SidecarProperties sidecarProperties) { + + NewService service = new NewService(); + String appName = getAppName(properties, context.getEnvironment()); + service.setId(getInstanceId(sidecarProperties, context.getEnvironment())); + if (!properties.isPreferAgentAddress()) { + service.setAddress(sidecarProperties.getIp()); + } + service.setName(normalizeForDns(appName)); + service.setTags(createTags(properties)); - NewService service = new NewService(); - String appName = getAppName(properties, context.getEnvironment()); - service.setId(getInstanceId(sidecarProperties, context.getEnvironment())); - if (!properties.isPreferAgentAddress()) { - service.setAddress(sidecarProperties.getIp()); - } - service.setName(normalizeForDns(appName)); - service.setTags(createTags(properties)); + // set health check, use alibaba sidecar self's port rather than polyglot app's + // port. + service.setPort( + Integer.valueOf(context.getEnvironment().getProperty("server.port"))); + setCheck(service, autoServiceRegistrationProperties, properties, context, + heartbeatProperties); - // set health check, use alibaba sidecar self's port rather than polyglot app's port. - service.setPort(Integer.valueOf(context.getEnvironment().getProperty("server.port"))); - setCheck(service, autoServiceRegistrationProperties, properties, context, - heartbeatProperties); + service.setPort(sidecarProperties.getPort()); - service.setPort(sidecarProperties.getPort()); + ConsulAutoRegistration registration = new ConsulAutoRegistration(service, + autoServiceRegistrationProperties, properties, context, + heartbeatProperties, managementRegistrationCustomizers); + customize(registrationCustomizers, registration); + return registration; + } - ConsulAutoRegistration registration = new ConsulAutoRegistration(service, - autoServiceRegistrationProperties, properties, context, - heartbeatProperties, managementRegistrationCustomizers); - customize(registrationCustomizers, registration); - return registration; - } + public static String getInstanceId(SidecarProperties sidecarProperties, + Environment environment) { + return String.format("%s-%s-%s", + environment.getProperty("spring.application.name"), + sidecarProperties.getIp(), sidecarProperties.getPort()); + } - public static String getInstanceId(SidecarProperties sidecarProperties, - Environment environment) { - return String.format("%s-%s-%s", - environment.getProperty("spring.application.name"), - sidecarProperties.getIp(), - sidecarProperties.getPort()); - } } diff --git a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/consul/SidecarConsulDiscoveryClient.java b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/consul/SidecarConsulDiscoveryClient.java index 689e5d9b4..49088f3a1 100644 --- a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/consul/SidecarConsulDiscoveryClient.java +++ b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/consul/SidecarConsulDiscoveryClient.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,9 +17,9 @@ package com.alibaba.cloud.sidecar.consul; import com.alibaba.cloud.sidecar.SidecarDiscoveryClient; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties; import org.springframework.cloud.consul.serviceregistry.ConsulAutoRegistration; import org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistry; @@ -27,30 +27,42 @@ import org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistry; /** * @author www.itmuch.com */ -@Slf4j -@RequiredArgsConstructor(onConstructor = @__(@Autowired)) public class SidecarConsulDiscoveryClient implements SidecarDiscoveryClient { - private final ConsulDiscoveryProperties properties; - private final ConsulServiceRegistry serviceRegistry; - private final ConsulAutoRegistration registration; - @Override - public void registerInstance(String applicationName, String ip, Integer port) { + private static final Logger log = LoggerFactory + .getLogger(SidecarConsulDiscoveryClient.class); + + private final ConsulDiscoveryProperties properties; + + private final ConsulServiceRegistry serviceRegistry; + + private final ConsulAutoRegistration registration; + + public SidecarConsulDiscoveryClient(ConsulDiscoveryProperties properties, + ConsulServiceRegistry serviceRegistry, ConsulAutoRegistration registration) { + this.properties = properties; + this.serviceRegistry = serviceRegistry; + this.registration = registration; + } + + @Override + public void registerInstance(String applicationName, String ip, Integer port) { + + if (!this.properties.isRegister()) { + log.debug("Registration disabled."); + return; + } - if (!this.properties.isRegister()) { - log.debug("Registration disabled."); - return; - } + serviceRegistry.register(registration); - serviceRegistry.register(registration); + } - } + @Override + public void deregisterInstance(String applicationName, String ip, Integer port) { + if (!this.properties.isRegister() || !this.properties.isDeregister()) { + return; + } + serviceRegistry.deregister(registration); + } - @Override - public void deregisterInstance(String applicationName, String ip, Integer port) { - if (!this.properties.isRegister() || !this.properties.isDeregister()) { - return; - } - serviceRegistry.deregister(registration); - } } diff --git a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/nacos/SidecarNacosAutoConfiguration.java b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/nacos/SidecarNacosAutoConfiguration.java index cb03c735e..8c39c4c6b 100644 --- a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/nacos/SidecarNacosAutoConfiguration.java +++ b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/nacos/SidecarNacosAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,6 +21,7 @@ import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientAutoConfiguration; import com.alibaba.cloud.sidecar.SidecarAutoConfiguration; import com.alibaba.cloud.sidecar.SidecarDiscoveryClient; import com.alibaba.cloud.sidecar.SidecarProperties; + import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -31,18 +32,23 @@ import org.springframework.context.annotation.Configuration; * @author www.itmuch.com */ @Configuration -@AutoConfigureBefore({NacosDiscoveryClientAutoConfiguration.class, SidecarAutoConfiguration.class}) +@AutoConfigureBefore({ NacosDiscoveryClientAutoConfiguration.class, + SidecarAutoConfiguration.class }) @ConditionalOnClass(NacosDiscoveryProperties.class) public class SidecarNacosAutoConfiguration { - @Bean - @ConditionalOnMissingBean - public SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties(SidecarProperties sidecarProperties) { - return new SidecarNacosDiscoveryProperties(sidecarProperties); - } - @Bean - @ConditionalOnMissingBean - public SidecarDiscoveryClient sidecarDiscoveryClient(SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties) { - return new SidecarNacosDiscoveryClient(sidecarNacosDiscoveryProperties); - } + @Bean + @ConditionalOnMissingBean + public SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties( + SidecarProperties sidecarProperties) { + return new SidecarNacosDiscoveryProperties(sidecarProperties); + } + + @Bean + @ConditionalOnMissingBean + public SidecarDiscoveryClient sidecarDiscoveryClient( + SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties) { + return new SidecarNacosDiscoveryClient(sidecarNacosDiscoveryProperties); + } + } diff --git a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/nacos/SidecarNacosDiscoveryClient.java b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/nacos/SidecarNacosDiscoveryClient.java index e5184db03..e4302afee 100644 --- a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/nacos/SidecarNacosDiscoveryClient.java +++ b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/nacos/SidecarNacosDiscoveryClient.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,35 +18,44 @@ package com.alibaba.cloud.sidecar.nacos; import com.alibaba.cloud.sidecar.SidecarDiscoveryClient; import com.alibaba.nacos.api.exception.NacosException; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author www.itmuch.com */ -@Slf4j -@RequiredArgsConstructor(onConstructor = @__(@Autowired)) public class SidecarNacosDiscoveryClient implements SidecarDiscoveryClient { - private final SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties; - - @Override - public void registerInstance(String applicationName, String ip, Integer port) { - try { - this.sidecarNacosDiscoveryProperties.namingServiceInstance() - .registerInstance(applicationName, ip, port); - } catch (NacosException e) { - log.warn("nacos exception happens", e); - } - } - - @Override - public void deregisterInstance(String applicationName, String ip, Integer port) { - try { - this.sidecarNacosDiscoveryProperties.namingServiceInstance() - .deregisterInstance(applicationName, ip, port); - } catch (NacosException e) { - log.warn("nacos exception happens", e); - } - } + + private static final Logger log = LoggerFactory + .getLogger(SidecarNacosDiscoveryClient.class); + + private final SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties; + + public SidecarNacosDiscoveryClient( + SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties) { + this.sidecarNacosDiscoveryProperties = sidecarNacosDiscoveryProperties; + } + + @Override + public void registerInstance(String applicationName, String ip, Integer port) { + try { + this.sidecarNacosDiscoveryProperties.namingServiceInstance() + .registerInstance(applicationName, ip, port); + } + catch (NacosException e) { + log.warn("nacos exception happens", e); + } + } + + @Override + public void deregisterInstance(String applicationName, String ip, Integer port) { + try { + this.sidecarNacosDiscoveryProperties.namingServiceInstance() + .deregisterInstance(applicationName, ip, port); + } + catch (NacosException e) { + log.warn("nacos exception happens", e); + } + } + } diff --git a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/nacos/SidecarNacosDiscoveryProperties.java b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/nacos/SidecarNacosDiscoveryProperties.java index 8d49e708f..d58c60c16 100644 --- a/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/nacos/SidecarNacosDiscoveryProperties.java +++ b/spring-cloud-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/nacos/SidecarNacosDiscoveryProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,31 +16,34 @@ package com.alibaba.cloud.sidecar.nacos; +import java.net.SocketException; + import com.alibaba.cloud.nacos.NacosDiscoveryProperties; import com.alibaba.cloud.sidecar.SidecarProperties; -import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; - -import java.net.SocketException; /** * @author itmuch.com */ -@RequiredArgsConstructor(onConstructor = @__(@Autowired)) public class SidecarNacosDiscoveryProperties extends NacosDiscoveryProperties { - private final SidecarProperties sidecarProperties; - @Override - public void init() throws SocketException { - super.init(); + private final SidecarProperties sidecarProperties; + + public SidecarNacosDiscoveryProperties(SidecarProperties sidecarProperties) { + this.sidecarProperties = sidecarProperties; + } + + @Override + public void init() throws SocketException { + super.init(); + + String ip = sidecarProperties.getIp(); + if (StringUtils.isNotBlank(ip)) { + this.setIp(ip); + } - String ip = sidecarProperties.getIp(); - if (StringUtils.isNotBlank(ip)) { - this.setIp(ip); - } + Integer port = sidecarProperties.getPort(); + this.setPort(port); + } - Integer port = sidecarProperties.getPort(); - this.setPort(port); - } } diff --git a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/AcmAutoConfiguration.java b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/AcmAutoConfiguration.java index ac82882fa..21c5af288 100644 --- a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/AcmAutoConfiguration.java +++ b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/AcmAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,11 @@ package com.alibaba.alicloud.acm; +import com.alibaba.alicloud.acm.refresh.AcmContextRefresher; +import com.alibaba.alicloud.acm.refresh.AcmRefreshHistory; +import com.alibaba.alicloud.context.acm.AcmIntegrationProperties; +import com.taobao.diamond.client.Diamond; + import org.springframework.beans.BeansException; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -25,12 +30,6 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.alibaba.alicloud.acm.refresh.AcmContextRefresher; -import com.alibaba.alicloud.acm.refresh.AcmRefreshHistory; -import com.alibaba.alicloud.context.acm.AcmIntegrationProperties; - -import com.taobao.diamond.client.Diamond; - /** * Created on 01/10/2017. * @@ -67,4 +66,5 @@ public class AcmAutoConfiguration implements ApplicationContextAware { throws BeansException { this.applicationContext = applicationContext; } + } diff --git a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/AcmPropertySourceRepository.java b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/AcmPropertySourceRepository.java index e16d686cb..2ea1d60a9 100644 --- a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/AcmPropertySourceRepository.java +++ b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/AcmPropertySourceRepository.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,13 +19,13 @@ package com.alibaba.alicloud.acm; import java.util.ArrayList; import java.util.List; +import com.alibaba.alicloud.acm.bootstrap.AcmPropertySource; + import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.PropertySource; -import com.alibaba.alicloud.acm.bootstrap.AcmPropertySource; - /** * @author juven.xuxb, 5/17/16. */ @@ -38,8 +38,8 @@ public class AcmPropertySourceRepository { } /** - * get all acm properties from application context - * @return + * get all acm properties from application context. + * @return list of acm propertysource */ public List getAll() { List result = new ArrayList<>(); @@ -66,4 +66,5 @@ public class AcmPropertySourceRepository { } } } + } diff --git a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySource.java b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySource.java index caf7e62a2..7d73ba8c2 100644 --- a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySource.java +++ b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySource.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -52,4 +52,5 @@ public class AcmPropertySource extends MapPropertySource { public boolean isGroupLevel() { return groupLevel; } + } diff --git a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySourceBuilder.java b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySourceBuilder.java index 5c45cfeba..17004f834 100644 --- a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySourceBuilder.java +++ b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySourceBuilder.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,15 +23,15 @@ import java.util.HashMap; import java.util.Map; import java.util.Properties; +import com.alibaba.edas.acm.ConfigService; +import com.alibaba.edas.acm.exception.ConfigException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; import org.springframework.core.io.ByteArrayResource; import org.springframework.util.StringUtils; -import com.alibaba.edas.acm.ConfigService; -import com.alibaba.edas.acm.exception.ConfigException; - /** * @author juven.xuxb * @author xiaolongzuo @@ -41,12 +41,11 @@ class AcmPropertySourceBuilder { private Logger log = LoggerFactory.getLogger(AcmPropertySourceBuilder.class); /** - * 传入 ACM 的 DataId 和 groupID,获取到解析后的 AcmProperty 对象 - * - * @param dataId - * @param diamondGroup - * @param groupLevel - * @return + * 传入 ACM 的 DataId 和 groupID,获取到解析后的 AcmProperty 对象. + * @param dataId dataid of diamond + * @param diamondGroup group of diamond + * @param groupLevel group level of diamond + * @return acm property source */ AcmPropertySource build(String dataId, String diamondGroup, boolean groupLevel) { Properties properties = loadDiamondData(dataId, diamondGroup); @@ -102,4 +101,5 @@ class AcmPropertySourceBuilder { } return result; } + } diff --git a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySourceLocator.java b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySourceLocator.java index 3dae07108..4f3fe56f3 100644 --- a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySourceLocator.java +++ b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySourceLocator.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,8 @@ package com.alibaba.alicloud.acm.bootstrap; +import com.alibaba.alicloud.context.acm.AcmIntegrationProperties; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.cloud.bootstrap.config.PropertySourceLocator; @@ -23,8 +25,6 @@ import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.Environment; import org.springframework.core.env.PropertySource; -import com.alibaba.alicloud.context.acm.AcmIntegrationProperties; - /** * @author juven.xuxb * @author xiaolongzuo @@ -69,4 +69,5 @@ public class AcmPropertySourceLocator implements PropertySourceLocator { composite.addFirstPropertySource(ps); } } + } diff --git a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmEndpoint.java b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmEndpoint.java index 172b058a9..6441cc4b3 100644 --- a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmEndpoint.java +++ b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmEndpoint.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,14 +23,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.springframework.boot.actuate.endpoint.annotation.Endpoint; -import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; - import com.alibaba.alicloud.acm.AcmPropertySourceRepository; import com.alibaba.alicloud.acm.bootstrap.AcmPropertySource; import com.alibaba.alicloud.acm.refresh.AcmRefreshHistory; import com.alibaba.alicloud.context.acm.AcmProperties; +import org.springframework.boot.actuate.endpoint.annotation.Endpoint; +import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; + /** * Created on 01/10/2017. * @@ -80,4 +80,5 @@ public class AcmEndpoint { result.put("runtime", runtime); return result; } + } diff --git a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmEndpointAutoConfiguration.java b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmEndpointAutoConfiguration.java index 587e90a2a..2aaf1f8a0 100644 --- a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmEndpointAutoConfiguration.java +++ b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmEndpointAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,10 @@ package com.alibaba.alicloud.acm.endpoint; +import com.alibaba.alicloud.acm.AcmPropertySourceRepository; +import com.alibaba.alicloud.acm.refresh.AcmRefreshHistory; +import com.alibaba.alicloud.context.acm.AcmProperties; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -24,15 +28,12 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.context.annotation.Bean; -import com.alibaba.alicloud.acm.AcmPropertySourceRepository; -import com.alibaba.alicloud.acm.refresh.AcmRefreshHistory; -import com.alibaba.alicloud.context.acm.AcmProperties; - /** * @author xiaojing */ @ConditionalOnWebApplication -@ConditionalOnClass(name = "org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration") +@ConditionalOnClass( + name = "org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration") @ConditionalOnProperty(name = "spring.cloud.alicloud.acm.enabled", matchIfMissing = true) public class AcmEndpointAutoConfiguration { @@ -59,4 +60,5 @@ public class AcmEndpointAutoConfiguration { AcmPropertySourceRepository acmPropertySourceRepository) { return new AcmHealthIndicator(acmProperties, acmPropertySourceRepository); } + } diff --git a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmHealthIndicator.java b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmHealthIndicator.java index d172baa4a..703e353af 100644 --- a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmHealthIndicator.java +++ b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmHealthIndicator.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,15 +19,15 @@ package com.alibaba.alicloud.acm.endpoint; import java.util.ArrayList; import java.util.List; -import org.springframework.boot.actuate.health.AbstractHealthIndicator; -import org.springframework.boot.actuate.health.Health; -import org.springframework.util.StringUtils; - import com.alibaba.alicloud.acm.AcmPropertySourceRepository; import com.alibaba.alicloud.acm.bootstrap.AcmPropertySource; import com.alibaba.alicloud.context.acm.AcmProperties; import com.alibaba.edas.acm.ConfigService; +import org.springframework.boot.actuate.health.AbstractHealthIndicator; +import org.springframework.boot.actuate.health.Health; +import org.springframework.util.StringUtils; + /** * @author leijuan * @author juven @@ -70,4 +70,5 @@ public class AcmHealthIndicator extends AbstractHealthIndicator { } builder.up().withDetail("dataIds", dataIds); } + } diff --git a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/refresh/AcmContextRefresher.java b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/refresh/AcmContextRefresher.java index 245d578e6..8cef7c476 100644 --- a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/refresh/AcmContextRefresher.java +++ b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/refresh/AcmContextRefresher.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,8 +23,13 @@ import java.security.NoSuchAlgorithmException; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import com.alibaba.alicloud.acm.AcmPropertySourceRepository; +import com.alibaba.alicloud.context.acm.AcmIntegrationProperties; +import com.alibaba.edas.acm.ConfigService; +import com.alibaba.edas.acm.listener.ConfigChangeListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.BeansException; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.cloud.context.refresh.ContextRefresher; @@ -34,11 +39,6 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationListener; import org.springframework.util.StringUtils; -import com.alibaba.alicloud.acm.AcmPropertySourceRepository; -import com.alibaba.alicloud.context.acm.AcmIntegrationProperties; -import com.alibaba.edas.acm.ConfigService; -import com.alibaba.edas.acm.listener.ConfigChangeListener; - /** * On application start up, AcmContextRefresher add diamond listeners to all application * level dataIds, when there is a change in the data, listeners will refresh @@ -120,4 +120,5 @@ public class AcmContextRefresher throws BeansException { this.applicationContext = applicationContext; } + } diff --git a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/refresh/AcmRefreshHistory.java b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/refresh/AcmRefreshHistory.java index f974dd653..cf6d44f60 100644 --- a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/refresh/AcmRefreshHistory.java +++ b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/refresh/AcmRefreshHistory.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -47,6 +47,7 @@ public class AcmRefreshHistory { public LinkedList getRecords() { return records; } + } class Record { @@ -57,7 +58,7 @@ class Record { private final String md5; - public Record(String timestamp, String dataId, String md5) { + Record(String timestamp, String dataId, String md5) { this.timestamp = timestamp; this.dataId = dataId; this.md5 = md5; @@ -74,4 +75,5 @@ class Record { public String getMd5() { return md5; } + } diff --git a/spring-cloud-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmConfigurationTests.java b/spring-cloud-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmConfigurationTests.java index 038983d96..c529a0792 100644 --- a/spring-cloud-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmConfigurationTests.java +++ b/spring-cloud-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmConfigurationTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,15 +16,15 @@ package com.alibaba.alicloud.acm; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; - import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; -import org.junit.Assert; +import com.alibaba.alicloud.acm.bootstrap.AcmPropertySourceLocator; +import com.alibaba.alicloud.acm.endpoint.AcmEndpointAutoConfiguration; +import com.alibaba.alicloud.context.acm.AcmContextBootstrapConfiguration; +import com.alibaba.alicloud.context.acm.AcmIntegrationProperties; +import com.alibaba.alicloud.context.acm.AcmProperties; +import com.alibaba.edas.acm.ConfigService; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; @@ -32,6 +32,7 @@ import org.powermock.api.support.MethodProxy; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -40,12 +41,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.alicloud.acm.bootstrap.AcmPropertySourceLocator; -import com.alibaba.alicloud.acm.endpoint.AcmEndpointAutoConfiguration; -import com.alibaba.alicloud.context.acm.AcmContextBootstrapConfiguration; -import com.alibaba.alicloud.context.acm.AcmIntegrationProperties; -import com.alibaba.alicloud.context.acm.AcmProperties; -import com.alibaba.edas.acm.ConfigService; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; /** * @author xiaojing @@ -54,16 +51,18 @@ import com.alibaba.edas.acm.ConfigService; @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(SpringRunner.class) @PrepareForTest({ ConfigService.class }) -@SpringBootTest(classes = AcmConfigurationTests.TestConfig.class, properties = { - "spring.application.name=test-name", "spring.profiles.active=dev,test", - "spring.cloud.alicloud.acm.server-list=127.0.0.1", - "spring.cloud.alicloud.acm.server-port=8848", - "spring.cloud.alicloud.acm.endpoint=test-endpoint", - "spring.cloud.alicloud.acm.namespace=test-namespace", - "spring.cloud.alicloud.acm.timeout=1000", - "spring.cloud.alicloud.acm.group=test-group", - "spring.cloud.alicloud.acm.refresh-enabled=false", - "spring.cloud.alicloud.acm.file-extension=properties" }, webEnvironment = NONE) +@SpringBootTest(classes = AcmConfigurationTests.TestConfig.class, + properties = { "spring.application.name=test-name", + "spring.profiles.active=dev,test", + "spring.cloud.alicloud.acm.server-list=127.0.0.1", + "spring.cloud.alicloud.acm.server-port=8848", + "spring.cloud.alicloud.acm.endpoint=test-endpoint", + "spring.cloud.alicloud.acm.namespace=test-namespace", + "spring.cloud.alicloud.acm.timeout=1000", + "spring.cloud.alicloud.acm.group=test-group", + "spring.cloud.alicloud.acm.refresh-enabled=false", + "spring.cloud.alicloud.acm.file-extension=properties" }, + webEnvironment = NONE) public class AcmConfigurationTests { static { @@ -112,9 +111,9 @@ public class AcmConfigurationTests { @Test public void contextLoads() throws Exception { - assertNotNull("AcmPropertySourceLocator was not created", locator); - assertNotNull("AcmProperties was not created", properties); - assertNotNull("AcmIntegrationProperties was not created", integrationProperties); + assertThat(locator).isNotNull(); + assertThat(properties).isNotNull(); + assertThat(integrationProperties).isNotNull(); checkoutAcmServerAddr(); checkoutAcmServerPort(); @@ -130,60 +129,48 @@ public class AcmConfigurationTests { } private void checkoutAcmServerAddr() { - assertEquals("AcmProperties server address is wrong", "127.0.0.1", - properties.getServerList()); - + assertThat(properties.getServerList()).isEqualTo("127.0.0.1"); } private void checkoutAcmServerPort() { - assertEquals("AcmProperties server port is wrong", "8848", - properties.getServerPort()); - + assertThat(properties.getServerPort()).isEqualTo("8848"); } private void checkoutAcmEndpoint() { - assertEquals("AcmProperties endpoint is wrong", "test-endpoint", - properties.getEndpoint()); - + assertThat(properties.getEndpoint()).isEqualTo("test-endpoint"); } private void checkoutAcmNamespace() { - assertEquals("AcmProperties namespace is wrong", "test-namespace", - properties.getNamespace()); - + assertThat(properties.getNamespace()).isEqualTo("test-namespace"); } private void checkoutAcmGroup() { - assertEquals("AcmProperties' group is wrong", "test-group", - properties.getGroup()); + assertThat(properties.getGroup()).isEqualTo("test-group"); } private void checkoutAcmFileExtension() { - assertEquals("AcmProperties' file extension is wrong", "properties", - properties.getFileExtension()); + assertThat(properties.getFileExtension()).isEqualTo("properties"); } private void checkoutAcmTimeout() { - assertEquals("AcmProperties' timeout is wrong", 1000, properties.getTimeout()); + assertThat(properties.getTimeout()).isEqualTo(1000); } private void checkoutAcmRefreshEnabled() { - assertEquals("AcmProperties' refresh enabled is wrong", false, - properties.isRefreshEnabled()); + assertThat(properties.isRefreshEnabled()).isEqualTo(false); } private void checkoutAcmProfiles() { - assertArrayEquals("AcmProperties' profiles is wrong", - new String[] { "dev", "test" }, - integrationProperties.getActiveProfiles()); + assertThat(integrationProperties.getActiveProfiles()) + .isEqualTo(new String[] { "dev", "test" }); } private void checkoutDataLoad() { - Assert.assertEquals(environment.getProperty("user.age"), "12"); + assertThat(environment.getProperty("user.age")).isEqualTo("12"); } private void checkoutProfileDataLoad() { - Assert.assertEquals(environment.getProperty("user.name"), "dev"); + assertThat(environment.getProperty("user.name")).isEqualTo("dev"); } @Configuration @@ -191,5 +178,7 @@ public class AcmConfigurationTests { @ImportAutoConfiguration({ AcmEndpointAutoConfiguration.class, AcmAutoConfiguration.class, AcmContextBootstrapConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmFileExtensionTest.java b/spring-cloud-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmFileExtensionTest.java index 52daad490..cfaca532e 100644 --- a/spring-cloud-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmFileExtensionTest.java +++ b/spring-cloud-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmFileExtensionTest.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,11 +16,12 @@ package com.alibaba.alicloud.acm; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; - import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; +import com.alibaba.alicloud.acm.endpoint.AcmEndpointAutoConfiguration; +import com.alibaba.alicloud.context.acm.AcmContextBootstrapConfiguration; +import com.alibaba.edas.acm.ConfigService; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -29,6 +30,7 @@ import org.powermock.api.support.MethodProxy; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -37,9 +39,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.alicloud.acm.endpoint.AcmEndpointAutoConfiguration; -import com.alibaba.alicloud.context.acm.AcmContextBootstrapConfiguration; -import com.alibaba.edas.acm.ConfigService; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; /** * @author xiaojing @@ -48,11 +48,12 @@ import com.alibaba.edas.acm.ConfigService; @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(SpringRunner.class) @PrepareForTest({ ConfigService.class }) -@SpringBootTest(classes = AcmFileExtensionTest.TestConfig.class, properties = { - "spring.application.name=test-name", - "spring.cloud.alicloud.acm.server-list=127.0.0.1", - "spring.cloud.alicloud.acm.server-port=8080", - "spring.cloud.alicloud.acm.file-extension=yaml" }, webEnvironment = NONE) +@SpringBootTest(classes = AcmFileExtensionTest.TestConfig.class, + properties = { "spring.application.name=test-name", + "spring.cloud.alicloud.acm.server-list=127.0.0.1", + "spring.cloud.alicloud.acm.server-port=8080", + "spring.cloud.alicloud.acm.file-extension=yaml" }, + webEnvironment = NONE) public class AcmFileExtensionTest { static { @@ -94,5 +95,7 @@ public class AcmFileExtensionTest { @ImportAutoConfiguration({ AcmEndpointAutoConfiguration.class, AcmAutoConfiguration.class, AcmContextBootstrapConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmGroupConfigurationTest.java b/spring-cloud-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmGroupConfigurationTest.java index ba25f8db1..087703d45 100644 --- a/spring-cloud-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmGroupConfigurationTest.java +++ b/spring-cloud-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmGroupConfigurationTest.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,11 +16,12 @@ package com.alibaba.alicloud.acm; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; - import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; +import com.alibaba.alicloud.acm.endpoint.AcmEndpointAutoConfiguration; +import com.alibaba.alicloud.context.acm.AcmContextBootstrapConfiguration; +import com.alibaba.edas.acm.ConfigService; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -29,6 +30,7 @@ import org.powermock.api.support.MethodProxy; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -37,9 +39,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.alicloud.acm.endpoint.AcmEndpointAutoConfiguration; -import com.alibaba.alicloud.context.acm.AcmContextBootstrapConfiguration; -import com.alibaba.edas.acm.ConfigService; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; /** * @author xiaojing @@ -48,12 +48,14 @@ import com.alibaba.edas.acm.ConfigService; @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(SpringRunner.class) @PrepareForTest({ ConfigService.class }) -@SpringBootTest(classes = AcmGroupConfigurationTest.TestConfig.class, properties = { - "spring.application.name=test-name", "spring.application.group=com.test.hello", - "spring.cloud.alicloud.acm.server-list=127.0.0.1", - "spring.cloud.alicloud.acm.server-port=8080", - "spring.cloud.alicloud.acm.timeout=1000", - "spring.cloud.alicloud.acm.group=test-group" }, webEnvironment = NONE) +@SpringBootTest(classes = AcmGroupConfigurationTest.TestConfig.class, + properties = { "spring.application.name=test-name", + "spring.application.group=com.test.hello", + "spring.cloud.alicloud.acm.server-list=127.0.0.1", + "spring.cloud.alicloud.acm.server-port=8080", + "spring.cloud.alicloud.acm.timeout=1000", + "spring.cloud.alicloud.acm.group=test-group" }, + webEnvironment = NONE) public class AcmGroupConfigurationTest { static { @@ -102,5 +104,7 @@ public class AcmGroupConfigurationTest { @ImportAutoConfiguration({ AcmEndpointAutoConfiguration.class, AcmAutoConfiguration.class, AcmContextBootstrapConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/endpoint/AcmEndpointTests.java b/spring-cloud-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/endpoint/AcmEndpointTests.java index 36376ae9e..24ece7380 100644 --- a/spring-cloud-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/endpoint/AcmEndpointTests.java +++ b/spring-cloud-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/endpoint/AcmEndpointTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,15 +16,18 @@ package com.alibaba.alicloud.acm.endpoint; -import static org.junit.Assert.assertEquals; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; - import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.Map; +import com.alibaba.alicloud.acm.AcmAutoConfiguration; +import com.alibaba.alicloud.acm.AcmPropertySourceRepository; +import com.alibaba.alicloud.acm.refresh.AcmRefreshHistory; +import com.alibaba.alicloud.context.acm.AcmContextBootstrapConfiguration; +import com.alibaba.alicloud.context.acm.AcmProperties; +import com.alibaba.edas.acm.ConfigService; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -33,6 +36,7 @@ import org.powermock.api.support.MethodProxy; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.health.Health.Builder; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -41,12 +45,8 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.alicloud.acm.AcmAutoConfiguration; -import com.alibaba.alicloud.acm.AcmPropertySourceRepository; -import com.alibaba.alicloud.acm.refresh.AcmRefreshHistory; -import com.alibaba.alicloud.context.acm.AcmContextBootstrapConfiguration; -import com.alibaba.alicloud.context.acm.AcmProperties; -import com.alibaba.edas.acm.ConfigService; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; /** * @author xiaojing @@ -55,11 +55,12 @@ import com.alibaba.edas.acm.ConfigService; @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(SpringRunner.class) @PrepareForTest({ ConfigService.class }) -@SpringBootTest(classes = AcmEndpointTests.TestConfig.class, properties = { - "spring.application.name=test-name", - "spring.cloud.alicloud.acm.server-list=127.0.0.1", - "spring.cloud.alicloud.acm.server-port=8848", - "spring.cloud.alicloud.acm.file-extension=properties" }, webEnvironment = NONE) +@SpringBootTest(classes = AcmEndpointTests.TestConfig.class, + properties = { "spring.application.name=test-name", + "spring.cloud.alicloud.acm.server-list=127.0.0.1", + "spring.cloud.alicloud.acm.server-port=8848", + "spring.cloud.alicloud.acm.file-extension=properties" }, + webEnvironment = NONE) public class AcmEndpointTests { static { @@ -134,9 +135,9 @@ public class AcmEndpointTests { AcmEndpoint acmEndpoint = new AcmEndpoint(properties, refreshHistory, propertySourceRepository); Map map = acmEndpoint.invoke(); - assertEquals(map.get("config"), properties); - assertEquals(((Map) map.get("runtime")).get("refreshHistory"), - refreshHistory.getRecords()); + assertThat(properties).isEqualTo(map.get("config")); + assertThat(refreshHistory.getRecords()) + .isEqualTo(((Map) map.get("runtime")).get("refreshHistory")); } @Configuration @@ -144,5 +145,7 @@ public class AcmEndpointTests { @ImportAutoConfiguration({ AcmEndpointAutoConfiguration.class, AcmAutoConfiguration.class, AcmContextBootstrapConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsAutoConfiguration.java b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsAutoConfiguration.java index c86049e94..ea1b3e4cb 100644 --- a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsAutoConfiguration.java +++ b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,11 @@ package com.alibaba.alicloud.ans; +import com.alibaba.alicloud.ans.registry.AnsAutoServiceRegistration; +import com.alibaba.alicloud.ans.registry.AnsRegistration; +import com.alibaba.alicloud.ans.registry.AnsServiceRegistry; +import com.alibaba.alicloud.context.ans.AnsProperties; + import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -28,18 +33,15 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.alibaba.alicloud.ans.registry.AnsAutoServiceRegistration; -import com.alibaba.alicloud.ans.registry.AnsRegistration; -import com.alibaba.alicloud.ans.registry.AnsServiceRegistry; -import com.alibaba.alicloud.context.ans.AnsProperties; - /** * @author xiaolongzuo */ @Configuration @EnableConfigurationProperties -@ConditionalOnClass(name = "org.springframework.boot.web.context.WebServerInitializedEvent") -@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true) +@ConditionalOnClass( + name = "org.springframework.boot.web.context.WebServerInitializedEvent") +@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", + matchIfMissing = true) @ConditionalOnAnsEnabled @AutoConfigureAfter({ AutoServiceRegistrationConfiguration.class, AutoServiceRegistrationAutoConfiguration.class }) @@ -52,7 +54,9 @@ public class AnsAutoConfiguration { @Bean @ConditionalOnBean(AutoServiceRegistrationProperties.class) - @ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true) + @ConditionalOnProperty( + value = "spring.cloud.service-registry.auto-registration.enabled", + matchIfMissing = true) public AnsRegistration ansRegistration(AnsProperties ansProperties, ApplicationContext applicationContext) { return new AnsRegistration(ansProperties, applicationContext); @@ -60,7 +64,9 @@ public class AnsAutoConfiguration { @Bean @ConditionalOnBean(AutoServiceRegistrationProperties.class) - @ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true) + @ConditionalOnProperty( + value = "spring.cloud.service-registry.auto-registration.enabled", + matchIfMissing = true) public AnsAutoServiceRegistration ansAutoServiceRegistration( AnsServiceRegistry registry, AutoServiceRegistrationProperties autoServiceRegistrationProperties, diff --git a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsDiscoveryClient.java b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsDiscoveryClient.java index 7f7d34abd..420342f05 100644 --- a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsDiscoveryClient.java +++ b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsDiscoveryClient.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,18 +23,21 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.springframework.cloud.client.ServiceInstance; -import org.springframework.cloud.client.discovery.DiscoveryClient; - import com.alibaba.ans.core.NamingService; import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; +import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.client.discovery.DiscoveryClient; + /** * @author xiaolongzuo * @author pbting */ public class AnsDiscoveryClient implements DiscoveryClient { + /** + * Description of Ans Discovery. + */ public static final String DESCRIPTION = "Spring Cloud ANS Discovery Client"; @Override diff --git a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsDiscoveryClientAutoConfiguration.java b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsDiscoveryClientAutoConfiguration.java index 6cb092070..185dec813 100644 --- a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsDiscoveryClientAutoConfiguration.java +++ b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsDiscoveryClientAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsServiceInstance.java b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsServiceInstance.java index 2c7bc37c8..aa9123923 100644 --- a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsServiceInstance.java +++ b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsServiceInstance.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ConditionalOnAnsEnabled.java b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ConditionalOnAnsEnabled.java index 98926d596..0633c6911 100644 --- a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ConditionalOnAnsEnabled.java +++ b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ConditionalOnAnsEnabled.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -30,4 +30,5 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @Target({ ElementType.TYPE, ElementType.METHOD }) @ConditionalOnProperty(value = "spring.cloud.ans.enabled", matchIfMissing = true) public @interface ConditionalOnAnsEnabled { + } diff --git a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/endpoint/AnsEndpoint.java b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/endpoint/AnsEndpoint.java index d119791dd..a7def20f2 100644 --- a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/endpoint/AnsEndpoint.java +++ b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/endpoint/AnsEndpoint.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,15 +21,15 @@ import java.util.List; import java.util.Map; import java.util.Set; +import com.alibaba.alicloud.context.ans.AnsProperties; +import com.alibaba.ans.core.NamingService; +import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; -import com.alibaba.alicloud.context.ans.AnsProperties; -import com.alibaba.ans.core.NamingService; -import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; - /** * @author xiaolongzuo * @author pbting diff --git a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/endpoint/AnsEndpointAutoConfiguration.java b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/endpoint/AnsEndpointAutoConfiguration.java index befe67334..552dd7d5f 100644 --- a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/endpoint/AnsEndpointAutoConfiguration.java +++ b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/endpoint/AnsEndpointAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,13 @@ package com.alibaba.alicloud.ans.endpoint; +import com.alibaba.alicloud.context.ans.AnsProperties; + import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.context.annotation.Bean; -import com.alibaba.alicloud.context.ans.AnsProperties; - /** * @author xiaolongzuo */ @@ -34,4 +34,5 @@ public class AnsEndpointAutoConfiguration { public AnsEndpoint ansEndpoint(AnsProperties ansProperties) { return new AnsEndpoint(ansProperties); } + } diff --git a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistration.java b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistration.java index c76126989..1d5b4cf4a 100644 --- a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistration.java +++ b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,6 +18,7 @@ package com.alibaba.alicloud.ans.registry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration; import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties; import org.springframework.cloud.client.serviceregistry.ServiceRegistry; @@ -30,6 +31,7 @@ import org.springframework.util.StringUtils; */ public class AnsAutoServiceRegistration extends AbstractAutoServiceRegistration { + private static final Logger log = LoggerFactory .getLogger(AnsAutoServiceRegistration.class); diff --git a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsRegistration.java b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsRegistration.java index 8f7382604..142cd9902 100644 --- a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsRegistration.java +++ b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsRegistration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,6 +21,8 @@ import java.util.Map; import javax.annotation.PostConstruct; +import com.alibaba.alicloud.context.ans.AnsProperties; + import org.springframework.cloud.client.DefaultServiceInstance; import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.ManagementServerPortUtils; @@ -29,8 +31,6 @@ import org.springframework.context.ApplicationContext; import org.springframework.core.env.Environment; import org.springframework.util.StringUtils; -import com.alibaba.alicloud.context.ans.AnsProperties; - /** * @author xiaolongzuo */ @@ -42,6 +42,7 @@ public class AnsRegistration implements Registration, ServiceInstance { static final String MANAGEMENT_ENDPOINT_BASE_PATH = "management.endpoints.web.base-path"; private AnsProperties ansProperties; + private ApplicationContext context; public AnsRegistration(AnsProperties ansProperties, ApplicationContext context) { diff --git a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsServiceRegistry.java b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsServiceRegistry.java index fda957380..afcd5dba5 100644 --- a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsServiceRegistry.java +++ b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsServiceRegistry.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,13 +20,13 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import com.alibaba.ans.core.NamingService; +import com.alibaba.ans.shaded.com.taobao.vipserver.client.ipms.NodeReactor; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.cloud.client.serviceregistry.ServiceRegistry; -import com.alibaba.ans.core.NamingService; -import com.alibaba.ans.shaded.com.taobao.vipserver.client.ipms.NodeReactor; +import org.springframework.cloud.client.serviceregistry.ServiceRegistry; /** * @author xiaolongzuo diff --git a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsRibbonClientConfiguration.java b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsRibbonClientConfiguration.java index 59ba3fa6c..81bd95c83 100644 --- a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsRibbonClientConfiguration.java +++ b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsRibbonClientConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,13 @@ package com.alibaba.alicloud.ans.ribbon; +import com.netflix.client.config.IClientConfig; +import com.netflix.loadbalancer.ServerList; + import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.netflix.client.config.IClientConfig; -import com.netflix.loadbalancer.ServerList; - /** * @author xiaolongzuo * @author pbting @@ -37,4 +37,4 @@ public class AnsRibbonClientConfiguration { return serverList; } -} \ No newline at end of file +} diff --git a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsServer.java b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsServer.java index 5d36f51c6..e335642e1 100644 --- a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsServer.java +++ b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsServer.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,7 +20,6 @@ import java.util.Collections; import java.util.Map; import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; - import com.netflix.loadbalancer.Server; /** @@ -29,7 +28,9 @@ import com.netflix.loadbalancer.Server; public class AnsServer extends Server { private final MetaInfo metaInfo; + private final Host host; + private final Map metadata; public AnsServer(final Host host, final String dom) { @@ -78,4 +79,5 @@ public class AnsServer extends Server { return "AnsServer{" + "metaInfo=" + metaInfo + ", host=" + host + ", metadata=" + metadata + '}'; } + } diff --git a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsServerList.java b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsServerList.java index b3f749f40..1ae1d9fd8 100644 --- a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsServerList.java +++ b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsServerList.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,7 +21,6 @@ import java.util.List; import com.alibaba.ans.core.NamingService; import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; - import com.netflix.client.config.IClientConfig; import com.netflix.loadbalancer.AbstractServerList; @@ -76,4 +75,5 @@ public class AnsServerList extends AbstractServerList { public void initWithNiwsConfig(IClientConfig iClientConfig) { this.dom = iClientConfig.getClientName(); } + } diff --git a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/ConditionalOnRibbonAns.java b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/ConditionalOnRibbonAns.java index 7094d43bf..f404fbe14 100644 --- a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/ConditionalOnRibbonAns.java +++ b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/ConditionalOnRibbonAns.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/RibbonAnsAutoConfiguration.java b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/RibbonAnsAutoConfiguration.java index 5c4ddb887..8d6cf69e6 100644 --- a/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/RibbonAnsAutoConfiguration.java +++ b/spring-cloud-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/RibbonAnsAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,8 @@ package com.alibaba.alicloud.ans.ribbon; +import com.alibaba.alicloud.ans.ConditionalOnAnsEnabled; + import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -24,8 +26,6 @@ import org.springframework.cloud.netflix.ribbon.RibbonClients; import org.springframework.cloud.netflix.ribbon.SpringClientFactory; import org.springframework.context.annotation.Configuration; -import com.alibaba.alicloud.ans.ConditionalOnAnsEnabled; - /** * @author xiaolongzuo */ @@ -37,4 +37,5 @@ import com.alibaba.alicloud.ans.ConditionalOnAnsEnabled; @AutoConfigureAfter(RibbonAutoConfiguration.class) @RibbonClients(defaultConfiguration = AnsRibbonClientConfiguration.class) public class RibbonAnsAutoConfiguration { + } diff --git a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/AnsDiscoveryClientTests.java b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/AnsDiscoveryClientTests.java index 009db660a..67bfb692c 100644 --- a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/AnsDiscoveryClientTests.java +++ b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/AnsDiscoveryClientTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,26 +16,26 @@ package com.alibaba.alicloud.ans; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.when; - import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; +import com.alibaba.alicloud.ans.test.AnsMockTest; +import com.alibaba.ans.core.NamingService; +import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; + import org.springframework.cloud.client.ServiceInstance; -import com.alibaba.alicloud.ans.test.AnsMockTest; -import com.alibaba.ans.core.NamingService; -import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; /** * @author xiaojing @@ -45,7 +45,9 @@ import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; public class AnsDiscoveryClientTests { private String host = "123.123.123.123"; + private int port = 8888; + private String serviceName = "test-service"; @Test @@ -113,4 +115,5 @@ public class AnsDiscoveryClientTests { return "http://" + host + ":" + port; } + } diff --git a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationEnabledTests.java b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationEnabledTests.java index 21c78b6b1..3763449d4 100644 --- a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationEnabledTests.java +++ b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationEnabledTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,12 +16,12 @@ package com.alibaba.alicloud.ans.registry; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - +import com.alibaba.alicloud.ans.AnsAutoConfiguration; +import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; +import com.alibaba.alicloud.context.ans.AnsProperties; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -30,20 +30,20 @@ import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationC import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.alicloud.ans.AnsAutoConfiguration; -import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; -import com.alibaba.alicloud.context.ans.AnsProperties; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; /** * @author xiaojing */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = AnsAutoServiceRegistrationEnabledTests.TestConfig.class, properties = { - "spring.application.name=myTestService1", - "spring.cloud.alicloud.ans.server-list=127.0.0.1", - "spring.cloud.alicloud.ans.server-port=8080", - "spring.cloud.alicloud.ans.register-enabled=false" }, webEnvironment = RANDOM_PORT) +@SpringBootTest(classes = AnsAutoServiceRegistrationEnabledTests.TestConfig.class, + properties = { "spring.application.name=myTestService1", + "spring.cloud.alicloud.ans.server-list=127.0.0.1", + "spring.cloud.alicloud.ans.server-port=8080", + "spring.cloud.alicloud.ans.register-enabled=false" }, + webEnvironment = RANDOM_PORT) public class AnsAutoServiceRegistrationEnabledTests { @Autowired @@ -57,19 +57,16 @@ public class AnsAutoServiceRegistrationEnabledTests { @Test public void contextLoads() throws Exception { - - assertNotNull("AnsRegistration was not created", registration); - assertNotNull("AnsProperties was not created", properties); - assertNotNull("AnsAutoServiceRegistration was not created", - ansAutoServiceRegistration); + assertThat(registration).isNotNull(); + assertThat(properties).isNotNull(); + assertThat(ansAutoServiceRegistration).isNotNull(); checkEnabled(); } private void checkEnabled() { - assertFalse("Ans Auto Registration should not start", - ansAutoServiceRegistration.isEnabled()); + assertThat(ansAutoServiceRegistration.isEnabled()).isEqualTo(Boolean.FALSE); } @Configuration @@ -77,5 +74,7 @@ public class AnsAutoServiceRegistrationEnabledTests { @ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, AnsDiscoveryClientAutoConfiguration.class, AnsAutoConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationIpNetworkInterfaceTests.java b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationIpNetworkInterfaceTests.java index ebfbf0909..90867ea22 100644 --- a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationIpNetworkInterfaceTests.java +++ b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationIpNetworkInterfaceTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,17 +16,17 @@ package com.alibaba.alicloud.ans.registry; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - import java.net.Inet4Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.util.Enumeration; +import com.alibaba.alicloud.ans.AnsAutoConfiguration; +import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; +import com.alibaba.alicloud.context.ans.AnsProperties; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -36,19 +36,20 @@ import org.springframework.cloud.commons.util.InetUtils; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.alicloud.ans.AnsAutoConfiguration; -import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; -import com.alibaba.alicloud.context.ans.AnsProperties; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; /** * @author xiaojing */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = AnsAutoServiceRegistrationIpNetworkInterfaceTests.TestConfig.class, properties = { - "spring.application.name=myTestService1", - "spring.cloud.alicloud.ans.server-list=127.0.0.1", - "spring.cloud.alicloud.ans.server-port=8080" }, webEnvironment = RANDOM_PORT) +@SpringBootTest( + classes = AnsAutoServiceRegistrationIpNetworkInterfaceTests.TestConfig.class, + properties = { "spring.application.name=myTestService1", + "spring.cloud.alicloud.ans.server-list=127.0.0.1", + "spring.cloud.alicloud.ans.server-port=8080" }, + webEnvironment = RANDOM_PORT) public class AnsAutoServiceRegistrationIpNetworkInterfaceTests { @Autowired @@ -66,20 +67,17 @@ public class AnsAutoServiceRegistrationIpNetworkInterfaceTests { @Test public void contextLoads() throws Exception { - assertNotNull("AnsRegistration was not created", registration); - assertNotNull("AnsProperties was not created", properties); - assertNotNull("AnsAutoServiceRegistration was not created", - ansAutoServiceRegistration); + assertThat(registration).isNotNull(); + assertThat(properties).isNotNull(); + assertThat(ansAutoServiceRegistration).isNotNull(); checkoutAnsDiscoveryServiceIP(); } private void checkoutAnsDiscoveryServiceIP() { - assertEquals("AnsProperties service IP was wrong", - getIPFromNetworkInterface(TestConfig.netWorkInterfaceName), - registration.getHost()); - + assertThat(registration.getHost()) + .isEqualTo(getIPFromNetworkInterface(TestConfig.netWorkInterfaceName)); } private String getIPFromNetworkInterface(String networkInterface) { @@ -143,6 +141,7 @@ public class AnsAutoServiceRegistrationIpNetworkInterfaceTests { } } + } } diff --git a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationIpTests.java b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationIpTests.java index ed185a986..036a7ffa8 100644 --- a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationIpTests.java +++ b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationIpTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,12 +16,12 @@ package com.alibaba.alicloud.ans.registry; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - +import com.alibaba.alicloud.ans.AnsAutoConfiguration; +import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; +import com.alibaba.alicloud.context.ans.AnsProperties; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -30,22 +30,22 @@ import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationC import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.alicloud.ans.AnsAutoConfiguration; -import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; -import com.alibaba.alicloud.context.ans.AnsProperties; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; /** * @author xiaojing */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = AnsAutoServiceRegistrationIpTests.TestConfig.class, properties = { - "spring.application.name=myTestService1", - "spring.cloud.alicloud.ans.client-domains=myTestService2", - "spring.cloud.alicloud.ans.server-list=127.0.0.1", - "spring.cloud.alicloud.ans.client-weight=2", - "spring.cloud.alicloud.ans.server-port=8080", - "spring.cloud.alicloud.ans.client-ip=123.123.123.123" }, webEnvironment = RANDOM_PORT) +@SpringBootTest(classes = AnsAutoServiceRegistrationIpTests.TestConfig.class, + properties = { "spring.application.name=myTestService1", + "spring.cloud.alicloud.ans.client-domains=myTestService2", + "spring.cloud.alicloud.ans.server-list=127.0.0.1", + "spring.cloud.alicloud.ans.client-weight=2", + "spring.cloud.alicloud.ans.server-port=8080", + "spring.cloud.alicloud.ans.client-ip=123.123.123.123" }, + webEnvironment = RANDOM_PORT) public class AnsAutoServiceRegistrationIpTests { @Autowired @@ -60,10 +60,9 @@ public class AnsAutoServiceRegistrationIpTests { @Test public void contextLoads() throws Exception { - assertNotNull("AnsRegistration was not created", registration); - assertNotNull("AnsProperties was not created", properties); - assertNotNull("AnsAutoServiceRegistration was not created", - ansAutoServiceRegistration); + assertThat(registration).isNotNull(); + assertThat(properties).isNotNull(); + assertThat(ansAutoServiceRegistration).isNotNull(); checkoutAnsDiscoveryServiceIP(); checkoutAnsDiscoveryServiceName(); @@ -71,17 +70,15 @@ public class AnsAutoServiceRegistrationIpTests { } private void checkoutAnsDiscoveryServiceIP() { - assertEquals("AnsProperties service IP was wrong", "123.123.123.123", - registration.getHost()); + assertThat(registration.getHost()).isEqualTo("123.123.123.123"); } private void checkoutAnsDiscoveryServiceName() { - assertEquals("AnsDiscoveryProperties service name was wrong", "myTestService2", - properties.getClientDomains()); + assertThat(properties.getClientDomains()).isEqualTo("myTestService2"); } private void checkoutAnsDiscoveryWeight() { - assertEquals(2L, properties.getClientWeight(), 0); + assertThat(properties.getClientWeight()).isEqualTo(2L); } @Configuration @@ -89,5 +86,7 @@ public class AnsAutoServiceRegistrationIpTests { @ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, AnsDiscoveryClientAutoConfiguration.class, AnsAutoConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationManagementPortTests.java b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationManagementPortTests.java index 0b2b29687..e8a1846ca 100644 --- a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationManagementPortTests.java +++ b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationManagementPortTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,12 +16,12 @@ package com.alibaba.alicloud.ans.registry; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - +import com.alibaba.alicloud.ans.AnsAutoConfiguration; +import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; +import com.alibaba.alicloud.context.ans.AnsProperties; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -30,20 +30,21 @@ import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationC import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.alicloud.ans.AnsAutoConfiguration; -import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; -import com.alibaba.alicloud.context.ans.AnsProperties; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; /** * @author xiaojing */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = AnsAutoServiceRegistrationManagementPortTests.TestConfig.class, properties = { - "spring.application.name=myTestService1", "management.server.port=8888", - "management.server.servlet.context-path=/test-context-path", - "spring.cloud.alicloud.ans.server-list=127.0.0.1", - "spring.cloud.alicloud.ans.server-port=8080" }, webEnvironment = RANDOM_PORT) +@SpringBootTest(classes = AnsAutoServiceRegistrationManagementPortTests.TestConfig.class, + properties = { "spring.application.name=myTestService1", + "management.server.port=8888", + "management.server.servlet.context-path=/test-context-path", + "spring.cloud.alicloud.ans.server-list=127.0.0.1", + "spring.cloud.alicloud.ans.server-port=8080" }, + webEnvironment = RANDOM_PORT) public class AnsAutoServiceRegistrationManagementPortTests { @Autowired @@ -58,23 +59,20 @@ public class AnsAutoServiceRegistrationManagementPortTests { @Test public void contextLoads() throws Exception { - assertNotNull("AnsRegistration was not created", registration); - assertNotNull("AnsProperties was not created", properties); - assertNotNull("AnsAutoServiceRegistration was not created", - ansAutoServiceRegistration); + assertThat(registration).isNotNull(); + assertThat(properties).isNotNull(); + assertThat(ansAutoServiceRegistration).isNotNull(); checkoutNacosDiscoveryManagementData(); } private void checkoutNacosDiscoveryManagementData() { - assertEquals("AnsProperties management port was wrong", "8888", - properties.getClientMetadata().get(AnsRegistration.MANAGEMENT_PORT)); - - assertEquals("AnsProperties management context path was wrong", - "/test-context-path", properties.getClientMetadata() - .get(AnsRegistration.MANAGEMENT_CONTEXT_PATH)); - + assertThat(properties.getClientMetadata().get(AnsRegistration.MANAGEMENT_PORT)) + .isEqualTo("8888"); + assertThat(properties.getClientMetadata() + .get(AnsRegistration.MANAGEMENT_CONTEXT_PATH)) + .isEqualTo("/test-context-path"); } @Configuration @@ -82,5 +80,7 @@ public class AnsAutoServiceRegistrationManagementPortTests { @ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, AnsDiscoveryClientAutoConfiguration.class, AnsAutoConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationPortTests.java b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationPortTests.java index 46ed81b22..7e997b6c8 100644 --- a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationPortTests.java +++ b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationPortTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,12 +16,12 @@ package com.alibaba.alicloud.ans.registry; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - +import com.alibaba.alicloud.ans.AnsAutoConfiguration; +import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; +import com.alibaba.alicloud.context.ans.AnsProperties; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -30,20 +30,20 @@ import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationC import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.alicloud.ans.AnsAutoConfiguration; -import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; -import com.alibaba.alicloud.context.ans.AnsProperties; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; /** * @author xiaojing */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = AnsAutoServiceRegistrationPortTests.TestConfig.class, properties = { - "spring.application.name=myTestService1", - "spring.cloud.alicloud.ans.server-list=127.0.0.1", - "spring.cloud.alicloud.ans.server-port=8080", - "spring.cloud.alicloud.ans.client-port=8888" }, webEnvironment = RANDOM_PORT) +@SpringBootTest(classes = AnsAutoServiceRegistrationPortTests.TestConfig.class, + properties = { "spring.application.name=myTestService1", + "spring.cloud.alicloud.ans.server-list=127.0.0.1", + "spring.cloud.alicloud.ans.server-port=8080", + "spring.cloud.alicloud.ans.client-port=8888" }, + webEnvironment = RANDOM_PORT) public class AnsAutoServiceRegistrationPortTests { @Autowired @@ -58,19 +58,16 @@ public class AnsAutoServiceRegistrationPortTests { @Test public void contextLoads() throws Exception { - assertNotNull("AnsRegistration was not created", registration); - assertNotNull("AnsDiscoveryProperties was not created", properties); - assertNotNull("AnsAutoServiceRegistration was not created", - ansAutoServiceRegistration); + assertThat(registration).isNotNull(); + assertThat(properties).isNotNull(); + assertThat(ansAutoServiceRegistration).isNotNull(); checkoutAnsDiscoveryServicePort(); } private void checkoutAnsDiscoveryServicePort() { - assertEquals("AnsDiscoveryProperties service Port was wrong", 8888, - registration.getPort()); - + assertThat(registration.getPort()).isEqualTo(8888); } @Configuration @@ -78,5 +75,7 @@ public class AnsAutoServiceRegistrationPortTests { @ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, AnsDiscoveryClientAutoConfiguration.class, AnsAutoConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationTests.java b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationTests.java index e44467fce..b9782373b 100644 --- a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationTests.java +++ b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,18 +16,20 @@ package com.alibaba.alicloud.ans.registry; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import com.alibaba.alicloud.ans.AnsAutoConfiguration; +import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; +import com.alibaba.alicloud.ans.endpoint.AnsEndpoint; +import com.alibaba.alicloud.context.ans.AnsProperties; +import com.alibaba.ans.core.NamingService; +import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -38,24 +40,21 @@ import org.springframework.cloud.commons.util.InetUtils; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; -import com.alibaba.alicloud.ans.AnsAutoConfiguration; -import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; -import com.alibaba.alicloud.ans.endpoint.AnsEndpoint; -import com.alibaba.alicloud.context.ans.AnsProperties; -import com.alibaba.ans.core.NamingService; -import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; /** * @author xiaojing */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = AnsAutoServiceRegistrationTests.TestConfig.class, properties = { - "spring.application.name=myTestService1", - "spring.cloud.alicloud.ans.server-list=127.0.0.1", - "spring.cloud.alicloud.ans.server-port=8080", - "spring.cloud.alicloud.ans.secure=true", - "spring.cloud.alicloud.ans.endpoint=test-endpoint" }, webEnvironment = RANDOM_PORT) +@SpringBootTest(classes = AnsAutoServiceRegistrationTests.TestConfig.class, + properties = { "spring.application.name=myTestService1", + "spring.cloud.alicloud.ans.server-list=127.0.0.1", + "spring.cloud.alicloud.ans.server-port=8080", + "spring.cloud.alicloud.ans.secure=true", + "spring.cloud.alicloud.ans.endpoint=test-endpoint" }, + webEnvironment = RANDOM_PORT) public class AnsAutoServiceRegistrationTests { @Autowired @@ -76,10 +75,9 @@ public class AnsAutoServiceRegistrationTests { @Test public void contextLoads() throws Exception { - assertNotNull("AnsRegistration was not created", registration); - assertNotNull("AnsProperties was not created", properties); - assertNotNull("AnsAutoServiceRegistration was not created", - ansAutoServiceRegistration); + assertThat(registration).isNotNull(); + assertThat(properties).isNotNull(); + assertThat(ansAutoServiceRegistration).isNotNull(); checkoutAnsDiscoveryServerList(); checkoutAnsDiscoveryServerPort(); @@ -96,45 +94,39 @@ public class AnsAutoServiceRegistrationTests { } private void checkAutoRegister() { - assertTrue("Ans Auto Registration was not start", - ansAutoServiceRegistration.isRunning()); + assertThat(ansAutoServiceRegistration.isRunning()).isEqualTo(Boolean.TRUE); } private void checkoutAnsDiscoveryServerList() { - assertEquals("AnsDiscoveryProperties server list was wrong", "127.0.0.1", - properties.getServerList()); + assertThat(properties.getServerList()).isEqualTo("127.0.0.1"); } private void checkoutAnsDiscoveryServerPort() { - assertEquals("AnsDiscoveryProperties server port was wrong", "8080", - properties.getServerPort()); + assertThat(properties.getServerPort()).isEqualTo("8080"); } private void checkoutAnsDiscoveryServiceName() { - assertEquals("AnsDiscoveryProperties service name was wrong", "myTestService1", - properties.getClientDomains()); + assertThat(properties.getClientDomains()).isEqualTo("myTestService1"); } private void checkoutAnsDiscoveryServiceIP() { - assertEquals("AnsDiscoveryProperties service IP was wrong", - inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(), - registration.getHost()); + assertThat(registration.getHost()) + .isEqualTo(inetUtils.findFirstNonLoopbackHostInfo().getIpAddress()); } private void checkoutAnsDiscoveryServicePort() { - assertEquals("AnsDiscoveryProperties service Port was wrong", port, - registration.getPort()); + assertThat(registration.getPort()).isEqualTo(port); } private void checkoutAnsDiscoverySecure() { - assertTrue("AnsDiscoveryProperties secure should be true", properties.isSecure()); + assertThat(properties.isSecure()).isEqualTo(Boolean.TRUE); } private void checkoutEndpoint() throws Exception { AnsEndpoint ansEndpoint = new AnsEndpoint(properties); Map map = ansEndpoint.invoke(); - assertEquals(map.get("ansProperties"), properties); + assertThat(properties).isEqualTo(map.get("ansProperties")); Map subscribes = new HashMap<>(); Set subscribeServices = NamingService.getDomsSubscribed(); @@ -148,7 +140,7 @@ public class AnsAutoServiceRegistrationTests { } } - assertEquals(map.get("subscribes"), subscribes); + assertThat(subscribes).isEqualTo(map.get("subscribes")); } @Configuration @@ -156,5 +148,7 @@ public class AnsAutoServiceRegistrationTests { @ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, AnsDiscoveryClientAutoConfiguration.class, AnsAutoConfiguration.class }) public static class TestConfig { + } + } diff --git a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsRibbonClientConfigurationTests.java b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsRibbonClientConfigurationTests.java index f5d1587ef..e5710e1e8 100644 --- a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsRibbonClientConfigurationTests.java +++ b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsRibbonClientConfigurationTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,11 +16,13 @@ package com.alibaba.alicloud.ans.ribbon; -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - +import com.alibaba.alicloud.ans.AnsAutoConfiguration; +import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; +import com.netflix.client.config.DefaultClientConfigImpl; +import com.netflix.client.config.IClientConfig; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -32,21 +34,19 @@ import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.client.RestTemplate; -import com.alibaba.alicloud.ans.AnsAutoConfiguration; -import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; - -import com.netflix.client.config.DefaultClientConfigImpl; -import com.netflix.client.config.IClientConfig; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; /** * @author xiaojing */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = AnsRibbonClientConfigurationTests.TestConfig.class, properties = { - "spring.application.name=myTestService1", - "spring.cloud.alicloud.ans.server-list=127.0.0.1", - "spring.cloud.alicloud.ans.server-port=8080", - "spring.cloud.alicloud.ans.endpoint=test-endpoint" }, webEnvironment = RANDOM_PORT) +@SpringBootTest(classes = AnsRibbonClientConfigurationTests.TestConfig.class, + properties = { "spring.application.name=myTestService1", + "spring.cloud.alicloud.ans.server-list=127.0.0.1", + "spring.cloud.alicloud.ans.server-port=8080", + "spring.cloud.alicloud.ans.endpoint=test-endpoint" }, + webEnvironment = RANDOM_PORT) public class AnsRibbonClientConfigurationTests { @Autowired @@ -82,6 +82,7 @@ public class AnsRibbonClientConfigurationTests { AnsRibbonTestConfiguration.class, RibbonAnsAutoConfiguration.class, AnsRibbonClientConfiguration.class }) public static class TestConfig { + } } diff --git a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsServerListTests.java b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsServerListTests.java index 9d62610db..344792a70 100644 --- a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsServerListTests.java +++ b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsServerListTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,18 +16,16 @@ package com.alibaba.alicloud.ans.ribbon; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.stream.Collectors; +import com.alibaba.alicloud.ans.test.AnsMockTest; +import com.alibaba.ans.core.NamingService; +import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; +import com.netflix.client.config.IClientConfig; import org.assertj.core.api.Assertions; import org.junit.Test; import org.junit.runner.RunWith; @@ -35,11 +33,11 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import com.alibaba.alicloud.ans.test.AnsMockTest; -import com.alibaba.ans.core.NamingService; -import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; - -import com.netflix.client.config.IClientConfig; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * @author xiaojing @@ -139,4 +137,5 @@ public class AnsServerListTests { assertThat(servers.get(0).getHealthService().isValid()).isEqualTo(true); } -} \ No newline at end of file + +} diff --git a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsServiceListTests.java b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsServiceListTests.java index bef39ad7a..57d6faa29 100644 --- a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsServiceListTests.java +++ b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsServiceListTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,20 +16,16 @@ package com.alibaba.alicloud.ans.ribbon; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; - import java.util.Arrays; import java.util.List; -import org.junit.Test; - import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; - import com.netflix.loadbalancer.Server; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; /** * @author xiaolongzuo @@ -44,19 +40,18 @@ public class AnsServiceListTests { public void testAnsServer() { AnsServerList serverList = getAnsServerList(); List servers = serverList.getInitialListOfServers(); - assertNotNull("servers was null", servers); - assertEquals("servers was not size 1", 1, servers.size()); + assertThat(servers).isNotNull(); + assertThat(servers.size()).isEqualTo(1); Server des = assertAnsServer(servers); - assertEquals("hostPort was wrong", IP_ADDR + ":" + PORT, des.getHostPort()); + assertThat(des.getHostPort()).isEqualTo(IP_ADDR + ":" + PORT); } protected Server assertAnsServer(List servers) { Server actualServer = servers.get(0); - assertTrue("server was not a DomainExtractingServer", - actualServer instanceof AnsServer); + assertThat(actualServer instanceof AnsServer).isEqualTo(Boolean.TRUE); AnsServer des = AnsServer.class.cast(actualServer); - assertNotNull("host is null", des.getHealthService()); - assertEquals("unit was wrong", "DEFAULT", des.getHealthService().getUnit()); + assertThat(des.getHealthService()).isNotNull(); + assertThat(des.getHealthService().getUnit()).isEqualTo("DEFAULT"); return des; } diff --git a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/test/AnsMockTest.java b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/test/AnsMockTest.java index 8eaeb0e71..694672f85 100644 --- a/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/test/AnsMockTest.java +++ b/spring-cloud-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/test/AnsMockTest.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -42,4 +42,5 @@ public class AnsMockTest { host.setHostname(serviceName); return host; } + } diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/AliCloudContextAutoConfiguration.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/AliCloudContextAutoConfiguration.java index 32c93b782..2044fd5b9 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/AliCloudContextAutoConfiguration.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/AliCloudContextAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/AliCloudProperties.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/AliCloudProperties.java index a43c695de..43af7e1e7 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/AliCloudProperties.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/AliCloudProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,10 +16,10 @@ package com.alibaba.alicloud.context; -import org.springframework.boot.context.properties.ConfigurationProperties; - import com.alibaba.cloud.context.AliCloudConfiguration; +import org.springframework.boot.context.properties.ConfigurationProperties; + /** * @author xiaolongzuo */ diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/Constants.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/Constants.java index 8e3fe8935..36aadc0fa 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/Constants.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/Constants.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,15 +19,53 @@ package com.alibaba.alicloud.context; /** * @author Jim */ -public interface Constants { - - interface Sentinel { - String PROPERTY_PREFIX = "spring.cloud.sentinel"; - String NACOS_DATASOURCE_AK = PROPERTY_PREFIX + ".nacos.config.access-key"; - String NACOS_DATASOURCE_SK = PROPERTY_PREFIX + ".nacos.config.secret-key"; - String NACOS_DATASOURCE_NAMESPACE = PROPERTY_PREFIX + ".nacos.config.namespace"; - String NACOS_DATASOURCE_ENDPOINT = PROPERTY_PREFIX + ".nacos.config.endpoint"; - String PROJECT_NAME = PROPERTY_PREFIX + ".nacos.config.project-name"; +public final class Constants { + + private Constants() { + throw new AssertionError("Must not instantiate constant utility class"); + } + + public final class Sentinel { + + /** + * prefix of sentinel. + */ + public static final String PROPERTY_PREFIX = "spring.cloud.sentinel"; + + /** + * nacos access key. + */ + public static final String NACOS_DATASOURCE_AK = PROPERTY_PREFIX + + ".nacos.config.access-key"; + + /** + * nacos secret key. + */ + public static final String NACOS_DATASOURCE_SK = PROPERTY_PREFIX + + ".nacos.config.secret-key"; + + /** + * nacos namespace. + */ + public static final String NACOS_DATASOURCE_NAMESPACE = PROPERTY_PREFIX + + ".nacos.config.namespace"; + + /** + * nacos endpoint. + */ + public static final String NACOS_DATASOURCE_ENDPOINT = PROPERTY_PREFIX + + ".nacos.config.endpoint"; + + /** + * nacos project name. + */ + public static final String PROJECT_NAME = PROPERTY_PREFIX + + ".nacos.config.project-name"; + + private Sentinel() { + throw new AssertionError("Must not instantiate constant utility class"); + } + } } diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmContextBootstrapConfiguration.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmContextBootstrapConfiguration.java index 0be77f620..6c92512c1 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmContextBootstrapConfiguration.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmContextBootstrapConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,6 +18,11 @@ package com.alibaba.alicloud.context.acm; import javax.annotation.PostConstruct; +import com.alibaba.alicloud.context.AliCloudProperties; +import com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration; +import com.alibaba.alicloud.context.edas.EdasProperties; +import com.alibaba.cloud.context.acm.AliCloudAcmInitializer; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -28,11 +33,6 @@ import org.springframework.core.env.Environment; import org.springframework.util.Assert; import org.springframework.util.StringUtils; -import com.alibaba.alicloud.context.AliCloudProperties; -import com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration; -import com.alibaba.alicloud.context.edas.EdasProperties; -import com.alibaba.cloud.context.acm.AliCloudAcmInitializer; - /** * @author xiaolongzuo */ diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmIntegrationProperties.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmIntegrationProperties.java index da5abac5e..88d355795 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmIntegrationProperties.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmIntegrationProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -99,4 +99,5 @@ public class AcmIntegrationProperties { public AcmProperties getAcmProperties() { return acmProperties; } + } diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmProperties.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmProperties.java index f66ba2302..dea832245 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmProperties.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,13 @@ package com.alibaba.alicloud.context.acm; -import org.springframework.boot.context.properties.ConfigurationProperties; - import com.alibaba.cloud.context.AliCloudServerMode; import com.alibaba.cloud.context.acm.AcmConfiguration; +import org.springframework.boot.context.properties.ConfigurationProperties; + /** - * acm properties + * acm properties. * * @author leijuan * @author xiaolongzuo @@ -37,27 +37,27 @@ public class AcmProperties implements AcmConfiguration { private String serverPort = "8080"; /** - * diamond group + * diamond group. */ private String group = "DEFAULT_GROUP"; /** - * timeout to get configuration + * timeout to get configuration. */ private int timeout = 3000; /** - * the AliYun endpoint for ACM + * the AliYun endpoint for ACM. */ private String endpoint; /** - * ACM namespace + * ACM namespace. */ private String namespace; /** - * name of ram role granted to ECS + * name of ram role granted to ECS. */ private String ramRoleName; @@ -153,4 +153,5 @@ public class AcmProperties implements AcmConfiguration { public void setServerMode(AliCloudServerMode serverMode) { this.serverMode = serverMode; } + } diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsContextApplicationListener.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsContextApplicationListener.java index 6d0283317..2100b5fb4 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsContextApplicationListener.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsContextApplicationListener.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,15 +16,15 @@ package com.alibaba.alicloud.context.ans; -import org.springframework.context.ApplicationContext; -import org.springframework.context.event.ContextRefreshedEvent; - import com.alibaba.alicloud.context.AliCloudProperties; import com.alibaba.alicloud.context.edas.EdasProperties; import com.alibaba.alicloud.context.listener.AbstractOnceApplicationListener; import com.alibaba.cloud.context.ans.AliCloudAnsInitializer; import com.alibaba.cloud.context.edas.AliCloudEdasSdk; +import org.springframework.context.ApplicationContext; +import org.springframework.context.event.ContextRefreshedEvent; + /** * Init {@link com.alibaba.ans.core.NamingService} properties. * diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsContextAutoConfiguration.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsContextAutoConfiguration.java index 56f8ebc93..64f1d8539 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsContextAutoConfiguration.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsContextAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,13 @@ package com.alibaba.alicloud.context.ans; +import com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration; + import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Configuration; -import com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration; - /** * @author xiaolongzuo */ diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsProperties.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsProperties.java index 99aa4a696..cf5592e0f 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsProperties.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -26,15 +26,15 @@ import java.util.Map; import javax.annotation.PostConstruct; +import com.alibaba.cloud.context.AliCloudServerMode; +import com.alibaba.cloud.context.ans.AnsConfiguration; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.cloud.commons.util.InetUtils; import org.springframework.util.StringUtils; -import com.alibaba.cloud.context.AliCloudServerMode; -import com.alibaba.cloud.context.ans.AnsConfiguration; - /** * @author xiaolongzuo */ @@ -340,4 +340,5 @@ public class AnsProperties implements AnsConfiguration { + '\'' + ", port=" + clientPort + ", env='" + env + '\'' + ", secure=" + secure + ", tags=" + tags + '}'; } + } diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/edas/EdasContextAutoConfiguration.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/edas/EdasContextAutoConfiguration.java index 61a8e1da3..1984e0250 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/edas/EdasContextAutoConfiguration.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/edas/EdasContextAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,11 @@ package com.alibaba.alicloud.context.edas; +import com.alibaba.alicloud.context.AliCloudContextAutoConfiguration; +import com.alibaba.alicloud.context.AliCloudProperties; +import com.alibaba.cloud.context.edas.AliCloudEdasSdk; +import com.alibaba.cloud.context.edas.AliCloudEdasSdkFactory; + import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -23,11 +28,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.alibaba.alicloud.context.AliCloudContextAutoConfiguration; -import com.alibaba.alicloud.context.AliCloudProperties; -import com.alibaba.cloud.context.edas.AliCloudEdasSdk; -import com.alibaba.cloud.context.edas.AliCloudEdasSdkFactory; - /** * @author xiaolongzuo */ diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/edas/EdasProperties.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/edas/EdasProperties.java index c34979c90..8cc4ffe93 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/edas/EdasProperties.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/edas/EdasProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,11 +16,11 @@ package com.alibaba.alicloud.context.edas; +import com.alibaba.cloud.context.edas.EdasConfiguration; + import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; -import com.alibaba.cloud.context.edas.EdasConfiguration; - /** * @author xiaolongzuo */ @@ -36,7 +36,7 @@ public class EdasProperties implements EdasConfiguration { private String applicationName; /** - * edas namespace + * edas namespace. */ private String namespace; @@ -84,4 +84,5 @@ public class EdasProperties implements EdasConfiguration { public void setEnabled(boolean enabled) { this.enabled = enabled; } + } diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/listener/AbstractOnceApplicationListener.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/listener/AbstractOnceApplicationListener.java index ffc09c7b7..bff31292f 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/listener/AbstractOnceApplicationListener.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/listener/AbstractOnceApplicationListener.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -68,15 +68,13 @@ public abstract class AbstractOnceApplicationListener { + private static final Logger log = LoggerFactory .getLogger(NacosConfigParameterInitListener.class); @@ -52,4 +69,5 @@ public class NacosConfigParameterInitListener System.getProperties().setProperty("spring.cloud.nacos.config.secret-key", edasChangeOrderConfiguration.getDauthSecretKey()); } -} \ No newline at end of file + +} diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/nacos/NacosDiscoveryParameterInitListener.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/nacos/NacosDiscoveryParameterInitListener.java index 2abba6eec..145605e3b 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/nacos/NacosDiscoveryParameterInitListener.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/nacos/NacosDiscoveryParameterInitListener.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,17 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.alicloud.context.nacos; import java.util.Properties; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; - import com.alibaba.alicloud.context.listener.AbstractOnceApplicationListener; import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration; import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; /** * @author pbting @@ -31,6 +32,7 @@ import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory; */ public class NacosDiscoveryParameterInitListener extends AbstractOnceApplicationListener { + private static final Logger log = LoggerFactory .getLogger(NacosDiscoveryParameterInitListener.class); @@ -70,4 +72,5 @@ public class NacosDiscoveryParameterInitListener properties.setProperty("nacos.naming.web.context", "/vipserver"); properties.setProperty("nacos.naming.exposed.port", "80"); } -} \ No newline at end of file + +} diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/oss/OssContextAutoConfiguration.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/oss/OssContextAutoConfiguration.java index 840783f83..f1dfe5aa9 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/oss/OssContextAutoConfiguration.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/oss/OssContextAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,12 @@ package com.alibaba.alicloud.context.oss; +import com.alibaba.alicloud.context.AliCloudContextAutoConfiguration; +import com.alibaba.alicloud.context.AliCloudProperties; +import com.alibaba.cloud.context.AliCloudAuthorizationMode; +import com.aliyun.oss.OSS; +import com.aliyun.oss.OSSClientBuilder; + import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -26,15 +32,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.util.Assert; import org.springframework.util.StringUtils; -import com.alibaba.alicloud.context.AliCloudContextAutoConfiguration; -import com.alibaba.alicloud.context.AliCloudProperties; -import com.alibaba.cloud.context.AliCloudAuthorizationMode; - -import com.aliyun.oss.OSS; -import com.aliyun.oss.OSSClientBuilder; - /** - * OSS Auto {@link Configuration} + * OSS Auto {@link Configuration}. * * @author Jim * @author xiaolongzuo diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/oss/OssProperties.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/oss/OssProperties.java index a261e6adc..468a485e1 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/oss/OssProperties.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/oss/OssProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,12 @@ package com.alibaba.alicloud.context.oss; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.properties.ConfigurationProperties; - import com.alibaba.cloud.context.AliCloudAuthorizationMode; - import com.aliyun.oss.ClientBuilderConfiguration; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.ConfigurationProperties; + /** * {@link ConfigurationProperties} for configuring OSS. * diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/scx/ScxContextAutoConfiguration.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/scx/ScxContextAutoConfiguration.java index 69504bb95..d99f01cba 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/scx/ScxContextAutoConfiguration.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/scx/ScxContextAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,13 @@ package com.alibaba.alicloud.context.scx; +import com.alibaba.alicloud.context.AliCloudProperties; +import com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration; +import com.alibaba.alicloud.context.edas.EdasProperties; +import com.alibaba.cloud.context.edas.AliCloudEdasSdk; +import com.alibaba.cloud.context.scx.AliCloudScxInitializer; +import com.alibaba.edas.schedulerx.SchedulerXClient; + import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -24,13 +31,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.alibaba.alicloud.context.AliCloudProperties; -import com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration; -import com.alibaba.alicloud.context.edas.EdasProperties; -import com.alibaba.cloud.context.edas.AliCloudEdasSdk; -import com.alibaba.cloud.context.scx.AliCloudScxInitializer; -import com.alibaba.edas.schedulerx.SchedulerXClient; - /** * @author xiaolongzuo */ diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/scx/ScxProperties.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/scx/ScxProperties.java index e0671705d..1fdce76dd 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/scx/ScxProperties.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/scx/ScxProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,10 +16,10 @@ package com.alibaba.alicloud.context.scx; -import org.springframework.boot.context.properties.ConfigurationProperties; - import com.alibaba.cloud.context.scx.ScxConfiguration; +import org.springframework.boot.context.properties.ConfigurationProperties; + /** * @author xiaolongzuo */ diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sentinel/SentinelAliCloudListener.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sentinel/SentinelAliCloudListener.java index 2a0c6b506..29dc96375 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sentinel/SentinelAliCloudListener.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sentinel/SentinelAliCloudListener.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,14 +16,14 @@ package com.alibaba.alicloud.context.sentinel; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; - import com.alibaba.alicloud.context.Constants; import com.alibaba.alicloud.context.listener.AbstractOnceApplicationListener; import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration; import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; /** * @author Jim diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sms/SmsContextAutoConfiguration.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sms/SmsContextAutoConfiguration.java index b3665b7ca..9ec821f77 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sms/SmsContextAutoConfiguration.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sms/SmsContextAutoConfiguration.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.alicloud.context.sms; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -15,4 +31,4 @@ import org.springframework.context.annotation.Configuration; @ConditionalOnProperty(name = "spring.cloud.alicloud.sms.enabled", matchIfMissing = true) public class SmsContextAutoConfiguration { -} \ No newline at end of file +} diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sms/SmsProperties.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sms/SmsProperties.java index 8ada0a80a..3f1fc9615 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sms/SmsProperties.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sms/SmsProperties.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.alicloud.context.sms; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -71,4 +87,4 @@ public class SmsProperties { this.upQueueName = upQueueName; } -} \ No newline at end of file +} diff --git a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/statistics/StatisticsTaskStarter.java b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/statistics/StatisticsTaskStarter.java index c3e64a663..69454e1c7 100644 --- a/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/statistics/StatisticsTaskStarter.java +++ b/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/statistics/StatisticsTaskStarter.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,11 +19,6 @@ package com.alibaba.alicloud.context.statistics; import java.util.ArrayList; import java.util.List; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.context.annotation.Configuration; - import com.alibaba.alicloud.context.acm.AcmContextBootstrapConfiguration; import com.alibaba.alicloud.context.acm.AcmProperties; import com.alibaba.alicloud.context.ans.AnsContextAutoConfiguration; @@ -37,6 +32,11 @@ import com.alibaba.cloud.context.AliCloudServerMode; import com.alibaba.cloud.context.edas.AliCloudEdasSdk; import com.alibaba.cloud.context.statistics.StatisticsTask; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.context.annotation.Configuration; + /** * @author xiaolongzuo */ diff --git a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/acm/AcmAutoConfiguration.java b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/acm/AcmAutoConfiguration.java index 9fbb2ed8a..938102210 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/acm/AcmAutoConfiguration.java +++ b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/acm/AcmAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,4 +20,5 @@ package com.alibaba.alicloud.acm; * @author xiaolongzuo */ public class AcmAutoConfiguration { + } diff --git a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/ans/AnsAutoConfiguration.java b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/ans/AnsAutoConfiguration.java index 94946f00a..9f472639b 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/ans/AnsAutoConfiguration.java +++ b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/ans/AnsAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,4 +20,5 @@ package com.alibaba.alicloud.ans; * @author xiaolongzuo */ public class AnsAutoConfiguration { + } diff --git a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/AliCloudPropertiesTests.java b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/AliCloudPropertiesTests.java index 34afd2236..e2b1d51c5 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/AliCloudPropertiesTests.java +++ b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/AliCloudPropertiesTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,12 +16,13 @@ package com.alibaba.alicloud.context; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - import org.junit.Test; + import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + /** * @author xiaolongzuo */ diff --git a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/BaseAliCloudSpringApplication.java b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/BaseAliCloudSpringApplication.java index 72fe9d28e..9634b647a 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/BaseAliCloudSpringApplication.java +++ b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/BaseAliCloudSpringApplication.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,6 +20,7 @@ import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; + import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @@ -30,17 +31,18 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(SpringRunner.class) @PowerMockIgnore("javax.management.*") -@SpringBootTest(classes = BaseAliCloudSpringApplication.AliCloudApplication.class, properties = { - "spring.application.name=myapp", - "spring.cloud.alicloud.edas.application.name=myapp", - "spring.cloud.alicloud.access-key=ak", "spring.cloud.alicloud.secret-key=sk", - "spring.cloud.alicloud.oss.endpoint=test", - "spring.cloud.alicloud.scx.group-id=1-2-3-4", - "spring.cloud.alicloud.edas.namespace=cn-test", - "spring.cloud.alicloud.ans.server-list=192.168.1.100", - "spring.cloud.alicloud.ans.server-port=8888", - "spring.cloud.alicloud.oss.enabled=false", - "spring.cloud.alicloud.scx.enabled=false" }) +@SpringBootTest(classes = BaseAliCloudSpringApplication.AliCloudApplication.class, + properties = { "spring.application.name=myapp", + "spring.cloud.alicloud.edas.application.name=myapp", + "spring.cloud.alicloud.access-key=ak", + "spring.cloud.alicloud.secret-key=sk", + "spring.cloud.alicloud.oss.endpoint=test", + "spring.cloud.alicloud.scx.group-id=1-2-3-4", + "spring.cloud.alicloud.edas.namespace=cn-test", + "spring.cloud.alicloud.ans.server-list=192.168.1.100", + "spring.cloud.alicloud.ans.server-port=8888", + "spring.cloud.alicloud.oss.enabled=false", + "spring.cloud.alicloud.scx.enabled=false" }) public abstract class BaseAliCloudSpringApplication { @SpringBootApplication diff --git a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/acm/AcmPropertiesTests.java b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/acm/AcmPropertiesTests.java index cbd4ff905..55339edb8 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/acm/AcmPropertiesTests.java +++ b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/acm/AcmPropertiesTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,15 +16,15 @@ package com.alibaba.alicloud.context.acm; -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; - +import com.alibaba.alicloud.context.AliCloudContextAutoConfiguration; +import com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration; +import com.alibaba.cloud.context.AliCloudServerMode; import org.junit.Test; + import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import com.alibaba.alicloud.context.AliCloudContextAutoConfiguration; -import com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration; -import com.alibaba.cloud.context.AliCloudServerMode; +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; /** * @author xiaolongzuo diff --git a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/ans/AnsContextApplicationListenerTests.java b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/ans/AnsContextApplicationListenerTests.java index a60923be4..f39f2ff68 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/ans/AnsContextApplicationListenerTests.java +++ b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/ans/AnsContextApplicationListenerTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,11 +16,10 @@ package com.alibaba.alicloud.context.ans; -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; - +import com.alibaba.alicloud.context.BaseAliCloudSpringApplication; import org.junit.Test; -import com.alibaba.alicloud.context.BaseAliCloudSpringApplication; +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; /** * @author xiaolongzuo diff --git a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/ans/AnsPropertiesTests.java b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/ans/AnsPropertiesTests.java index 93242733b..3b7859e2e 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/ans/AnsPropertiesTests.java +++ b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/ans/AnsPropertiesTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,25 +16,25 @@ package com.alibaba.alicloud.context.ans; -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; - import java.net.Inet4Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.Vector; +import com.alibaba.alicloud.context.AliCloudContextAutoConfiguration; +import com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration; +import com.alibaba.cloud.context.AliCloudServerMode; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; + import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import com.alibaba.alicloud.context.AliCloudContextAutoConfiguration; -import com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration; -import com.alibaba.cloud.context.AliCloudServerMode; +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; /** * @author xiaolongzuo @@ -121,7 +121,7 @@ public class AnsPropertiesTests { }); } - //@Test + // @Test public void testConfigurationValuesAreCorrectlyLoaded3() throws SocketException { NetworkInterface networkInterface = PowerMockito.mock(NetworkInterface.class); Vector inetAddressList = new Vector<>(); diff --git a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/edas/EdasPropertiesTests.java b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/edas/EdasPropertiesTests.java index f16d9f6cf..bc3380334 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/edas/EdasPropertiesTests.java +++ b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/edas/EdasPropertiesTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,13 @@ package com.alibaba.alicloud.context.edas; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - +import com.alibaba.alicloud.context.AliCloudContextAutoConfiguration; import org.junit.Test; + import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import com.alibaba.alicloud.context.AliCloudContextAutoConfiguration; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; /** * @author xiaolongzuo diff --git a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/nacos/NacosConfigParameterInitListenerTests.java b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/nacos/NacosConfigParameterInitListenerTests.java index 6b028f099..221e1ff26 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/nacos/NacosConfigParameterInitListenerTests.java +++ b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/nacos/NacosConfigParameterInitListenerTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,16 +16,15 @@ package com.alibaba.alicloud.context.nacos; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.powermock.core.classloader.annotations.PrepareForTest; - import com.alibaba.alicloud.context.BaseAliCloudSpringApplication; import com.alibaba.alicloud.utils.ChangeOrderUtils; import com.alibaba.cloud.context.ans.AliCloudAnsInitializer; import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory; +import org.junit.BeforeClass; +import org.junit.Test; +import org.powermock.core.classloader.annotations.PrepareForTest; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; /** * @author xiaolongzuo @@ -55,4 +54,5 @@ public class NacosConfigParameterInitListenerTests extends BaseAliCloudSpringApp .isEqualTo("testSK"); } + } diff --git a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/nacos/NacosDiscoveryParameterInitListenerTests.java b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/nacos/NacosDiscoveryParameterInitListenerTests.java index 58ceebd68..35d1489e7 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/nacos/NacosDiscoveryParameterInitListenerTests.java +++ b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/nacos/NacosDiscoveryParameterInitListenerTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,16 +16,15 @@ package com.alibaba.alicloud.context.nacos; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.powermock.core.classloader.annotations.PrepareForTest; - import com.alibaba.alicloud.context.BaseAliCloudSpringApplication; import com.alibaba.alicloud.utils.ChangeOrderUtils; import com.alibaba.cloud.context.ans.AliCloudAnsInitializer; import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory; +import org.junit.BeforeClass; +import org.junit.Test; +import org.powermock.core.classloader.annotations.PrepareForTest; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; /** * @author xiaolongzuo @@ -59,4 +58,5 @@ public class NacosDiscoveryParameterInitListenerTests assertThat(System.getProperties().getProperty("nacos.naming.exposed.port")) .isEqualTo("80"); } + } diff --git a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/oss/OssAutoConfigurationTests.java b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/oss/OssAutoConfigurationTests.java index b3317a29f..5195cbe03 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/oss/OssAutoConfigurationTests.java +++ b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/oss/OssAutoConfigurationTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,16 +16,15 @@ package com.alibaba.alicloud.context.oss; -import static org.assertj.core.api.Assertions.assertThat; - +import com.alibaba.alicloud.context.AliCloudProperties; +import com.aliyun.oss.OSS; +import com.aliyun.oss.OSSClient; import org.junit.Test; + import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import com.alibaba.alicloud.context.AliCloudProperties; - -import com.aliyun.oss.OSS; -import com.aliyun.oss.OSSClient; +import static org.assertj.core.api.Assertions.assertThat; /** * {@link OSS} {@link OssProperties} Test diff --git a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/scx/ScxAutoConfigurationTests.java b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/scx/ScxAutoConfigurationTests.java index c9803f810..ce3f78ac7 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/scx/ScxAutoConfigurationTests.java +++ b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/scx/ScxAutoConfigurationTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,13 @@ package com.alibaba.alicloud.context.scx; -import static org.assertj.core.api.Assertions.assertThat; - +import com.alibaba.alicloud.context.edas.EdasProperties; import org.junit.Test; + import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import com.alibaba.alicloud.context.edas.EdasProperties; +import static org.assertj.core.api.Assertions.assertThat; /** * @author xiaolongzuo diff --git a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/sentinel/SentinelAliCloudListenerTests.java b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/sentinel/SentinelAliCloudListenerTests.java index abc88e334..389361d64 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/sentinel/SentinelAliCloudListenerTests.java +++ b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/sentinel/SentinelAliCloudListenerTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,16 +16,15 @@ package com.alibaba.alicloud.context.sentinel; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.powermock.core.classloader.annotations.PrepareForTest; - import com.alibaba.alicloud.context.BaseAliCloudSpringApplication; import com.alibaba.alicloud.context.Constants; import com.alibaba.alicloud.utils.ChangeOrderUtils; import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory; +import org.junit.BeforeClass; +import org.junit.Test; +import org.powermock.core.classloader.annotations.PrepareForTest; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; /** * @author xiaolongzuo @@ -53,4 +52,5 @@ public class SentinelAliCloudListenerTests extends BaseAliCloudSpringApplication .isEqualTo("testSK"); } + } diff --git a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/sms/SmsPropertiesTests.java b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/sms/SmsPropertiesTests.java index acc8201a8..b3c674e68 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/sms/SmsPropertiesTests.java +++ b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/sms/SmsPropertiesTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,14 +16,14 @@ package com.alibaba.alicloud.context.sms; -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; - +import com.alibaba.alicloud.context.AliCloudContextAutoConfiguration; +import com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration; import org.junit.Test; + import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import com.alibaba.alicloud.context.AliCloudContextAutoConfiguration; -import com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration; +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; /** * @author xiaolongzuo diff --git a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/oss/OssAutoConfiguration.java b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/oss/OssAutoConfiguration.java index 159d28ee0..568d475c1 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/oss/OssAutoConfiguration.java +++ b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/oss/OssAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,4 +20,5 @@ package com.alibaba.alicloud.oss; * @author xiaolongzuo */ public class OssAutoConfiguration { + } diff --git a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/scx/ScxAutoConfiguration.java b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/scx/ScxAutoConfiguration.java index cae4aade3..80e810313 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/scx/ScxAutoConfiguration.java +++ b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/scx/ScxAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,4 +20,5 @@ package com.alibaba.alicloud.scx; * @author xiaolongzuo */ public class ScxAutoConfiguration { + } diff --git a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/utils/ChangeOrderUtils.java b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/utils/ChangeOrderUtils.java index 316f1758f..2c5b0fe5e 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/utils/ChangeOrderUtils.java +++ b/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/utils/ChangeOrderUtils.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,15 +16,14 @@ package com.alibaba.alicloud.utils; -import org.powermock.api.mockito.PowerMockito; - import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration; import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory; +import org.powermock.api.mockito.PowerMockito; /** * @author xiaolongzuo */ -public class ChangeOrderUtils { +public final class ChangeOrderUtils { private ChangeOrderUtils() { } @@ -51,4 +50,5 @@ public class ChangeOrderUtils { .getEdasChangeOrderConfiguration()) .thenReturn(edasChangeOrderConfiguration); } + } diff --git a/spring-cloud-alicloud-context/src/test/java/com/alibaba/cloud/nacos/NacosConfigAutoConfiguration.java b/spring-cloud-alicloud-context/src/test/java/com/alibaba/cloud/nacos/NacosConfigAutoConfiguration.java index bef131714..b39d75ec2 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/alibaba/cloud/nacos/NacosConfigAutoConfiguration.java +++ b/spring-cloud-alicloud-context/src/test/java/com/alibaba/cloud/nacos/NacosConfigAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,4 +20,5 @@ package com.alibaba.cloud.nacos; * @author xiaolongzuo */ public class NacosConfigAutoConfiguration { + } diff --git a/spring-cloud-alicloud-context/src/test/java/com/alibaba/cloud/nacos/NacosDiscoveryAutoConfiguration.java b/spring-cloud-alicloud-context/src/test/java/com/alibaba/cloud/nacos/NacosDiscoveryAutoConfiguration.java index d9f47e117..4b5842398 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/alibaba/cloud/nacos/NacosDiscoveryAutoConfiguration.java +++ b/spring-cloud-alicloud-context/src/test/java/com/alibaba/cloud/nacos/NacosDiscoveryAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,4 +20,5 @@ package com.alibaba.cloud.nacos; * @author xiaolongzuo */ public class NacosDiscoveryAutoConfiguration { + } diff --git a/spring-cloud-alicloud-context/src/test/java/com/alibaba/csp/sentinel/datasource/nacos/NacosDataSource.java b/spring-cloud-alicloud-context/src/test/java/com/alibaba/csp/sentinel/datasource/nacos/NacosDataSource.java index 7159a2f41..3ea26682b 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/alibaba/csp/sentinel/datasource/nacos/NacosDataSource.java +++ b/spring-cloud-alicloud-context/src/test/java/com/alibaba/csp/sentinel/datasource/nacos/NacosDataSource.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,4 +20,5 @@ package com.alibaba.csp.sentinel.datasource.nacos; * @author xiaolongzuo */ public class NacosDataSource { + } diff --git a/spring-cloud-alicloud-context/src/test/java/com/aliyuncs/dysmsapi/model/v20170525/SendSmsRequest.java b/spring-cloud-alicloud-context/src/test/java/com/aliyuncs/dysmsapi/model/v20170525/SendSmsRequest.java index ef660e84e..5f9430182 100644 --- a/spring-cloud-alicloud-context/src/test/java/com/aliyuncs/dysmsapi/model/v20170525/SendSmsRequest.java +++ b/spring-cloud-alicloud-context/src/test/java/com/aliyuncs/dysmsapi/model/v20170525/SendSmsRequest.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,4 +20,5 @@ package com.aliyuncs.dysmsapi.model.v20170525; * @author xiaolongzuo */ public class SendSmsRequest { + } diff --git a/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/OssApplicationListener.java b/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/OssApplicationListener.java index 7024cfc2b..030464d14 100644 --- a/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/OssApplicationListener.java +++ b/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/OssApplicationListener.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,16 +18,16 @@ package com.alibaba.alicloud.oss; import java.util.Map; +import com.aliyun.oss.OSS; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextClosedEvent; -import com.aliyun.oss.OSS; - /** * Shutdown All OSS Clients when {@code ApplicationContext} gets closed - * {@link ApplicationListener} + * {@link ApplicationListener}. * * @author Jim */ @@ -46,4 +46,5 @@ public class OssApplicationListener implements ApplicationListenerJim */ @Configuration @ConditionalOnClass(OSS.class) -@ConditionalOnProperty(name = OssConstants.ENABLED, havingValue = "true", matchIfMissing = true) +@ConditionalOnProperty(name = OssConstants.ENABLED, havingValue = "true", + matchIfMissing = true) public class OssAutoConfiguration { @Bean diff --git a/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/OssConstants.java b/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/OssConstants.java index 8384092a6..6552959a6 100644 --- a/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/OssConstants.java +++ b/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/OssConstants.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,15 +17,29 @@ package com.alibaba.alicloud.oss; /** - * OSS constants + * OSS constants. * * @author Jim */ -public interface OssConstants { +public final class OssConstants { - String PREFIX = "spring.cloud.alibaba.oss"; - String ENABLED = PREFIX + ".enabled"; + /** + * Prefix of OSSConfigurationProperties. + */ + public static final String PREFIX = "spring.cloud.alibaba.oss"; - String OSS_TASK_EXECUTOR_BEAN_NAME = "ossTaskExecutor"; + /** + * Enable OSS. + */ + public static final String ENABLED = PREFIX + ".enabled"; + + /** + * OSS ThreadPool bean name. + */ + public static final String OSS_TASK_EXECUTOR_BEAN_NAME = "ossTaskExecutor"; + + private OssConstants() { + throw new AssertionError("Must not instantiate constant utility class"); + } } diff --git a/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/endpoint/OssEndpoint.java b/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/endpoint/OssEndpoint.java index e7ef504d5..96d14a824 100644 --- a/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/endpoint/OssEndpoint.java +++ b/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/endpoint/OssEndpoint.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,15 +21,15 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import com.aliyun.oss.OSSClient; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import org.springframework.context.ApplicationContext; -import com.aliyun.oss.OSSClient; - /** - * Actuator {@link Endpoint} to expose OSS Meta Data + * Actuator {@link Endpoint} to expose OSS Meta Data. * * @author Jim */ diff --git a/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/endpoint/OssEndpointAutoConfiguration.java b/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/endpoint/OssEndpointAutoConfiguration.java index e4e49f343..8ac753c7c 100644 --- a/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/endpoint/OssEndpointAutoConfiguration.java +++ b/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/endpoint/OssEndpointAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,7 +24,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** - * OSS {@link Endpoint} Auto-{@link Configuration} + * OSS {@link Endpoint} Auto-{@link Configuration}. * * @author Jim */ diff --git a/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/resource/OssStorageProtocolResolver.java b/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/resource/OssStorageProtocolResolver.java index eb6111631..7273f9009 100644 --- a/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/resource/OssStorageProtocolResolver.java +++ b/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/resource/OssStorageProtocolResolver.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,8 +16,10 @@ package com.alibaba.alicloud.oss.resource; +import com.aliyun.oss.OSS; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; @@ -27,8 +29,6 @@ import org.springframework.core.io.ProtocolResolver; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; -import com.aliyun.oss.OSS; - /** * A {@link ProtocolResolver} implementation for the {@code oss://} protocol. * @@ -37,6 +37,9 @@ import com.aliyun.oss.OSS; public class OssStorageProtocolResolver implements ProtocolResolver, BeanFactoryPostProcessor, ResourceLoaderAware { + /** + * protocol of oss resource. + */ public static final String PROTOCOL = "oss://"; private static final Logger log = LoggerFactory @@ -82,4 +85,5 @@ public class OssStorageProtocolResolver throws BeansException { this.beanFactory = beanFactory; } + } diff --git a/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/resource/OssStorageResource.java b/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/resource/OssStorageResource.java index 64e242f4c..3995518e6 100644 --- a/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/resource/OssStorageResource.java +++ b/spring-cloud-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/resource/OssStorageResource.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,18 @@ package com.alibaba.alicloud.oss.resource; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.concurrent.ExecutorService; + import com.aliyun.oss.ClientException; import com.aliyun.oss.OSS; import com.aliyun.oss.OSSException; @@ -23,17 +35,12 @@ import com.aliyun.oss.model.Bucket; import com.aliyun.oss.model.OSSObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.core.io.Resource; import org.springframework.core.io.WritableResource; import org.springframework.util.Assert; -import java.io.*; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.concurrent.ExecutorService; - import static com.alibaba.alicloud.oss.OssConstants.OSS_TASK_EXECUTOR_BEAN_NAME; /** @@ -48,25 +55,32 @@ import static com.alibaba.alicloud.oss.OssConstants.OSS_TASK_EXECUTOR_BEAN_NAME; */ public class OssStorageResource implements WritableResource { - private static final Logger logger = LoggerFactory.getLogger(OssStorageResource.class); + private static final Logger logger = LoggerFactory + .getLogger(OssStorageResource.class); private static final String MESSAGE_KEY_NOT_EXIST = "The specified key does not exist."; private final OSS oss; + private final String bucketName; + private final String objectKey; + private final URI location; + private final boolean autoCreateFiles; private final ExecutorService ossTaskExecutor; private final ConfigurableListableBeanFactory beanFactory; - public OssStorageResource(OSS oss, String location, ConfigurableListableBeanFactory beanFactory) { - this(oss, location, beanFactory,false); - } + public OssStorageResource(OSS oss, String location, + ConfigurableListableBeanFactory beanFactory) { + this(oss, location, beanFactory, false); + } - public OssStorageResource(OSS oss, String location,ConfigurableListableBeanFactory beanFactory, boolean autoCreateFiles) { + public OssStorageResource(OSS oss, String location, + ConfigurableListableBeanFactory beanFactory, boolean autoCreateFiles) { Assert.notNull(oss, "Object Storage Service can not be null"); Assert.isTrue(location.startsWith(OssStorageProtocolResolver.PROTOCOL), "Location must start with " + OssStorageProtocolResolver.PROTOCOL); @@ -89,7 +103,8 @@ public class OssStorageResource implements WritableResource { throw new IllegalArgumentException("Invalid location: " + location, e); } - this.ossTaskExecutor = this.beanFactory.getBean(OSS_TASK_EXECUTOR_BEAN_NAME, ExecutorService.class); + this.ossTaskExecutor = this.beanFactory.getBean(OSS_TASK_EXECUTOR_BEAN_NAME, + ExecutorService.class); } public boolean isAutoCreateFiles() { @@ -219,7 +234,7 @@ public class OssStorageResource implements WritableResource { /** * create a bucket. - * @return + * @return OSS Bucket */ public Bucket createBucket() { return this.oss.createBucket(this.bucketName); @@ -231,10 +246,10 @@ public class OssStorageResource implements WritableResource { } /** - * acquire an OutputStream for write. - * Note: please close the stream after writing is done - * @return - * @throws IOException + * acquire an OutputStream for write. Note: please close the stream after writing is + * done + * @return OutputStream of OSS resource + * @throws IOException throw by oss operation */ @Override public OutputStream getOutputStream() throws IOException { diff --git a/spring-cloud-alicloud-oss/src/test/java/com/alibaba/alicloud/oss/resource/DummyOssClient.java b/spring-cloud-alicloud-oss/src/test/java/com/alibaba/alicloud/oss/resource/DummyOssClient.java index d04a574a5..66eeb0794 100644 --- a/spring-cloud-alicloud-oss/src/test/java/com/alibaba/alicloud/oss/resource/DummyOssClient.java +++ b/spring-cloud-alicloud-oss/src/test/java/com/alibaba/alicloud/oss/resource/DummyOssClient.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,17 +16,22 @@ package com.alibaba.alicloud.oss.resource; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + import com.aliyun.oss.model.Bucket; import com.aliyun.oss.model.OSSObject; import com.aliyun.oss.model.ObjectMetadata; import com.aliyun.oss.model.PutObjectResult; -import org.springframework.util.StreamUtils; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; +import org.springframework.util.StreamUtils; /** * @author lich @@ -95,4 +100,5 @@ public class DummyOssClient { public List bucketList() { return new ArrayList<>(bucketSet.values()); } + } diff --git a/spring-cloud-alicloud-oss/src/test/java/com/alibaba/alicloud/oss/resource/OssStorageResourceTest.java b/spring-cloud-alicloud-oss/src/test/java/com/alibaba/alicloud/oss/resource/OssStorageResourceTest.java index b57eab484..7894a8b7a 100644 --- a/spring-cloud-alicloud-oss/src/test/java/com/alibaba/alicloud/oss/resource/OssStorageResourceTest.java +++ b/spring-cloud-alicloud-oss/src/test/java/com/alibaba/alicloud/oss/resource/OssStorageResourceTest.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,16 +16,26 @@ package com.alibaba.alicloud.oss.resource; +import java.io.ByteArrayInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Random; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.SynchronousQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + import com.aliyun.oss.OSS; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.Mockito; -import org.springframework.beans.BeansException; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.test.context.SpringBootTest; @@ -37,15 +47,8 @@ import org.springframework.core.io.WritableResource; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.StreamUtils; -import java.io.*; -import java.util.Random; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.SynchronousQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - import static com.alibaba.alicloud.oss.OssConstants.OSS_TASK_EXECUTOR_BEAN_NAME; -import static org.junit.Assert.*; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; @@ -82,45 +85,46 @@ public class OssStorageResourceTest { @Test public void testResourceType() { - assertEquals(OssStorageResource.class, remoteResource.getClass()); + assertThat(remoteResource.getClass()).isEqualTo(OssStorageResource.class); OssStorageResource ossStorageResource = (OssStorageResource) remoteResource; - assertEquals("myfilekey", ossStorageResource.getFilename()); - assertFalse(ossStorageResource.isBucket()); + assertThat(ossStorageResource.getFilename()).isEqualTo("myfilekey"); + assertThat(ossStorageResource.isBucket()).isEqualTo(false); } @Test public void testValidObject() throws Exception { - assertTrue(remoteResource.exists()); + assertThat(remoteResource.exists()).isEqualTo(true); OssStorageResource ossStorageResource = (OssStorageResource) remoteResource; - assertTrue(ossStorageResource.bucketExists()); - assertEquals(4096L, remoteResource.contentLength()); - assertEquals("oss://aliyun-test-bucket/myfilekey", - remoteResource.getURI().toString()); - assertEquals("myfilekey", remoteResource.getFilename()); + assertThat(ossStorageResource.bucketExists()).isEqualTo(true); + assertThat(remoteResource.contentLength()).isEqualTo(4096L); + assertThat(remoteResource.getURI().toString()) + .isEqualTo("oss://aliyun-test-bucket/myfilekey"); + assertThat(remoteResource.getFilename()).isEqualTo("myfilekey"); } @Test public void testBucketResource() throws Exception { - assertTrue(bucketResource.exists()); - assertTrue(((OssStorageResource) this.bucketResource).isBucket()); - assertTrue(((OssStorageResource) this.bucketResource).bucketExists()); - assertEquals("oss://aliyun-test-bucket/", bucketResource.getURI().toString()); - assertEquals("aliyun-test-bucket", this.bucketResource.getFilename()); + assertThat(bucketResource.exists()).isEqualTo(true); + assertThat(((OssStorageResource) this.bucketResource).isBucket()).isEqualTo(true); + assertThat(((OssStorageResource) this.bucketResource).bucketExists()) + .isEqualTo(true); + assertThat(bucketResource.getURI().toString()) + .isEqualTo("oss://aliyun-test-bucket/"); + assertThat(this.bucketResource.getFilename()).isEqualTo("aliyun-test-bucket"); } @Test public void testBucketNotEndingInSlash() { - assertTrue( + assertThat( new OssStorageResource(this.oss, "oss://aliyun-test-bucket", beanFactory) - .isBucket()); + .isBucket()).isEqualTo(true); } @Test public void testSpecifyPathCorrect() { OssStorageResource ossStorageResource = new OssStorageResource(this.oss, "oss://aliyun-test-bucket/myfilekey", beanFactory, false); - - assertTrue(ossStorageResource.exists()); + assertThat(ossStorageResource.exists()).isEqualTo(true); } @Test @@ -128,9 +132,10 @@ public class OssStorageResourceTest { OssStorageResource ossStorageResource = new OssStorageResource(this.oss, "oss://aliyun-test-bucket", beanFactory, false); - assertTrue(ossStorageResource.isBucket()); - assertEquals("aliyun-test-bucket", ossStorageResource.getBucket().getName()); - assertTrue(ossStorageResource.exists()); + assertThat(ossStorageResource.isBucket()).isEqualTo(true); + assertThat(ossStorageResource.getBucket().getName()) + .isEqualTo("aliyun-test-bucket"); + assertThat(ossStorageResource.exists()).isEqualTo(true); } @Test @@ -173,25 +178,27 @@ public class OssStorageResourceTest { @Test public void testBucketResourceStatuses() { - assertFalse(this.bucketResource.isOpen()); - assertFalse(((WritableResource) this.bucketResource).isWritable()); - assertTrue(this.bucketResource.exists()); + assertThat(this.bucketResource.isOpen()).isEqualTo(false); + assertThat(((WritableResource) this.bucketResource).isWritable()) + .isEqualTo(false); + assertThat(this.bucketResource.exists()).isEqualTo(true); } @Test public void testWritable() throws Exception { - assertTrue(this.remoteResource instanceof WritableResource); + assertThat(this.remoteResource instanceof WritableResource).isEqualTo(true); WritableResource writableResource = (WritableResource) this.remoteResource; - assertTrue(writableResource.isWritable()); + assertThat(writableResource.isWritable()).isEqualTo(true); writableResource.getOutputStream(); } @Test public void testWritableOutputStream() throws Exception { String location = "oss://aliyun-test-bucket/test"; - OssStorageResource resource = new OssStorageResource(this.oss, location, beanFactory,true); + OssStorageResource resource = new OssStorageResource(this.oss, location, + beanFactory, true); OutputStream os = resource.getOutputStream(); - assertNotNull(os); + assertThat(os).isNotNull(); byte[] randomBytes = generateRandomBytes(1203); String expectedString = new String(randomBytes); @@ -204,18 +211,18 @@ public class OssStorageResourceTest { byte[] result = StreamUtils.copyToByteArray(in); String actualString = new String(result); - assertEquals(expectedString, actualString); + assertThat(actualString).isEqualTo(expectedString); } @Test public void testCreateBucket() { String location = "oss://my-new-test-bucket/"; - OssStorageResource resource = new OssStorageResource(this.oss, location, beanFactory, true); + OssStorageResource resource = new OssStorageResource(this.oss, location, + beanFactory, true); resource.createBucket(); - assertTrue(resource.bucketExists()); - + assertThat(resource.bucketExists()).isEqualTo(true); } /** @@ -228,8 +235,8 @@ public class OssStorageResourceTest { @Bean(name = OSS_TASK_EXECUTOR_BEAN_NAME) @ConditionalOnMissingBean public ExecutorService ossTaskExecutor() { - return new ThreadPoolExecutor(8, 128, - 60, TimeUnit.SECONDS, new SynchronousQueue<>()); + return new ThreadPoolExecutor(8, 128, 60, TimeUnit.SECONDS, + new SynchronousQueue<>()); } @Bean diff --git a/spring-cloud-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/ScxAutoConfiguration.java b/spring-cloud-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/ScxAutoConfiguration.java index 47beae5cc..9795403ed 100644 --- a/spring-cloud-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/ScxAutoConfiguration.java +++ b/spring-cloud-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/ScxAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,7 +19,7 @@ package com.alibaba.alicloud.scx; import org.springframework.context.annotation.Configuration; /** - * placeholder configuration + * placeholder configuration. * * @author xiaolongzuo */ diff --git a/spring-cloud-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/endpoint/ScxEndpoint.java b/spring-cloud-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/endpoint/ScxEndpoint.java index 2f1736663..64801f945 100644 --- a/spring-cloud-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/endpoint/ScxEndpoint.java +++ b/spring-cloud-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/endpoint/ScxEndpoint.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,14 +19,14 @@ package com.alibaba.alicloud.scx.endpoint; import java.util.HashMap; import java.util.Map; +import com.alibaba.alicloud.context.edas.EdasProperties; +import com.alibaba.alicloud.context.scx.ScxProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; -import com.alibaba.alicloud.context.edas.EdasProperties; -import com.alibaba.alicloud.context.scx.ScxProperties; - /** * @author xiaolongzuo */ diff --git a/spring-cloud-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/endpoint/ScxEndpointAutoConfiguration.java b/spring-cloud-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/endpoint/ScxEndpointAutoConfiguration.java index 98563e3a7..366cc5406 100644 --- a/spring-cloud-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/endpoint/ScxEndpointAutoConfiguration.java +++ b/spring-cloud-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/endpoint/ScxEndpointAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,9 @@ package com.alibaba.alicloud.scx.endpoint; +import com.alibaba.alicloud.context.edas.EdasProperties; +import com.alibaba.alicloud.context.scx.ScxProperties; + import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -23,9 +26,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.context.annotation.Bean; -import com.alibaba.alicloud.context.edas.EdasProperties; -import com.alibaba.alicloud.context.scx.ScxProperties; - /** * @author xiaolongzuo */ diff --git a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/AbstractSmsService.java b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/AbstractSmsService.java index b27c5dab7..4101ae9cd 100644 --- a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/AbstractSmsService.java +++ b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/AbstractSmsService.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.alicloud.sms; import java.util.concurrent.ConcurrentHashMap; @@ -22,7 +23,6 @@ import com.aliyuncs.IAcsClient; import com.aliyuncs.profile.DefaultProfile; /** - * * @author pbting */ public abstract class AbstractSmsService implements ISmsService { @@ -44,4 +44,4 @@ public abstract class AbstractSmsService implements ISmsService { return regionId + ":" + accessKeyId + ":" + accessKeySecret; } -} \ No newline at end of file +} diff --git a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/ISmsService.java b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/ISmsService.java index 45f81b443..882009dba 100644 --- a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/ISmsService.java +++ b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/ISmsService.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.alicloud.sms; import com.aliyuncs.IAcsClient; @@ -30,91 +31,30 @@ import com.aliyuncs.exceptions.ServerException; */ public interface ISmsService { - /** - * - * @param accessKeyId - * @param secret - * @return IAcsClient - */ IAcsClient getHangZhouRegionClientProfile(String accessKeyId, String secret); - /** - * - * @param sendSmsRequest - * @throws ServerException - * @throws ClientException - * @return SendSmsResponse - */ SendSmsResponse sendSmsRequest(SendSmsRequest sendSmsRequest) throws ServerException, ClientException; - /** - * - * @param sendBatchSmsRequest - * @throws ServerException - * @throws ClientException - * @return SendBatchSmsResponse - */ SendBatchSmsResponse sendSmsBatchRequest(SendBatchSmsRequest sendBatchSmsRequest) throws ServerException, ClientException; - /** - * 因为阿里云支持多个 - * accessKeyId/accessKeySecret,当不想使用默认的配置accessKeyId/accessKeySecret时,可以使用这个方法来支持额外 - * 的accessKeyId/accessKeySecret 发送 - * @param sendSmsRequest - * @param accessKeyId - * @param accessKeySecret - * @return - * @throws ServerException - * @throws ClientException - */ SendSmsResponse sendSmsRequest(SendSmsRequest sendSmsRequest, String accessKeyId, String accessKeySecret) throws ServerException, ClientException; - /** - * - * @param sendSmsRequest - * @param accessKeyId - * @param accessKeySecret - * @throws ServerException - * @throws ClientException - * @return SendBatchSmsResponse - */ SendBatchSmsResponse sendSmsBatchRequest(SendBatchSmsRequest sendSmsRequest, String accessKeyId, String accessKeySecret) throws ServerException, ClientException; - /** - * - * @param smsReportMessageListener - * @return boolean - */ boolean startSmsReportMessageListener( SmsReportMessageListener smsReportMessageListener); - /** - * - * @param smsUpMessageListener - * @return boolean - */ boolean startSmsUpMessageListener(SmsUpMessageListener smsUpMessageListener); - /** - * - * @param request - * @param accessKeyId - * @param accessKeySecret - * @return QuerySendDetailsResponse - */ QuerySendDetailsResponse querySendDetails(QuerySendDetailsRequest request, String accessKeyId, String accessKeySecret) throws ClientException; - /** - * - * @param request - * @return QuerySendDetailsResponse - */ QuerySendDetailsResponse querySendDetails(QuerySendDetailsRequest request) throws ClientException; -} \ No newline at end of file + +} diff --git a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsInitializerEventListener.java b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsInitializerEventListener.java index 5724785c4..a356b0b50 100644 --- a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsInitializerEventListener.java +++ b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsInitializerEventListener.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,21 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.alicloud.sms; import java.util.Collection; import java.util.concurrent.atomic.AtomicBoolean; -import org.springframework.boot.context.event.ApplicationStartedEvent; -import org.springframework.context.ApplicationListener; -import org.springframework.stereotype.Component; - import com.alibaba.alicloud.context.sms.SmsProperties; import com.alibaba.alicloud.sms.base.MessageListener; - import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.profile.DefaultProfile; +import org.springframework.boot.context.event.ApplicationStartedEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.stereotype.Component; + /** * @author pbting */ @@ -104,4 +104,5 @@ public class SmsInitializerEventListener "initialize sms profile end point cause an exception"); } } -} \ No newline at end of file + +} diff --git a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsMessageListener.java b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsMessageListener.java index 5904f0538..3df32e941 100644 --- a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsMessageListener.java +++ b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsMessageListener.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.alicloud.sms; import com.alibaba.alicloud.sms.base.MessageListener; @@ -21,4 +22,5 @@ import com.alibaba.alicloud.sms.base.MessageListener; * @author pbting */ public interface SmsMessageListener extends MessageListener { + } diff --git a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsReportMessageListener.java b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsReportMessageListener.java index 39deafa69..7194a3a15 100644 --- a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsReportMessageListener.java +++ b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsReportMessageListener.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,10 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.alicloud.sms; /** * @author pbting */ public interface SmsReportMessageListener extends SmsMessageListener { -} \ No newline at end of file + +} diff --git a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsServiceImpl.java b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsServiceImpl.java index b7e6ea3bf..f5c495767 100644 --- a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsServiceImpl.java +++ b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsServiceImpl.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,19 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.alicloud.sms; import java.text.ParseException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.alibaba.alicloud.context.AliCloudProperties; import com.alibaba.alicloud.context.sms.SmsProperties; import com.alibaba.alicloud.sms.base.DefaultAlicomMessagePuller; import com.alibaba.alicloud.sms.endpoint.EndpointManager; import com.alibaba.alicloud.sms.endpoint.ReceiveMessageEntity; - import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsRequest; import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsResponse; import com.aliyuncs.dysmsapi.model.v20170525.SendBatchSmsRequest; @@ -34,6 +31,8 @@ import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.exceptions.ServerException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author pbting @@ -41,10 +40,9 @@ import com.aliyuncs.exceptions.ServerException; public final class SmsServiceImpl extends AbstractSmsService { private static final Logger log = LoggerFactory.getLogger(SmsServiceImpl.class); + /** - * will expose user to call this method send sms message - * @param sendSmsRequest - * @return + * will expose user to call this method send sms message. */ private SmsProperties smsProperties; @@ -64,17 +62,6 @@ public final class SmsServiceImpl extends AbstractSmsService { aliCloudProperties.getSecretKey()); } - /** - * 因为阿里云支持多个 - * accessKeyId/accessKeySecret,当不想使用默认的配置accessKeyId/accessKeySecret时,可以使用这个方法来支持额外 - * 的accessKeyId/accessKeySecret 发送 - * @param sendSmsRequest - * @param accessKeyId - * @param accessKeySecret - * @throws ServerException - * @throws ClientException - * @return SendSmsResponse - */ @Override public SendSmsResponse sendSmsRequest(SendSmsRequest sendSmsRequest, String accessKeyId, String accessKeySecret) @@ -85,11 +72,6 @@ public final class SmsServiceImpl extends AbstractSmsService { .getAcsResponse(sendSmsRequest); } - /** - * - * @param smsReportMessageListener - * @return boolean - */ @Override public boolean startSmsReportMessageListener( SmsReportMessageListener smsReportMessageListener) { @@ -99,11 +81,6 @@ public final class SmsServiceImpl extends AbstractSmsService { return startReceiveMsg(messageType, queueName, smsReportMessageListener); } - /** - * - * @param smsUpMessageListener - * @return boolean - */ @Override public boolean startSmsUpMessageListener(SmsUpMessageListener smsUpMessageListener) { // 短信回执:SmsReport,短信上行:SmsUp @@ -112,13 +89,6 @@ public final class SmsServiceImpl extends AbstractSmsService { return startReceiveMsg(messageType, queueName, smsUpMessageListener); } - /** - * - * @param messageType - * @param queueName - * @param messageListener - * @return boolean - */ private boolean startReceiveMsg(String messageType, String queueName, SmsMessageListener messageListener) { String accessKeyId = aliCloudProperties.getAccessKey(); @@ -141,13 +111,6 @@ public final class SmsServiceImpl extends AbstractSmsService { return result; } - /** - * - * @param sendBatchSmsRequest - * @throws ServerException - * @throws ClientException - * @return SendBatchSmsResponse - */ @Override public SendBatchSmsResponse sendSmsBatchRequest( SendBatchSmsRequest sendBatchSmsRequest) @@ -157,14 +120,6 @@ public final class SmsServiceImpl extends AbstractSmsService { aliCloudProperties.getSecretKey()); } - /** - * - * @param sendBatchSmsRequest - * @param accessKeyId - * @param accessKeySecret - * @throws ClientException - * @return SendBatchSmsResponse - */ @Override public SendBatchSmsResponse sendSmsBatchRequest( SendBatchSmsRequest sendBatchSmsRequest, String accessKeyId, @@ -174,14 +129,6 @@ public final class SmsServiceImpl extends AbstractSmsService { .getAcsResponse(sendBatchSmsRequest); } - /** - * - * @param request - * @param accessKeyId - * @param accessKeySecret - * @throws ClientException - * @return QuerySendDetailsResponse - */ @Override public QuerySendDetailsResponse querySendDetails(QuerySendDetailsRequest request, String accessKeyId, String accessKeySecret) throws ClientException { @@ -189,16 +136,11 @@ public final class SmsServiceImpl extends AbstractSmsService { .getAcsResponse(request); } - /** - * - * @param request - * @throws ClientException - * @return QuerySendDetailsResponse - */ @Override public QuerySendDetailsResponse querySendDetails(QuerySendDetailsRequest request) throws ClientException { return querySendDetails(request, aliCloudProperties.getAccessKey(), aliCloudProperties.getSecretKey()); } -} \ No newline at end of file + +} diff --git a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsUpMessageListener.java b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsUpMessageListener.java index 9e4e8124d..b6c5242a7 100644 --- a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsUpMessageListener.java +++ b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsUpMessageListener.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,10 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.alicloud.sms; /** * @author pbting */ public interface SmsUpMessageListener extends SmsMessageListener { -} \ No newline at end of file + +} diff --git a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/DefaultAlicomMessagePuller.java b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/DefaultAlicomMessagePuller.java index 4cf87d7b2..c823ac4fc 100755 --- a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/DefaultAlicomMessagePuller.java +++ b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/DefaultAlicomMessagePuller.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.alicloud.sms.base; import java.text.ParseException; @@ -25,32 +26,40 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; -import org.apache.commons.lang3.concurrent.BasicThreadFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.aliyun.mns.client.CloudQueue; import com.aliyun.mns.common.ClientException; import com.aliyun.mns.common.ServiceException; import com.aliyun.mns.model.Message; +import org.apache.commons.lang3.concurrent.BasicThreadFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** - * 阿里通信官方消息默认拉取工具类 + * 阿里通信官方消息默认拉取工具类. */ public class DefaultAlicomMessagePuller { private static final Logger log = LoggerFactory .getLogger(DefaultAlicomMessagePuller.class); - private String mnsAccountEndpoint = "https://1943695596114318.mns.cn-hangzhou.aliyuncs.com/";// 阿里通信消息的endpoint,固定。 + private String mnsAccountEndpoint = "https://1943695596114318.mns.cn-hangzhou.aliyuncs.com/"; // 阿里通信消息的endpoint,固定。 + private String endpointNameForPop = "cn-hangzhou"; + private String regionIdForPop = "cn-hangzhou"; + private String domainForPop = "dybaseapi.aliyuncs.com"; + private TokenGetterForAlicom tokenGetter; + private MessageListener messageListener; + private boolean isRunning = false; + private Integer pullMsgThreadSize = 1; + private boolean debugLogOpen = false; + private Integer sleepSecondWhenNoData = 30; public void openDebugLog(boolean debugLogOpen) { @@ -86,7 +95,9 @@ public class DefaultAlicomMessagePuller { } protected static final Map S_LOCK_OBJ_MAP = new HashMap<>(); + protected static Map sPollingMap = new ConcurrentHashMap<>(); + protected Object lockObj; public boolean setPolling(String queueName) { @@ -118,8 +129,155 @@ public class DefaultAlicomMessagePuller { isRunning = running; } + /** + * @param accessKeyId accessKeyId + * @param accessKeySecret accessKeySecret + * @param messageType 消息类型 + * @param queueName 队列名称 + * @param messageListener 回调的listener,用户自己实现 + * @throws com.aliyuncs.exceptions.ClientException throw by sdk + * @throws ParseException throw parse exception + */ + public void startReceiveMsg(String accessKeyId, String accessKeySecret, + String messageType, String queueName, MessageListener messageListener) + throws com.aliyuncs.exceptions.ClientException, ParseException { + + tokenGetter = new TokenGetterForAlicom(accessKeyId, accessKeySecret, + endpointNameForPop, regionIdForPop, domainForPop, null); + + this.messageListener = messageListener; + isRunning = true; + PullMessageTask task = new PullMessageTask(); + task.messageType = messageType; + task.queueName = queueName; + + synchronized (S_LOCK_OBJ_MAP) { + lockObj = S_LOCK_OBJ_MAP.get(queueName); + if (lockObj == null) { + lockObj = new Object(); + S_LOCK_OBJ_MAP.put(queueName, lockObj); + } + } + + if (executorService == null) { + ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor( + pullMsgThreadSize, + new BasicThreadFactory.Builder() + .namingPattern( + "PullMessageTask-" + messageType + "-thread-pool-%d") + .daemon(true).build()); + executorService = scheduledExecutorService; + } + for (int i = 0; i < pullMsgThreadSize; i++) { + executorService.execute(task); + } + } + + /** + * @param accessKeyId accessKeyId + * @param accessKeySecret accessKeySecret + * @param messageType 消息类型 + * @param queueName 队列名称 + * @param regionIdForPop region + * @param endpointNameForPop endpoint name + * @param domainForPop domain + * @param mnsAccountEndpoint mns account endpoint + * @param messageListener 回调的listener,用户自己实现 + * @throws com.aliyuncs.exceptions.ClientException throw by sdk + * @throws ParseException throw parse exception + */ + public void startReceiveMsgForVPC(String accessKeyId, String accessKeySecret, + String messageType, String queueName, String regionIdForPop, + String endpointNameForPop, String domainForPop, String mnsAccountEndpoint, + MessageListener messageListener) + throws com.aliyuncs.exceptions.ClientException, ParseException { + this.mnsAccountEndpoint = mnsAccountEndpoint; + tokenGetter = new TokenGetterForAlicom(accessKeyId, accessKeySecret, + endpointNameForPop, regionIdForPop, domainForPop, null); + + this.messageListener = messageListener; + isRunning = true; + PullMessageTask task = new PullMessageTask(); + task.messageType = messageType; + task.queueName = queueName; + + synchronized (S_LOCK_OBJ_MAP) { + lockObj = S_LOCK_OBJ_MAP.get(queueName); + if (lockObj == null) { + lockObj = new Object(); + S_LOCK_OBJ_MAP.put(queueName, lockObj); + } + } + + if (executorService == null) { + ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor( + pullMsgThreadSize, + new BasicThreadFactory.Builder() + .namingPattern( + "PullMessageTask-" + messageType + "-thread-pool-%d") + .daemon(true).build()); + executorService = scheduledExecutorService; + } + for (int i = 0; i < pullMsgThreadSize; i++) { + executorService.execute(task); + } + } + + /** + * 虚商用户定制接收消息方法. + * @param accessKeyId accessKeyId + * @param accessKeySecret accessKeySecret + * @param ownerId 实际的ownerId + * @param messageType 消息类型 + * @param queueName 队列名称 + * @param messageListener 回调listener + * @throws com.aliyuncs.exceptions.ClientException throw by sdk + * @throws ParseException throw parse exception + */ + public void startReceiveMsgForPartnerUser(String accessKeyId, String accessKeySecret, + Long ownerId, String messageType, String queueName, + MessageListener messageListener) + throws com.aliyuncs.exceptions.ClientException, ParseException { + + tokenGetter = new TokenGetterForAlicom(accessKeyId, accessKeySecret, + endpointNameForPop, regionIdForPop, domainForPop, ownerId); + + this.messageListener = messageListener; + isRunning = true; + PullMessageTask task = new PullMessageTask(); + task.messageType = messageType; + task.queueName = queueName; + + synchronized (S_LOCK_OBJ_MAP) { + lockObj = S_LOCK_OBJ_MAP.get(queueName); + if (lockObj == null) { + lockObj = new Object(); + S_LOCK_OBJ_MAP.put(queueName, lockObj); + } + } + + if (executorService == null) { + ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor( + pullMsgThreadSize, + new BasicThreadFactory.Builder() + .namingPattern( + "PullMessageTask-" + messageType + "-thread-pool-%d") + .daemon(true).build()); + executorService = scheduledExecutorService; + } + for (int i = 0; i < pullMsgThreadSize; i++) { + executorService.execute(task); + } + } + + public void stop() { + isRunning = false; + } + private class PullMessageTask implements Runnable { + private String messageType; + private String queueName; @Override @@ -287,145 +445,4 @@ public class DefaultAlicomMessagePuller { } - /** - * @param accessKeyId accessKeyId - * @param accessKeySecret accessKeySecret - * @param messageType 消息类型 - * @param queueName 队列名称 - * @param messageListener 回调的listener,用户自己实现 - * @throws com.aliyuncs.exceptions.ClientException - * @throws ParseException - */ - public void startReceiveMsg(String accessKeyId, String accessKeySecret, - String messageType, String queueName, MessageListener messageListener) - throws com.aliyuncs.exceptions.ClientException, ParseException { - - tokenGetter = new TokenGetterForAlicom(accessKeyId, accessKeySecret, - endpointNameForPop, regionIdForPop, domainForPop, null); - - this.messageListener = messageListener; - isRunning = true; - PullMessageTask task = new PullMessageTask(); - task.messageType = messageType; - task.queueName = queueName; - - synchronized (S_LOCK_OBJ_MAP) { - lockObj = S_LOCK_OBJ_MAP.get(queueName); - if (lockObj == null) { - lockObj = new Object(); - S_LOCK_OBJ_MAP.put(queueName, lockObj); - } - } - - if (executorService == null) { - ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor( - pullMsgThreadSize, - new BasicThreadFactory.Builder() - .namingPattern( - "PullMessageTask-" + messageType + "-thread-pool-%d") - .daemon(true).build()); - executorService = scheduledExecutorService; - } - for (int i = 0; i < pullMsgThreadSize; i++) { - executorService.execute(task); - } - } - - /** - * @param accessKeyId accessKeyId - * @param accessKeySecret accessKeySecret - * @param messageType 消息类型 - * @param queueName 队列名称 - * @param messageListener 回调的listener,用户自己实现 - * @throws com.aliyuncs.exceptions.ClientException - * @throws ParseException - */ - public void startReceiveMsgForVPC(String accessKeyId, String accessKeySecret, - String messageType, String queueName, String regionIdForPop, - String endpointNameForPop, String domainForPop, String mnsAccountEndpoint, - MessageListener messageListener) - throws com.aliyuncs.exceptions.ClientException, ParseException { - this.mnsAccountEndpoint = mnsAccountEndpoint; - tokenGetter = new TokenGetterForAlicom(accessKeyId, accessKeySecret, - endpointNameForPop, regionIdForPop, domainForPop, null); - - this.messageListener = messageListener; - isRunning = true; - PullMessageTask task = new PullMessageTask(); - task.messageType = messageType; - task.queueName = queueName; - - synchronized (S_LOCK_OBJ_MAP) { - lockObj = S_LOCK_OBJ_MAP.get(queueName); - if (lockObj == null) { - lockObj = new Object(); - S_LOCK_OBJ_MAP.put(queueName, lockObj); - } - } - - if (executorService == null) { - ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor( - pullMsgThreadSize, - new BasicThreadFactory.Builder() - .namingPattern( - "PullMessageTask-" + messageType + "-thread-pool-%d") - .daemon(true).build()); - executorService = scheduledExecutorService; - } - for (int i = 0; i < pullMsgThreadSize; i++) { - executorService.execute(task); - } - } - - /** - * 虚商用户定制接收消息方法 - * @param accessKeyId accessKeyId - * @param accessKeySecret accessKeySecret - * @param ownerId 实际的ownerId - * @param messageType 消息类型 - * @param queueName 队列名称 - * @param messageListener 回调listener - * @throws com.aliyuncs.exceptions.ClientException - * @throws ParseException - */ - public void startReceiveMsgForPartnerUser(String accessKeyId, String accessKeySecret, - Long ownerId, String messageType, String queueName, - MessageListener messageListener) - throws com.aliyuncs.exceptions.ClientException, ParseException { - - tokenGetter = new TokenGetterForAlicom(accessKeyId, accessKeySecret, - endpointNameForPop, regionIdForPop, domainForPop, ownerId); - - this.messageListener = messageListener; - isRunning = true; - PullMessageTask task = new PullMessageTask(); - task.messageType = messageType; - task.queueName = queueName; - - synchronized (S_LOCK_OBJ_MAP) { - lockObj = S_LOCK_OBJ_MAP.get(queueName); - if (lockObj == null) { - lockObj = new Object(); - S_LOCK_OBJ_MAP.put(queueName, lockObj); - } - } - - if (executorService == null) { - ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor( - pullMsgThreadSize, - new BasicThreadFactory.Builder() - .namingPattern( - "PullMessageTask-" + messageType + "-thread-pool-%d") - .daemon(true).build()); - executorService = scheduledExecutorService; - } - for (int i = 0; i < pullMsgThreadSize; i++) { - executorService.execute(task); - } - } - - public void stop() { - isRunning = false; - } - } diff --git a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/MessageListener.java b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/MessageListener.java index 9e857f2a1..9717f0505 100755 --- a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/MessageListener.java +++ b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/MessageListener.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.alicloud.sms.base; import com.aliyun.mns.model.Message; diff --git a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueRequest.java b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueRequest.java index e8214812d..8a8889cd4 100644 --- a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueRequest.java +++ b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueRequest.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,15 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.alicloud.sms.base; import com.aliyuncs.RpcAcsRequest; public class QueryTokenForMnsQueueRequest extends RpcAcsRequest { + private String resourceOwnerAccount; + private String messageType; + private Long resourceOwnerId; + private Long ownerId; public QueryTokenForMnsQueueRequest() { @@ -80,4 +85,5 @@ public class QueryTokenForMnsQueueRequest public Class getResponseClass() { return QueryTokenForMnsQueueResponse.class; } -} \ No newline at end of file + +} diff --git a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueResponse.java b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueResponse.java index 724804e88..3b1a2b3e2 100644 --- a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueResponse.java +++ b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueResponse.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,15 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.alicloud.sms.base; import com.aliyuncs.AcsResponse; import com.aliyuncs.transform.UnmarshallerContext; public class QueryTokenForMnsQueueResponse extends AcsResponse { + private String requestId; + private String code; + private String message; + private QueryTokenForMnsQueueResponse.MessageTokenDTO messageTokenDTO; public QueryTokenForMnsQueueResponse() { @@ -66,10 +71,15 @@ public class QueryTokenForMnsQueueResponse extends AcsResponse { } public static class MessageTokenDTO { + private String accessKeyId; + private String accessKeySecret; + private String securityToken; + private String createTime; + private String expireTime; public MessageTokenDTO() { @@ -114,5 +124,7 @@ public class QueryTokenForMnsQueueResponse extends AcsResponse { public void setExpireTime(String expireTime) { this.expireTime = expireTime; } + } -} \ No newline at end of file + +} diff --git a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueResponseUnmarshaller.java b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueResponseUnmarshaller.java index 87c58c28c..36ca1f696 100644 --- a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueResponseUnmarshaller.java +++ b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueResponseUnmarshaller.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.alicloud.sms.base; import com.aliyuncs.transform.UnmarshallerContext; -public class QueryTokenForMnsQueueResponseUnmarshaller { +public final class QueryTokenForMnsQueueResponseUnmarshaller { - public QueryTokenForMnsQueueResponseUnmarshaller() { + private QueryTokenForMnsQueueResponseUnmarshaller() { } public static QueryTokenForMnsQueueResponse unmarshall( @@ -45,4 +46,5 @@ public class QueryTokenForMnsQueueResponseUnmarshaller { queryTokenForMnsQueueResponse.setMessageTokenDTO(messageTokenDTO); return queryTokenForMnsQueueResponse; } -} \ No newline at end of file + +} diff --git a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/TokenForAlicom.java b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/TokenForAlicom.java index 443e8517f..97b670723 100755 --- a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/TokenForAlicom.java +++ b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/TokenForAlicom.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,22 +13,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.alicloud.sms.base; import com.aliyun.mns.client.CloudQueue; import com.aliyun.mns.client.MNSClient; /** - * 用于接收云通信消息的临时token + * 用于接收云通信消息的临时token. * */ public class TokenForAlicom { + private String messageType; + private String token; + private Long expireTime; + private String tempAccessKeyId; + private String tempAccessKeySecret; + private MNSClient client; + private CloudQueue queue; public String getMessageType() { diff --git a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/TokenGetterForAlicom.java b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/TokenGetterForAlicom.java index 70def7400..54e15df6d 100755 --- a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/TokenGetterForAlicom.java +++ b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/TokenGetterForAlicom.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.alicloud.sms.base; import java.text.ParseException; @@ -21,9 +22,6 @@ import java.util.TimeZone; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.aliyun.mns.client.CloudAccount; import com.aliyun.mns.client.CloudQueue; import com.aliyun.mns.client.MNSClient; @@ -36,23 +34,36 @@ import com.aliyuncs.http.MethodType; import com.aliyuncs.http.ProtocolType; import com.aliyuncs.profile.DefaultProfile; import com.aliyuncs.profile.IClientProfile; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** - * 获取接收云通信消息的临时token - * + * 获取接收云通信消息的临时token. */ public class TokenGetterForAlicom { + private static final Logger log = LoggerFactory.getLogger(TokenGetterForAlicom.class); + private String accessKeyId; + private String accessKeySecret; + private String endpointNameForPop; + private String regionIdForPop; + private String domainForPop; + private IAcsClient iAcsClient; + private Long ownerId; + private final static String PRODUCT_NAME = "Dybaseapi"; - private long bufferTime = 1000 * 60 * 2;// 过期时间小于2分钟则重新获取,防止服务器时间误差 + + private long bufferTime = 1000 * 60 * 2; // 过期时间小于2分钟则重新获取,防止服务器时间误差 + private final Object lock = new Object(); + private ConcurrentMap tokenMap = new ConcurrentHashMap(); public TokenGetterForAlicom(String accessKeyId, String accessKeySecret, @@ -112,7 +123,7 @@ public class TokenGetterForAlicom { throws ServerException, ClientException, ParseException { TokenForAlicom token = tokenMap.get(messageType); Long now = System.currentTimeMillis(); - if (token == null || (token.getExpireTime() - now) < bufferTime) {// 过期时间小于2分钟则重新获取,防止服务器时间误差 + if (token == null || (token.getExpireTime() - now) < bufferTime) { // 过期时间小于2分钟则重新获取,防止服务器时间误差 synchronized (lock) { token = tokenMap.get(messageType); if (token == null || (token.getExpireTime() - now) < bufferTime) { @@ -138,4 +149,5 @@ public class TokenGetterForAlicom { } return token; } + } diff --git a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/config/SmsAutoConfiguration.java b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/config/SmsAutoConfiguration.java index 08e750984..836d82259 100644 --- a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/config/SmsAutoConfiguration.java +++ b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/config/SmsAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,28 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.alicloud.sms.config; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; +package com.alibaba.alicloud.sms.config; import com.alibaba.alicloud.context.AliCloudProperties; import com.alibaba.alicloud.context.sms.SmsProperties; import com.alibaba.alicloud.sms.ISmsService; import com.alibaba.alicloud.sms.SmsInitializerEventListener; import com.alibaba.alicloud.sms.SmsServiceImpl; - import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + /** * @author pbting */ @Configuration @EnableConfigurationProperties -@ConditionalOnClass(value = SendSmsRequest.class) +@ConditionalOnClass(SendSmsRequest.class) @ConditionalOnProperty(value = "spring.cloud.alicloud.sms.enable", matchIfMissing = true) public class SmsAutoConfiguration { @@ -49,4 +49,5 @@ public class SmsAutoConfiguration { SmsProperties smsProperties, ISmsService smsService) { return new SmsInitializerEventListener(smsProperties, smsService); } -} \ No newline at end of file + +} diff --git a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/EndpointManager.java b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/EndpointManager.java index 79354f245..963a26511 100644 --- a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/EndpointManager.java +++ b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/EndpointManager.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.alicloud.sms.endpoint; import java.util.HashMap; @@ -26,20 +27,27 @@ import com.aliyuncs.dysmsapi.model.v20170525.SendBatchSmsRequest; import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; /** - * + * */ public final class EndpointManager { + private EndpointManager() { + + } + private final static int BACKLOG_SIZE = 20; private final static ReentrantLock SEND_REENTRANT_LOCK = new ReentrantLock(true); + private final static ReentrantLock SEND_BATCH_REENTRANT_LOCK = new ReentrantLock( true); private final static LinkedBlockingQueue SEND_SMS_REQUESTS = new LinkedBlockingQueue( BACKLOG_SIZE); + private final static LinkedBlockingQueue SEND_BATCH_SMS_REQUESTS = new LinkedBlockingQueue( BACKLOG_SIZE); + private final static LinkedBlockingQueue RECEIVE_MESSAGE_ENTITIES = new LinkedBlockingQueue( BACKLOG_SIZE); @@ -103,4 +111,5 @@ public final class EndpointManager { return endpointMessages; } -} \ No newline at end of file + +} diff --git a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/ReceiveMessageEntity.java b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/ReceiveMessageEntity.java index 685fbe972..df3ea7c7e 100644 --- a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/ReceiveMessageEntity.java +++ b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/ReceiveMessageEntity.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.alicloud.sms.endpoint; import java.io.Serializable; @@ -23,8 +24,11 @@ import com.alibaba.alicloud.sms.base.MessageListener; * @author pbting */ public class ReceiveMessageEntity implements Serializable { + private String messageType; + private String queueName; + private MessageListener messageListener; public ReceiveMessageEntity(String messageType, String queueName, @@ -57,4 +61,5 @@ public class ReceiveMessageEntity implements Serializable { public void setMessageListener(MessageListener messageListener) { this.messageListener = messageListener; } -} \ No newline at end of file + +} diff --git a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/SmsEndpoint.java b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/SmsEndpoint.java index 57da7bd5f..7f87d67cd 100644 --- a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/SmsEndpoint.java +++ b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/SmsEndpoint.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.alicloud.sms.endpoint; import java.util.Map; @@ -28,4 +29,5 @@ public class SmsEndpoint { return EndpointManager.getSmsEndpointMessage(); } -} \ No newline at end of file + +} diff --git a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/SmsEndpointAutoConfiguration.java b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/SmsEndpointAutoConfiguration.java index cf8a6bb77..f788aae06 100644 --- a/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/SmsEndpointAutoConfiguration.java +++ b/spring-cloud-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/SmsEndpointAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.alicloud.sms.endpoint; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; @@ -28,4 +29,5 @@ public class SmsEndpointAutoConfiguration { public SmsEndpoint smsEndpoint() { return new SmsEndpoint(); } -} \ No newline at end of file + +} diff --git a/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreaker.java b/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreaker.java index e2cd8bf57..37e5a2f6f 100644 --- a/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreaker.java +++ b/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreaker.java @@ -101,4 +101,4 @@ public class ReactiveSentinelCircuitBreaker implements ReactiveCircuitBreaker { return toReturn; } -} \ No newline at end of file +} diff --git a/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerAutoConfiguration.java b/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerAutoConfiguration.java index e4592e0b6..14a7bc181 100644 --- a/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerAutoConfiguration.java +++ b/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerAutoConfiguration.java @@ -33,8 +33,8 @@ import org.springframework.context.annotation.Configuration; * @author Eric Zhao */ @Configuration -@ConditionalOnClass(name = { "reactor.core.publisher.Mono", - "reactor.core.publisher.Flux" }) +@ConditionalOnClass( + name = { "reactor.core.publisher.Mono", "reactor.core.publisher.Flux" }) public class ReactiveSentinelCircuitBreakerAutoConfiguration { @Bean @@ -44,8 +44,8 @@ public class ReactiveSentinelCircuitBreakerAutoConfiguration { } @Configuration - @ConditionalOnClass(name = { "reactor.core.publisher.Mono", - "reactor.core.publisher.Flux" }) + @ConditionalOnClass( + name = { "reactor.core.publisher.Mono", "reactor.core.publisher.Flux" }) public static class ReactiveSentinelCustomizerConfiguration { @Autowired(required = false) @@ -61,4 +61,4 @@ public class ReactiveSentinelCircuitBreakerAutoConfiguration { } -} \ No newline at end of file +} diff --git a/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerFactory.java b/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerFactory.java index 5ebb97b3f..a56d9b8e3 100644 --- a/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerFactory.java +++ b/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerFactory.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.function.Function; import com.alibaba.cloud.circuitbreaker.sentinel.SentinelConfigBuilder.SentinelCircuitBreakerConfiguration; + import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreaker; import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory; import org.springframework.util.Assert; @@ -55,4 +56,4 @@ public class ReactiveSentinelCircuitBreakerFactory extends this.defaultConfiguration = defaultConfiguration; } -} \ No newline at end of file +} diff --git a/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreaker.java b/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreaker.java index acbc7db38..34ef03448 100644 --- a/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreaker.java +++ b/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreaker.java @@ -111,4 +111,4 @@ public class SentinelCircuitBreaker implements CircuitBreaker { } } -} \ No newline at end of file +} diff --git a/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerAutoConfiguration.java b/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerAutoConfiguration.java index e8a96b939..2d22ba077 100644 --- a/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerAutoConfiguration.java +++ b/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerAutoConfiguration.java @@ -62,4 +62,4 @@ public class SentinelCircuitBreakerAutoConfiguration { } -} \ No newline at end of file +} diff --git a/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerFactory.java b/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerFactory.java index 6b8b665e2..692555e41 100644 --- a/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerFactory.java +++ b/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerFactory.java @@ -19,9 +19,9 @@ package com.alibaba.cloud.circuitbreaker.sentinel; import java.util.ArrayList; import java.util.function.Function; +import com.alibaba.cloud.circuitbreaker.sentinel.SentinelConfigBuilder.SentinelCircuitBreakerConfiguration; import com.alibaba.csp.sentinel.EntryType; -import com.alibaba.cloud.circuitbreaker.sentinel.SentinelConfigBuilder.SentinelCircuitBreakerConfiguration; import org.springframework.cloud.client.circuitbreaker.CircuitBreaker; import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; import org.springframework.util.Assert; @@ -54,4 +54,4 @@ public class SentinelCircuitBreakerFactory extends this.defaultConfiguration = defaultConfiguration; } -} \ No newline at end of file +} diff --git a/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelConfigBuilder.java b/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelConfigBuilder.java index 35de02308..b37b5d351 100644 --- a/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelConfigBuilder.java +++ b/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelConfigBuilder.java @@ -109,4 +109,4 @@ public class SentinelConfigBuilder implements } -} \ No newline at end of file +} diff --git a/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerIntegrationTest.java b/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerIntegrationTest.java index 9f90a71c4..5d2ed9892 100644 --- a/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerIntegrationTest.java +++ b/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerIntegrationTest.java @@ -50,8 +50,9 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen * @author Ryan Baxter */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = RANDOM_PORT, classes = ReactiveSentinelCircuitBreakerIntegrationTest.Application.class, properties = { - "spring.cloud.discovery.client.health-indicator.enabled=false" }) +@SpringBootTest(webEnvironment = RANDOM_PORT, + classes = ReactiveSentinelCircuitBreakerIntegrationTest.Application.class, + properties = { "spring.cloud.discovery.client.health-indicator.enabled=false" }) @DirtiesContext public class ReactiveSentinelCircuitBreakerIntegrationTest { @@ -205,4 +206,4 @@ public class ReactiveSentinelCircuitBreakerIntegrationTest { } -} \ No newline at end of file +} diff --git a/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerTest.java b/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerTest.java index 63a650645..59d5bcaf7 100644 --- a/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerTest.java +++ b/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerTest.java @@ -77,4 +77,4 @@ public class ReactiveSentinelCircuitBreakerTest { .block()).isEqualTo(Arrays.asList("fallback")); } -} \ No newline at end of file +} diff --git a/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerIntegrationTest.java b/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerIntegrationTest.java index 34c51ea52..d63abfb5d 100644 --- a/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerIntegrationTest.java +++ b/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerIntegrationTest.java @@ -48,8 +48,9 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen * @author Eric Zhao */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = RANDOM_PORT, classes = SentinelCircuitBreakerIntegrationTest.Application.class, properties = { - "spring.cloud.discovery.client.health-indicator.enabled=false" }) +@SpringBootTest(webEnvironment = RANDOM_PORT, + classes = SentinelCircuitBreakerIntegrationTest.Application.class, + properties = { "spring.cloud.discovery.client.health-indicator.enabled=false" }) @DirtiesContext public class SentinelCircuitBreakerIntegrationTest { @@ -151,4 +152,4 @@ public class SentinelCircuitBreakerIntegrationTest { } -} \ No newline at end of file +} diff --git a/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerTest.java b/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerTest.java index 8dba3efd0..439d15c7d 100644 --- a/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerTest.java +++ b/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerTest.java @@ -21,7 +21,6 @@ import java.util.Collections; import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager; - import org.junit.After; import org.junit.Test; @@ -78,9 +77,9 @@ public class SentinelCircuitBreakerTest { public void testRunWithFallback() { CircuitBreaker cb = new SentinelCircuitBreakerFactory() .create("testSentinelRunWithFallback"); - assertThat(cb. run(() -> { + assertThat(cb.run(() -> { throw new RuntimeException("boom"); }, t -> "fallback")).isEqualTo("fallback"); } -} \ No newline at end of file +} diff --git a/spring-cloud-starter-alibaba/spring-cloud-starter-bus-rocketmq/src/main/java/com/alibaba/cloud/bus/rocketmq/env/RocketMQBusEnvironmentPostProcessor.java b/spring-cloud-starter-alibaba/spring-cloud-starter-bus-rocketmq/src/main/java/com/alibaba/cloud/bus/rocketmq/env/RocketMQBusEnvironmentPostProcessor.java index ffb28a1c2..d062dc239 100644 --- a/spring-cloud-starter-alibaba/spring-cloud-starter-bus-rocketmq/src/main/java/com/alibaba/cloud/bus/rocketmq/env/RocketMQBusEnvironmentPostProcessor.java +++ b/spring-cloud-starter-alibaba/spring-cloud-starter-bus-rocketmq/src/main/java/com/alibaba/cloud/bus/rocketmq/env/RocketMQBusEnvironmentPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.cloud.bus.rocketmq.env; -import static org.springframework.cloud.bus.SpringCloudBusClient.INPUT; +package com.alibaba.cloud.bus.rocketmq.env; import java.util.HashMap; import java.util.Map; @@ -29,19 +28,21 @@ import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; +import static org.springframework.cloud.bus.SpringCloudBusClient.INPUT; + /** * The lowest precedence {@link EnvironmentPostProcessor} configures default RocketMQ Bus - * Properties that will be appended into {@link SpringApplication#defaultProperties} + * Properties that will be appended into {@link SpringApplication#defaultProperties}. * * @author Mercy - * @see BusEnvironmentPostProcessor * @since 0.2.1 + * @see BusEnvironmentPostProcessor */ public class RocketMQBusEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered { /** - * The name of {@link PropertySource} of {@link SpringApplication#defaultProperties} + * The name of {@link PropertySource} of {@link SpringApplication#defaultProperties}. */ private static final String PROPERTY_SOURCE_NAME = "defaultProperties"; @@ -81,9 +82,8 @@ public class RocketMQBusEnvironmentPostProcessor } /** - * Copy from + * Copy from. * {@link BusEnvironmentPostProcessor#addOrReplace(MutablePropertySources, Map)} - * * @param propertySources {@link MutablePropertySources} * @param map Default RocketMQ Bus Properties */ @@ -113,4 +113,5 @@ public class RocketMQBusEnvironmentPostProcessor public int getOrder() { return LOWEST_PRECEDENCE; } + } diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQBinderConstants.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQBinderConstants.java index e2a527dde..47e4b9e7f 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQBinderConstants.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQBinderConstants.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,23 +22,30 @@ import static org.apache.rocketmq.spring.support.RocketMQHeaders.PREFIX; * @author Jim * @author Xiejiashuai */ -public interface RocketMQBinderConstants { +public final class RocketMQBinderConstants { /** - * Header key + * Header key for RocketMQ Transactional Args. */ - String ROCKET_TRANSACTIONAL_ARG = "TRANSACTIONAL_ARG"; + public static final String ROCKET_TRANSACTIONAL_ARG = "TRANSACTIONAL_ARG"; /** - * Default value + * Default NameServer value. */ - String DEFAULT_NAME_SERVER = "127.0.0.1:9876"; + public static final String DEFAULT_NAME_SERVER = "127.0.0.1:9876"; - String DEFAULT_GROUP = PREFIX + "binder_default_group_name"; + /** + * Default group for SCS RocketMQ Binder. + */ + public static final String DEFAULT_GROUP = PREFIX + "binder_default_group_name"; /** - * RocketMQ re-consume times + * RocketMQ re-consume times. */ - String ROCKETMQ_RECONSUME_TIMES = PREFIX + "RECONSUME_TIMES"; + public static final String ROCKETMQ_RECONSUME_TIMES = PREFIX + "RECONSUME_TIMES"; + + private RocketMQBinderConstants() { + throw new AssertionError("Must not instantiate constant utility class"); + } } diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQBinderUtils.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQBinderUtils.java index 673d33708..3cd7c85bd 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQBinderUtils.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQBinderUtils.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,15 +16,19 @@ package com.alibaba.cloud.stream.binder.rocketmq; +import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQBinderConfigurationProperties; import org.apache.rocketmq.spring.autoconfigure.RocketMQProperties; -import org.springframework.util.StringUtils; -import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQBinderConfigurationProperties; +import org.springframework.util.StringUtils; /** * @author Jim */ -public class RocketMQBinderUtils { +public final class RocketMQBinderUtils { + + private RocketMQBinderUtils() { + + } public static RocketMQBinderConfigurationProperties mergeProperties( RocketMQBinderConfigurationProperties rocketBinderConfigurationProperties, diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQMessageChannelBinder.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQMessageChannelBinder.java index e580594e5..73629f19d 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQMessageChannelBinder.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQMessageChannelBinder.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,6 +22,20 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; +import com.alibaba.cloud.stream.binder.rocketmq.consuming.RocketMQListenerBindingContainer; +import com.alibaba.cloud.stream.binder.rocketmq.integration.RocketMQInboundChannelAdapter; +import com.alibaba.cloud.stream.binder.rocketmq.integration.RocketMQMessageHandler; +import com.alibaba.cloud.stream.binder.rocketmq.integration.RocketMQMessageSource; +import com.alibaba.cloud.stream.binder.rocketmq.metrics.InstrumentationManager; +import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQBinderConfigurationProperties; +import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQConsumerProperties; +import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQExtendedBindingProperties; +import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQProducerProperties; +import com.alibaba.cloud.stream.binder.rocketmq.provisioning.RocketMQTopicProvisioner; +import com.alibaba.cloud.stream.binder.rocketmq.provisioning.selector.PartitionMessageQueueSelector; +import com.alibaba.cloud.stream.binder.rocketmq.support.JacksonRocketMQHeaderMapper; +import com.alibaba.cloud.stream.binder.rocketmq.support.RocketMQHeaderMapper; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.rocketmq.acl.common.AclClientRPCHook; import org.apache.rocketmq.acl.common.SessionCredentials; import org.apache.rocketmq.client.producer.DefaultMQProducer; @@ -30,6 +44,7 @@ import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.spring.autoconfigure.RocketMQProperties; import org.apache.rocketmq.spring.core.RocketMQTemplate; import org.apache.rocketmq.spring.support.RocketMQUtil; + import org.springframework.cloud.stream.binder.AbstractMessageChannelBinder; import org.springframework.cloud.stream.binder.BinderSpecificPropertiesProvider; import org.springframework.cloud.stream.binder.ExtendedConsumerProperties; @@ -48,22 +63,6 @@ import org.springframework.messaging.MessageHandler; import org.springframework.messaging.MessagingException; import org.springframework.util.StringUtils; -import com.alibaba.cloud.stream.binder.rocketmq.consuming.RocketMQListenerBindingContainer; -import com.alibaba.cloud.stream.binder.rocketmq.integration.RocketMQInboundChannelAdapter; -import com.alibaba.cloud.stream.binder.rocketmq.integration.RocketMQMessageHandler; -import com.alibaba.cloud.stream.binder.rocketmq.integration.RocketMQMessageSource; -import com.alibaba.cloud.stream.binder.rocketmq.metrics.InstrumentationManager; -import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQBinderConfigurationProperties; -import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQConsumerProperties; -import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQExtendedBindingProperties; -import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQProducerProperties; -import com.alibaba.cloud.stream.binder.rocketmq.provisioning.RocketMQTopicProvisioner; -import com.alibaba.cloud.stream.binder.rocketmq.provisioning.selector.PartitionMessageQueueSelector; -import com.alibaba.cloud.stream.binder.rocketmq.support.JacksonRocketMQHeaderMapper; -import com.alibaba.cloud.stream.binder.rocketmq.support.RocketMQHeaderMapper; - -import com.fasterxml.jackson.databind.ObjectMapper; - /** * @author Jim */ @@ -75,7 +74,9 @@ public class RocketMQMessageChannelBinder extends private RocketMQExtendedBindingProperties extendedBindingProperties = new RocketMQExtendedBindingProperties(); private final RocketMQBinderConfigurationProperties rocketBinderConfigurationProperties; + private final RocketMQProperties rocketMQProperties; + private final InstrumentationManager instrumentationManager; private Map topicInUse = new HashMap<>(); @@ -101,8 +102,7 @@ public class RocketMQMessageChannelBinder extends // if producerGroup is empty, using destination String extendedProducerGroup = producerProperties.getExtension().getGroup(); String producerGroup = StringUtils.isEmpty(extendedProducerGroup) - ? destination.getName() - : extendedProducerGroup; + ? destination.getName() : extendedProducerGroup; RocketMQBinderConfigurationProperties mergedProperties = RocketMQBinderUtils .mergeProperties(rocketBinderConfigurationProperties, diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/actuator/RocketMQBinderHealthIndicator.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/actuator/RocketMQBinderHealthIndicator.java index c75398225..1c49359ea 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/actuator/RocketMQBinderHealthIndicator.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/actuator/RocketMQBinderHealthIndicator.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,13 @@ package com.alibaba.cloud.stream.binder.rocketmq.actuator; +import com.alibaba.cloud.stream.binder.rocketmq.metrics.Instrumentation; +import com.alibaba.cloud.stream.binder.rocketmq.metrics.InstrumentationManager; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.health.AbstractHealthIndicator; import org.springframework.boot.actuate.health.Health; -import com.alibaba.cloud.stream.binder.rocketmq.metrics.Instrumentation; -import com.alibaba.cloud.stream.binder.rocketmq.metrics.InstrumentationManager; - /** * @author Timur Valiev * @author Jim @@ -50,4 +50,5 @@ public class RocketMQBinderHealthIndicator extends AbstractHealthIndicator { .forEach(instrumentation1 -> builder .withException(instrumentation1.getStartException())); } + } diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/config/RocketMQBinderAutoConfiguration.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/config/RocketMQBinderAutoConfiguration.java index 66a26ec15..1d8a5416a 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/config/RocketMQBinderAutoConfiguration.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/config/RocketMQBinderAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,20 +16,20 @@ package com.alibaba.cloud.stream.binder.rocketmq.config; +import com.alibaba.cloud.stream.binder.rocketmq.RocketMQMessageChannelBinder; +import com.alibaba.cloud.stream.binder.rocketmq.metrics.InstrumentationManager; +import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQBinderConfigurationProperties; +import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQExtendedBindingProperties; +import com.alibaba.cloud.stream.binder.rocketmq.provisioning.RocketMQTopicProvisioner; import org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration; import org.apache.rocketmq.spring.autoconfigure.RocketMQProperties; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; -import com.alibaba.cloud.stream.binder.rocketmq.RocketMQMessageChannelBinder; -import com.alibaba.cloud.stream.binder.rocketmq.metrics.InstrumentationManager; -import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQBinderConfigurationProperties; -import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQExtendedBindingProperties; -import com.alibaba.cloud.stream.binder.rocketmq.provisioning.RocketMQTopicProvisioner; - /** * @author Timur Valiev * @author Jim diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/config/RocketMQBinderHealthIndicatorAutoConfiguration.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/config/RocketMQBinderHealthIndicatorAutoConfiguration.java index cdc3537a2..d99eb5d7d 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/config/RocketMQBinderHealthIndicatorAutoConfiguration.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/config/RocketMQBinderHealthIndicatorAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,13 +16,13 @@ package com.alibaba.cloud.stream.binder.rocketmq.config; +import com.alibaba.cloud.stream.binder.rocketmq.actuator.RocketMQBinderHealthIndicator; + import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.alibaba.cloud.stream.binder.rocketmq.actuator.RocketMQBinderHealthIndicator; - /** * @author Jim */ diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/config/RocketMQComponent4BinderAutoConfiguration.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/config/RocketMQComponent4BinderAutoConfiguration.java index 33186962c..4e17eccec 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/config/RocketMQComponent4BinderAutoConfiguration.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/config/RocketMQComponent4BinderAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,8 @@ package com.alibaba.cloud.stream.binder.rocketmq.config; +import com.alibaba.cloud.stream.binder.rocketmq.RocketMQBinderConstants; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.rocketmq.acl.common.AclClientRPCHook; import org.apache.rocketmq.acl.common.SessionCredentials; import org.apache.rocketmq.client.producer.DefaultMQProducer; @@ -24,6 +26,7 @@ import org.apache.rocketmq.spring.config.RocketMQConfigUtils; import org.apache.rocketmq.spring.config.RocketMQTransactionAnnotationProcessor; import org.apache.rocketmq.spring.config.TransactionHandlerRegistry; import org.apache.rocketmq.spring.core.RocketMQTemplate; + import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -32,10 +35,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.util.StringUtils; -import com.alibaba.cloud.stream.binder.rocketmq.RocketMQBinderConstants; - -import com.fasterxml.jackson.databind.ObjectMapper; - /** * @author Jim */ diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/consuming/RocketMQListenerBindingContainer.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/consuming/RocketMQListenerBindingContainer.java index 8e00a249c..0e384b3e0 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/consuming/RocketMQListenerBindingContainer.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/consuming/RocketMQListenerBindingContainer.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,11 +16,13 @@ package com.alibaba.cloud.stream.binder.rocketmq.consuming; -import static com.alibaba.cloud.stream.binder.rocketmq.RocketMQBinderConstants.ROCKETMQ_RECONSUME_TIMES; - import java.util.List; import java.util.Objects; +import com.alibaba.cloud.stream.binder.rocketmq.RocketMQMessageChannelBinder; +import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQBinderConfigurationProperties; +import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQConsumerProperties; +import com.alibaba.cloud.stream.binder.rocketmq.support.RocketMQHeaderMapper; import org.apache.rocketmq.acl.common.AclClientRPCHook; import org.apache.rocketmq.acl.common.SessionCredentials; import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; @@ -45,6 +47,7 @@ import org.apache.rocketmq.spring.support.RocketMQListenerContainer; import org.apache.rocketmq.spring.support.RocketMQUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.InitializingBean; import org.springframework.cloud.stream.binder.ExtendedConsumerProperties; import org.springframework.context.SmartLifecycle; @@ -53,13 +56,10 @@ import org.springframework.messaging.Message; import org.springframework.util.Assert; import org.springframework.util.StringUtils; -import com.alibaba.cloud.stream.binder.rocketmq.RocketMQMessageChannelBinder; -import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQBinderConfigurationProperties; -import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQConsumerProperties; -import com.alibaba.cloud.stream.binder.rocketmq.support.RocketMQHeaderMapper; +import static com.alibaba.cloud.stream.binder.rocketmq.RocketMQBinderConstants.ROCKETMQ_RECONSUME_TIMES; /** - * A class that Listen on rocketmq message + * A class that Listen on rocketmq message. *

    * this class will delegate {@link RocketMQListener} to handle message * @@ -104,12 +104,16 @@ public class RocketMQListenerBindingContainer private final ExtendedConsumerProperties rocketMQConsumerProperties; private final RocketMQMessageChannelBinder rocketMQMessageChannelBinder; + private final RocketMQBinderConfigurationProperties rocketBinderConfigurationProperties; // The following properties came from RocketMQConsumerProperties. private ConsumeMode consumeMode; + private SelectorType selectorType; + private String selectorExpression; + private MessageModel messageModel; public RocketMQListenerBindingContainer( @@ -120,8 +124,7 @@ public class RocketMQListenerBindingContainer this.rocketBinderConfigurationProperties = rocketBinderConfigurationProperties; this.rocketMQMessageChannelBinder = rocketMQMessageChannelBinder; this.consumeMode = rocketMQConsumerProperties.getExtension().getOrderly() - ? ConsumeMode.ORDERLY - : ConsumeMode.CONCURRENTLY; + ? ConsumeMode.ORDERLY : ConsumeMode.CONCURRENTLY; if (StringUtils.isEmpty(rocketMQConsumerProperties.getExtension().getSql())) { this.selectorType = SelectorType.TAG; this.selectorExpression = rocketMQConsumerProperties.getExtension().getTags(); @@ -131,8 +134,7 @@ public class RocketMQListenerBindingContainer this.selectorExpression = rocketMQConsumerProperties.getExtension().getSql(); } this.messageModel = rocketMQConsumerProperties.getExtension().getBroadcasting() - ? MessageModel.BROADCASTING - : MessageModel.CLUSTERING; + ? MessageModel.BROADCASTING : MessageModel.CLUSTERING; } @Override @@ -386,6 +388,23 @@ public class RocketMQListenerBindingContainer this.headerMapper = headerMapper; } + /** + * Convert rocketmq {@link MessageExt} to Spring {@link Message}. + * @param messageExt the rocketmq message + * @return the converted Spring {@link Message} + */ + @SuppressWarnings("unchecked") + private Message convertToSpringMessage(MessageExt messageExt) { + + // add reconsume-times header to messageExt + int reconsumeTimes = messageExt.getReconsumeTimes(); + messageExt.putUserProperty(ROCKETMQ_RECONSUME_TIMES, + String.valueOf(reconsumeTimes)); + Message message = RocketMQUtil.convertToSpringMessage(messageExt); + return MessageBuilder.fromMessage(message) + .copyHeaders(headerMapper.toHeaders(messageExt.getProperties())).build(); + } + public class DefaultMessageListenerConcurrently implements MessageListenerConcurrently { @@ -411,6 +430,7 @@ public class RocketMQListenerBindingContainer return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; } + } public class DefaultMessageListenerOrderly implements MessageListenerOrderly { @@ -438,24 +458,7 @@ public class RocketMQListenerBindingContainer return ConsumeOrderlyStatus.SUCCESS; } - } - - /** - * Convert rocketmq {@link MessageExt} to Spring {@link Message} - * - * @param messageExt the rocketmq message - * @return the converted Spring {@link Message} - */ - @SuppressWarnings("unchecked") - private Message convertToSpringMessage(MessageExt messageExt) { - // add reconsume-times header to messageExt - int reconsumeTimes = messageExt.getReconsumeTimes(); - messageExt.putUserProperty(ROCKETMQ_RECONSUME_TIMES, - String.valueOf(reconsumeTimes)); - Message message = RocketMQUtil.convertToSpringMessage(messageExt); - return MessageBuilder.fromMessage(message) - .copyHeaders(headerMapper.toHeaders(messageExt.getProperties())).build(); } } diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/consuming/RocketMQMessageQueueChooser.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/consuming/RocketMQMessageQueueChooser.java index 627248273..948555924 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/consuming/RocketMQMessageQueueChooser.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/consuming/RocketMQMessageQueueChooser.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,4 +58,5 @@ public class RocketMQMessageQueueChooser { public List getMessageQueues() { return messageQueues; } + } diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/RocketMQInboundChannelAdapter.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/RocketMQInboundChannelAdapter.java index eeb8d3ef9..a3b680419 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/RocketMQInboundChannelAdapter.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/RocketMQInboundChannelAdapter.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,9 +16,14 @@ package com.alibaba.cloud.stream.binder.rocketmq.integration; +import com.alibaba.cloud.stream.binder.rocketmq.consuming.RocketMQListenerBindingContainer; +import com.alibaba.cloud.stream.binder.rocketmq.metrics.Instrumentation; +import com.alibaba.cloud.stream.binder.rocketmq.metrics.InstrumentationManager; +import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQConsumerProperties; import org.apache.rocketmq.spring.core.RocketMQListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.cloud.stream.binder.ExtendedConsumerProperties; import org.springframework.integration.endpoint.MessageProducerSupport; import org.springframework.integration.support.MessageBuilder; @@ -31,11 +36,6 @@ import org.springframework.retry.RetryListener; import org.springframework.retry.support.RetryTemplate; import org.springframework.util.Assert; -import com.alibaba.cloud.stream.binder.rocketmq.consuming.RocketMQListenerBindingContainer; -import com.alibaba.cloud.stream.binder.rocketmq.metrics.Instrumentation; -import com.alibaba.cloud.stream.binder.rocketmq.metrics.InstrumentationManager; -import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQConsumerProperties; - /** * @author Jim */ @@ -170,6 +170,7 @@ public class RocketMQInboundChannelAdapter extends MessageProducerSupport { RetryCallback callback, Throwable throwable) { } + } } diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/RocketMQMessageHandler.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/RocketMQMessageHandler.java index 000754bfa..2bf3fa627 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/RocketMQMessageHandler.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/RocketMQMessageHandler.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,6 +20,11 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import com.alibaba.cloud.stream.binder.rocketmq.RocketMQBinderConstants; +import com.alibaba.cloud.stream.binder.rocketmq.metrics.Instrumentation; +import com.alibaba.cloud.stream.binder.rocketmq.metrics.InstrumentationManager; +import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQProducerProperties; +import com.alibaba.cloud.stream.binder.rocketmq.support.RocketMQHeaderMapper; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.client.producer.SendCallback; import org.apache.rocketmq.client.producer.SendResult; @@ -30,6 +35,7 @@ import org.apache.rocketmq.spring.core.RocketMQTemplate; import org.apache.rocketmq.spring.support.RocketMQHeaders; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.cloud.stream.binder.BinderHeaders; import org.springframework.cloud.stream.binder.ExtendedProducerProperties; import org.springframework.cloud.stream.binding.MessageConverterConfigurer; @@ -45,12 +51,6 @@ import org.springframework.messaging.support.ErrorMessage; import org.springframework.util.Assert; import org.springframework.util.StringUtils; -import com.alibaba.cloud.stream.binder.rocketmq.RocketMQBinderConstants; -import com.alibaba.cloud.stream.binder.rocketmq.metrics.Instrumentation; -import com.alibaba.cloud.stream.binder.rocketmq.metrics.InstrumentationManager; -import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQProducerProperties; -import com.alibaba.cloud.stream.binder.rocketmq.support.RocketMQHeaderMapper; - /** * @author Jim */ @@ -298,4 +298,5 @@ public class RocketMQMessageHandler extends AbstractMessageHandler implements Li public void setHeaderMapper(RocketMQHeaderMapper headerMapper) { this.headerMapper = headerMapper; } -} \ No newline at end of file + +} diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/RocketMQMessageSource.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/RocketMQMessageSource.java index 1d1ec5d68..7fe459a70 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/RocketMQMessageSource.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/RocketMQMessageSource.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,9 @@ package com.alibaba.cloud.stream.binder.rocketmq.integration; import java.util.List; import java.util.Set; +import com.alibaba.cloud.stream.binder.rocketmq.consuming.RocketMQMessageQueueChooser; +import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQBinderConfigurationProperties; +import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQConsumerProperties; import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer; import org.apache.rocketmq.client.consumer.MessageQueueListener; import org.apache.rocketmq.client.consumer.MessageSelector; @@ -31,6 +34,7 @@ import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; import org.apache.rocketmq.spring.support.RocketMQUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.DisposableBean; import org.springframework.cloud.stream.binder.ExtendedConsumerProperties; import org.springframework.context.Lifecycle; @@ -43,10 +47,6 @@ import org.springframework.messaging.Message; import org.springframework.util.Assert; import org.springframework.util.StringUtils; -import com.alibaba.cloud.stream.binder.rocketmq.consuming.RocketMQMessageQueueChooser; -import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQBinderConfigurationProperties; -import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQConsumerProperties; - /** * @author Jim */ @@ -324,6 +324,7 @@ public class RocketMQMessageSource extends AbstractMessageSource return "RocketMQAckCallback{" + "ackInfo=" + ackInfo + ", acknowledged=" + acknowledged + ", autoAckEnabled=" + autoAckEnabled + '}'; } + } public class RocketMQAckInfo { @@ -374,6 +375,7 @@ public class RocketMQMessageSource extends AbstractMessageSource + pullResult + ", consumer=" + consumer + ", oldOffset=" + oldOffset + '}'; } + } } diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/metrics/Instrumentation.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/metrics/Instrumentation.java index f62b018e4..080bebf90 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/metrics/Instrumentation.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/metrics/Instrumentation.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,8 +23,11 @@ import java.util.concurrent.atomic.AtomicBoolean; * @author Jim */ public class Instrumentation { + private final String name; + protected final AtomicBoolean started = new AtomicBoolean(false); + protected Exception startException = null; public Instrumentation(String name) { @@ -63,4 +66,5 @@ public class Instrumentation { public Exception getStartException() { return startException; } + } diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/metrics/InstrumentationManager.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/metrics/InstrumentationManager.java index 1152bf546..8b4939585 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/metrics/InstrumentationManager.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/metrics/InstrumentationManager.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQBinderConfigurationProperties.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQBinderConfigurationProperties.java index 4fda8c8fe..f903bcc08 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQBinderConfigurationProperties.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQBinderConfigurationProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,10 +16,10 @@ package com.alibaba.cloud.stream.binder.rocketmq.properties; +import com.alibaba.cloud.stream.binder.rocketmq.RocketMQBinderConstants; import org.apache.rocketmq.common.MixAll; -import org.springframework.boot.context.properties.ConfigurationProperties; -import com.alibaba.cloud.stream.binder.rocketmq.RocketMQBinderConstants; +import org.springframework.boot.context.properties.ConfigurationProperties; /** * @author Timur Valiev @@ -93,4 +93,5 @@ public class RocketMQBinderConfigurationProperties { public void setCustomizedTraceTopic(String customizedTraceTopic) { this.customizedTraceTopic = customizedTraceTopic; } + } diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQBindingProperties.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQBindingProperties.java index 0829325db..814ae1018 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQBindingProperties.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQBindingProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -45,4 +45,5 @@ public class RocketMQBindingProperties implements BinderSpecificPropertiesProvid public void setProducer(RocketMQProducerProperties producer) { this.producer = producer; } + } diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQConsumerProperties.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQConsumerProperties.java index 53489355e..9c059ec56 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQConsumerProperties.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQConsumerProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,6 +18,7 @@ package com.alibaba.cloud.stream.binder.rocketmq.properties; import java.util.Set; +import com.alibaba.cloud.stream.binder.rocketmq.support.JacksonRocketMQHeaderMapper; import org.apache.rocketmq.client.consumer.MQPushConsumer; import org.apache.rocketmq.client.consumer.MessageSelector; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; @@ -25,8 +26,6 @@ import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; import org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly; import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; -import com.alibaba.cloud.stream.binder.rocketmq.support.JacksonRocketMQHeaderMapper; - /** * @author Timur Valiev * @author Jim @@ -34,43 +33,43 @@ import com.alibaba.cloud.stream.binder.rocketmq.support.JacksonRocketMQHeaderMap public class RocketMQConsumerProperties { /** - * using '||' to split tag {@link MQPushConsumer#subscribe(String, String)} + * using '||' to split tag {@link MQPushConsumer#subscribe(String, String)}. */ private String tags; /** * {@link MQPushConsumer#subscribe(String, MessageSelector)} - * {@link MessageSelector#bySql(String)} + * {@link MessageSelector#bySql(String)}. */ private String sql; /** - * {@link MessageModel#BROADCASTING} + * {@link MessageModel#BROADCASTING}. */ private Boolean broadcasting = false; /** * if orderly is true, using {@link MessageListenerOrderly} else if orderly if false, - * using {@link MessageListenerConcurrently} + * using {@link MessageListenerConcurrently}. */ private Boolean orderly = false; /** * for concurrently listener. message consume retry strategy. see * {@link ConsumeConcurrentlyContext#delayLevelWhenNextConsume}. -1 means dlq(or - * discard, see {@link this#shouldRequeue}), others means requeue + * discard, see {@link this#shouldRequeue}), others means requeue. */ private int delayLevelWhenNextConsume = 0; /** - * for orderly listener. next retry delay time + * for orderly listener. next retry delay time. */ private long suspendCurrentQueueTimeMillis = 1000; private Boolean enabled = true; /** - * {@link JacksonRocketMQHeaderMapper#addTrustedPackages(String...)} + * {@link JacksonRocketMQHeaderMapper#addTrustedPackages(String...)}. */ private Set trustedPackages; @@ -165,4 +164,5 @@ public class RocketMQConsumerProperties { public void setTrustedPackages(Set trustedPackages) { this.trustedPackages = trustedPackages; } + } diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQExtendedBindingProperties.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQExtendedBindingProperties.java index 3583873dd..890d22500 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQExtendedBindingProperties.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQExtendedBindingProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -39,4 +39,5 @@ public class RocketMQExtendedBindingProperties extends public Class getExtendedPropertiesEntryClass() { return RocketMQBindingProperties.class; } + } diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQProducerProperties.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQProducerProperties.java index 2d4d197e3..ab2a92a3a 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQProducerProperties.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQProducerProperties.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -163,4 +163,4 @@ public class RocketMQProducerProperties { this.retryNextServer = retryNextServer; } -} \ No newline at end of file +} diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/provisioning/RocketMQTopicProvisioner.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/provisioning/RocketMQTopicProvisioner.java index 95f0b5fb1..2b8fd198f 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/provisioning/RocketMQTopicProvisioner.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/provisioning/RocketMQTopicProvisioner.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,8 +16,11 @@ package com.alibaba.cloud.stream.binder.rocketmq.provisioning; +import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQConsumerProperties; +import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQProducerProperties; import org.apache.rocketmq.client.Validators; import org.apache.rocketmq.client.exception.MQClientException; + import org.springframework.cloud.stream.binder.ExtendedConsumerProperties; import org.springframework.cloud.stream.binder.ExtendedProducerProperties; import org.springframework.cloud.stream.provisioning.ConsumerDestination; @@ -25,9 +28,6 @@ import org.springframework.cloud.stream.provisioning.ProducerDestination; import org.springframework.cloud.stream.provisioning.ProvisioningException; import org.springframework.cloud.stream.provisioning.ProvisioningProvider; -import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQConsumerProperties; -import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQProducerProperties; - /** * @author Timur Valiev * @author Jim diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/provisioning/selector/PartitionMessageQueueSelector.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/provisioning/selector/PartitionMessageQueueSelector.java index 38603346a..694dcdc96 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/provisioning/selector/PartitionMessageQueueSelector.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/provisioning/selector/PartitionMessageQueueSelector.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.alibaba.cloud.stream.binder.rocketmq.provisioning.selector; import java.util.List; @@ -7,11 +23,11 @@ import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.common.message.MessageQueue; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.cloud.stream.binder.BinderHeaders; /** * @author wangxing - * @create 2019/7/3 */ public class PartitionMessageQueueSelector implements MessageQueueSelector { @@ -36,4 +52,4 @@ public class PartitionMessageQueueSelector implements MessageQueueSelector { return mqs.get(partition); } -} \ No newline at end of file +} diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/support/AbstractRocketMQHeaderMapper.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/support/AbstractRocketMQHeaderMapper.java index bd9e997b6..71d12840d 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/support/AbstractRocketMQHeaderMapper.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/support/AbstractRocketMQHeaderMapper.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,6 +20,7 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import org.apache.rocketmq.common.message.MessageConst; + import org.springframework.messaging.MessageHeaders; import org.springframework.util.Assert; @@ -30,6 +31,7 @@ import org.springframework.util.Assert; * @since 2.1.1.RELEASE */ public abstract class AbstractRocketMQHeaderMapper implements RocketMQHeaderMapper { + private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8; private Charset charset; @@ -60,4 +62,5 @@ public abstract class AbstractRocketMQHeaderMapper implements RocketMQHeaderMapp Assert.notNull(charset, "'charset' cannot be null"); this.charset = charset; } + } diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/support/JacksonRocketMQHeaderMapper.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/support/JacksonRocketMQHeaderMapper.java index 2c582b97b..1310c8402 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/support/JacksonRocketMQHeaderMapper.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/support/JacksonRocketMQHeaderMapper.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,23 +20,23 @@ import java.io.IOException; import java.nio.charset.Charset; import java.util.Arrays; import java.util.Collection; +import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.lang.Nullable; import org.springframework.messaging.MessageHeaders; import org.springframework.util.ClassUtils; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.collect.Maps; - /** * jackson header mapper for RocketMQ. Header types are added to a special header * {@link #JSON_TYPES}. @@ -45,6 +45,7 @@ import com.google.common.collect.Maps; * @since 2.1.1.RELEASE */ public class JacksonRocketMQHeaderMapper extends AbstractRocketMQHeaderMapper { + private final static Logger log = LoggerFactory .getLogger(JacksonRocketMQHeaderMapper.class); @@ -57,6 +58,7 @@ public class JacksonRocketMQHeaderMapper extends AbstractRocketMQHeaderMapper { public static final String JSON_TYPES = "spring_json_header_types"; private final ObjectMapper objectMapper; + private final Set trustedPackages = new LinkedHashSet<>( DEFAULT_TRUSTED_PACKAGES); @@ -71,8 +73,8 @@ public class JacksonRocketMQHeaderMapper extends AbstractRocketMQHeaderMapper { @Override public Map fromHeaders(MessageHeaders headers) { - final Map target = Maps.newHashMap(); - final Map jsonHeaders = Maps.newHashMap(); + final Map target = new HashMap<>(); + final Map jsonHeaders = new HashMap<>(); headers.forEach((key, value) -> { if (matches(key)) { if (value instanceof String) { @@ -104,7 +106,7 @@ public class JacksonRocketMQHeaderMapper extends AbstractRocketMQHeaderMapper { @Override public MessageHeaders toHeaders(Map source) { - final Map target = Maps.newHashMap(); + final Map target = new HashMap<>(); final Map jsonTypes = decodeJsonTypes(source); source.forEach((key, value) -> { if (matches(key) && !(key.equals(JSON_TYPES))) { @@ -281,4 +283,5 @@ public class JacksonRocketMQHeaderMapper extends AbstractRocketMQHeaderMapper { } } + } diff --git a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/support/RocketMQHeaderMapper.java b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/support/RocketMQHeaderMapper.java index e291e8c7e..892df4e7a 100644 --- a/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/support/RocketMQHeaderMapper.java +++ b/spring-cloud-stream-binder-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/support/RocketMQHeaderMapper.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2019 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,12 +21,13 @@ import java.util.Map; import org.springframework.messaging.MessageHeaders; /** - * header value mapper for RocketMQ + * header value mapper for RocketMQ. * * @author caotc * @since 2.1.1.RELEASE */ public interface RocketMQHeaderMapper { + /** * Map from the given {@link MessageHeaders} to the specified target message. * @param headers the abstracted MessageHeaders. @@ -40,4 +41,5 @@ public interface RocketMQHeaderMapper { * @return the target headers. */ MessageHeaders toHeaders(Map source); + } diff --git a/spring-cloud-stream-binder-rocketmq/src/test/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQAutoConfigurationTests.java b/spring-cloud-stream-binder-rocketmq/src/test/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQAutoConfigurationTests.java index cdecbeabb..d4f7defa7 100644 --- a/spring-cloud-stream-binder-rocketmq/src/test/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQAutoConfigurationTests.java +++ b/spring-cloud-stream-binder-rocketmq/src/test/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQAutoConfigurationTests.java @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,15 +16,15 @@ package com.alibaba.cloud.stream.binder.rocketmq; -import static org.assertj.core.api.Assertions.assertThat; - +import com.alibaba.cloud.stream.binder.rocketmq.config.RocketMQBinderAutoConfiguration; +import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQBinderConfigurationProperties; +import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQExtendedBindingProperties; import org.junit.Test; + import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import com.alibaba.cloud.stream.binder.rocketmq.config.RocketMQBinderAutoConfiguration; -import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQBinderConfigurationProperties; -import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQExtendedBindingProperties; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Jim @@ -68,4 +68,4 @@ public class RocketMQAutoConfigurationTests { }); } -} \ No newline at end of file +}