You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2020/01/31 08:11:49 UTC
[dubbo] branch master updated: When using zookeeper and
ConfigCenterConfig is null, don't set port attribute (#5617)
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new 9ae6ed7 When using zookeeper and ConfigCenterConfig is null,don't set port attribute (#5617)
9ae6ed7 is described below
commit 9ae6ed76c9ed7f3e3cf7b9e5f3c79e8f1504b3a0
Author: lkj41110 <80...@qq.com>
AuthorDate: Fri Jan 31 16:11:35 2020 +0800
When using zookeeper and ConfigCenterConfig is null,don't set port attribute (#5617)
fix #5322
---
.../apache/dubbo/config/ConfigCenterConfig.java | 46 ++++++++++++++++++++++
.../dubbo/config/bootstrap/DubboBootstrap.java | 1 +
2 files changed, 47 insertions(+)
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java
index 0b552bf..0e01609 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java
@@ -18,6 +18,7 @@ package org.apache.dubbo.config;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.CommonConstants;
+import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.common.utils.UrlUtils;
import org.apache.dubbo.config.support.Parameter;
@@ -42,6 +43,7 @@ public class ConfigCenterConfig extends AbstractConfig {
private String protocol;
private String address;
+ private Integer port;
/* The config center cluster, it's real meaning may very on different Config Center products. */
private String cluster;
@@ -138,6 +140,26 @@ public class ConfigCenterConfig extends AbstractConfig {
public void setAddress(String address) {
this.address = address;
+ if (address != null) {
+ try {
+ URL url = URL.valueOf(address);
+ setUsername(url.getUsername());
+ setPassword(url.getPassword());
+ updateIdIfAbsent(url.getProtocol());
+ updateProtocolIfAbsent(url.getProtocol());
+ updatePortIfAbsent(url.getPort());
+ updateParameters(url.getParameters());
+ } catch (Exception ignored) {
+ }
+ }
+ }
+
+ public Integer getPort() {
+ return port;
+ }
+
+ public void setPort(Integer port) {
+ this.port = port;
}
public String getCluster() {
@@ -240,4 +262,28 @@ public class ConfigCenterConfig extends AbstractConfig {
return address.contains("://") || StringUtils.isNotEmpty(protocol);
}
+
+ protected void updatePortIfAbsent(Integer value) {
+ if (value != null && value > 0 && port == null) {
+ this.port = value;
+ }
+ }
+
+ protected void updateProtocolIfAbsent(String value) {
+ if (StringUtils.isNotEmpty(value) && StringUtils.isEmpty(protocol)) {
+ this.protocol = value;
+ }
+ }
+
+ public void updateParameters(Map<String, String> parameters) {
+ if (CollectionUtils.isEmptyMap(parameters)) {
+ return;
+ }
+ if (this.parameters == null) {
+ this.parameters = parameters;
+ } else {
+ this.parameters.putAll(parameters);
+ }
+ }
+
}
diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java
index a6830ca..702d198 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java
@@ -642,6 +642,7 @@ public class DubboBootstrap extends GenericEventListener {
}
cc.getParameters().put(CLIENT_KEY, registryConfig.getClient());
cc.setProtocol(registryConfig.getProtocol());
+ cc.setPort(registryConfig.getPort());
cc.setAddress(registryConfig.getAddress());
cc.setNamespace(registryConfig.getGroup());
cc.setUsername(registryConfig.getUsername());