Update Dubbo Spring Boot Starter 2.7.1

pull/534/head
mercyblitz 6 years ago
parent 3230a61a23
commit c12252566a

@ -15,7 +15,6 @@
<properties> <properties>
<dubbo.version>2.7.1</dubbo.version> <dubbo.version>2.7.1</dubbo.version>
<dubbo-spring-boot.version>2.7.0</dubbo-spring-boot.version>
<spring-cloud-zookeeper.version>2.1.0.RELEASE</spring-cloud-zookeeper.version> <spring-cloud-zookeeper.version>2.1.0.RELEASE</spring-cloud-zookeeper.version>
<spring-cloud-consul.version>2.1.0.RELEASE</spring-cloud-consul.version> <spring-cloud-consul.version>2.1.0.RELEASE</spring-cloud-consul.version>
<curator.version>4.0.1</curator.version> <curator.version>4.0.1</curator.version>
@ -179,7 +178,7 @@
<dependency> <dependency>
<groupId>org.apache.dubbo</groupId> <groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId> <artifactId>dubbo-spring-boot-starter</artifactId>
<version>${dubbo-spring-boot.version}</version> <version>${dubbo.version}</version>
</dependency> </dependency>
<!-- Netty --> <!-- Netty -->

@ -16,12 +16,8 @@
*/ */
package org.springframework.cloud.alibaba.dubbo.autoconfigure; package org.springframework.cloud.alibaba.dubbo.autoconfigure;
import org.apache.dubbo.common.utils.Assert;
import org.apache.dubbo.config.spring.util.PropertySourcesUtils;
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 org.springframework.boot.context.properties.source.ConfigurationPropertySources;
import org.springframework.cloud.alibaba.dubbo.env.DubboCloudProperties; import org.springframework.cloud.alibaba.dubbo.env.DubboCloudProperties;
import org.springframework.cloud.alibaba.dubbo.service.DubboGenericServiceExecutionContextFactory; import org.springframework.cloud.alibaba.dubbo.service.DubboGenericServiceExecutionContextFactory;
import org.springframework.cloud.alibaba.dubbo.service.DubboGenericServiceFactory; import org.springframework.cloud.alibaba.dubbo.service.DubboGenericServiceFactory;
@ -32,18 +28,6 @@ import org.springframework.cloud.alibaba.dubbo.service.parameter.RequestParamSer
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;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.AbstractEnvironment;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertyResolver;
import org.springframework.lang.Nullable;
import java.util.Map;
import static org.apache.dubbo.spring.boot.util.DubboUtils.BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME;
import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_SCAN_PREFIX;
/** /**
* Spring Boot Auto-Configuration class for Dubbo Service * Spring Boot Auto-Configuration class for Dubbo Service
@ -71,81 +55,81 @@ public class DubboServiceAutoConfiguration {
static class ParameterResolversConfiguration { static class ParameterResolversConfiguration {
} }
/** // /**
* Bugfix code for an issue : https://github.com/apache/incubator-dubbo-spring-boot-project/issues/459 // * Bugfix code for an issue : https://github.com/apache/incubator-dubbo-spring-boot-project/issues/459
* // *
* @param environment {@link ConfigurableEnvironment} // * @param environment {@link ConfigurableEnvironment}
* @return a Bean of {@link PropertyResolver} // * @return a Bean of {@link PropertyResolver}
*/ // */
@Primary // @Primary
@Bean(name = BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME) // @Bean(name = BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME)
public PropertyResolver dubboScanBasePackagesPropertyResolver(ConfigurableEnvironment environment) { // public PropertyResolver dubboScanBasePackagesPropertyResolver(ConfigurableEnvironment environment) {
ConfigurableEnvironment propertyResolver = new AbstractEnvironment() { // ConfigurableEnvironment propertyResolver = new AbstractEnvironment() {
@Override // @Override
protected void customizePropertySources(MutablePropertySources propertySources) { // protected void customizePropertySources(MutablePropertySources propertySources) {
Map<String, Object> dubboScanProperties = PropertySourcesUtils.getSubProperties(environment, DUBBO_SCAN_PREFIX); // Map<String, Object> dubboScanProperties = PropertySourcesUtils.getSubProperties(environment, DUBBO_SCAN_PREFIX);
propertySources.addLast(new MapPropertySource("dubboScanProperties", dubboScanProperties)); // propertySources.addLast(new MapPropertySource("dubboScanProperties", dubboScanProperties));
} // }
}; // };
ConfigurationPropertySources.attach(propertyResolver); // ConfigurationPropertySources.attach(propertyResolver);
return new DelegatingPropertyResolver(propertyResolver); // return new DelegatingPropertyResolver(propertyResolver);
} // }
//
//
private static class DelegatingPropertyResolver implements PropertyResolver { // private static class DelegatingPropertyResolver implements PropertyResolver {
//
private final PropertyResolver delegate; // private final PropertyResolver delegate;
//
DelegatingPropertyResolver(PropertyResolver delegate) { // DelegatingPropertyResolver(PropertyResolver delegate) {
Assert.notNull(delegate, "The delegate of PropertyResolver must not be null"); // Assert.notNull(delegate, "The delegate of PropertyResolver must not be null");
this.delegate = delegate; // this.delegate = delegate;
} // }
//
@Override // @Override
public boolean containsProperty(String key) { // public boolean containsProperty(String key) {
return delegate.containsProperty(key); // return delegate.containsProperty(key);
} // }
//
@Override // @Override
@Nullable // @Nullable
public String getProperty(String key) { // public String getProperty(String key) {
return delegate.getProperty(key); // return delegate.getProperty(key);
} // }
//
@Override // @Override
public String getProperty(String key, String defaultValue) { // public String getProperty(String key, String defaultValue) {
return delegate.getProperty(key, defaultValue); // return delegate.getProperty(key, defaultValue);
} // }
//
@Override // @Override
@Nullable // @Nullable
public <T> T getProperty(String key, Class<T> targetType) { // public <T> T getProperty(String key, Class<T> targetType) {
return delegate.getProperty(key, targetType); // return delegate.getProperty(key, targetType);
} // }
//
@Override // @Override
public <T> T getProperty(String key, Class<T> targetType, T defaultValue) { // public <T> T getProperty(String key, Class<T> targetType, T defaultValue) {
return delegate.getProperty(key, targetType, defaultValue); // return delegate.getProperty(key, targetType, defaultValue);
} // }
//
@Override // @Override
public String getRequiredProperty(String key) throws IllegalStateException { // public String getRequiredProperty(String key) throws IllegalStateException {
return delegate.getRequiredProperty(key); // return delegate.getRequiredProperty(key);
} // }
//
@Override // @Override
public <T> T getRequiredProperty(String key, Class<T> targetType) throws IllegalStateException { // public <T> T getRequiredProperty(String key, Class<T> targetType) throws IllegalStateException {
return delegate.getRequiredProperty(key, targetType); // return delegate.getRequiredProperty(key, targetType);
} // }
//
@Override // @Override
public String resolvePlaceholders(String text) { // public String resolvePlaceholders(String text) {
return delegate.resolvePlaceholders(text); // return delegate.resolvePlaceholders(text);
} // }
//
@Override // @Override
public String resolveRequiredPlaceholders(String text) throws IllegalArgumentException { // public String resolveRequiredPlaceholders(String text) throws IllegalArgumentException {
return delegate.resolveRequiredPlaceholders(text); // return delegate.resolveRequiredPlaceholders(text);
} // }
} // }
} }

