1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

Format Code

This commit is contained in:
mercyblitz 2019-08-01 13:55:55 +08:00
parent 532c1dd0f2
commit 12efadd61f
37 changed files with 317 additions and 316 deletions

View File

@ -16,17 +16,19 @@
*/ */
package com.alibaba.cloud.dubbo.actuate; 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.endpoint.condition.ConditionalOnEnabledEndpoint;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration; import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import com.alibaba.cloud.dubbo.actuate.endpoint.DubboRestMetadataEndpoint;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource; import org.springframework.context.annotation.PropertySource;
/** /**
* 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") @ConditionalOnClass(name = "org.springframework.boot.actuate.endpoint.annotation.Endpoint")
@PropertySource(value = "classpath:/META-INF/dubbo/default/actuator-endpoints.properties") @PropertySource(value = "classpath:/META-INF/dubbo/default/actuator-endpoints.properties")

View File

@ -16,15 +16,17 @@
*/ */
package com.alibaba.cloud.dubbo.actuate.endpoint; package com.alibaba.cloud.dubbo.actuate.endpoint;
import com.alibaba.cloud.dubbo.service.DubboMetadataService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; 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; 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>
*/ */
@Endpoint(id = "dubborestmetadata") @Endpoint(id = "dubborestmetadata")
public class DubboRestMetadataEndpoint { public class DubboRestMetadataEndpoint {

View File

@ -49,6 +49,7 @@ import static org.apache.dubbo.rpc.cluster.Constants.DEFAULT_RETRIES;
* </ol> * </ol>
* <p> * <p>
* *
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @see FeignClient * @see FeignClient
* @see LoadBalanced * @see LoadBalanced
*/ */

View File

@ -16,6 +16,13 @@
*/ */
package com.alibaba.cloud.dubbo.autoconfigure; package com.alibaba.cloud.dubbo.autoconfigure;
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.BeanClassLoaderAware;
import org.springframework.beans.factory.SmartInitializingSingleton; import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
@ -25,13 +32,6 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.boot.context.event.ApplicationStartedEvent;
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.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor; import org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor;
import org.springframework.cloud.client.loadbalancer.RestTemplateCustomizer; import org.springframework.cloud.client.loadbalancer.RestTemplateCustomizer;

View File

@ -20,11 +20,6 @@ import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.spring.ServiceBean; import org.apache.dubbo.config.spring.ServiceBean;
import org.apache.dubbo.config.spring.context.event.ServiceBeanExportedEvent; import org.apache.dubbo.config.spring.context.event.ServiceBeanExportedEvent;
import feign.Contract;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.event.ApplicationFailedEvent;
import com.alibaba.cloud.dubbo.metadata.DubboProtocolConfigSupplier; import com.alibaba.cloud.dubbo.metadata.DubboProtocolConfigSupplier;
import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository; import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository;
import com.alibaba.cloud.dubbo.metadata.resolver.DubboServiceBeanMetadataResolver; import com.alibaba.cloud.dubbo.metadata.resolver.DubboServiceBeanMetadataResolver;
@ -34,6 +29,11 @@ import com.alibaba.cloud.dubbo.service.DubboMetadataServiceExporter;
import com.alibaba.cloud.dubbo.service.DubboMetadataServiceProxy; import com.alibaba.cloud.dubbo.service.DubboMetadataServiceProxy;
import com.alibaba.cloud.dubbo.service.IntrospectiveDubboMetadataService; import com.alibaba.cloud.dubbo.service.IntrospectiveDubboMetadataService;
import com.alibaba.cloud.dubbo.util.JSONUtils; import com.alibaba.cloud.dubbo.util.JSONUtils;
import feign.Contract;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;

View File

@ -16,14 +16,12 @@
*/ */
package com.alibaba.cloud.dubbo.autoconfigure; package com.alibaba.cloud.dubbo.autoconfigure;
import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository;
import com.alibaba.cloud.dubbo.openfeign.TargeterBeanPostProcessor; import com.alibaba.cloud.dubbo.openfeign.TargeterBeanPostProcessor;
import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContextFactory; import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContextFactory;
import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory; import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;

View File

@ -16,18 +16,16 @@
*/ */
package com.alibaba.cloud.dubbo.autoconfigure; 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.DubboGenericServiceExecutionContextFactory;
import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory; import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory;
import com.alibaba.cloud.dubbo.service.parameter.PathVariableServiceParameterResolver; import com.alibaba.cloud.dubbo.service.parameter.PathVariableServiceParameterResolver;
import com.alibaba.cloud.dubbo.service.parameter.RequestBodyServiceParameterResolver; import com.alibaba.cloud.dubbo.service.parameter.RequestBodyServiceParameterResolver;
import com.alibaba.cloud.dubbo.service.parameter.RequestHeaderServiceParameterResolver; import com.alibaba.cloud.dubbo.service.parameter.RequestHeaderServiceParameterResolver;
import com.alibaba.cloud.dubbo.service.parameter.RequestParamServiceParameterResolver; import com.alibaba.cloud.dubbo.service.parameter.RequestParamServiceParameterResolver;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import com.alibaba.cloud.dubbo.env.DubboCloudProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
@ -50,17 +48,6 @@ public class DubboServiceAutoConfiguration {
return new DubboGenericServiceFactory(); return new DubboGenericServiceFactory();
} }
@Configuration
@Import(value = {
DubboGenericServiceExecutionContextFactory.class,
RequestParamServiceParameterResolver.class,
RequestBodyServiceParameterResolver.class,
RequestHeaderServiceParameterResolver.class,
PathVariableServiceParameterResolver.class
})
static class ParameterResolversConfiguration {
}
/** /**
* Build a primary {@link PropertyResolver} bean to {@link Autowired @Autowired} * Build a primary {@link PropertyResolver} bean to {@link Autowired @Autowired}
* *
@ -72,4 +59,15 @@ public class DubboServiceAutoConfiguration {
public PropertyResolver primaryPropertyResolver(Environment environment) { public PropertyResolver primaryPropertyResolver(Environment environment) {
return environment; return environment;
} }
@Configuration
@Import(value = {
DubboGenericServiceExecutionContextFactory.class,
RequestParamServiceParameterResolver.class,
RequestBodyServiceParameterResolver.class,
RequestHeaderServiceParameterResolver.class,
PathVariableServiceParameterResolver.class
})
static class ParameterResolversConfiguration {
}
} }

View File

@ -107,6 +107,23 @@ public class DubboServiceRegistrationAutoConfiguration {
attachDubboMetadataServiceMetadata(registration); attachDubboMetadataServiceMetadata(registration);
} }
private void attachDubboMetadataServiceMetadata(Registration registration) {
if (registration == null) {
return;
}
synchronized (registration) {
Map<String, String> metadata = registration.getMetadata();
attachDubboMetadataServiceMetadata(metadata);
}
}
private void attachDubboMetadataServiceMetadata(Map<String, String> metadata) {
Map<String, String> serviceMetadata = dubboServiceMetadataRepository.getDubboMetadataServiceMetadata();
if (!isEmpty(serviceMetadata)) {
metadata.putAll(serviceMetadata);
}
}
@Configuration @Configuration
@ConditionalOnBean(name = EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME) @ConditionalOnBean(name = EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME)
@Aspect @Aspect
@ -169,21 +186,4 @@ public class DubboServiceRegistrationAutoConfiguration {
} }
} }
} }
private void attachDubboMetadataServiceMetadata(Registration registration) {
if (registration == null) {
return;
}
synchronized (registration) {
Map<String, String> metadata = registration.getMetadata();
attachDubboMetadataServiceMetadata(metadata);
}
}
private void attachDubboMetadataServiceMetadata(Map<String, String> metadata) {
Map<String, String> serviceMetadata = dubboServiceMetadataRepository.getDubboMetadataServiceMetadata();
if (!isEmpty(serviceMetadata)) {
metadata.putAll(serviceMetadata);
}
}
} }

View File

@ -16,9 +16,9 @@
*/ */
package com.alibaba.cloud.dubbo.autoconfigure.condition; package com.alibaba.cloud.dubbo.autoconfigure.condition;
import com.alibaba.cloud.dubbo.registry.SpringCloudRegistry;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome; import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition; import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import com.alibaba.cloud.dubbo.registry.SpringCloudRegistry;
import org.springframework.context.annotation.Condition; import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
@ -27,12 +27,13 @@ import org.springframework.util.StringUtils;
import java.util.Map; import java.util.Map;
import static org.apache.dubbo.config.spring.util.PropertySourcesUtils.getSubProperties;
import static com.alibaba.cloud.dubbo.registry.SpringCloudRegistryFactory.PROTOCOL; 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 * @see SpringCloudRegistry
* @see Condition * @see Condition
*/ */

View File

@ -17,6 +17,7 @@
package com.alibaba.cloud.dubbo.client.loadbalancer; package com.alibaba.cloud.dubbo.client.loadbalancer;
import org.apache.dubbo.rpc.service.GenericException; import org.apache.dubbo.rpc.service.GenericException;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.ClientHttpResponse;

View File

@ -17,6 +17,7 @@
package com.alibaba.cloud.dubbo.client.loadbalancer; package com.alibaba.cloud.dubbo.client.loadbalancer;
import org.apache.dubbo.rpc.service.GenericException; import org.apache.dubbo.rpc.service.GenericException;
import com.alibaba.cloud.dubbo.http.converter.HttpMessageConverterHolder; import com.alibaba.cloud.dubbo.http.converter.HttpMessageConverterHolder;
import com.alibaba.cloud.dubbo.http.util.HttpMessageConverterResolver; import com.alibaba.cloud.dubbo.http.util.HttpMessageConverterResolver;
import com.alibaba.cloud.dubbo.metadata.RequestMetadata; import com.alibaba.cloud.dubbo.metadata.RequestMetadata;

View File

@ -70,6 +70,10 @@ public class DubboNonWebApplicationEnvironmentPostProcessor implements Environme
private final Logger logger = LoggerFactory.getLogger(DubboNonWebApplicationEnvironmentPostProcessor.class); private final Logger logger = LoggerFactory.getLogger(DubboNonWebApplicationEnvironmentPostProcessor.class);
private static boolean isRestProtocol(String protocol) {
return REST_PROTOCOL.equalsIgnoreCase(protocol);
}
@Override @Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
WebApplicationType webApplicationType = application.getWebApplicationType(); WebApplicationType webApplicationType = application.getWebApplicationType();
@ -200,8 +204,4 @@ public class DubboNonWebApplicationEnvironmentPostProcessor implements Environme
public int getOrder() { // Keep LOWEST_PRECEDENCE public int getOrder() { // Keep LOWEST_PRECEDENCE
return LOWEST_PRECEDENCE; return LOWEST_PRECEDENCE;
} }
private static boolean isRestProtocol(String protocol) {
return REST_PROTOCOL.equalsIgnoreCase(protocol);
}
} }

