fix: hotfix issue 2560
This commit is contained in:
parent
fd523b5e53
commit
d8714843a0
@ -33,6 +33,7 @@ import com.alibaba.nacos.client.config.utils.ContentUtils;
|
||||
import com.alibaba.nacos.client.config.utils.ParamUtils;
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.utils.ParamUtil;
|
||||
import com.alibaba.nacos.client.utils.ValidatorUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@ -70,6 +71,7 @@ public class NacosConfigService implements ConfigService {
|
||||
private ConfigFilterChainManager configFilterChainManager = new ConfigFilterChainManager();
|
||||
|
||||
public NacosConfigService(Properties properties) throws NacosException {
|
||||
ValidatorUtils.checkInitParam(properties);
|
||||
String encodeTmp = properties.getProperty(PropertyKeyConst.ENCODE);
|
||||
if (StringUtils.isBlank(encodeTmp)) {
|
||||
encode = Constants.ENCODE;
|
||||
|
@ -38,10 +38,10 @@ public class PropertiesChangeParser extends AbstractConfigChangeParser {
|
||||
Properties oldProps = new Properties();
|
||||
Properties newProps = new Properties();
|
||||
|
||||
if (StringUtils.isNotBlank(oldContent)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isNotBlank(oldContent)) {
|
||||
oldProps.load(new StringReader(oldContent));
|
||||
}
|
||||
if (StringUtils.isNotBlank(newContent)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isNotBlank(newContent)) {
|
||||
newProps.load(new StringReader(newContent));
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ public class ServerListManager {
|
||||
}
|
||||
}
|
||||
serverUrls = new ArrayList<String>(serverAddrs);
|
||||
if (StringUtils.isBlank(namespace)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(namespace)) {
|
||||
name = FIXED_NAME + "-" + getFixedNameSuffix(serverAddrs.toArray(new String[serverAddrs.size()]));
|
||||
} else {
|
||||
this.namespace = namespace;
|
||||
@ -94,15 +94,15 @@ public class ServerListManager {
|
||||
properties.setProperty(PropertyKeyConst.ENDPOINT, endpoint);
|
||||
endpoint = initEndpoint(properties);
|
||||
|
||||
if (StringUtils.isBlank(endpoint)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(endpoint)) {
|
||||
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, "endpoint is blank");
|
||||
}
|
||||
if (StringUtils.isBlank(namespace)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(namespace)) {
|
||||
name = endpoint;
|
||||
addressServerUrl = String.format("http://%s:%d/%s/%s", endpoint, endpointPort, contentPath,
|
||||
serverListName);
|
||||
} else {
|
||||
if (StringUtils.isBlank(endpoint)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(endpoint)) {
|
||||
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, "endpoint is blank");
|
||||
}
|
||||
name = endpoint + "-" + namespace;
|
||||
@ -118,7 +118,7 @@ public class ServerListManager {
|
||||
serverAddrsStr = properties.getProperty(PropertyKeyConst.SERVER_ADDR);
|
||||
String namespace = properties.getProperty(PropertyKeyConst.NAMESPACE);
|
||||
initParam(properties);
|
||||
if (StringUtils.isNotEmpty(serverAddrsStr)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isNotEmpty(serverAddrsStr)) {
|
||||
isFixed = true;
|
||||
List<String> serverAddrs = new ArrayList<String>();
|
||||
String[] serverAddrsArr = serverAddrsStr.split(",");
|
||||
@ -135,7 +135,7 @@ public class ServerListManager {
|
||||
}
|
||||
}
|
||||
serverUrls = serverAddrs;
|
||||
if (StringUtils.isBlank(namespace)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(namespace)) {
|
||||
name = FIXED_NAME + "-" + getFixedNameSuffix(serverUrls.toArray(new String[serverUrls.size()]));
|
||||
} else {
|
||||
this.namespace = namespace;
|
||||
@ -144,11 +144,11 @@ public class ServerListManager {
|
||||
+ namespace;
|
||||
}
|
||||
} else {
|
||||
if (StringUtils.isBlank(endpoint)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(endpoint)) {
|
||||
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, "endpoint is blank");
|
||||
}
|
||||
isFixed = false;
|
||||
if (StringUtils.isBlank(namespace)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(namespace)) {
|
||||
name = endpoint;
|
||||
addressServerUrl = String.format("http://%s:%d/%s/%s", endpoint, endpointPort, contentPath,
|
||||
serverListName);
|
||||
@ -167,11 +167,11 @@ public class ServerListManager {
|
||||
endpoint = initEndpoint(properties);
|
||||
|
||||
String contentPathTmp = properties.getProperty(PropertyKeyConst.CONTEXT_PATH);
|
||||
if (!StringUtils.isBlank(contentPathTmp)) {
|
||||
if (!org.apache.commons.lang3.StringUtils.isBlank(contentPathTmp)) {
|
||||
contentPath = contentPathTmp;
|
||||
}
|
||||
String serverListNameTmp = properties.getProperty(PropertyKeyConst.CLUSTER_NAME);
|
||||
if (!StringUtils.isBlank(serverListNameTmp)) {
|
||||
if (!org.apache.commons.lang3.StringUtils.isBlank(serverListNameTmp)) {
|
||||
serverListName = serverListNameTmp;
|
||||
}
|
||||
}
|
||||
@ -185,7 +185,7 @@ public class ServerListManager {
|
||||
}
|
||||
});
|
||||
|
||||
if (StringUtils.isNotBlank(endpointPortTmp)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isNotBlank(endpointPortTmp)) {
|
||||
endpointPort = Integer.parseInt(endpointPortTmp);
|
||||
}
|
||||
|
||||
@ -198,13 +198,13 @@ public class ServerListManager {
|
||||
String.valueOf(ParamUtil.USE_ENDPOINT_PARSING_RULE_DEFAULT_VALUE)));
|
||||
if (Boolean.parseBoolean(isUseEndpointRuleParsing)) {
|
||||
String endpointUrl = ParamUtil.parsingEndpointRule(endpointTmp);
|
||||
if (StringUtils.isNotBlank(endpointUrl)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isNotBlank(endpointUrl)) {
|
||||
serverAddrsStr = "";
|
||||
}
|
||||
return endpointUrl;
|
||||
}
|
||||
|
||||
return StringUtils.isNotBlank(endpointTmp) ? endpointTmp : "";
|
||||
return org.apache.commons.lang3.StringUtils.isNotBlank(endpointTmp) ? endpointTmp : "";
|
||||
}
|
||||
|
||||
public synchronized void start() throws NacosException {
|
||||
@ -360,7 +360,7 @@ public class ServerListManager {
|
||||
}
|
||||
|
||||
public String getCurrentServerAddr() {
|
||||
if (StringUtils.isBlank(currentServerAddr)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(currentServerAddr)) {
|
||||
iterator = iterator();
|
||||
currentServerAddr = iterator.next();
|
||||
}
|
||||
|
@ -35,11 +35,11 @@ public class YmlChangeParser extends AbstractConfigChangeParser {
|
||||
Map<String, Object> oldMap = Collections.emptyMap();
|
||||
Map<String, Object> newMap = Collections.emptyMap();
|
||||
|
||||
if (StringUtils.isNotBlank(oldContent)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isNotBlank(oldContent)) {
|
||||
oldMap = (new Yaml()).load(oldContent);
|
||||
oldMap = getFlattenedMap(oldMap);
|
||||
}
|
||||
if (StringUtils.isNotBlank(newContent)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isNotBlank(newContent)) {
|
||||
newMap = (new Yaml()).load(newContent);
|
||||
newMap = getFlattenedMap(newMap);
|
||||
}
|
||||
@ -57,7 +57,7 @@ public class YmlChangeParser extends AbstractConfigChangeParser {
|
||||
for (Iterator<Map.Entry<String, Object>> itr = source.entrySet().iterator(); itr.hasNext(); ) {
|
||||
Map.Entry<String, Object> e = itr.next();
|
||||
String key = e.getKey();
|
||||
if (StringUtils.isNotBlank(path)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isNotBlank(path)) {
|
||||
if (e.getKey().startsWith("[")) {
|
||||
key = path + key;
|
||||
} else {
|
||||
|
@ -27,6 +27,7 @@ import com.alibaba.nacos.api.selector.ExpressionSelector;
|
||||
import com.alibaba.nacos.api.selector.NoneSelector;
|
||||
import com.alibaba.nacos.client.naming.net.NamingProxy;
|
||||
import com.alibaba.nacos.client.naming.utils.InitUtils;
|
||||
import com.alibaba.nacos.client.utils.ValidatorUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
@ -50,16 +51,15 @@ public class NacosNamingMaintainService implements NamingMaintainService {
|
||||
public NacosNamingMaintainService(String serverList) {
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(PropertyKeyConst.SERVER_ADDR, serverList);
|
||||
|
||||
init(properties);
|
||||
}
|
||||
|
||||
public NacosNamingMaintainService(Properties properties) {
|
||||
|
||||
init(properties);
|
||||
}
|
||||
|
||||
private void init(Properties properties) {
|
||||
ValidatorUtils.checkInitParam(properties);
|
||||
namespace = InitUtils.initNamespaceForNaming(properties);
|
||||
initServerAddr(properties);
|
||||
InitUtils.initWebRootContext();
|
||||
|
@ -35,6 +35,7 @@ import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
||||
import com.alibaba.nacos.client.naming.utils.InitUtils;
|
||||
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
|
||||
import com.alibaba.nacos.client.security.SecurityProxy;
|
||||
import com.alibaba.nacos.client.utils.ValidatorUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
@ -77,7 +78,6 @@ public class NacosNamingService implements NamingService {
|
||||
public NacosNamingService(String serverList) {
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(PropertyKeyConst.SERVER_ADDR, serverList);
|
||||
|
||||
init(properties);
|
||||
}
|
||||
|
||||
@ -86,6 +86,7 @@ public class NacosNamingService implements NamingService {
|
||||
}
|
||||
|
||||
private void init(Properties properties) {
|
||||
ValidatorUtils.checkInitParam(properties);
|
||||
namespace = InitUtils.initNamespaceForNaming(properties);
|
||||
initServerAddr(properties);
|
||||
InitUtils.initWebRootContext();
|
||||
|
@ -77,7 +77,7 @@ public class InitUtils {
|
||||
}
|
||||
});
|
||||
|
||||
if (StringUtils.isEmpty(tmpNamespace) && properties != null) {
|
||||
if (org.apache.commons.lang3.StringUtils.isEmpty(tmpNamespace) && properties != null) {
|
||||
tmpNamespace = properties.getProperty(PropertyKeyConst.NAMESPACE);
|
||||
}
|
||||
|
||||
@ -121,14 +121,14 @@ public class InitUtils {
|
||||
if (isUseEndpointParsingRule) {
|
||||
// Get the set domain name information
|
||||
endpointUrl = ParamUtil.parsingEndpointRule(properties.getProperty(PropertyKeyConst.ENDPOINT));
|
||||
if (StringUtils.isBlank(endpointUrl)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(endpointUrl)) {
|
||||
return "";
|
||||
}
|
||||
} else {
|
||||
endpointUrl = properties.getProperty(PropertyKeyConst.ENDPOINT);
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(endpointUrl)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(endpointUrl)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ public class AppNameUtils {
|
||||
}
|
||||
|
||||
if (serverHome != null && serverHome.startsWith(LINUX_ADMIN_HOME)) {
|
||||
return StringUtils.substringBetween(serverHome, LINUX_ADMIN_HOME, File.separator);
|
||||
return org.apache.commons.lang3.StringUtils.substringBetween(serverHome, LINUX_ADMIN_HOME, File.separator);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -38,7 +38,7 @@ public class IPUtil {
|
||||
}
|
||||
|
||||
private static boolean isMatch(String data, Pattern pattern) {
|
||||
if (StringUtils.isBlank(data)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(data)) {
|
||||
return false;
|
||||
}
|
||||
Matcher mat = pattern.matcher(data);
|
||||
|
@ -15,10 +15,11 @@
|
||||
*/
|
||||
package com.alibaba.nacos.client.utils;
|
||||
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
@ -30,76 +31,6 @@ import java.util.Locale;
|
||||
@Deprecated
|
||||
public class StringUtils {
|
||||
|
||||
private static final int INDEX_NOT_FOUND = -1;
|
||||
|
||||
public static final String EMPTY = "";
|
||||
|
||||
public static boolean isBlank(String str) {
|
||||
int strLen;
|
||||
if (str == null || (strLen = str.length()) == 0) {
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < strLen; i++) {
|
||||
if (!Character.isWhitespace(str.charAt(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isNotBlank(String str) {
|
||||
return !isBlank(str);
|
||||
}
|
||||
|
||||
public static boolean isNotEmpty(String str) {
|
||||
return !StringUtils.isEmpty(str);
|
||||
}
|
||||
|
||||
public static boolean isEmpty(String str) {
|
||||
return str == null || str.length() == 0;
|
||||
}
|
||||
|
||||
public static String defaultIfEmpty(String str, String defaultStr) {
|
||||
return StringUtils.isEmpty(str) ? defaultStr : str;
|
||||
}
|
||||
|
||||
public static boolean equals(String str1, String str2) {
|
||||
return str1 == null ? str2 == null : str1.equals(str2);
|
||||
}
|
||||
|
||||
public static String substringBetween(String str, String open, String close) {
|
||||
if (str == null || open == null || close == null) {
|
||||
return null;
|
||||
}
|
||||
int start = str.indexOf(open);
|
||||
if (start != INDEX_NOT_FOUND) {
|
||||
int end = str.indexOf(close, start + open.length());
|
||||
if (end != INDEX_NOT_FOUND) {
|
||||
return str.substring(start + open.length(), end);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String join(Collection collection, String separator) {
|
||||
if (collection == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
Object[] objects = collection.toArray();
|
||||
|
||||
for (int i = 0; i < collection.size() - 1; i++) {
|
||||
stringBuilder.append(objects[i].toString()).append(separator);
|
||||
}
|
||||
|
||||
if (collection.size() > 0) {
|
||||
stringBuilder.append(objects[collection.size() - 1]);
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
public static String escapeJavaScript(String str) {
|
||||
return escapeJavaStyleString(str, true, true);
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class TemplateUtils {
|
||||
|
||||
public static void stringNotEmptyAndThenExecute(String source, Runnable runnable) {
|
||||
|
||||
if (StringUtils.isNotEmpty(source)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isNotEmpty(source)) {
|
||||
|
||||
try {
|
||||
runnable.run();
|
||||
@ -37,7 +37,7 @@ public class TemplateUtils {
|
||||
|
||||
public static String stringEmptyAndThenExecute(String source, Callable<String> callable) {
|
||||
|
||||
if (StringUtils.isEmpty(source)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isEmpty(source)) {
|
||||
|
||||
try {
|
||||
return callable.call();
|
||||
@ -51,7 +51,7 @@ public class TemplateUtils {
|
||||
|
||||
public static String stringBlankAndThenExecute(String source, Callable<String> callable) {
|
||||
|
||||
if (StringUtils.isBlank(source)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(source)) {
|
||||
|
||||
try {
|
||||
return callable.call();
|
||||
|
@ -40,7 +40,7 @@ public class TenantUtil {
|
||||
public static String getUserTenantForAcm() {
|
||||
String tmp = userTenant;
|
||||
|
||||
if (StringUtils.isBlank(userTenant)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(userTenant)) {
|
||||
tmp = System.getProperty("acm.namespace", "");
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ public class TenantUtil {
|
||||
public static String getUserTenantForAns() {
|
||||
String tmp = userTenant;
|
||||
|
||||
if (StringUtils.isBlank(userTenant)) {
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(userTenant)) {
|
||||
tmp = System.getProperty("ans.namespace");
|
||||
}
|
||||
return tmp;
|
||||
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.client.utils;
|
||||
|
||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* All parameter validation tools
|
||||
*
|
||||
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
|
||||
*/
|
||||
public final class ValidatorUtils {
|
||||
|
||||
private static final Pattern CONTEXT_PATH_MATCH = Pattern.compile("(\\/)\\1+");
|
||||
private static final Pattern IP_MATCH = Pattern.compile("([^\\/:]+)(:\\d+)");
|
||||
|
||||
public static void checkInitParam(Properties properties) {
|
||||
checkServerAddr(properties.getProperty(PropertyKeyConst.SERVER_ADDR));
|
||||
checkContextPath(properties.getProperty(PropertyKeyConst.CONTEXT_PATH));
|
||||
}
|
||||
|
||||
public static void checkServerAddr(String serverAddr) {
|
||||
if (StringUtils.isEmpty(serverAddr)) {
|
||||
throw new IllegalArgumentException("Please set the serverAddr");
|
||||
}
|
||||
String[] addrs;
|
||||
if (serverAddr.contains(",")) {
|
||||
addrs = serverAddr.split(",");
|
||||
} else {
|
||||
addrs = new String[]{serverAddr};
|
||||
}
|
||||
for (String addr : addrs) {
|
||||
Matcher matcher = IP_MATCH.matcher(addr.trim());
|
||||
if (!matcher.find()) {
|
||||
throw new IllegalArgumentException("Incorrect serverAddr address : " + addr + ", example should like ip:port or domain:port");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkContextPath(String contextPath) {
|
||||
if (contextPath == null) {
|
||||
return;
|
||||
}
|
||||
Matcher matcher = CONTEXT_PATH_MATCH.matcher(contextPath);
|
||||
if (matcher.find()) {
|
||||
throw new IllegalArgumentException("Illegal url path expression");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
package com.alibaba.nacos.client;
|
||||
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import static com.alibaba.nacos.client.utils.StringUtils.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@Deprecated
|
||||
public class StringUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testisNotBlank() {
|
||||
assertTrue(isNotBlank("foo"));
|
||||
|
||||
assertFalse(isNotBlank(" "));
|
||||
assertFalse(isNotBlank(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNotEmpty() {
|
||||
assertFalse(isNotEmpty(""));
|
||||
|
||||
assertTrue(isNotEmpty("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultIfEmpty() {
|
||||
assertEquals("foo", defaultIfEmpty("", "foo"));
|
||||
assertEquals("bar", defaultIfEmpty("bar", "foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
assertTrue(StringUtils.equals("foo", "foo"));
|
||||
|
||||
assertFalse(StringUtils.equals("bar", "foo"));
|
||||
assertFalse(StringUtils.equals(" ", "foo"));
|
||||
assertFalse(StringUtils.equals("foo", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubstringBetween() {
|
||||
assertNull(substringBetween(null, null, null));
|
||||
assertNull(substringBetween("", "foo", ""));
|
||||
assertNull(substringBetween("foo", "bar", "baz"));
|
||||
|
||||
assertEquals("", substringBetween("foo", "foo", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoin() {
|
||||
assertNull(join(null, ""));
|
||||
|
||||
Collection collection = new ArrayList();
|
||||
collection.add("foo");
|
||||
collection.add("bar");
|
||||
assertEquals("foo,bar", join(collection, ","));
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package com.alibaba.nacos.client.utils;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ValidatorUtilsTest {
|
||||
|
||||
@Test
|
||||
public void test_context_path_legal() {
|
||||
String contextPath1 = "/nacos";
|
||||
ValidatorUtils.checkContextPath(contextPath1);
|
||||
String contextPath2 = "nacos";
|
||||
ValidatorUtils.checkContextPath(contextPath2);
|
||||
String contextPath3 = "/";
|
||||
ValidatorUtils.checkContextPath(contextPath3);
|
||||
String contextPath4 = "";
|
||||
ValidatorUtils.checkContextPath(contextPath4);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void test_context_path_illegal_1() {
|
||||
String contextPath1 = "//nacos/";
|
||||
ValidatorUtils.checkContextPath(contextPath1);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void test_context_path_illegal_2() {
|
||||
String contextPath2 = "/nacos//";
|
||||
ValidatorUtils.checkContextPath(contextPath2);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void test_context_path_illegal_3() {
|
||||
String contextPath3 = "///";
|
||||
ValidatorUtils.checkContextPath(contextPath3);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void test_context_path_illegal_4() {
|
||||
String contextPath4 = "//";
|
||||
ValidatorUtils.checkContextPath(contextPath4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_server_addr() {
|
||||
String serverAddr = "127.0.0.1:8848";
|
||||
ValidatorUtils.checkServerAddr(serverAddr);
|
||||
String serverAddrs = "127.0.0.1:8848,127.0.0.1:80,127.0.0.1:8809";
|
||||
ValidatorUtils.checkServerAddr(serverAddrs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_server_addr_k8s() {
|
||||
String serverAddr = "busybox-1.busybox-subdomain.default.svc.cluster.local:80";
|
||||
ValidatorUtils.checkServerAddr(serverAddr);
|
||||
String serverAddrs = "busybox-1.busybox-subdomain.default.svc.cluster.local:80,busybox-1.busybox-subdomain.default.svc.cluster.local:8111, busybox-1.busybox-subdomain.default.svc.cluster.local:8098";
|
||||
ValidatorUtils.checkServerAddr(serverAddrs);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void test_server_addr_err() {
|
||||
String serverAddr = "127.0.0.1";
|
||||
ValidatorUtils.checkServerAddr(serverAddr);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void test_server_addr_illegal_err() {
|
||||
String serverAddr = "127.0.0.1:";
|
||||
ValidatorUtils.checkServerAddr(serverAddr);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void test_server_addrs_err() {
|
||||
String serverAddrs = "127.0.0.1:8848,127.0.0.1,127.0.0.1:8809";
|
||||
ValidatorUtils.checkServerAddr(serverAddrs);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void test_server_addr_k8s_err() {
|
||||
String serverAddr = "busybox-1.busybox-subdomain.default.svc.cluster.local";
|
||||
ValidatorUtils.checkServerAddr(serverAddr);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void test_server_addrs_k8s_err() {
|
||||
String serverAddrs = "busybox-1.busybox-subdomain.default.svc.cluster.local,busybox-1.busybox-subdomain.default.svc.cluster.local:8111, busybox-1.busybox-subdomain.default.svc.cluster.local:8098";
|
||||
ValidatorUtils.checkServerAddr(serverAddrs);
|
||||
}
|
||||
|
||||
}
|
@ -40,13 +40,15 @@ public class Md5Utils {
|
||||
private static final int HEX_VALUE_COUNT = 16;
|
||||
|
||||
public static String getMD5(byte[] bytes) throws NoSuchAlgorithmException {
|
||||
|
||||
MessageDigest messageDigest = MESSAGE_DIGEST_LOCAL.get();
|
||||
if (messageDigest != null) {
|
||||
return new BigInteger(1, messageDigest.digest(bytes)).toString(HEX_VALUE_COUNT);
|
||||
try {
|
||||
MessageDigest messageDigest = MESSAGE_DIGEST_LOCAL.get();
|
||||
if (messageDigest != null) {
|
||||
return new BigInteger(1, messageDigest.digest(bytes)).toString(HEX_VALUE_COUNT);
|
||||
}
|
||||
throw new NoSuchAlgorithmException("MessageDigest get MD5 instance error");
|
||||
} finally {
|
||||
MESSAGE_DIGEST_LOCAL.remove();
|
||||
}
|
||||
|
||||
throw new NoSuchAlgorithmException("MessageDigest get MD5 instance error");
|
||||
}
|
||||
|
||||
public static String getMD5(String value, String encode) {
|
||||
|
Loading…
Reference in New Issue
Block a user