Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove parameters from registryUrl to prevent config pollution #7189

Merged
merged 6 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

/**
* 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> {

Expand All @@ -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");
}
Expand All @@ -72,8 +75,13 @@ public AbstractDirectory(URL url, RouterChain<T> routerChain) {
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();
chickenlj marked this conversation as resolved.
Show resolved Hide resolved
}
this.consumerUrl = consumerUrlFrom.addParameters(queryMap).removeParameter(MONITOR_KEY);

setRouterChain(routerChain);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public StaticDirectory(URL url, List<Invoker<T>> invokers) {
}

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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down