parent
eda178f27b
commit
2ee5122244
@ -30,8 +30,6 @@ import com.alibaba.nacos.common.utils.NumberUtils;
|
|||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IP under service.
|
* IP under service.
|
||||||
@ -54,8 +52,6 @@ public class Instance extends com.alibaba.nacos.api.naming.pojo.Instance impleme
|
|||||||
|
|
||||||
private String app;
|
private String app;
|
||||||
|
|
||||||
private static final Pattern ONLY_DIGIT_AND_DOT = Pattern.compile("(\\d|\\.)+");
|
|
||||||
|
|
||||||
private static final String SPLITER = "_";
|
private static final String SPLITER = "_";
|
||||||
|
|
||||||
public Instance() {
|
public Instance() {
|
||||||
@ -352,11 +348,9 @@ public class Instance extends com.alibaba.nacos.api.naming.pojo.Instance impleme
|
|||||||
* @throws NacosException if instance is not validate
|
* @throws NacosException if instance is not validate
|
||||||
*/
|
*/
|
||||||
public void validate() throws NacosException {
|
public void validate() throws NacosException {
|
||||||
if (onlyContainsDigitAndDot()) {
|
if (!InternetAddressUtil.isIP(getIp())) {
|
||||||
if (!InternetAddressUtil.containsPort(getIp() + InternetAddressUtil.IP_PORT_SPLITER + getPort())) {
|
throw new NacosException(NacosException.INVALID_PARAM,
|
||||||
throw new NacosException(NacosException.INVALID_PARAM,
|
"instance format invalid: Your IP address is spelled incorrectly");
|
||||||
"instance format invalid: Your IP address is spelled incorrectly");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getWeight() > com.alibaba.nacos.naming.constants.Constants.MAX_WEIGHT_VALUE
|
if (getWeight() > com.alibaba.nacos.naming.constants.Constants.MAX_WEIGHT_VALUE
|
||||||
@ -368,11 +362,6 @@ public class Instance extends com.alibaba.nacos.api.naming.pojo.Instance impleme
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean onlyContainsDigitAndDot() {
|
|
||||||
Matcher matcher = ONLY_DIGIT_AND_DOT.matcher(getIp());
|
|
||||||
return matcher.matches();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Object o) {
|
public int compareTo(Object o) {
|
||||||
if (!(o instanceof Instance)) {
|
if (!(o instanceof Instance)) {
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.naming.core;
|
package com.alibaba.nacos.naming.core;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
import com.alibaba.nacos.common.utils.JacksonUtils;
|
import com.alibaba.nacos.common.utils.JacksonUtils;
|
||||||
import com.alibaba.nacos.naming.healthcheck.RsInfo;
|
import com.alibaba.nacos.naming.healthcheck.RsInfo;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -131,4 +132,10 @@ public class InstanceTest {
|
|||||||
RsInfo info1 = JacksonUtils.toObj(json, RsInfo.class);
|
RsInfo info1 = JacksonUtils.toObj(json, RsInfo.class);
|
||||||
System.out.println(info1);
|
System.out.println(info1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = NacosException.class)
|
||||||
|
public void testIpValidate() throws NacosException {
|
||||||
|
Instance instance1 = new Instance("192.168.1.3d", 8080);
|
||||||
|
instance1.validate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user