use of org.apache.servicecomb.serviceregistry.api.registry.BasePath in project incubator-servicecomb-java-chassis by apache.
the class ConfigurePropertyUtils method getMicroservicePaths.
@SuppressWarnings("unchecked")
public static List<BasePath> getMicroservicePaths(Configuration configuration) {
List<BasePath> basePaths = new ArrayList<>();
for (Object path : configuration.getList("service_description.paths")) {
BasePath basePath = new BasePath();
Map<String, ?> pathMap = (Map<String, ?>) path;
basePath.setPath(buildPath((String) pathMap.get("path")));
basePath.setProperty((Map<String, String>) pathMap.get("property"));
basePaths.add(basePath);
}
return basePaths;
}
use of org.apache.servicecomb.serviceregistry.api.registry.BasePath in project incubator-servicecomb-java-chassis by apache.
the class TestConfigurePropertyUtils method testGetPropertiesWithPrefix.
@Test
public void testGetPropertiesWithPrefix() {
Configuration configuration = ConfigUtil.createLocalConfig();
String prefix = "service_description.properties";
Map<String, String> expectedMap = new HashMap<>();
expectedMap.put("key1", "value1");
expectedMap.put("key2", "value2");
Assert.assertEquals(expectedMap, ConfigurePropertyUtils.getPropertiesWithPrefix(configuration, prefix));
List<BasePath> paths = ConfigurePropertyUtils.getMicroservicePaths(configuration);
Assert.assertEquals(2, paths.size());
Assert.assertEquals(paths.get(0).getPath(), "/test1/testpath");
Assert.assertEquals(paths.get(0).getProperty().get("checksession"), false);
System.setProperty(Const.URL_PREFIX, "/webroot");
paths = ConfigurePropertyUtils.getMicroservicePaths(configuration);
Assert.assertEquals(2, paths.size());
Assert.assertEquals(paths.get(0).getPath(), "/webroot/test1/testpath");
Assert.assertEquals(paths.get(0).getProperty().get("checksession"), false);
}
use of org.apache.servicecomb.serviceregistry.api.registry.BasePath in project incubator-servicecomb-java-chassis by apache.
the class SchemaLoader method putSelfBasePathIfAbsent.
public void putSelfBasePathIfAbsent(String microserviceName, String basePath) {
if (basePath == null || basePath.length() == 0) {
return;
}
Microservice microservice = RegistryUtils.getMicroservice();
if (!microservice.getServiceName().equals(microserviceName)) {
return;
}
String urlPrefix = System.getProperty(Const.URL_PREFIX);
if (!StringUtils.isEmpty(urlPrefix) && !basePath.startsWith(urlPrefix)) {
basePath = urlPrefix + basePath;
}
List<BasePath> paths = microservice.getPaths();
for (BasePath path : paths) {
if (path.getPath().equals(basePath)) {
return;
}
}
BasePath basePathObj = new BasePath();
basePathObj.setPath(basePath);
paths.add(basePathObj);
}
Aggregations