未验证 提交 b064e90e 编写于 作者: X Xiangdong Huang 提交者: GitHub

[IOTDB-531] fix that JDBC URL does not support domain issue (#1118)

* fix iotdb-531, jdbc url does not support domain issue
上级 d68f616a
......@@ -37,6 +37,8 @@ import org.apache.iotdb.tsfile.utils.BytesUtils;
*/
public class Utils {
static final Pattern URL_PATTERN = Pattern.compile("([^:]+):([0-9]{1,5})/?");
/**
* Parse JDBC connection URL The only supported format of the URL is:
* jdbc:iotdb://localhost:6667/.
......@@ -48,31 +50,19 @@ public class Utils {
return params;
}
boolean isUrlLegal = false;
Pattern pattern = Pattern.compile("^"
+ "(((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}" // Domain name
+ "|"
+ "localhost" // localhost
+ "|"
+ "(([0-9]{1,3}\\.){3})[0-9]{1,3})" // Ip
+ ":"
+ "[0-9]{1,5}" // Port
+ "/?$");
String subURL = url.substring(Config.IOTDB_URL_PREFIX.length());
Matcher matcher = pattern.matcher(subURL);
if(matcher.matches()) {
isUrlLegal = true;
}
String[] DomainAndPort;
if(subURL.contains("/")) {
DomainAndPort = subURL.substring(0, subURL.length()-1).split(":");
} else {
DomainAndPort = subURL.split(":");
Matcher matcher = null;
if (url.startsWith(Config.IOTDB_URL_PREFIX)) {
String subURL = url.substring(Config.IOTDB_URL_PREFIX.length());
matcher = URL_PATTERN.matcher(subURL);
if (matcher.matches()) {
isUrlLegal = true;
}
}
params.setHost(DomainAndPort[0]);
params.setPort(Integer.parseInt(DomainAndPort[1]));
if (!isUrlLegal) {
throw new IoTDBURLException("Error url format, url should be jdbc:iotdb://domain|ip:port/ or jdbc:iotdb://domain|ip:port");
throw new IoTDBURLException("Error url format, url should be jdbc:iotdb://anything:port/ or jdbc:iotdb://anything:port");
}
params.setHost(matcher.group(1));
params.setPort(Integer.parseInt(matcher.group(2)));
if (info.containsKey(Config.AUTH_USER)) {
params.setUsername(info.getProperty(Config.AUTH_USER));
......
......@@ -99,7 +99,7 @@ public class UtilsTest {
assertEquals(params.getPort(), port);
}
@Test(expected = NumberFormatException.class)
@Test(expected = IoTDBURLException.class)
public void testParseWrongDomain() throws IoTDBURLException {
String userName = "test";
String userPwd = "test";
......@@ -113,7 +113,7 @@ public class UtilsTest {
properties);
}
@Test(expected = IoTDBURLException.class)
@Test
public void testParseWrongIP() throws IoTDBURLException {
String userName = "test";
String userPwd = "test";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册