@ -1,188 +1,181 @@
//package org.springframework.cloud.alibaba.dubbo.gateway; package org.springframework.cloud.alibaba.dubbo.gateway;
//
//import org.apache.commons.lang.StringUtils; import org.apache.dubbo.rpc.service.GenericException;
//import org.apache.dubbo.rpc.service.GenericException; import org.apache.dubbo.rpc.service.GenericService;
//import org.apache.dubbo.rpc.service.GenericService;
//import org.springframework.cloud.alibaba.dubbo.http.MutableHttpServerRequest; import org.springframework.cloud.alibaba.dubbo.http.MutableHttpServerRequest;
//import org.springframework.cloud.alibaba.dubbo.metadata.DubboServiceMetadata; import org.springframework.cloud.alibaba.dubbo.metadata.DubboRestServiceMetadata;
//import org.springframework.cloud.alibaba.dubbo.metadata.DubboTransportedMetadata; import org.springframework.cloud.alibaba.dubbo.metadata.RequestMetadata;
//import org.springframework.cloud.alibaba.dubbo.metadata.RequestMetadata; import org.springframework.cloud.alibaba.dubbo.metadata.RestMethodMetadata;
//import org.springframework.cloud.alibaba.dubbo.metadata.RestMethodMetadata; import org.springframework.cloud.alibaba.dubbo.metadata.repository.DubboServiceMetadataRepository;
//import org.springframework.cloud.alibaba.dubbo.metadata.repository.DubboServiceMetadataRepository; import org.springframework.cloud.alibaba.dubbo.service.DubboGenericServiceExecutionContext;
//import org.springframework.cloud.alibaba.dubbo.service.DubboGenericServiceExecutionContext; import org.springframework.cloud.alibaba.dubbo.service.DubboGenericServiceExecutionContextFactory;
//import org.springframework.cloud.alibaba.dubbo.service.DubboGenericServiceExecutionContextFactory; import org.springframework.cloud.alibaba.dubbo.service.DubboGenericServiceFactory;
//import org.springframework.cloud.alibaba.dubbo.service.DubboGenericServiceFactory; import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpHeaders; import org.springframework.http.HttpRequest;
//import org.springframework.http.HttpRequest; import org.springframework.util.AntPathMatcher;
//import org.springframework.util.AntPathMatcher; import org.springframework.util.PathMatcher;
//import org.springframework.util.CollectionUtils; import org.springframework.util.StreamUtils;
//import org.springframework.util.PathMatcher; import org.springframework.web.servlet.HttpServletBean;
//import org.springframework.util.StreamUtils; import org.springframework.web.util.UriComponents;
//import org.springframework.web.util.UriComponents;
// import javax.servlet.ServletException;
//import javax.servlet.ServletException; import javax.servlet.ServletInputStream;
//import javax.servlet.ServletInputStream; import javax.servlet.annotation.WebServlet;
//import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletResponse;
//import javax.servlet.http.HttpServletRequest; import java.io.IOException;
//import javax.servlet.http.HttpServletResponse; import java.net.URI;
//import java.io.IOException; import java.net.URISyntaxException;
//import java.net.URI; import java.util.Arrays;
//import java.net.URISyntaxException; import java.util.Collections;
//import java.util.*; import java.util.Enumeration;
// import java.util.HashMap;
//import static org.springframework.web.util.UriComponentsBuilder.fromUriString; import java.util.LinkedHashMap;
// import java.util.List;
//@WebServlet(urlPatterns = "/dsc/*") import java.util.Map;
//public class DubboGatewayServlet extends HttpServlet {
// import static org.apache.commons.lang3.StringUtils.substringAfter;
// private final DubboServiceMetadataRepository repository; import static org.apache.commons.lang3.StringUtils.substringBetween;
// import static org.springframework.web.util.UriComponentsBuilder.fromUriString;
// private final DubboTransportedMetadata dubboTransportedMetadata;
// @WebServlet(urlPatterns = "/dsc/*")
// private final DubboGenericServiceFactory serviceFactory; public class DubboGatewayServlet extends HttpServletBean {
//
// private final DubboGenericServiceExecutionContextFactory contextFactory; private final DubboServiceMetadataRepository repository;
//
// private final PathMatcher pathMatcher = new AntPathMatcher(); private final DubboGenericServiceFactory serviceFactory;
//
// public DubboGatewayServlet(DubboServiceMetadataRepository repository, private final DubboGenericServiceExecutionContextFactory contextFactory;
// DubboGenericServiceFactory serviceFactory,
// DubboGenericServiceExecutionContextFactory contextFactory) { private final PathMatcher pathMatcher = new AntPathMatcher();
// this.repository = repository;
// this.dubboTransportedMetadata = new DubboTransportedMetadata(); private final Map<String, Object> dubboTranslatedAttributes = new HashMap<>();
// dubboTransportedMetadata.setProtocol("dubbo");
// dubboTransportedMetadata.setCluster("failover"); public DubboGatewayServlet(DubboServiceMetadataRepository repository,
// this.serviceFactory = serviceFactory; DubboGenericServiceFactory serviceFactory,
// this.contextFactory = contextFactory; DubboGenericServiceExecutionContextFactory contextFactory) {
// } this.repository = repository;
// this.serviceFactory = serviceFactory;
// public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { this.contextFactory = contextFactory;
// dubboTranslatedAttributes.put("protocol", "dubbo");
// // /g/{app-name}/{rest-path} dubboTranslatedAttributes.put("cluster", "failover");
// String requestURI = request.getRequestURI(); }
// // /g/
// String servletPath = request.getServletPath(); private String resolveServiceName(HttpServletRequest request) {
//
// String part = StringUtils.substringAfter(requestURI, servletPath); // /g/{app-name}/{rest-path}
// String requestURI = request.getRequestURI();
// String serviceName = StringUtils.substringBetween(part, "/", "/"); // /g/
// String servletPath = request.getServletPath();
// // App name= spring-cloud-alibaba-dubbo-web-provider (127.0.0.1:8080)
// String part = substringAfter(requestURI, servletPath);
// String restPath = StringUtils.substringAfter(part, serviceName);
// String serviceName = substringBetween(part, "/", "/");
// // 初始化 serviceName 的 REST 请求元数据
// repository.initialize(serviceName); return serviceName;
// // 将 HttpServletRequest 转化为 RequestMetadata }
// RequestMetadata clientMetadata = buildRequestMetadata(request, restPath);
// public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// DubboServiceMetadata dubboServiceMetadata = repository.get(serviceName, clientMetadata);
// String serviceName = resolveServiceName(request);
// if (dubboServiceMetadata == null) {
// // if DubboServiceMetadata is not found, executes next String restPath = substringAfter(request.getRequestURI(), serviceName);
// throw new ServletException("DubboServiceMetadata can't be found!");
// } // 初始化 serviceName 的 REST 请求元数据
// repository.initialize(serviceName);
// RestMethodMetadata dubboRestMethodMetadata = dubboServiceMetadata.getRestMethodMetadata(); // 将 HttpServletRequest 转化为 RequestMetadata
// RequestMetadata clientMetadata = buildRequestMetadata(request, restPath);
// GenericService genericService = serviceFactory.create(dubboServiceMetadata, dubboTransportedMetadata);
// DubboRestServiceMetadata dubboRestServiceMetadata = repository.get(serviceName, clientMetadata);
// // TODO: Get the Request Body from HttpServletRequest
// byte[] body = getRequestBody(request); if (dubboRestServiceMetadata == null) {
// // if DubboServiceMetadata is not found, executes next
// MutableHttpServerRequest httpServerRequest = new MutableHttpServerRequest(new HttpRequestAdapter(request), body); throw new ServletException("DubboServiceMetadata can't be found!");
// }
//// customizeRequest(httpServerRequest, dubboRestMethodMetadata, clientMetadata);
// RestMethodMetadata dubboRestMethodMetadata = dubboRestServiceMetadata.getRestMethodMetadata();
// DubboGenericServiceExecutionContext context = contextFactory.create(dubboRestMethodMetadata, httpServerRequest);
// GenericService genericService = serviceFactory.create(dubboRestServiceMetadata, dubboTranslatedAttributes);
// Object result = null;
// GenericException exception = null; // TODO: Get the Request Body from HttpServletRequest
// byte[] body = getRequestBody(request);
// try {
// result = genericService.$invoke(context.getMethodName(), context.getParameterTypes(), context.getParameters()); MutableHttpServerRequest httpServerRequest = new MutableHttpServerRequest(new HttpRequestAdapter(request), body);
// } catch (GenericException e) {
// exception = e; DubboGenericServiceExecutionContext context = contextFactory.create(dubboRestMethodMetadata, httpServerRequest);
// }
// response.getWriter().println(result); Object result = null;
// } GenericException exception = null;
//
// private byte[] getRequestBody(HttpServletRequest request) throws IOException { try {
// ServletInputStream inputStream = request.getInputStream(); result = genericService.$invoke(context.getMethodName(), context.getParameterTypes(), context.getParameters());
// return StreamUtils.copyToByteArray(inputStream); } catch (GenericException e) {
// } exception = e;
// }
// private static class HttpRequestAdapter implements HttpRequest { response.getWriter().println(result);
// }
// private final HttpServletRequest request;
// private byte[] getRequestBody(HttpServletRequest request) throws IOException {
// private HttpRequestAdapter(HttpServletRequest request) { ServletInputStream inputStream = request.getInputStream();
// this.request = request; return StreamUtils.copyToByteArray(inputStream);
// } }
//
// @Override private static class HttpRequestAdapter implements HttpRequest {
// public String getMethodValue() {
// return request.getMethod(); private final HttpServletRequest request;
// }
// private HttpRequestAdapter(HttpServletRequest request) {
// @Override this.request = request;
// public URI getURI() { }
// try {
// return new URI(request.getRequestURL().toString() + "?" + request.getQueryString()); @Override
// } catch (URISyntaxException e) { public String getMethodValue() {
// e.printStackTrace(); return request.getMethod();
// } }
// throw new RuntimeException();
// } @Override
// public URI getURI() {
// @Override try {
// public HttpHeaders getHeaders() { return new URI(request.getRequestURL().toString() + "?" + request.getQueryString());
// return new HttpHeaders(); } catch (URISyntaxException e) {
// } e.printStackTrace();
// } }
// throw new RuntimeException();
//// protected void customizeRequest(MutableHttpServerRequest httpServerRequest, }
//// RestMethodMetadata dubboRestMethodMetadata, RequestMetadata clientMetadata) {
//// @Override
//// RequestMetadata dubboRequestMetadata = dubboRestMethodMetadata.getRequest(); public HttpHeaders getHeaders() {
//// String pathPattern = dubboRequestMetadata.getPath(); return new HttpHeaders();
//// }
//// Map<String, String> pathVariables = pathMatcher.extractUriTemplateVariables(pathPattern, httpServerRequest.getPath()); }
////
//// if (!CollectionUtils.isEmpty(pathVariables)) { private RequestMetadata buildRequestMetadata(HttpServletRequest request, String restPath) {
//// // Put path variables Map into query parameters Map UriComponents uriComponents = fromUriString(request.getRequestURI()).build(true);
//// httpServerRequest.params(pathVariables); RequestMetadata requestMetadata = new RequestMetadata();
//// } requestMetadata.setPath(restPath);
//// requestMetadata.setMethod(request.getMethod());
//// } requestMetadata.setParams(getParams(request));
// requestMetadata.setHeaders(getHeaders(request));
// private RequestMetadata buildRequestMetadata(HttpServletRequest request, String restPath) { return requestMetadata;
// UriComponents uriComponents = fromUriString(request.getRequestURI()).build(true); }
// RequestMetadata requestMetadata = new RequestMetadata();
// requestMetadata.setPath(restPath); private Map<String, List<String>> getHeaders(HttpServletRequest request) {
// requestMetadata.setMethod(request.getMethod()); Map<String, List<String>> map = new LinkedHashMap<>();
// requestMetadata.setParams(getParams(request)); Enumeration<String> headerNames = request.getHeaderNames();
// requestMetadata.setHeaders(getHeaders(request)); while (headerNames.hasMoreElements()) {
// return requestMetadata; String headerName = headerNames.nextElement();
// } Enumeration<String> headerValues = request.getHeaders(headerName);
// map.put(headerName, Collections.list(headerValues));
// private Map<String, List<String>> getHeaders(HttpServletRequest request) { }
// Map<String, List<String>> map = new LinkedHashMap<>(); return map;
// Enumeration<String> headerNames = request.getHeaderNames(); }
// while (headerNames.hasMoreElements()) {
// String headerName = headerNames.nextElement(); private Map<String, List<String>> getParams(HttpServletRequest request) {
// Enumeration<String> headerValues = request.getHeaders(headerName); Map<String, List<String>> map = new LinkedHashMap<>();
// map.put(headerName, Collections.list(headerValues)); for (Map.Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
// } map.put(entry.getKey(), Arrays.asList(entry.getValue()));
// return map; }
// } return map;
// }
// private Map<String, List<String>> getParams(HttpServletRequest request) { }
// Map<String, List<String>> map = new LinkedHashMap<>();
// for (Map.Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
// map.put(entry.getKey(), Arrays.asList(entry.getValue()));
// }
// return map;
// }
//}

Loading…
Cancel
Save