View File

@ -17,6 +17,7 @@
package com.alibaba.cloud.dubbo.http; package com.alibaba.cloud.dubbo.http;
import org.apache.dubbo.common.io.UnsafeByteArrayInputStream; import org.apache.dubbo.common.io.UnsafeByteArrayInputStream;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpInputMessage; import org.springframework.http.HttpInputMessage;

View File

@ -49,6 +49,10 @@ public class DefaultHttpRequest implements HttpRequest {
this.headers.putAll(headers); this.headers.putAll(headers);
} }
public static Builder builder() {
return new Builder();
}
private URI buildURI(String path, Map<String, List<String>> params) { private URI buildURI(String path, Map<String, List<String>> params) {
UriComponentsBuilder builder = fromPath(path) UriComponentsBuilder builder = fromPath(path)
.queryParams(new LinkedMultiValueMap<>(params)); .queryParams(new LinkedMultiValueMap<>(params));
@ -75,10 +79,6 @@ public class DefaultHttpRequest implements HttpRequest {
return headers; return headers;
} }
public static Builder builder() {
return new Builder();
}
/** /**
* {@link HttpRequest} Builder * {@link HttpRequest} Builder
*/ */

View File

@ -27,50 +27,50 @@ import java.util.Iterator;
*/ */
public abstract class AbstractHttpRequestMatcher implements HttpRequestMatcher { public abstract class AbstractHttpRequestMatcher implements HttpRequestMatcher {
/** /**
* Return the discrete items a request condition is composed of. * Return the discrete items a request condition is composed of.
* <p> * <p>
* For example URL patterns, HTTP request methods, param expressions, etc. * For example URL patterns, HTTP request methods, param expressions, etc.
* *
* @return a collection of objects, never {@code null} * @return a collection of objects, never {@code null}
*/ */
protected abstract Collection<?> getContent(); protected abstract Collection<?> getContent();
/** /**
* The notation to use when printing discrete items of content. * The notation to use when printing discrete items of content.
* <p> * <p>
* For example {@code " || "} for URL patterns or {@code " && "} for param * For example {@code " || "} for URL patterns or {@code " && "} for param
* expressions. * expressions.
*/ */
protected abstract String getToStringInfix(); protected abstract String getToStringInfix();
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
if (this == other) { if (this == other) {
return true; return true;
} }
if (other == null || getClass() != other.getClass()) { if (other == null || getClass() != other.getClass()) {
return false; return false;
} }
return getContent().equals(((AbstractHttpRequestMatcher) other).getContent()); return getContent().equals(((AbstractHttpRequestMatcher) other).getContent());
} }
@Override @Override
public int hashCode() { public int hashCode() {
return getContent().hashCode(); return getContent().hashCode();
} }
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder("["); StringBuilder builder = new StringBuilder("[");
for (Iterator<?> iterator = getContent().iterator(); iterator.hasNext();) { for (Iterator<?> iterator = getContent().iterator(); iterator.hasNext(); ) {
Object expression = iterator.next(); Object expression = iterator.next();
builder.append(expression.toString()); builder.append(expression.toString());
if (iterator.hasNext()) { if (iterator.hasNext()) {
builder.append(getToStringInfix()); builder.append(getToStringInfix());
} }
} }
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }
} }

