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

[Dubbo-SPECIFY-ADDRESS] fix npe when zk push url #167

Merged
merged 2 commits into from
Nov 21, 2022
Merged
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 @@ -20,8 +20,10 @@
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.url.component.DubboServiceAddressURL;
import org.apache.dubbo.common.url.component.PathURLAddress;
import org.apache.dubbo.common.url.component.ServiceConfigURL;
import org.apache.dubbo.common.url.component.URLParam;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.registry.client.InstanceAddressURL;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
Expand All @@ -47,24 +49,42 @@ public DefaultUserSpecifiedServiceAddressBuilder(ApplicationModel applicationMod

@Override
public <T> URL buildAddress(List<Invoker<T>> invokers, Address address, Invocation invocation, URL consumerUrl) {

boolean useFixed = false;
URL template = null;
if (!invokers.isEmpty()) {
URL template = invokers.iterator().next().getUrl();
template = template.setHost(address.getIp());
if (address.getPort() != 0) {
template = template.setPort(address.getPort());
template = invokers.iterator().next().getUrl();
if (template instanceof InstanceAddressURL) {
useFixed = true;
} else {
if (template.getUrlAddress() == null) {
PathURLAddress urlAddress = new PathURLAddress(template.getProtocol(), template.getUsername(), template.getPassword(), template.getPath(), address.getIp(), address.getPort());
template = new ServiceConfigURL(urlAddress, template.getUrlParam(), template.getAttributes());
} else {
template = template.setHost(address.getIp());
if (address.getPort() != 0) {
template = template.setPort(address.getPort());
}
}
}
return template;

} else {
useFixed = true;
}

if (useFixed) {
String ip = address.getIp();
int port = address.getPort();
String protocol = consumerUrl.getParameter(PROTOCOL_KEY, DUBBO);
if (port == 0) {
port = protocolExtensionLoader.getExtension(protocol).getDefaultPort();
}
return new DubboServiceAddressURL(
new PathURLAddress(protocol, null, null, consumerUrl.getPath(), ip, port),
URLParam.parse(""), consumerUrl, null);
template = new DubboServiceAddressURL(
new PathURLAddress(protocol, null, null, consumerUrl.getPath(), ip, port),
URLParam.parse(""), consumerUrl, null);
}

return template;
}

@Override
Expand All @@ -75,7 +95,7 @@ public <T> URL rebuildAddress(List<Invoker<T>> invokers, Address address, Invoca
parameters.put(GROUP_KEY, consumerUrl.getGroup());
String protocol = StringUtils.isEmpty(url.getProtocol()) ? consumerUrl.getParameter(PROTOCOL_KEY, DUBBO) : url.getProtocol();
return new DubboServiceAddressURL(
new PathURLAddress(protocol, null, null, consumerUrl.getPath(), url.getHost(), url.getPort()),
URLParam.parse(parameters), consumerUrl, null);
new PathURLAddress(protocol, null, null, consumerUrl.getPath(), url.getHost(), url.getPort()),
URLParam.parse(parameters), consumerUrl, null);
}
}