This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch dev-metadata
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
The following commit(s) were added to refs/heads/dev-metadata by this push:
new 123c66d Clear dependency of commons-lang in RegistryProtocol
123c66d is described below
commit 123c66d9cce964ae8c6a3a84c6138e1a4b6424a4
Author: ken.lj <[email protected]>
AuthorDate: Wed Oct 17 16:48:05 2018 +0800
Clear dependency of commons-lang in RegistryProtocol
---
dubbo-dependencies-bom/pom.xml | 6 +++
.../registry/integration/RegistryProtocol.java | 52 ++++++++--------------
dubbo-registry/dubbo-registry-default/pom.xml | 5 +++
.../dubbo/registry/dubbo/RegistryProtocolTest.java | 13 +++---
4 files changed, 36 insertions(+), 40 deletions(-)
diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml
index 9c08d92..4cd3a04 100644
--- a/dubbo-dependencies-bom/pom.xml
+++ b/dubbo-dependencies-bom/pom.xml
@@ -102,6 +102,7 @@
<archaius_version>0.7.6</archaius_version>
<snakeyaml_version>1.20</snakeyaml_version>
<commons_configuration_version>1.8</commons_configuration_version>
+ <commons_lang3_version>3.8.1</commons_lang3_version>
<rs_api_version>2.0</rs_api_version>
<resteasy_version>3.0.19.Final</resteasy_version>
@@ -379,6 +380,11 @@
<version>${commons_configuration_version}</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>${commons_lang3_version}</version>
+ </dependency>
<!-- for dubbo-rpc-webservice -->
diff --git
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
index 7c112e2..35b6eaf 100644
---
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
+++
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
@@ -16,7 +16,6 @@
*/
package org.apache.dubbo.registry.integration;
-import org.apache.commons.lang.ArrayUtils;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
@@ -60,32 +59,17 @@ import java.util.stream.Collectors;
import static org.apache.dubbo.common.Constants.ACCEPT_FOREIGN_IP;
import static org.apache.dubbo.common.Constants.ADD_PARAM_KEYS_KEY;
import static org.apache.dubbo.common.Constants.APPLICATION_KEY;
-import static org.apache.dubbo.common.Constants.CLUSTER_KEY;
-import static org.apache.dubbo.common.Constants.CODEC_KEY;
import static org.apache.dubbo.common.Constants.CONFIGURATORS_SUFFIX;
import static org.apache.dubbo.common.Constants.CONFIG_PROTOCOL;
-import static org.apache.dubbo.common.Constants.CONNECTIONS_KEY;
-import static org.apache.dubbo.common.Constants.DEPRECATED_KEY;
-import static org.apache.dubbo.common.Constants.EXCHANGER_KEY;
+import static org.apache.dubbo.common.Constants.EXCHANGING_KEYS;
import static org.apache.dubbo.common.Constants.EXPORT_KEY;
-import static org.apache.dubbo.common.Constants.GROUP_KEY;
import static org.apache.dubbo.common.Constants.INTERFACES;
import static org.apache.dubbo.common.Constants.INTERFACE_KEY;
-import static org.apache.dubbo.common.Constants.LOADBALANCE_KEY;
import static org.apache.dubbo.common.Constants.METHODS_KEY;
-import static org.apache.dubbo.common.Constants.MOCK_KEY;
-import static org.apache.dubbo.common.Constants.PATH_KEY;
import static org.apache.dubbo.common.Constants.QOS_ENABLE;
import static org.apache.dubbo.common.Constants.QOS_PORT;
import static org.apache.dubbo.common.Constants.REFER_KEY;
-import static org.apache.dubbo.common.Constants.SERIALIZATION_KEY;
-import static org.apache.dubbo.common.Constants.TIMEOUT_KEY;
-import static org.apache.dubbo.common.Constants.TIMESTAMP_KEY;
-import static org.apache.dubbo.common.Constants.TOKEN_KEY;
import static org.apache.dubbo.common.Constants.VALIDATION_KEY;
-import static org.apache.dubbo.common.Constants.VERSION_KEY;
-import static org.apache.dubbo.common.Constants.WARMUP_KEY;
-import static org.apache.dubbo.common.Constants.WEIGHT_KEY;
/**
* RegistryProtocol
@@ -301,7 +285,7 @@ public class RegistryProtocol implements Protocol {
*/
private URL getRegistedProviderUrl(final URL providerUrl, final URL
registryUrl) {
//The address you see at the registry
- if(!registryUrl.getParameter(Constants.SIMPLE_KEY,false)){
+ if (!registryUrl.getParameter(Constants.SIMPLE_KEY, false)) {
final URL registedProviderUrl =
providerUrl.removeParameters(getFilteredKeys(providerUrl))
.removeParameter(Constants.MONITOR_KEY)
.removeParameter(Constants.BIND_IP_KEY)
@@ -312,13 +296,8 @@ public class RegistryProtocol implements Protocol {
.removeParameter(VALIDATION_KEY)
.removeParameter(INTERFACES);
return registedProviderUrl;
- }else{
- String[] addionalParameterKeys =
registryUrl.getParameter(ADD_PARAM_KEYS_KEY, new String[0]);
- String[] registryParams = {APPLICATION_KEY, CODEC_KEY,
EXCHANGER_KEY, SERIALIZATION_KEY, CLUSTER_KEY, CONNECTIONS_KEY, DEPRECATED_KEY,
- GROUP_KEY, LOADBALANCE_KEY, MOCK_KEY, PATH_KEY,
TIMEOUT_KEY, TOKEN_KEY, VERSION_KEY, WARMUP_KEY, WEIGHT_KEY, TIMESTAMP_KEY};
- ArrayUtils.addAll(registryParams, addionalParameterKeys);
- String[] methods = providerUrl.getParameter(METHODS_KEY,
(String[]) null);
- return URL.valueOf(providerUrl, registryParams, methods);
+ } else {
+ return URL.valueOf(providerUrl,
getParamsToRegistry(registryUrl.getParameter(ADD_PARAM_KEYS_KEY, new
String[0])), providerUrl.getParameter(METHODS_KEY, (String[]) null));
}
}
@@ -405,20 +384,25 @@ public class RegistryProtocol implements Protocol {
}
private URL getRegistedConsumerUrl(final URL consumerUrl, URL registryUrl)
{
- if(!registryUrl.getParameter(Constants.SIMPLE_KEY,false)){
+ if (!registryUrl.getParameter(Constants.SIMPLE_KEY, false)) {
return consumerUrl.addParameters(Constants.CATEGORY_KEY,
Constants.CONSUMERS_CATEGORY,
Constants.CHECK_KEY, String.valueOf(false));
- }else{
- String[] addionalParameterKeys =
registryUrl.getParameter(ADD_PARAM_KEYS_KEY, new String[0]);
- String[] registryParams = {APPLICATION_KEY, CODEC_KEY,
EXCHANGER_KEY, SERIALIZATION_KEY, CLUSTER_KEY, CONNECTIONS_KEY, DEPRECATED_KEY,
- GROUP_KEY, LOADBALANCE_KEY, MOCK_KEY, PATH_KEY,
TIMEOUT_KEY, TOKEN_KEY, VERSION_KEY, WARMUP_KEY, WEIGHT_KEY, TIMESTAMP_KEY};
- ArrayUtils.addAll(registryParams, addionalParameterKeys);
- String[] methods = consumerUrl.getParameter(METHODS_KEY,
(String[]) null);
- return URL.valueOf(consumerUrl, registryParams,
methods).addParameters(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY,
- Constants.CHECK_KEY, String.valueOf(false));
+ } else {
+ return URL.valueOf(consumerUrl, getParamsToRegistry(registryUrl
+ .getParameter(ADD_PARAM_KEYS_KEY, new String[0])),
consumerUrl.getParameter(METHODS_KEY, (String[]) null))
+ .addParameters(Constants.CATEGORY_KEY,
Constants.CONSUMERS_CATEGORY, Constants.CHECK_KEY, String.valueOf(false));
}
}
+ // available to test
+ public String[] getParamsToRegistry(String[] addionalParameterKeys) {
+ int additionalLen = addionalParameterKeys.length;
+ String[] registryParams = new String[EXCHANGING_KEYS.length +
additionalLen];
+ System.arraycopy(EXCHANGING_KEYS, 0, registryParams, 0,
EXCHANGING_KEYS.length);
+ System.arraycopy(addionalParameterKeys, 0, registryParams,
EXCHANGING_KEYS.length, additionalLen);
+ return registryParams;
+ }
+
@Override
public void destroy() {
List<Exporter<?>> exporters = new
ArrayList<Exporter<?>>(bounds.values());
diff --git a/dubbo-registry/dubbo-registry-default/pom.xml
b/dubbo-registry/dubbo-registry-default/pom.xml
index 3144efb..ff9bb63 100644
--- a/dubbo-registry/dubbo-registry-default/pom.xml
+++ b/dubbo-registry/dubbo-registry-default/pom.xml
@@ -59,5 +59,10 @@
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
diff --git
a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryProtocolTest.java
b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryProtocolTest.java
index 994f77d..855a010 100644
---
a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryProtocolTest.java
+++
b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryProtocolTest.java
@@ -16,6 +16,7 @@
*/
package org.apache.dubbo.registry.dubbo;
+import org.apache.commons.lang3.ArrayUtils;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
@@ -58,12 +59,12 @@ public class RegistryProtocolTest {
final private Protocol protocol =
ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
@Test
- public void testSystemArray() {
- String[] addionalParameterKeys = {"key1", "key2"};
- int additionalLen = addionalParameterKeys.length;
- String[] registryParams = new String[additionalLen +
EXCHANGING_KEYS.length];
- System.arraycopy(addionalParameterKeys, 0, registryParams,
EXCHANGING_KEYS.length, additionalLen);
- System.out.println(addionalParameterKeys);
+ public void testGetParamsToRegistry() {
+ RegistryProtocol registryProtocol = new RegistryProtocol();
+ String[] additionalParams = new String[]{"key1", "key2"};
+ String[] registryParams =
registryProtocol.getParamsToRegistry(additionalParams);
+ String[] expectParams = ArrayUtils.addAll(EXCHANGING_KEYS,
additionalParams);
+ Assert.assertArrayEquals(expectParams, registryParams);
}
@Test