View File

@ -69,6 +69,24 @@ public class HttpRequestConsumersMatcher extends AbstractHttpRequestMatcher {
Collections.sort(this.expressions); Collections.sort(this.expressions);
} }
private static Set<ConsumeMediaTypeExpression> parseExpressions(String[] consumes, String[] headers) {
Set<ConsumeMediaTypeExpression> result = new LinkedHashSet<>();
if (headers != null) {
for (String header : headers) {
HeaderExpression expr = new HeaderExpression(header);
if ("Content-Type".equalsIgnoreCase(expr.name) && expr.value != null) {
for (MediaType mediaType : MediaType.parseMediaTypes(expr.value)) {
result.add(new ConsumeMediaTypeExpression(mediaType, expr.negated));
}
}
}
}
for (String consume : consumes) {
result.add(new ConsumeMediaTypeExpression(consume));
}
return result;
}
@Override @Override
public boolean match(HttpRequest request) { public boolean match(HttpRequest request) {
@ -93,24 +111,6 @@ public class HttpRequestConsumersMatcher extends AbstractHttpRequestMatcher {
return true; return true;
} }
private static Set<ConsumeMediaTypeExpression> parseExpressions(String[] consumes, String[] headers) {
Set<ConsumeMediaTypeExpression> result = new LinkedHashSet<>();
if (headers != null) {
for (String header : headers) {
HeaderExpression expr = new HeaderExpression(header);
if ("Content-Type".equalsIgnoreCase(expr.name) && expr.value != null) {
for (MediaType mediaType : MediaType.parseMediaTypes(expr.value)) {
result.add(new ConsumeMediaTypeExpression(mediaType, expr.negated));
}
}
}
}
for (String consume : consumes) {
result.add(new ConsumeMediaTypeExpression(consume));
}
return result;
}
@Override @Override
protected Collection<ConsumeMediaTypeExpression> getContent() { protected Collection<ConsumeMediaTypeExpression> getContent() {
return this.expressions; return this.expressions;

View File

@ -43,6 +43,14 @@ public class HttpRequestParamsMatcher extends AbstractHttpRequestMatcher {
this.expressions = parseExpressions(params); this.expressions = parseExpressions(params);
} }
private static Set<ParamExpression> parseExpressions(String... params) {
Set<ParamExpression> expressions = new LinkedHashSet<>();
for (String param : params) {
expressions.add(new ParamExpression(param));
}
return expressions;
}
@Override @Override
public boolean match(HttpRequest request) { public boolean match(HttpRequest request) {
if (CollectionUtils.isEmpty(expressions)) { if (CollectionUtils.isEmpty(expressions)) {
@ -56,14 +64,6 @@ public class HttpRequestParamsMatcher extends AbstractHttpRequestMatcher {
return false; return false;
} }
private static Set<ParamExpression> parseExpressions(String... params) {
Set<ParamExpression> expressions = new LinkedHashSet<>();
for (String param : params) {
expressions.add(new ParamExpression(param));
}
return expressions;
}
@Override @Override
protected Collection<ParamExpression> getContent() { protected Collection<ParamExpression> getContent() {
return this.expressions; return this.expressions;

View File

@ -45,6 +45,17 @@ public class HttpRequestPathMatcher extends AbstractHttpRequestMatcher {
this.pathMatcher = new AntPathMatcher(); this.pathMatcher = new AntPathMatcher();
} }
private static Set<String> prependLeadingSlash(String[] patterns) {
Set<String> result = new LinkedHashSet<>(patterns.length);
for (String pattern : patterns) {
if (StringUtils.hasLength(pattern) && !pattern.startsWith("/")) {
pattern = "/" + pattern;
}
result.add(pattern);
}
return result;
}
@Override @Override
public boolean match(HttpRequest request) { public boolean match(HttpRequest request) {
List<String> matches = getMatchingPatterns(request); List<String> matches = getMatchingPatterns(request);
@ -94,17 +105,6 @@ public class HttpRequestPathMatcher extends AbstractHttpRequestMatcher {
return uri.getPath(); return uri.getPath();
} }
private static Set<String> prependLeadingSlash(String[] patterns) {
Set<String> result = new LinkedHashSet<>(patterns.length);
for (String pattern : patterns) {
if (StringUtils.hasLength(pattern) && !pattern.startsWith("/")) {
pattern = "/" + pattern;
}
result.add(pattern);
}
return result;
}
@Override @Override
protected Collection<String> getContent() { protected Collection<String> getContent() {
return this.patterns; return this.patterns;

View File

@ -69,6 +69,24 @@ public class HttpRequestProducesMatcher extends AbstractHttpRequestMatcher {
Collections.sort(this.expressions); Collections.sort(this.expressions);
} }
private static Set<ProduceMediaTypeExpression> parseExpressions(String[] produces, String[] headers) {
Set<ProduceMediaTypeExpression> result = new LinkedHashSet<>();
if (headers != null) {
for (String header : headers) {
HeaderExpression expr = new HeaderExpression(header);
if (HttpHeaders.ACCEPT.equalsIgnoreCase(expr.name) && expr.value != null) {
for (MediaType mediaType : MediaType.parseMediaTypes(expr.value)) {
result.add(new ProduceMediaTypeExpression(mediaType, expr.negated));
}
}
}
}
for (String produce : produces) {
result.add(new ProduceMediaTypeExpression(produce));
}
return result;
}
@Override @Override
public boolean match(HttpRequest request) { public boolean match(HttpRequest request) {
@ -89,24 +107,6 @@ public class HttpRequestProducesMatcher extends AbstractHttpRequestMatcher {
return true; return true;
} }
private static Set<ProduceMediaTypeExpression> parseExpressions(String[] produces, String[] headers) {
Set<ProduceMediaTypeExpression> result = new LinkedHashSet<>();
if (headers != null) {
for (String header : headers) {
HeaderExpression expr = new HeaderExpression(header);
if (HttpHeaders.ACCEPT.equalsIgnoreCase(expr.name) && expr.value != null) {
for (MediaType mediaType : MediaType.parseMediaTypes(expr.value)) {
result.add(new ProduceMediaTypeExpression(mediaType, expr.negated));
}
}
}
}
for (String produce : produces) {
result.add(new ProduceMediaTypeExpression(produce));
}
return result;
}
@Override @Override
protected Collection<ProduceMediaTypeExpression> getContent() { protected Collection<ProduceMediaTypeExpression> getContent() {
return expressions; return expressions;

View File

@ -71,6 +71,63 @@ public class RequestMetadata {
headers(requestTemplate.headers()); headers(requestTemplate.headers());
} }
/**
* 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>
*/
public static RequestMetadata getBestMatch(NavigableMap<RequestMetadata, RequestMetadata> requestMetadataMap,
RequestMetadata requestMetadata) {
RequestMetadata key = requestMetadata;
RequestMetadata result = requestMetadataMap.get(key);
if (result == null) {
SortedMap<RequestMetadata, RequestMetadata> headMap = requestMetadataMap.headMap(key, true);
result = headMap.isEmpty() ? null : requestMetadataMap.get(headMap.lastKey());
}
return result;
}
private static void add(String key, String value, MultiValueMap<String, String> destination) {
destination.add(key, value);
}
private static <T extends Collection<String>> void addAll(Map<String, T> source,
MultiValueMap<String, String> destination) {
for (Map.Entry<String, T> entry : source.entrySet()) {
String key = entry.getKey();
for (String value : entry.getValue()) {
add(key, value, destination);
}
}
}
private static void mediaTypes(HttpHeaders httpHeaders, String headerName, Collection<String> destination) {
List<String> value = httpHeaders.get(headerName);
List<MediaType> mediaTypes = parseMediaTypes(value);
destination.addAll(toMediaTypeValues(mediaTypes));
}
private static List<String> toMediaTypeValues(List<MediaType> mediaTypes) {
List<String> list = new ArrayList<>(mediaTypes.size());
for (MediaType mediaType : mediaTypes) {
list.add(mediaType.toString());
}
return list;
}
private static List<MediaType> toMediaTypes(Collection<String> mediaTypeValues) {
if (mediaTypeValues.isEmpty()) {
return Collections.singletonList(MediaType.ALL);
}
return parseMediaTypes(new LinkedList<>(mediaTypeValues));
}
public String getMethod() { public String getMethod() {
return method; return method;
} }
@ -176,63 +233,6 @@ public class RequestMetadata {
return this; return this;
} }
/**
* 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>
*/
public static RequestMetadata getBestMatch(NavigableMap<RequestMetadata, RequestMetadata> requestMetadataMap,
RequestMetadata requestMetadata) {
RequestMetadata key = requestMetadata;
RequestMetadata result = requestMetadataMap.get(key);
if (result == null) {
SortedMap<RequestMetadata, RequestMetadata> headMap = requestMetadataMap.headMap(key, true);
result = headMap.isEmpty() ? null : requestMetadataMap.get(headMap.lastKey());
}
return result;
}
private static void add(String key, String value, MultiValueMap<String, String> destination) {
destination.add(key, value);
}
private static <T extends Collection<String>> void addAll(Map<String, T> source,
MultiValueMap<String, String> destination) {
for (Map.Entry<String, T> entry : source.entrySet()) {
String key = entry.getKey();
for (String value : entry.getValue()) {
add(key, value, destination);
}
}
}
private static void mediaTypes(HttpHeaders httpHeaders, String headerName, Collection<String> destination) {
List<String> value = httpHeaders.get(headerName);
List<MediaType> mediaTypes = parseMediaTypes(value);
destination.addAll(toMediaTypeValues(mediaTypes));
}
private static List<String> toMediaTypeValues(List<MediaType> mediaTypes) {
List<String> list = new ArrayList<>(mediaTypes.size());
for (MediaType mediaType : mediaTypes) {
list.add(mediaType.toString());
}
return list;
}
private static List<MediaType> toMediaTypes(Collection<String> mediaTypeValues) {
if (mediaTypeValues.isEmpty()) {
return Collections.singletonList(MediaType.ALL);
}
return parseMediaTypes(new LinkedList<>(mediaTypeValues));
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) { if (this == o) {

View File

@ -102,29 +102,17 @@ public class DubboServiceMetadataRepository implements SmartInitializingSingleto
* Monitor object for synchronization * Monitor object for synchronization
*/ */
private final Object monitor = new Object(); private final Object monitor = new Object();
private ApplicationEventPublisher applicationEventPublisher;
/** /**
* 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<>(); private final Set<String> initializedServices = new LinkedHashSet<>();
// =================================== Registration =================================== //
/** /**
* All exported {@link URL urls} {@link Map} whose key is the return value of {@link URL#getServiceKey()} method * 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} * and value is the {@link List} of {@link URL URLs}
*/ */
private final MultiValueMap<String, URL> allExportedURLs = new LinkedMultiValueMap<>(); private final MultiValueMap<String, URL> allExportedURLs = new LinkedMultiValueMap<>();
// ==================================================================================== // // =================================== Registration =================================== //
// =================================== Subscription =================================== //
private volatile Set<String> subscribedServices = emptySet();
/** /**
* The subscribed {@link URL urls} {@link Map} of {@link DubboMetadataService}, * 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 * whose key is the return value of {@link URL#getServiceKey()} method and value is the {@link List} of
@ -135,14 +123,19 @@ public class DubboServiceMetadataRepository implements SmartInitializingSingleto
// ==================================================================================== // // ==================================================================================== //
// =================================== REST Metadata ================================== // // =================================== Subscription =================================== //
/** /**
* A Map to store REST metadata temporary, its' key is the special service name for a Dubbo service, * A Map to store REST metadata temporary, its' key is the special service name for a Dubbo service,
* the value is a JSON content of JAX-RS or Spring MVC REST metadata from the annotated methods. * the value is a JSON content of JAX-RS or Spring MVC REST metadata from the annotated methods.
*/ */
private final Set<ServiceRestMetadata> serviceRestMetadata = new LinkedHashSet<>(); private final Set<ServiceRestMetadata> serviceRestMetadata = new LinkedHashSet<>();
private ApplicationEventPublisher applicationEventPublisher;
// ==================================================================================== //
// =================================== REST Metadata ================================== //
private volatile Set<String> subscribedServices = emptySet();
/** /**
* Key is application name * Key is application name
* Value is Map<RequestMetadata, DubboRestServiceMetadata> * Value is Map<RequestMetadata, DubboRestServiceMetadata>
@ -178,6 +171,23 @@ public class DubboServiceMetadataRepository implements SmartInitializingSingleto
// ==================================================================================== // // ==================================================================================== //
private static <K, V> Map<K, V> getMap(Map<String, Map<K, V>> repository, String key) {
return getOrDefault(repository, key, newHashMap());
}
private static <K, V> V getOrDefault(Map<K, V> source, K key, V defaultValue) {
V value = source.get(key);
if (value == null) {
value = defaultValue;
source.put(key, value);
}
return value;
}
private static <K, V> Map<K, V> newHashMap() {
return new LinkedHashMap<>();
}
/** /**
* Initialize {@link #subscribedServices the subscribed services} * Initialize {@link #subscribedServices the subscribed services}
* *
@ -556,23 +566,6 @@ public class DubboServiceMetadataRepository implements SmartInitializingSingleto
return metadata; return metadata;
} }
private static <K, V> Map<K, V> getMap(Map<String, Map<K, V>> repository, String key) {
return getOrDefault(repository, key, newHashMap());
}
private static <K, V> V getOrDefault(Map<K, V> source, K key, V defaultValue) {
V value = source.get(key);
if (value == null) {
value = defaultValue;
source.put(key, value);
}
return value;
}
private static <K, V> Map<K, V> newHashMap() {
return new LinkedHashMap<>();
}
private void excludeSelf(Set<String> subscribedServices) { private void excludeSelf(Set<String> subscribedServices) {
subscribedServices.remove(currentApplicationName); subscribedServices.remove(currentApplicationName);
} }

View File

@ -16,18 +16,19 @@
*/ */
package com.alibaba.cloud.dubbo.metadata.resolver; package com.alibaba.cloud.dubbo.metadata.resolver;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.config.spring.ServiceBean;
import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata;
import com.alibaba.cloud.dubbo.metadata.ServiceRestMetadata;
import feign.Contract; import feign.Contract;
import feign.Feign; import feign.Feign;
import feign.MethodMetadata; import feign.MethodMetadata;
import feign.Util; 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.BeanUtils;
import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.SmartInitializingSingleton; import org.springframework.beans.factory.SmartInitializingSingleton;
import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata;
import com.alibaba.cloud.dubbo.metadata.ServiceRestMetadata;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import java.lang.reflect.Method; import java.lang.reflect.Method;

View File

@ -16,11 +16,11 @@
*/ */
package com.alibaba.cloud.dubbo.metadata.resolver; package com.alibaba.cloud.dubbo.metadata.resolver;
import feign.Contract;
import com.alibaba.cloud.dubbo.annotation.DubboTransported; import com.alibaba.cloud.dubbo.annotation.DubboTransported;
import com.alibaba.cloud.dubbo.metadata.DubboTransportedMethodMetadata; import com.alibaba.cloud.dubbo.metadata.DubboTransportedMethodMetadata;
import com.alibaba.cloud.dubbo.metadata.MethodMetadata; import com.alibaba.cloud.dubbo.metadata.MethodMetadata;
import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata;
import feign.Contract;
import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.env.PropertyResolver; import org.springframework.core.env.PropertyResolver;

View File

@ -17,6 +17,7 @@
package com.alibaba.cloud.dubbo.metadata.resolver; package com.alibaba.cloud.dubbo.metadata.resolver;
import org.apache.dubbo.config.spring.ServiceBean; import org.apache.dubbo.config.spring.ServiceBean;
import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata;
import com.alibaba.cloud.dubbo.metadata.ServiceRestMetadata; import com.alibaba.cloud.dubbo.metadata.ServiceRestMetadata;

View File

@ -17,6 +17,7 @@
package com.alibaba.cloud.dubbo.openfeign; package com.alibaba.cloud.dubbo.openfeign;
import org.apache.dubbo.rpc.service.GenericService; import org.apache.dubbo.rpc.service.GenericService;
import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata;
import java.lang.reflect.Method; import java.lang.reflect.Method;

View File

@ -16,18 +16,16 @@
*/ */
package com.alibaba.cloud.dubbo.openfeign; package com.alibaba.cloud.dubbo.openfeign;
import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository;
import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContextFactory; import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContextFactory;
import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory; import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.BeanPostProcessor;
import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import static java.lang.reflect.Proxy.newProxyInstance;
import static com.alibaba.cloud.dubbo.autoconfigure.DubboOpenFeignAutoConfiguration.TARGETER_CLASS_NAME; 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.getUserClass;
import static org.springframework.util.ClassUtils.isPresent; import static org.springframework.util.ClassUtils.isPresent;
import static org.springframework.util.ClassUtils.resolveClassName; import static org.springframework.util.ClassUtils.resolveClassName;

View File

@ -78,6 +78,10 @@ class TargeterInvocationHandler implements InvocationHandler {
this.contextFactory = contextFactory; this.contextFactory = contextFactory;
} }
private static <T> T cast(Object object) {
return (T) object;
}
@Override @Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
/** /**
@ -168,8 +172,4 @@ class TargeterInvocationHandler implements InvocationHandler {
return feignMethodMetadataMap; return feignMethodMetadataMap;
} }
private static <T> T cast(Object object) {
return (T) object;
}
} }

View File

@ -16,11 +16,11 @@
*/ */
package com.alibaba.cloud.dubbo.registry; 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.After;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Before;
import com.alibaba.cloud.dubbo.registry.event.ServiceInstancePreRegisteredEvent;
import com.alibaba.cloud.dubbo.registry.event.ServiceInstanceRegisteredEvent;
import org.springframework.cloud.client.serviceregistry.Registration; import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry; import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;

View File

@ -59,6 +59,10 @@ public class SpringCloudRegistryFactory implements RegistryFactory {
public SpringCloudRegistryFactory() { public SpringCloudRegistryFactory() {
} }
public static void setApplicationContext(ConfigurableApplicationContext applicationContext) {
SpringCloudRegistryFactory.applicationContext = applicationContext;
}
protected void init() { protected void init() {
if (initialized || applicationContext == null) { if (initialized || applicationContext == null) {
return; return;
@ -75,8 +79,4 @@ public class SpringCloudRegistryFactory implements RegistryFactory {
return new SpringCloudRegistry(url, discoveryClient, dubboServiceMetadataRepository, return new SpringCloudRegistry(url, discoveryClient, dubboServiceMetadataRepository,
dubboMetadataConfigServiceProxy, jsonUtils, applicationContext); dubboMetadataConfigServiceProxy, jsonUtils, applicationContext);
} }
public static void setApplicationContext(ConfigurableApplicationContext applicationContext) {
SpringCloudRegistryFactory.applicationContext = applicationContext;
}
} }

View File

@ -27,6 +27,8 @@ import static java.util.Collections.unmodifiableCollection;
/** /**
* An event raised after the {@link ServiceInstance instances} of one service has been changed. * An event raised after the {@link ServiceInstance instances} of one service has been changed.
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/ */
public class ServiceInstancesChangedEvent extends ApplicationEvent { public class ServiceInstancesChangedEvent extends ApplicationEvent {

View File

@ -16,12 +16,12 @@
*/ */
package com.alibaba.cloud.dubbo.service; package com.alibaba.cloud.dubbo.service;
import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.cloud.dubbo.http.HttpServerRequest; import com.alibaba.cloud.dubbo.http.HttpServerRequest;
import com.alibaba.cloud.dubbo.metadata.MethodMetadata; import com.alibaba.cloud.dubbo.metadata.MethodMetadata;
import com.alibaba.cloud.dubbo.metadata.MethodParameterMetadata; import com.alibaba.cloud.dubbo.metadata.MethodParameterMetadata;
import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata;
import com.alibaba.cloud.dubbo.service.parameter.DubboGenericServiceParameterResolver; import com.alibaba.cloud.dubbo.service.parameter.DubboGenericServiceParameterResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;

View File

@ -67,8 +67,8 @@ public interface DubboMetadataService {
* 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<URL> of {@link URL URLs} by the serviceInterface , group and version
* *
* @param serviceInterface The class name of service interface * @param serviceInterface The class name of service interface
* @param group {@link Service#group() the service group} (optional) * @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} * @return non-null read-only {@link List}
* @see URL * @see URL
*/ */

View File

@ -26,14 +26,14 @@ 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 { public class DubboMetadataServiceProxy implements BeanClassLoaderAware, DisposableBean {
private final DubboGenericServiceFactory dubboGenericServiceFactory; private final DubboGenericServiceFactory dubboGenericServiceFactory;
private ClassLoader classLoader;
private final Map<String, DubboMetadataService> dubboMetadataServiceCache = new ConcurrentHashMap<>(); private final Map<String, DubboMetadataService> dubboMetadataServiceCache = new ConcurrentHashMap<>();
private ClassLoader classLoader;
public DubboMetadataServiceProxy(DubboGenericServiceFactory dubboGenericServiceFactory) { public DubboMetadataServiceProxy(DubboGenericServiceFactory dubboGenericServiceFactory) {
this.dubboGenericServiceFactory = dubboGenericServiceFactory; this.dubboGenericServiceFactory = dubboGenericServiceFactory;

View File

@ -18,13 +18,13 @@ package com.alibaba.cloud.dubbo.service;
import org.apache.dubbo.common.URL; import org.apache.dubbo.common.URL;
import com.alibaba.cloud.dubbo.metadata.ServiceRestMetadata;
import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository;
import com.alibaba.cloud.dubbo.util.JSONUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired; 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 java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;

View File

@ -16,67 +16,67 @@
*/ */
package com.alibaba.cloud.dubbo.service.parameter; package com.alibaba.cloud.dubbo.service.parameter;
import static org.springframework.context.ConfigurableApplicationContext.CONVERSION_SERVICE_BEAN_NAME;
import static org.springframework.util.ClassUtils.resolveClassName;
import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.format.support.DefaultFormattingConversionService; 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> * @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/ */
public abstract class AbstractDubboGenericServiceParameterResolver public abstract class AbstractDubboGenericServiceParameterResolver
implements DubboGenericServiceParameterResolver, BeanClassLoaderAware { implements DubboGenericServiceParameterResolver, BeanClassLoaderAware {
private int order; private int order;
@Autowired(required = false) @Autowired(required = false)
@Qualifier(CONVERSION_SERVICE_BEAN_NAME) @Qualifier(CONVERSION_SERVICE_BEAN_NAME)
private ConversionService conversionService = new DefaultFormattingConversionService(); private ConversionService conversionService = new DefaultFormattingConversionService();
private ClassLoader classLoader; private ClassLoader classLoader;
public ConversionService getConversionService() { public ConversionService getConversionService() {
return conversionService; return conversionService;
} }
public void setConversionService(ConversionService conversionService) { public void setConversionService(ConversionService conversionService) {
this.conversionService = conversionService; this.conversionService = conversionService;
} }
public ClassLoader getClassLoader() { public ClassLoader getClassLoader() {
return classLoader; return classLoader;
} }
@Override @Override
public void setBeanClassLoader(ClassLoader classLoader) { public void setBeanClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader; this.classLoader = classLoader;
} }
public void setOrder(int order) { @Override
this.order = order; public int getOrder() {
} return order;
}
@Override public void setOrder(int order) {
public int getOrder() { this.order = order;
return order; }
}
protected Class<?> resolveClass(String className) { protected Class<?> resolveClass(String className) {
return resolveClassName(className, classLoader); return resolveClassName(className, classLoader);
} }
protected Object resolveValue(Object parameterValue, String parameterType) { protected Object resolveValue(Object parameterValue, String parameterType) {
Class<?> targetType = resolveClass(parameterType); Class<?> targetType = resolveClass(parameterType);
return resolveValue(parameterValue, targetType); return resolveValue(parameterValue, targetType);
} }
protected Object resolveValue(Object parameterValue, Class<?> parameterType) { protected Object resolveValue(Object parameterValue, Class<?> parameterType) {
return conversionService.convert(parameterValue, parameterType); return conversionService.convert(parameterValue, parameterType);
} }
} }

View File

@ -16,10 +16,10 @@
*/ */
package com.alibaba.cloud.dubbo.service.parameter; package com.alibaba.cloud.dubbo.service.parameter;
import com.alibaba.cloud.dubbo.metadata.MethodParameterMetadata;
import org.apache.dubbo.rpc.service.GenericService; import org.apache.dubbo.rpc.service.GenericService;
import com.alibaba.cloud.dubbo.http.HttpServerRequest; import com.alibaba.cloud.dubbo.http.HttpServerRequest;
import com.alibaba.cloud.dubbo.metadata.MethodParameterMetadata;
import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;

View File

@ -16,14 +16,14 @@
*/ */
package com.alibaba.cloud.dubbo.service.parameter; package com.alibaba.cloud.dubbo.service.parameter;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import com.alibaba.cloud.dubbo.http.HttpServerRequest; import com.alibaba.cloud.dubbo.http.HttpServerRequest;
import com.alibaba.cloud.dubbo.http.converter.HttpMessageConverterHolder; import com.alibaba.cloud.dubbo.http.converter.HttpMessageConverterHolder;
import com.alibaba.cloud.dubbo.http.util.HttpMessageConverterResolver; import com.alibaba.cloud.dubbo.http.util.HttpMessageConverterResolver;
import com.alibaba.cloud.dubbo.metadata.MethodParameterMetadata; import com.alibaba.cloud.dubbo.metadata.MethodParameterMetadata;
import com.alibaba.cloud.dubbo.metadata.RestMethodMetadata; 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.HttpMessageConverter;
import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotReadableException;