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 2021/02/22 03:25:03 UTC
[dubbo] branch master updated: Remove parameters from registryUrl
to prevent config pollution (#7189)
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 b0016ff Remove parameters from registryUrl to prevent config pollution (#7189)
b0016ff is described below
commit b0016ff69212a7c15e23f2fda5065d5b1c16b869
Author: Albumen Kevin <jh...@gmail.com>
AuthorDate: Mon Feb 22 11:24:34 2021 +0800
Remove parameters from registryUrl to prevent config pollution (#7189)
Fix #7188
---
.../dubbo/rpc/cluster/directory/AbstractDirectory.java | 18 +++++++++++++-----
.../dubbo/rpc/cluster/directory/StaticDirectory.java | 2 +-
.../dubbo/registry/integration/DynamicDirectory.java | 2 +-
3 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java
index fffb40e..95a540c 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java
@@ -40,7 +40,6 @@ import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY;
/**
* Abstract implementation of Directory: Invoker list returned from this Directory's list method have been filtered by Routers
- *
*/
public abstract class AbstractDirectory<T> implements Directory<T> {
@@ -59,10 +58,14 @@ public abstract class AbstractDirectory<T> implements Directory<T> {
protected RouterChain<T> routerChain;
public AbstractDirectory(URL url) {
- this(url, null);
+ this(url, null, false);
+ }
+
+ public AbstractDirectory(URL url, boolean isUrlFromRegistry) {
+ this(url, null, isUrlFromRegistry);
}
- public AbstractDirectory(URL url, RouterChain<T> routerChain) {
+ public AbstractDirectory(URL url, RouterChain<T> routerChain, boolean isUrlFromRegistry) {
if (url == null) {
throw new IllegalArgumentException("url == null");
}
@@ -72,8 +75,13 @@ public abstract class AbstractDirectory<T> implements Directory<T> {
this.consumedProtocol = this.queryMap.get(PROTOCOL_KEY) == null ? DUBBO : this.queryMap.get(PROTOCOL_KEY);
this.url = url.removeParameter(REFER_KEY).removeParameter(MONITOR_KEY);
- this.consumerUrl = this.url.setProtocol(consumedProtocol).setPath(path == null ? queryMap.get(INTERFACE_KEY) : path).addParameters(queryMap)
- .removeParameter(MONITOR_KEY);
+ URL consumerUrlFrom = this.url.setProtocol(consumedProtocol)
+ .setPath(path == null ? queryMap.get(INTERFACE_KEY) : path);
+ if (isUrlFromRegistry) {
+ // reserve parameters if url is already a consumer url
+ consumerUrlFrom = consumerUrlFrom.clearParameters();
+ }
+ this.consumerUrl = consumerUrlFrom.addParameters(queryMap).removeParameter(MONITOR_KEY);
setRouterChain(routerChain);
}
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java
index 0595c63..db1b202 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java
@@ -49,7 +49,7 @@ public class StaticDirectory<T> extends AbstractDirectory<T> {
}
public StaticDirectory(URL url, List<Invoker<T>> invokers, RouterChain<T> routerChain) {
- super(url == null && CollectionUtils.isNotEmpty(invokers) ? invokers.get(0).getUrl() : url, routerChain);
+ super(url == null && CollectionUtils.isNotEmpty(invokers) ? invokers.get(0).getUrl() : url, routerChain, false);
if (CollectionUtils.isEmpty(invokers)) {
throw new IllegalArgumentException("invokers == null");
}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/DynamicDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/DynamicDirectory.java
index 01b0600..486fd57 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/DynamicDirectory.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/DynamicDirectory.java
@@ -95,7 +95,7 @@ public abstract class DynamicDirectory<T> extends AbstractDirectory<T> implement
protected ServiceInstancesChangedListener serviceListener;
public DynamicDirectory(Class<T> serviceType, URL url) {
- super(url);
+ super(url, true);
if (serviceType == null) {
throw new IllegalArgumentException("service type is null.");
}