阻断修复

This commit is contained in:
zhangqinbin
2022-03-22 11:39:05 +08:00
parent 4577034e40
commit 15f1eb1903

View File

@ -294,31 +294,31 @@ public final class Utils {
}
}
public static Properties parseGrpcUrl(String url) {
if (isNullOrEmpty(url)) {
throw new RuntimeException("URL cannot be null or empty");
}
Properties props = new Properties();
final String regex = "([^:]+)[:]//([^:]+)[:]([0-9]+)";
final Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(url);
if (m.matches()) {
props.setProperty("protocol", m.group(1));
props.setProperty("host", m.group(2));
props.setProperty("port", m.group(3));
String protocol = props.getProperty("protocol");
if (!"grpc".equals(protocol) && !"grpcs".equals(protocol)) {
throw new RuntimeException(format("Invalid protocol expected grpc or grpcs and found %s.", protocol));
}
} else {
throw new RuntimeException("URL must be of the format protocol://host:port. Found: '" + url + "'");
}
// TODO: allow all possible formats of the URL
return props;
}
// public static Properties parseGrpcUrl(String url) {
// if (isNullOrEmpty(url)) {
// throw new RuntimeException("URL cannot be null or empty");
// }
//
// Properties props = new Properties();
// final String regex = "([^:]+)[:]//([^:]+)[:]([0-9]+)";
// final Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
// Matcher m = p.matcher(url);
// if (m.matches()) {
// props.setProperty("protocol", m.group(1));
// props.setProperty("host", m.group(2));
// props.setProperty("port", m.group(3));
//
// String protocol = props.getProperty("protocol");
// if (!"grpc".equals(protocol) && !"grpcs".equals(protocol)) {
// throw new RuntimeException(format("Invalid protocol expected grpc or grpcs and found %s.", protocol));
// }
// } else {
// throw new RuntimeException("URL must be of the format protocol://host:port. Found: '" + url + "'");
// }
//
// // TODO: allow all possible formats of the URL
// return props;
// }
/**
* Check if the strings Grpc url is valid
@ -326,16 +326,16 @@ public final class Utils {
* @param url
* @return Return the io.seata.core.exception that indicates the error or null if ok.
*/
public static Exception checkGrpcUrl(String url) {
try {
parseGrpcUrl(url);
return null;
} catch (Exception e) {
return e;
}
}
// public static Exception checkGrpcUrl(String url) {
// try {
//
// parseGrpcUrl(url);
// return null;
//
// } catch (Exception e) {
// return e;
// }
// }
/**
* Check if a string is null or empty.