format code with maven plugins

pull/922/head
fangjian0423 6 years ago
parent ed6942d9df
commit 2435167e1e

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@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();
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -38,4 +39,5 @@ public class DubboRestMetadataEndpoint {
public String get() {
return dubboMetadataService.getServiceRestMetadata();
}
}

@ -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 {};
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -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<String, Object> dubboTranslatedAttributes) {

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -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();
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@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

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -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 {
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @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<HeartbeatEvent>}
* @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<HeartbeatEvent> 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<InstanceRegisteredEvent> {
/**
* 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} :
* <p>
* <p>
* ${{@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<String> 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 <code>false</code> 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<TreeCacheListener> 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<String> 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 <code>false</code> forever
*/
@Bean
@ -547,5 +552,7 @@ public class DubboServiceDiscoveryAutoConfiguration {
}
}
}
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@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 {
}
}
}
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@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);
}
}
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @see SpringCloudRegistry
@ -76,4 +77,5 @@ public class MissingSpringCloudRegistryConfigPropertyCondition
"'spring-cloud' protocol was found in 'dubbo.registries.*'")
: ConditionOutcome.match();
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @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;
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -37,7 +38,7 @@ class DubboClientHttpResponseFactory {
private final HttpMessageConverterResolver httpMessageConverterResolver;
public DubboClientHttpResponseFactory(List<HttpMessageConverter<?>> messageConverters,
DubboClientHttpResponseFactory(List<HttpMessageConverter<?>> messageConverters,
ClassLoader classLoader) {
this.httpMessageConverterResolver = new HttpMessageConverterResolver(
messageConverters, classLoader);
@ -64,4 +65,5 @@ class DubboClientHttpResponseFactory {
return new DubboClientHttpResponse(httpOutputMessage, exception);
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -41,4 +42,5 @@ class DubboHttpOutputMessage implements HttpOutputMessage {
public HttpHeaders getHeaders() {
return httpHeaders;
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -53,4 +54,5 @@ public class DubboMetadataInitializerInterceptor implements ClientHttpRequestInt
// Execute next
return execution.execute(request, body);
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @see LoadBalancerInterceptor
@ -148,4 +149,5 @@ public class DubboTransporterInterceptor implements ClientHttpRequestInterceptor
requestMetadata.setHeaders(request.getHeaders());
return requestMetadata;
}
}

@ -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);
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -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<String> subscribedServices() {
@ -78,4 +78,5 @@ public class DubboCloudProperties {
return Collections.unmodifiableSet(subscribedServices);
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -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<String, Object> 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;
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -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;
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -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);
}
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
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<String, String> getQueryParams();

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -96,4 +97,5 @@ public class MutableHttpServerRequest implements HttpServerRequest {
public MultiValueMap<String, String> getQueryParams() {
return queryParams;
}
}

@ -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;
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
@ -30,7 +31,6 @@ public abstract class AbstractHttpRequestMatcher implements HttpRequestMatcher {
* Return the discrete items a request condition is composed of.
* <p>
* 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();
}
}

@ -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();
}
}

@ -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<T> implements NameValueExpression<T>
/**
* 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("{")

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -69,4 +70,5 @@ public abstract class CompositeHttpRequestMatcher extends AbstractHttpRequestMat
protected String getToStringInfix() {
return " && ";
}
}

@ -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.
* <p>
* 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);
}
}

@ -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.
* <p>
* 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> {
String headerValue = httpHeaders.getFirst(this.name);
return ObjectUtils.nullSafeEquals(this.value, headerValue);
}
}

@ -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 " || ";
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -67,4 +68,5 @@ public class HttpRequestHeadersMatcher extends AbstractHttpRequestMatcher {
protected String getToStringInfix() {
return " && ";
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
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 <code>true</code>, or <code>false</code>.
*/
boolean match(HttpRequest request);
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -78,4 +79,5 @@ public class HttpRequestMethodsMatcher extends AbstractHttpRequestMatcher {
protected String getToStringInfix() {
return " || ";
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -72,4 +73,5 @@ public class HttpRequestParamsMatcher extends AbstractHttpRequestMatcher {
protected String getToStringInfix() {
return " && ";
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -113,4 +114,5 @@ public class HttpRequestPathMatcher extends AbstractHttpRequestMatcher {
protected String getToStringInfix() {
return " || ";
}
}

@ -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 " || ";
}
}

@ -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;

@ -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
* <p>
* The some source code is scratched from
* org.springframework.web.servlet.mvc.condition.NameValueExpression
* org.springframework.web.servlet.mvc.condition.NameValueExpression.
*
* @param <T> the value type
* @author Rossen Stoyanchev

@ -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.
* <p>
* 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> {
String parameterValue = parametersMap.getFirst(this.name);
return ObjectUtils.nullSafeEquals(this.value, parameterValue);
}
}

@ -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.
* <p>
* 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;
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -43,4 +44,5 @@ public class RequestMetadataMatcher extends CompositeHttpRequestMatcher {
new HttpRequestProducesMatcher(
metadata.getProduces().toArray(new String[0])));
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -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<MediaType> 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 {
* <li>The producible media types specified in the request mappings, or
* <li>Media types of configured converters that can write the specific return value,
* or
* <li>{@link MediaType#ALL}
* <li>{@link MediaType#ALL}.
* </ul>
*
* @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<MediaType> getAllSupportedMediaTypes(
List<HttpMessageConverter<?>> messageConverters) {
@ -243,4 +237,5 @@ public class HttpMessageConverterResolver {
return (MediaType.SPECIFICITY_COMPARATOR.compare(acceptType,
produceTypeToUse) <= 0 ? acceptType : produceTypeToUse);
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
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:
* <ol>
* <li>To remove query string if presents</li>
* <li>To remove duplicated slash("/") if exists</li>
* <li>To remove duplicated slash("/") if exists.</li>
* </ol>
*
* @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<String, String> getParameters(HttpRequest request) {
URI uri = request.getURI();
@ -92,7 +106,6 @@ public abstract class HttpUtils {
/**
* Get Parameters from the specified query string.
* <p>
*
* @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.
* <p>
*
* @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.
* <p>
*
* @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);
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -68,4 +70,5 @@ public class DubboProtocolConfigSupplier implements Supplier<ProtocolConfig> {
return protocolConfig;
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -59,4 +60,5 @@ public class DubboRestServiceMetadata {
public int hashCode() {
return Objects.hash(serviceRestMetadata, restMethodMetadata);
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -91,4 +92,5 @@ public class DubboTransportedMethodMetadata {
public int hashCode() {
return Objects.hash(methodMetadata, attributes);
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -132,4 +133,5 @@ public class MethodMetadata {
return "MethodMetadata{" + "name='" + name + '\'' + ", returnType='" + returnType
+ '\'' + ", params=" + params + ", method=" + method + '}';
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -81,4 +82,5 @@ public class MethodParameterMetadata {
return "MethodParameterMetadata{" + "index=" + index + ", name='" + name + '\''
+ ", type='" + type + '\'' + '}';
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -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 <code>null</code>
@ -270,4 +269,5 @@ public class RequestMetadata {
+ ", params=" + params + ", headers=" + headers + ", consumes=" + consumes
+ ", produces=" + produces + '}';
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -229,4 +230,5 @@ public class RestMethodMetadata {
+ ", indexToName=" + indexToName + ", formParams=" + formParams
+ ", indexToEncoded=" + indexToEncoded + '}';
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @see RestMethodMetadata
@ -65,4 +66,5 @@ public class ServiceRestMetadata {
public int hashCode() {
return Objects.hash(url, meta);
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -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<String> 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<String, URL> 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<String, URL> subscribedDubboMetadataServiceURLs = new LinkedMultiValueMap<>();
@ -137,6 +139,7 @@ public class DubboServiceMetadataRepository
* from the annotated methods.
*/
private final Set<ServiceRestMetadata> serviceRestMetadata = new LinkedHashSet<>();
private ApplicationEventPublisher applicationEventPublisher;
// ====================================================================================
@ -145,8 +148,10 @@ public class DubboServiceMetadataRepository
// =================================== REST Metadata
// ================================== //
private volatile Set<String> subscribedServices = emptySet();
/**
* Key is application name Value is Map<RequestMetadata, DubboRestServiceMetadata>
* Key is application name Value is Map&lt;RequestMetadata,
* DubboRestServiceMetadata&gt;.
*/
private Map<String, Map<RequestMetadataMatcher, DubboRestServiceMetadata>> 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<String> 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<String, String> 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<ServiceRestMetadata> 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<String, List<URL>> 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<String> 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 <code>null</code>
@ -661,4 +654,5 @@ public class DubboServiceMetadataRepository
ApplicationEventPublisher applicationEventPublisher) {
this.applicationEventPublisher = applicationEventPublisher;
}
}

@ -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 <a href="mailto:liuxx-u@outlook.com">liuxx</a>
*/
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<ServiceInstance> choose(List<ServiceInstance> serviceInstances);
}

@ -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<Contract> contracts;
@ -153,9 +153,8 @@ public class DubboServiceBeanMetadataResolver
* Select feign contract methods
* <p>
* 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<Method> selectFeignContractMethods(Class<?> targetType) {

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -53,4 +54,5 @@ public class DubboTransportedAttributesResolver {
}
return resolvedAttributes;
}
}

@ -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;
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
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<ServiceRestMetadata> 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<RestMethodMetadata> resolveMethodRestMetadata(Class<?> targetType);
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -87,4 +88,5 @@ public class DubboInvocationHandler implements InvocationHandler {
String returnType = dubboRestMethodMetadata.getReturnType();
return ClassUtils.resolveClassName(returnType, classLoader);
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -53,4 +53,5 @@ class FeignMethodMetadata {
RestMethodMetadata getFeignMethodMetadata() {
return feignMethodMetadata;
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -84,4 +85,5 @@ public class TargeterBeanPostProcessor
public void setBeanClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -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<T> target
* FeignContext context args[3]: Target.HardCodedTarget&lt;T&gt; target
*/
FeignContext feignContext = cast(args[2]);
Target.HardCodedTarget<?> target = cast(args[3]);
@ -183,4 +183,5 @@ class TargeterInvocationHandler implements InvocationHandler {
return feignMethodMetadataMap;
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
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<String> 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());
}
}

@ -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();
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @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;
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -52,4 +53,5 @@ public class SpringCloudRegistry extends AbstractSpringCloudRegistry {
protected void doUnregister0(URL url) {
dubboServiceMetadataRepository.unexportURL(url);
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @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);
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -36,4 +37,5 @@ public class ServiceInstancePreRegisteredEvent extends ApplicationEvent {
public Registration getSource() {
return (Registration) super.getSource();
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -35,4 +36,5 @@ public class ServiceInstanceRegisteredEvent extends ApplicationEvent {
public Registration getSource() {
return (Registration) super.getSource();
}
}

@ -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<ServiceInstance> 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 <code>true</code>, or <code>false</code>
*/
public boolean isProcessed() {
return processed;
}
}

@ -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.
* <p>
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
@ -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;
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -48,4 +49,5 @@ public class DubboGenericServiceExecutionContext {
public Object[] getParameters() {
return parameters;
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @see DubboGenericServiceParameterResolver
@ -154,4 +155,5 @@ public class DubboGenericServiceExecutionContextFactory {
return parameters;
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/

@ -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.
* <p>
* The interface contract's version must be {@link #VERSION} constant and group must be
* current Dubbo application name
* current Dubbo application name.
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
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 <code>null</code> 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<String> 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<URL> of
* {@link URL URLs}
*
* of {@link URL#getServiceKey()} method and value is the json content of
* List&lt;URL&gt; of {@link URL URLs}.
* @return non-null read-only {@link Map}
*/
Map<String, String> getAllExportedURLs();
/**
* Get the json content of an exported List<URL> 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);
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -59,8 +61,7 @@ public class DubboMetadataServiceExporter {
private ServiceConfig<DubboMetadataService> serviceConfig;
/**
* export {@link DubboMetadataService} as Dubbo service
*
* export {@link DubboMetadataService} as Dubbo service.
* @return the exported {@link URL URLs}
*/
public List<URL> 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());
}
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -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]);
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
public class DubboMetadataServiceProxy implements BeanClassLoaderAware, DisposableBean {
private final DubboGenericServiceFactory dubboGenericServiceFactory;
private final Map<String, DubboMetadataService> 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));
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -94,4 +95,5 @@ public class IntrospectiveDubboMetadataService implements DubboMetadataService {
private DubboServiceMetadataRepository getRepository() {
return dubboServiceMetadataRepository.getIfAvailable();
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -78,4 +79,5 @@ public abstract class AbstractDubboGenericServiceParameterResolver
protected Object resolveValue(Object parameterValue, Class<?> parameterType) {
return conversionService.convert(parameterValue, parameterType);
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -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<String, String> getNameAndValuesMap(
HttpServerRequest request);

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -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);
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
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();
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
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];
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
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();
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
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();
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -84,4 +85,5 @@ public class JSONUtils {
}
return list;
}
}

@ -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 {
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/

@ -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 AbstractMediaTypeExpressionTest<T extends AbstractMediaTyp
Assert.assertEquals(0, createExpression(MediaType.APPLICATION_JSON_VALUE)
.compareTo(createExpression(MediaType.APPLICATION_JSON_VALUE)));
}
}

@ -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.matcher;
import java.lang.reflect.Constructor;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.BeanUtils;
import org.springframework.core.ResolvableType;
/**
* {@link AbstractNameValueExpression} Test
* {@link AbstractNameValueExpression} Test.
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -78,4 +80,5 @@ public abstract class AbstractNameValueExpressionTest<T extends AbstractNameValu
Assert.assertNotEquals(createExpression("a").hashCode(),
createExpression("b").hashCode());
}
}

@ -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,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.dubbo.http.matcher;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.http.MediaType;
/**
* {@link ConsumeMediaTypeExpression} Test
* {@link ConsumeMediaTypeExpression} Test.
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -42,4 +44,5 @@ public class ConsumeMediaTypeExpressionTest
expression = createExpression(MediaType.TEXT_HTML_VALUE);
Assert.assertFalse(expression.match(MediaType.APPLICATION_JSON_UTF8));
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -92,4 +94,5 @@ public class HttpRequestParamsMatcherTest {
request.setURI(URI.create("http://dummy/?d=1"));
Assert.assertFalse(matcher.match(request));
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -39,4 +41,5 @@ public class ProduceMediaTypeExpressionTest
expression = createExpression(MediaType.APPLICATION_JSON_VALUE);
Assert.assertFalse(expression.match(Arrays.asList(MediaType.APPLICATION_XML)));
}
}

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/

@ -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 <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
@ -57,4 +58,5 @@ public class DubboTransportedMethodMetadataResolverTest {
String test(String message);
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save