From 1e76aeeb8fd81537af4bc4b1e329fb6a7ee9c9aa Mon Sep 17 00:00:00 2001 From: "ken.lj" Date: Tue, 31 Oct 2017 20:21:17 +0800 Subject: [PATCH] Merge pull request #778 from chickenlj:specify_registry_ip&port Feature: support specify ip & port registered to registry from environment properties --- .../com/alibaba/dubbo/common/Constants.java | 14 ++ .../dubbo/common/utils/ConfigUtils.java | 14 ++ .../alibaba/dubbo/config/ReferenceConfig.java | 12 ++ .../alibaba/dubbo/config/ServiceConfig.java | 185 +++++++++++++----- .../integration/RegistryProtocol.java | 11 +- .../remoting/transport/AbstractServer.java | 11 +- .../remoting/http/jetty/JettyHttpServer.java | 12 +- .../http/servlet/ServletHttpServer.java | 3 +- .../rpc/protocol/AbstractProxyProtocol.java | 10 + .../rpc/protocol/hessian/HessianProtocol.java | 2 +- .../dubbo/rpc/protocol/http/HttpProtocol.java | 2 +- .../webservice/WebServiceProtocol.java | 2 +- 12 files changed, 213 insertions(+), 65 deletions(-) diff --git a/dubbo-common/src/main/java/com/alibaba/dubbo/common/Constants.java b/dubbo-common/src/main/java/com/alibaba/dubbo/common/Constants.java index b12c632039c..53c4b48649f 100644 --- a/dubbo-common/src/main/java/com/alibaba/dubbo/common/Constants.java +++ b/dubbo-common/src/main/java/com/alibaba/dubbo/common/Constants.java @@ -582,6 +582,20 @@ public class Constants { public static final String GENERIC_SERIALIZATION_BEAN = "bean"; + public static final String DUBBO_IP_TO_REGISTRY = "DUBBO_IP_TO_REGISTRY"; + + public static final String DUBBO_PORT_TO_REGISTRY = "DUBBO_PORT_TO_REGISTRY"; + + public static final String DUBBO_IP_TO_BIND = "DUBBO_IP_TO_BIND"; + + public static final String DUBBO_PORT_TO_BIND = "DUBBO_PORT_TO_BIND"; + + public static final String BIND_IP_KEY = "bind.ip"; + + public static final String BIND_PORT_KEY = "bind.port"; + + public static final String REGISTER_IP_KEY = "register.ip"; + /* * private Constants(){ } */ diff --git a/dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/ConfigUtils.java b/dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/ConfigUtils.java index 5febdb82f0d..145a7cb5807 100644 --- a/dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/ConfigUtils.java +++ b/dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/ConfigUtils.java @@ -186,6 +186,20 @@ public static String getProperty(String key, String defaultValue) { return replaceProperty(properties.getProperty(key, defaultValue), (Map) properties); } + /** + *  系统环境变量 -> java命令参数-D + * + * @param key + * @return + */ + public static String getSystemProperty(String key) { + String value = System.getenv(key); + if (value == null || value.length() == 0) { + value = System.getProperty(key); + } + return value; + } + public static Properties loadProperties(String fileName) { return loadProperties(fileName, false, false); } diff --git a/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ReferenceConfig.java index 43127c857c9..bb13b621b60 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ReferenceConfig.java @@ -50,6 +50,8 @@ import java.util.Map; import java.util.Properties; +import static com.alibaba.dubbo.common.utils.NetUtils.isInvalidLocalHost; + /** * ReferenceConfig * @@ -315,6 +317,16 @@ private void init() { checkAndConvertImplicitConfig(method, map, attributes); } } + + // + String hostToRegistry = ConfigUtils.getSystemProperty(Constants.DUBBO_IP_TO_REGISTRY); + if (hostToRegistry == null || hostToRegistry.length() == 0) { + hostToRegistry = NetUtils.getLocalHost(); + } else if (isInvalidLocalHost(hostToRegistry)) { + throw new IllegalArgumentException("Specified invalid registry ip from property:" + Constants.DUBBO_IP_TO_REGISTRY + ", value:" + hostToRegistry); + } + map.put(Constants.REGISTER_IP_KEY, hostToRegistry); + //attributes通过系统context进行存储. StaticContext.getSystemContext().putAll(attributes); ref = createProxy(map); diff --git a/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ServiceConfig.java index 1b74943e816..70e4f51da77 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ServiceConfig.java @@ -23,7 +23,6 @@ import com.alibaba.dubbo.common.utils.ClassHelper; import com.alibaba.dubbo.common.utils.ConfigUtils; import com.alibaba.dubbo.common.utils.NamedThreadFactory; -import com.alibaba.dubbo.common.utils.NetUtils; import com.alibaba.dubbo.common.utils.StringUtils; import com.alibaba.dubbo.config.annotation.Service; import com.alibaba.dubbo.config.support.Parameter; @@ -52,6 +51,12 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import static com.alibaba.dubbo.common.utils.NetUtils.LOCALHOST; +import static com.alibaba.dubbo.common.utils.NetUtils.getAvailablePort; +import static com.alibaba.dubbo.common.utils.NetUtils.getLocalHost; +import static com.alibaba.dubbo.common.utils.NetUtils.isInvalidLocalHost; +import static com.alibaba.dubbo.common.utils.NetUtils.isInvalidPort; + /** * ServiceConfig * @@ -347,72 +352,151 @@ private void doExportUrls() { } } - private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List registryURLs) { - String name = protocolConfig.getName(); - if (name == null || name.length() == 0) { - name = "dubbo"; - } + /** + * provider注册&监听ip地址,注册与监听ip可独立配置 + * 配置优先级:系统环境变量 -> java命令参数-D -> 配置文件host属性 -> /etc/hosts中hostname-ip映射关系 -> 默认联通注册中心地址的网卡地址 -> 第一个可用的网卡地址 + * + * @param protocolConfig + * @param registryURLs + * @param map + * @return + */ + private String findConfigedHosts(ProtocolConfig protocolConfig, List registryURLs, Map map) { + boolean anyhost = false; - String host = protocolConfig.getHost(); - if (provider != null && (host == null || host.length() == 0)) { - host = provider.getHost(); + String hostToBind = ConfigUtils.getSystemProperty(Constants.DUBBO_IP_TO_BIND); + if (hostToBind != null && hostToBind.length() > 0 && isInvalidLocalHost(hostToBind)) { + throw new IllegalArgumentException("Specified invalid bind ip from property:" + Constants.DUBBO_IP_TO_BIND + ", value:" + hostToBind); } - boolean anyhost = false; - if (NetUtils.isInvalidLocalHost(host)) { - anyhost = true; - try { - host = InetAddress.getLocalHost().getHostAddress(); - } catch (UnknownHostException e) { - logger.warn(e.getMessage(), e); + + // 如果没通过环境变量设置bind ip,则继续按优先级查找 + if (hostToBind == null || hostToBind.length() == 0) { + hostToBind = protocolConfig.getHost(); + if (provider != null && (hostToBind == null || hostToBind.length() == 0)) { + hostToBind = provider.getHost(); } - if (NetUtils.isInvalidLocalHost(host)) { - if (registryURLs != null && registryURLs.size() > 0) { - for (URL registryURL : registryURLs) { - try { - Socket socket = new Socket(); + if (isInvalidLocalHost(hostToBind)) { + anyhost = true; + try { + hostToBind = InetAddress.getLocalHost().getHostAddress(); + } catch (UnknownHostException e) { + logger.warn(e.getMessage(), e); + } + if (isInvalidLocalHost(hostToBind)) { + if (registryURLs != null && registryURLs.size() > 0) { + for (URL registryURL : registryURLs) { try { - SocketAddress addr = new InetSocketAddress(registryURL.getHost(), registryURL.getPort()); - socket.connect(addr, 1000); - host = socket.getLocalAddress().getHostAddress(); - break; - } finally { + Socket socket = new Socket(); try { - socket.close(); - } catch (Throwable e) { + SocketAddress addr = new InetSocketAddress(registryURL.getHost(), registryURL.getPort()); + socket.connect(addr, 1000); + hostToBind = socket.getLocalAddress().getHostAddress(); + break; + } finally { + try { + socket.close(); + } catch (Throwable e) { + } } + } catch (Exception e) { + logger.warn(e.getMessage(), e); } - } catch (Exception e) { - logger.warn(e.getMessage(), e); } } - } - if (NetUtils.isInvalidLocalHost(host)) { - host = NetUtils.getLocalHost(); + if (isInvalidLocalHost(hostToBind)) { + hostToBind = getLocalHost(); + } } } } - Integer port = protocolConfig.getPort(); - if (provider != null && (port == null || port == 0)) { - port = provider.getPort(); + map.put(Constants.BIND_IP_KEY, hostToBind); + + // registry ip,默认不作为bind ip + String hostToRegistry = ConfigUtils.getSystemProperty(Constants.DUBBO_IP_TO_REGISTRY); + if (hostToRegistry != null && hostToRegistry.length() > 0 && isInvalidLocalHost(hostToRegistry)) { + throw new IllegalArgumentException("Specified invalid registry ip from property:" + Constants.DUBBO_IP_TO_REGISTRY + ", value:" + hostToRegistry); + } else if (hostToRegistry == null || hostToRegistry.length() == 0) { + // bind ip默认作为registry ip + hostToRegistry = hostToBind; + } + + map.put(Constants.ANYHOST_KEY, String.valueOf(anyhost)); + + return hostToRegistry; + } + + /** + * provider注册&监听端口,注册与监听port可独立配置 + * 配置优先级:启动环境变量 -> java命令参数-D -> protocol配置文件port属性配置 -> 协议默认端口 + * + * @param protocolConfig + * @param name + * @return + */ + private Integer findConfigedPorts(ProtocolConfig protocolConfig, String name, Map map) { + Integer portToBind = null; + + // 解析环境变量配置的bind port + String port = ConfigUtils.getSystemProperty(Constants.DUBBO_PORT_TO_BIND); + portToBind = parsePort(port); + + // 如未通过环境变量配置bind port,则继续按优先级查找 + if (portToBind == null) { + portToBind = protocolConfig.getPort(); + if (provider != null && (portToBind == null || portToBind == 0)) { + portToBind = provider.getPort(); + } + final int defaultPort = ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(name).getDefaultPort(); + if (portToBind == null || portToBind == 0) { + portToBind = defaultPort; + } + if (portToBind == null || portToBind <= 0) { + portToBind = getRandomPort(name); + if (portToBind == null || portToBind < 0) { + portToBind = getAvailablePort(defaultPort); + putRandomPort(name, portToBind); + } + logger.warn("Use random available port(" + portToBind + ") for protocol " + name); + } } - final int defaultPort = ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(name).getDefaultPort(); - if (port == null || port == 0) { - port = defaultPort; + + // 记录bind port,作为url的key + map.put(Constants.BIND_PORT_KEY, String.valueOf(portToBind)); + + // registry ip,默认不作为bind ip + String portToRegistryStr = ConfigUtils.getSystemProperty(Constants.DUBBO_PORT_TO_REGISTRY); + Integer portToRegistry = parsePort(portToRegistryStr); + if (portToRegistry == null) { + portToRegistry = portToBind; } - if (port == null || port <= 0) { - port = getRandomPort(name); - if (port == null || port < 0) { - port = NetUtils.getAvailablePort(defaultPort); - putRandomPort(name, port); + + return portToRegistry; + } + + private Integer parsePort(String configPort) { + Integer port = null; + if (configPort != null && configPort.length() > 0) { + try { + Integer intPort = Integer.parseInt(configPort); + if (isInvalidPort(intPort)) { + throw new IllegalArgumentException("Specified invalid port from env value:" + configPort); + } + port = intPort; + } catch (Exception e) { + throw new IllegalArgumentException("Specified invalid port from env value:" + configPort); } - logger.warn("Use random available port(" + port + ") for protocol " + name); } + return port; + } - Map map = new HashMap(); - if (anyhost) { - map.put(Constants.ANYHOST_KEY, "true"); + private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List registryURLs) { + String name = protocolConfig.getName(); + if (name == null || name.length() == 0) { + name = "dubbo"; } + + Map map = new HashMap(); map.put(Constants.SIDE_KEY, Constants.PROVIDER_SIDE); map.put(Constants.DUBBO_VERSION_KEY, Version.getVersion()); map.put(Constants.TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis())); @@ -513,6 +597,9 @@ private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List r if ((contextPath == null || contextPath.length() == 0) && provider != null) { contextPath = provider.getContextpath(); } + + String host = this.findConfigedHosts(protocolConfig, registryURLs, map); + Integer port = this.findConfigedPorts(protocolConfig, name, map); URL url = new URL(name, host, port, (contextPath == null || contextPath.length() == 0 ? "" : contextPath + "/") + path, map); if (ExtensionLoader.getExtensionLoader(ConfiguratorFactory.class) @@ -566,7 +653,7 @@ private void exportLocal(URL url) { if (!Constants.LOCAL_PROTOCOL.equalsIgnoreCase(url.getProtocol())) { URL local = URL.valueOf(url.toFullString()) .setProtocol(Constants.LOCAL_PROTOCOL) - .setHost(NetUtils.LOCALHOST) + .setHost(LOCALHOST) .setPort(0); Exporter exporter = protocol.export( proxyFactory.getInvoker(ref, (Class) interfaceClass, local)); diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/integration/RegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/integration/RegistryProtocol.java index 0db690db189..1a73fb570ed 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/integration/RegistryProtocol.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/integration/RegistryProtocol.java @@ -20,7 +20,6 @@ import com.alibaba.dubbo.common.extension.ExtensionLoader; import com.alibaba.dubbo.common.logger.Logger; import com.alibaba.dubbo.common.logger.LoggerFactory; -import com.alibaba.dubbo.common.utils.NetUtils; import com.alibaba.dubbo.common.utils.StringUtils; import com.alibaba.dubbo.common.utils.UrlUtils; import com.alibaba.dubbo.registry.NotifyListener; @@ -37,6 +36,7 @@ import com.alibaba.dubbo.rpc.protocol.InvokerWrapper; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -210,7 +210,10 @@ private Registry getRegistry(final Invoker originInvoker) { private URL getRegistedProviderUrl(final Invoker originInvoker) { URL providerUrl = getProviderUrl(originInvoker); //注册中心看到的地址 - final URL registedProviderUrl = providerUrl.removeParameters(getFilteredKeys(providerUrl)).removeParameter(Constants.MONITOR_KEY); + final URL registedProviderUrl = providerUrl.removeParameters(getFilteredKeys(providerUrl)) + .removeParameter(Constants.MONITOR_KEY) + .removeParameter(Constants.BIND_IP_KEY) + .removeParameter(Constants.BIND_PORT_KEY); return registedProviderUrl; } @@ -276,7 +279,9 @@ private Invoker doRefer(Cluster cluster, Registry registry, Class type RegistryDirectory directory = new RegistryDirectory(type, url); directory.setRegistry(registry); directory.setProtocol(protocol); - URL subscribeUrl = new URL(Constants.CONSUMER_PROTOCOL, NetUtils.getLocalHost(), 0, type.getName(), directory.getUrl().getParameters()); + // REFER_KEY的所有属性 + Map parameters = new HashMap(directory.getUrl().getParameters()); + URL subscribeUrl = new URL(Constants.CONSUMER_PROTOCOL, parameters.remove(Constants.REGISTER_IP_KEY), 0, type.getName(), parameters); if (!Constants.ANY_VALUE.equals(url.getServiceInterface()) && url.getParameter(Constants.REGISTER_KEY, true)) { registry.register(subscribeUrl.addParameters(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY, diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/AbstractServer.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/AbstractServer.java index 7ce8025f2fb..0d166f56e23 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/AbstractServer.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/AbstractServer.java @@ -52,10 +52,13 @@ public abstract class AbstractServer extends AbstractEndpoint implements Server public AbstractServer(URL url, ChannelHandler handler) throws RemotingException { super(url, handler); localAddress = getUrl().toInetSocketAddress(); - String host = url.getParameter(Constants.ANYHOST_KEY, false) - || NetUtils.isInvalidLocalHost(getUrl().getHost()) - ? NetUtils.ANYHOST : getUrl().getHost(); - bindAddress = new InetSocketAddress(host, getUrl().getPort()); + + String bindIp = getUrl().getParameter(Constants.BIND_IP_KEY, getUrl().getHost()); + int bindPort = getUrl().getParameter(Constants.BIND_PORT_KEY, getUrl().getPort()); + if (url.getParameter(Constants.ANYHOST_KEY, false) || NetUtils.isInvalidLocalHost(bindIp)) { + bindIp = NetUtils.ANYHOST; + } + bindAddress = new InetSocketAddress(bindIp, bindPort); this.accepts = url.getParameter(Constants.ACCEPTS_KEY, Constants.DEFAULT_ACCEPTS); this.idleTimeout = url.getParameter(Constants.IDLE_TIMEOUT_KEY, Constants.DEFAULT_IDLE_TIMEOUT); try { diff --git a/dubbo-remoting/dubbo-remoting-http/src/main/java/com/alibaba/dubbo/remoting/http/jetty/JettyHttpServer.java b/dubbo-remoting/dubbo-remoting-http/src/main/java/com/alibaba/dubbo/remoting/http/jetty/JettyHttpServer.java index 56e7f45fb03..fc478ce4fbd 100644 --- a/dubbo-remoting/dubbo-remoting-http/src/main/java/com/alibaba/dubbo/remoting/http/jetty/JettyHttpServer.java +++ b/dubbo-remoting/dubbo-remoting-http/src/main/java/com/alibaba/dubbo/remoting/http/jetty/JettyHttpServer.java @@ -38,7 +38,7 @@ public class JettyHttpServer extends AbstractHttpServer { public JettyHttpServer(URL url, final HttpHandler handler) { super(url, handler); - DispatcherServlet.addHttpHandler(url.getPort(), handler); + DispatcherServlet.addHttpHandler(url.getParameter(Constants.BIND_PORT_KEY, url.getPort()), handler); int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS); QueuedThreadPool threadPool = new QueuedThreadPool(); @@ -47,10 +47,12 @@ public JettyHttpServer(URL url, final HttpHandler handler) { threadPool.setMinThreads(threads); SelectChannelConnector connector = new SelectChannelConnector(); - if (!url.isAnyHost() && NetUtils.isValidLocalHost(url.getHost())) { - connector.setHost(url.getHost()); + + String bindIp = url.getParameter(Constants.BIND_IP_KEY, url.getHost()); + if (!url.isAnyHost() && NetUtils.isValidLocalHost(bindIp)) { + connector.setHost(bindIp); } - connector.setPort(url.getPort()); + connector.setPort(url.getParameter(Constants.BIND_PORT_KEY, url.getPort())); server = new Server(); server.setThreadPool(threadPool); @@ -65,7 +67,7 @@ public JettyHttpServer(URL url, final HttpHandler handler) { try { server.start(); } catch (Exception e) { - throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: " + throw new IllegalStateException("Failed to start jetty server on " + url.getParameter(Constants.BIND_IP_KEY) + ":" + url.getParameter(Constants.BIND_PORT_KEY) + ", cause: " + e.getMessage(), e); } } diff --git a/dubbo-remoting/dubbo-remoting-http/src/main/java/com/alibaba/dubbo/remoting/http/servlet/ServletHttpServer.java b/dubbo-remoting/dubbo-remoting-http/src/main/java/com/alibaba/dubbo/remoting/http/servlet/ServletHttpServer.java index 9f27354e232..c75cc1b50d7 100644 --- a/dubbo-remoting/dubbo-remoting-http/src/main/java/com/alibaba/dubbo/remoting/http/servlet/ServletHttpServer.java +++ b/dubbo-remoting/dubbo-remoting-http/src/main/java/com/alibaba/dubbo/remoting/http/servlet/ServletHttpServer.java @@ -15,6 +15,7 @@ */ package com.alibaba.dubbo.remoting.http.servlet; +import com.alibaba.dubbo.common.Constants; import com.alibaba.dubbo.common.URL; import com.alibaba.dubbo.remoting.http.HttpHandler; import com.alibaba.dubbo.remoting.http.support.AbstractHttpServer; @@ -23,7 +24,7 @@ public class ServletHttpServer extends AbstractHttpServer { public ServletHttpServer(URL url, HttpHandler handler) { super(url, handler); - DispatcherServlet.addHttpHandler(url.getPort(), handler); + DispatcherServlet.addHttpHandler(url.getParameter(Constants.BIND_PORT_KEY, 8080), handler); } } \ No newline at end of file diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/protocol/AbstractProxyProtocol.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/protocol/AbstractProxyProtocol.java index b26a41fd6bc..a088768c83e 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/protocol/AbstractProxyProtocol.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/protocol/AbstractProxyProtocol.java @@ -16,7 +16,9 @@ package com.alibaba.dubbo.rpc.protocol; +import com.alibaba.dubbo.common.Constants; import com.alibaba.dubbo.common.URL; +import com.alibaba.dubbo.common.utils.NetUtils; import com.alibaba.dubbo.rpc.Exporter; import com.alibaba.dubbo.rpc.Invocation; import com.alibaba.dubbo.rpc.Invoker; @@ -121,6 +123,14 @@ protected RpcException getRpcException(Class type, URL url, Invocation invoca return re; } + protected String getAddr(URL url) { + String bindIp = url.getParameter(Constants.BIND_IP_KEY, url.getHost()); + if (url.getParameter(Constants.ANYHOST_KEY, false)) { + bindIp = Constants.ANYHOST_VALUE; + } + return NetUtils.getIpByHost(bindIp) + ":" + url.getParameter(Constants.BIND_PORT_KEY, url.getPort()); + } + protected int getErrorCode(Throwable e) { return RpcException.UNKNOWN_EXCEPTION; } diff --git a/dubbo-rpc/dubbo-rpc-hessian/src/main/java/com/alibaba/dubbo/rpc/protocol/hessian/HessianProtocol.java b/dubbo-rpc/dubbo-rpc-hessian/src/main/java/com/alibaba/dubbo/rpc/protocol/hessian/HessianProtocol.java index bb0c5e6437d..33292631fbf 100644 --- a/dubbo-rpc/dubbo-rpc-hessian/src/main/java/com/alibaba/dubbo/rpc/protocol/hessian/HessianProtocol.java +++ b/dubbo-rpc/dubbo-rpc-hessian/src/main/java/com/alibaba/dubbo/rpc/protocol/hessian/HessianProtocol.java @@ -65,7 +65,7 @@ public int getDefaultPort() { } protected Runnable doExport(T impl, Class type, URL url) throws RpcException { - String addr = url.getIp() + ":" + url.getPort(); + String addr = getAddr(url); HttpServer server = serverMap.get(addr); if (server == null) { server = httpBinder.bind(url, new HessianHandler()); diff --git a/dubbo-rpc/dubbo-rpc-http/src/main/java/com/alibaba/dubbo/rpc/protocol/http/HttpProtocol.java b/dubbo-rpc/dubbo-rpc-http/src/main/java/com/alibaba/dubbo/rpc/protocol/http/HttpProtocol.java index a7cfa2a373a..f06bf676427 100644 --- a/dubbo-rpc/dubbo-rpc-http/src/main/java/com/alibaba/dubbo/rpc/protocol/http/HttpProtocol.java +++ b/dubbo-rpc/dubbo-rpc-http/src/main/java/com/alibaba/dubbo/rpc/protocol/http/HttpProtocol.java @@ -67,7 +67,7 @@ public int getDefaultPort() { } protected Runnable doExport(final T impl, Class type, URL url) throws RpcException { - String addr = url.getIp() + ":" + url.getPort(); + String addr = getAddr(url); HttpServer server = serverMap.get(addr); if (server == null) { server = httpBinder.bind(url, new InternalHandler()); diff --git a/dubbo-rpc/dubbo-rpc-webservice/src/main/java/com/alibaba/dubbo/rpc/protocol/webservice/WebServiceProtocol.java b/dubbo-rpc/dubbo-rpc-webservice/src/main/java/com/alibaba/dubbo/rpc/protocol/webservice/WebServiceProtocol.java index e9ad4692073..2900307c6b2 100644 --- a/dubbo-rpc/dubbo-rpc-webservice/src/main/java/com/alibaba/dubbo/rpc/protocol/webservice/WebServiceProtocol.java +++ b/dubbo-rpc/dubbo-rpc-webservice/src/main/java/com/alibaba/dubbo/rpc/protocol/webservice/WebServiceProtocol.java @@ -78,7 +78,7 @@ public int getDefaultPort() { } protected Runnable doExport(T impl, Class type, URL url) throws RpcException { - String addr = url.getIp() + ":" + url.getPort(); + String addr = getAddr(url); HttpServer httpServer = serverMap.get(addr); if (httpServer == null) { httpServer = httpBinder.bind(url, new WebServiceHandler());