Skip to content

Commit 6a70284

Browse files
kezhenxu94lixiaojiee
authored andcommitted
replace magic string "dubbo" with constants (#3602)
1 parent 25f2d4c commit 6a70284

File tree

5 files changed

+35
-28
lines changed

5 files changed

+35
-28
lines changed

dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,12 @@ public class Constants {
753753

754754
public static final String HOST_KEY = "host";
755755

756+
public static final String PORT_KEY = "port";
757+
758+
public static final String USERNAME_KEY = "username";
759+
760+
public static final String PASSWORD_KEY = "password";
761+
756762
public static final String ADDRESS_KEY = "address";
757763

758764
public static final String RETRY_TIMES_KEY = "retry.times";

dubbo-common/src/main/java/org/apache/dubbo/common/URL.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,22 +1122,22 @@ public URL clearParameters() {
11221122
}
11231123

11241124
public String getRawParameter(String key) {
1125-
if ("protocol".equals(key)) {
1125+
if (Constants.PROTOCOL_KEY.equals(key)) {
11261126
return protocol;
11271127
}
1128-
if ("username".equals(key)) {
1128+
if (Constants.USERNAME_KEY.equals(key)) {
11291129
return username;
11301130
}
1131-
if ("password".equals(key)) {
1131+
if (Constants.PASSWORD_KEY.equals(key)) {
11321132
return password;
11331133
}
1134-
if ("host".equals(key)) {
1134+
if (Constants.HOST_KEY.equals(key)) {
11351135
return host;
11361136
}
1137-
if ("port".equals(key)) {
1137+
if (Constants.PORT_KEY.equals(key)) {
11381138
return String.valueOf(port);
11391139
}
1140-
if ("path".equals(key)) {
1140+
if (Constants.PATH_KEY.equals(key)) {
11411141
return path;
11421142
}
11431143
return getParameter(key);
@@ -1146,22 +1146,22 @@ public String getRawParameter(String key) {
11461146
public Map<String, String> toMap() {
11471147
Map<String, String> map = new HashMap<String, String>(parameters);
11481148
if (protocol != null) {
1149-
map.put("protocol", protocol);
1149+
map.put(Constants.PROTOCOL_KEY, protocol);
11501150
}
11511151
if (username != null) {
1152-
map.put("username", username);
1152+
map.put(Constants.USERNAME_KEY, username);
11531153
}
11541154
if (password != null) {
1155-
map.put("password", password);
1155+
map.put(Constants.USERNAME_KEY, password);
11561156
}
11571157
if (host != null) {
1158-
map.put("host", host);
1158+
map.put(Constants.HOST_KEY, host);
11591159
}
11601160
if (port > 0) {
1161-
map.put("port", String.valueOf(port));
1161+
map.put(Constants.PORT_KEY, String.valueOf(port));
11621162
}
11631163
if (path != null) {
1164-
map.put("path", path);
1164+
map.put(Constants.PATH_KEY, path);
11651165
}
11661166
return map;
11671167
}

dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,22 @@ public static URL parseURL(String address, Map<String, String> defaults) {
6363
url += URL_PARAM_STARTING_SYMBOL + Constants.BACKUP_KEY + "=" + backup.toString();
6464
}
6565
}
66-
String defaultProtocol = defaults == null ? null : defaults.get("protocol");
66+
String defaultProtocol = defaults == null ? null : defaults.get(Constants.PROTOCOL_KEY);
6767
if (defaultProtocol == null || defaultProtocol.length() == 0) {
68-
defaultProtocol = "dubbo";
68+
defaultProtocol = Constants.DUBBO_PROTOCOL;
6969
}
70-
String defaultUsername = defaults == null ? null : defaults.get("username");
71-
String defaultPassword = defaults == null ? null : defaults.get("password");
72-
int defaultPort = StringUtils.parseInteger(defaults == null ? null : defaults.get("port"));
73-
String defaultPath = defaults == null ? null : defaults.get("path");
70+
String defaultUsername = defaults == null ? null : defaults.get(Constants.USERNAME_KEY);
71+
String defaultPassword = defaults == null ? null : defaults.get(Constants.PASSWORD_KEY);
72+
int defaultPort = StringUtils.parseInteger(defaults == null ? null : defaults.get(Constants.PORT_KEY));
73+
String defaultPath = defaults == null ? null : defaults.get(Constants.PATH_KEY);
7474
Map<String, String> defaultParameters = defaults == null ? null : new HashMap<String, String>(defaults);
7575
if (defaultParameters != null) {
76-
defaultParameters.remove("protocol");
77-
defaultParameters.remove("username");
78-
defaultParameters.remove("password");
79-
defaultParameters.remove("host");
80-
defaultParameters.remove("port");
81-
defaultParameters.remove("path");
76+
defaultParameters.remove(Constants.PROTOCOL_KEY);
77+
defaultParameters.remove(Constants.USERNAME_KEY);
78+
defaultParameters.remove(Constants.PASSWORD_KEY);
79+
defaultParameters.remove(Constants.HOST_KEY);
80+
defaultParameters.remove(Constants.PORT_KEY);
81+
defaultParameters.remove(Constants.PATH_KEY);
8282
}
8383
URL u = URL.valueOf(url);
8484
boolean changed = false;

dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,10 @@ protected List<URL> loadRegistries(boolean provider) {
296296
Map<String, String> map = new HashMap<String, String>();
297297
appendParameters(map, application);
298298
appendParameters(map, config);
299-
map.put("path", RegistryService.class.getName());
299+
map.put(Constants.PATH_KEY, RegistryService.class.getName());
300300
appendRuntimeParameters(map);
301-
if (!map.containsKey("protocol")) {
302-
map.put("protocol", "dubbo");
301+
if (!map.containsKey(Constants.PROTOCOL_KEY)) {
302+
map.put(Constants.PROTOCOL_KEY, Constants.DUBBO_PROTOCOL);
303303
}
304304
List<URL> urls = UrlUtils.parseURLs(address, map);
305305

dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitorFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.dubbo.rpc.ProxyFactory;
2727

2828
import static org.apache.dubbo.common.Constants.CHECK_KEY;
29+
import static org.apache.dubbo.common.Constants.DUBBO_PROTOCOL;
2930
import static org.apache.dubbo.common.Constants.PROTOCOL_KEY;
3031
import static org.apache.dubbo.common.Constants.REFERENCE_FILTER_KEY;
3132

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

4950
@Override
5051
protected Monitor createMonitor(URL url) {
51-
url = url.setProtocol(url.getParameter(PROTOCOL_KEY, "dubbo"));
52+
url = url.setProtocol(url.getParameter(PROTOCOL_KEY, DUBBO_PROTOCOL));
5253
if (StringUtils.isEmpty(url.getPath())) {
5354
url = url.setPath(MonitorService.class.getName());
5455
}

0 commit comments

Comments
 (0)