format code
This commit is contained in:
@@ -50,10 +50,9 @@ import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author francis
|
||||
@@ -95,11 +94,11 @@ public class ConfigLoader {
|
||||
clientInputConfig.setHeaders(cfgNode.select("$.headers").toObject(Map.class));
|
||||
clientInputConfig.setMethod(cfgNode.select("$.method").getString());
|
||||
clientInputConfig.setPath(cfgNode.select("$.path").getString());
|
||||
if(clientInputConfig.getPath().startsWith(TEST_PATH_PREFIX)) {
|
||||
if (clientInputConfig.getPath().startsWith(TEST_PATH_PREFIX)) {
|
||||
// always enable debug for testing
|
||||
clientInputConfig.setDebug(true);
|
||||
}else {
|
||||
if(cfgNode.select("$.debug") != null) {
|
||||
} else {
|
||||
if (cfgNode.select("$.debug") != null) {
|
||||
clientInputConfig.setDebug(cfgNode.select("$.debug").getBoolean());
|
||||
}
|
||||
}
|
||||
@@ -168,7 +167,7 @@ public class ConfigLoader {
|
||||
for (Object obj : requests) {
|
||||
Map<String, Object> request = (Map<String, Object>) obj;
|
||||
String envUrl = (String) request.get(appConfigProperties.getEnv() + "Url");
|
||||
if(!StringUtils.isEmpty(envUrl)) {
|
||||
if (!StringUtils.isEmpty(envUrl)) {
|
||||
request.put("url", request.get(appConfigProperties.getEnv() + "Url"));
|
||||
}
|
||||
}
|
||||
@@ -178,7 +177,7 @@ public class ConfigLoader {
|
||||
public synchronized void init() throws Exception {
|
||||
if (aggregateResources == null) {
|
||||
aggregateResources = new ConcurrentHashMap<>(1024);
|
||||
resourceKey2ConfigInfoMap = new ConcurrentHashMap<>(1024);
|
||||
resourceKey2ConfigInfoMap = new ConcurrentHashMap<>(1024);
|
||||
aggregateId2ResourceKeyMap = new ConcurrentHashMap<>(1024);
|
||||
}
|
||||
|
||||
@@ -244,7 +243,7 @@ public class ConfigLoader {
|
||||
JSONArray idArray = JSON.parseArray(configIds);
|
||||
idArray.forEach(it -> {
|
||||
String configId = (String) it;
|
||||
String existResourceKey =aggregateId2ResourceKeyMap.get(configId);
|
||||
String existResourceKey = aggregateId2ResourceKeyMap.get(configId);
|
||||
if (StringUtils.hasText(existResourceKey)) {
|
||||
LOGGER.debug("delete aggregation config: {}", existResourceKey);
|
||||
aggregateResources.remove(existResourceKey);
|
||||
@@ -264,7 +263,7 @@ public class ConfigLoader {
|
||||
}
|
||||
}
|
||||
String key = method.toUpperCase() + ":" + path;
|
||||
if(aggregateResources.containsKey(key) && aggregateResources.get(key) != null) {
|
||||
if (aggregateResources.containsKey(key) && aggregateResources.get(key) != null) {
|
||||
String configStr = aggregateResources.get(key);
|
||||
Input input = null;
|
||||
Pipeline pipeline = null;
|
||||
@@ -282,6 +281,7 @@ public class ConfigLoader {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private ConfigInfo buildConfigInfo(String configId, String configName, String method, String path, long version) {
|
||||
String serviceName = this.extractServiceName(path);
|
||||
ConfigInfo configInfo = new ConfigInfo();
|
||||
@@ -294,26 +294,27 @@ public class ConfigLoader {
|
||||
return configInfo;
|
||||
}
|
||||
|
||||
private static final String FORMAL_PATH_PREFIX = "/proxy/";
|
||||
private static final int FORMAL_PATH_SERVICE_NAME_START_INDEX = 7;
|
||||
private static final String TEST_PATH_PREFIX = "/proxytest/";
|
||||
private static final int TEST_PATH_SERVICE_NAME_START_INDEX = 11;
|
||||
private static final String FORMAL_PATH_PREFIX = "/proxy/";
|
||||
private static final int FORMAL_PATH_SERVICE_NAME_START_INDEX = 7;
|
||||
private static final String TEST_PATH_PREFIX = "/proxytest/";
|
||||
private static final int TEST_PATH_SERVICE_NAME_START_INDEX = 11;
|
||||
|
||||
private String extractServiceName(String path) {
|
||||
if (path != null) {
|
||||
if (path.startsWith(FORMAL_PATH_PREFIX)) {
|
||||
int endIndex = path.indexOf(FORWARD_SLASH, FORMAL_PATH_SERVICE_NAME_START_INDEX);
|
||||
if (endIndex > FORMAL_PATH_SERVICE_NAME_START_INDEX) {
|
||||
return path.substring(FORMAL_PATH_SERVICE_NAME_START_INDEX, endIndex);
|
||||
}
|
||||
} else if (path.startsWith(TEST_PATH_PREFIX)) {
|
||||
int endIndex = path.indexOf(FORWARD_SLASH, TEST_PATH_SERVICE_NAME_START_INDEX);
|
||||
if (endIndex > TEST_PATH_SERVICE_NAME_START_INDEX) {
|
||||
return path.substring(TEST_PATH_SERVICE_NAME_START_INDEX, endIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (path != null) {
|
||||
if (path.startsWith(FORMAL_PATH_PREFIX)) {
|
||||
int endIndex = path.indexOf(FORWARD_SLASH, FORMAL_PATH_SERVICE_NAME_START_INDEX);
|
||||
if (endIndex > FORMAL_PATH_SERVICE_NAME_START_INDEX) {
|
||||
return path.substring(FORMAL_PATH_SERVICE_NAME_START_INDEX, endIndex);
|
||||
}
|
||||
} else if (path.startsWith(TEST_PATH_PREFIX)) {
|
||||
int endIndex = path.indexOf(FORWARD_SLASH, TEST_PATH_SERVICE_NAME_START_INDEX);
|
||||
if (endIndex > TEST_PATH_SERVICE_NAME_START_INDEX) {
|
||||
return path.substring(TEST_PATH_SERVICE_NAME_START_INDEX, endIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class ConfigInfo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -353,12 +354,9 @@ public class ConfigLoader {
|
||||
return false;
|
||||
}
|
||||
ConfigInfo that = (ConfigInfo) o;
|
||||
return Objects.equals(configId, that.configId) &&
|
||||
Objects.equals(configName, that.configName) &&
|
||||
Objects.equals(serviceName, that.serviceName) &&
|
||||
Objects.equals(method, that.method) &&
|
||||
Objects.equals(path, that.path) &&
|
||||
Objects.equals(version, that.version);
|
||||
return Objects.equals(configId, that.configId) && Objects.equals(configName, that.configName)
|
||||
&& Objects.equals(serviceName, that.serviceName) && Objects.equals(method, that.method)
|
||||
&& Objects.equals(path, that.path) && Objects.equals(version, that.version);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user