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

[CLEAN-UP] Replace magic string with constants #3602

Merged
merged 1 commit into from
Mar 6, 2019
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
@@ -753,6 +753,12 @@ public class Constants {

public static final String HOST_KEY = "host";

public static final String PORT_KEY = "port";

public static final String USERNAME_KEY = "username";

public static final String PASSWORD_KEY = "password";

public static final String ADDRESS_KEY = "address";

public static final String RETRY_TIMES_KEY = "retry.times";
24 changes: 12 additions & 12 deletions dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
Original file line number Diff line number Diff line change
@@ -1122,22 +1122,22 @@ public URL clearParameters() {
}

public String getRawParameter(String key) {
if ("protocol".equals(key)) {
if (Constants.PROTOCOL_KEY.equals(key)) {
return protocol;
}
if ("username".equals(key)) {
if (Constants.USERNAME_KEY.equals(key)) {
return username;
}
if ("password".equals(key)) {
if (Constants.PASSWORD_KEY.equals(key)) {
return password;
}
if ("host".equals(key)) {
if (Constants.HOST_KEY.equals(key)) {
return host;
}
if ("port".equals(key)) {
if (Constants.PORT_KEY.equals(key)) {
return String.valueOf(port);
}
if ("path".equals(key)) {
if (Constants.PATH_KEY.equals(key)) {
return path;
}
return getParameter(key);
@@ -1146,22 +1146,22 @@ public String getRawParameter(String key) {
public Map<String, String> toMap() {
Map<String, String> map = new HashMap<String, String>(parameters);
if (protocol != null) {
map.put("protocol", protocol);
map.put(Constants.PROTOCOL_KEY, protocol);
}
if (username != null) {
map.put("username", username);
map.put(Constants.USERNAME_KEY, username);
}
if (password != null) {
map.put("password", password);
map.put(Constants.USERNAME_KEY, password);
}
if (host != null) {
map.put("host", host);
map.put(Constants.HOST_KEY, host);
}
if (port > 0) {
map.put("port", String.valueOf(port));
map.put(Constants.PORT_KEY, String.valueOf(port));
}
if (path != null) {
map.put("path", path);
map.put(Constants.PATH_KEY, path);
}
return map;
}
Original file line number Diff line number Diff line change
@@ -63,22 +63,22 @@ public static URL parseURL(String address, Map<String, String> defaults) {
url += URL_PARAM_STARTING_SYMBOL + Constants.BACKUP_KEY + "=" + backup.toString();
}
}
String defaultProtocol = defaults == null ? null : defaults.get("protocol");
String defaultProtocol = defaults == null ? null : defaults.get(Constants.PROTOCOL_KEY);
if (defaultProtocol == null || defaultProtocol.length() == 0) {
defaultProtocol = "dubbo";
defaultProtocol = Constants.DUBBO_PROTOCOL;
}
String defaultUsername = defaults == null ? null : defaults.get("username");
String defaultPassword = defaults == null ? null : defaults.get("password");
int defaultPort = StringUtils.parseInteger(defaults == null ? null : defaults.get("port"));
String defaultPath = defaults == null ? null : defaults.get("path");
String defaultUsername = defaults == null ? null : defaults.get(Constants.USERNAME_KEY);
String defaultPassword = defaults == null ? null : defaults.get(Constants.PASSWORD_KEY);
int defaultPort = StringUtils.parseInteger(defaults == null ? null : defaults.get(Constants.PORT_KEY));
String defaultPath = defaults == null ? null : defaults.get(Constants.PATH_KEY);
Map<String, String> defaultParameters = defaults == null ? null : new HashMap<String, String>(defaults);
if (defaultParameters != null) {
defaultParameters.remove("protocol");
defaultParameters.remove("username");
defaultParameters.remove("password");
defaultParameters.remove("host");
defaultParameters.remove("port");
defaultParameters.remove("path");
defaultParameters.remove(Constants.PROTOCOL_KEY);
defaultParameters.remove(Constants.USERNAME_KEY);
defaultParameters.remove(Constants.PASSWORD_KEY);
defaultParameters.remove(Constants.HOST_KEY);
defaultParameters.remove(Constants.PORT_KEY);
defaultParameters.remove(Constants.PATH_KEY);
}
URL u = URL.valueOf(url);
boolean changed = false;
Original file line number Diff line number Diff line change
@@ -296,10 +296,10 @@ protected List<URL> loadRegistries(boolean provider) {
Map<String, String> map = new HashMap<String, String>();
appendParameters(map, application);
appendParameters(map, config);
map.put("path", RegistryService.class.getName());
map.put(Constants.PATH_KEY, RegistryService.class.getName());
appendRuntimeParameters(map);
if (!map.containsKey("protocol")) {
map.put("protocol", "dubbo");
if (!map.containsKey(Constants.PROTOCOL_KEY)) {
map.put(Constants.PROTOCOL_KEY, Constants.DUBBO_PROTOCOL);
}
List<URL> urls = UrlUtils.parseURLs(address, map);

Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@
import org.apache.dubbo.rpc.ProxyFactory;

import static org.apache.dubbo.common.Constants.CHECK_KEY;
import static org.apache.dubbo.common.Constants.DUBBO_PROTOCOL;
import static org.apache.dubbo.common.Constants.PROTOCOL_KEY;
import static org.apache.dubbo.common.Constants.REFERENCE_FILTER_KEY;

@@ -48,7 +49,7 @@ public void setProxyFactory(ProxyFactory proxyFactory) {

@Override
protected Monitor createMonitor(URL url) {
url = url.setProtocol(url.getParameter(PROTOCOL_KEY, "dubbo"));
url = url.setProtocol(url.getParameter(PROTOCOL_KEY, DUBBO_PROTOCOL));
if (StringUtils.isEmpty(url.getPath())) {
url = url.setPath(MonitorService.class.getName());
}