阻断修复

This commit is contained in:
zhangqinbin
2022-03-22 11:34:36 +08:00
parent aca166eb19
commit b7a3edbae2

View File

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