Search in sources :

Example 1 with BasePath

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;
}
Also used : ArrayList(java.util.ArrayList) BasePath(org.apache.servicecomb.serviceregistry.api.registry.BasePath) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with BasePath

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);
}
Also used : Configuration(org.apache.commons.configuration.Configuration) HashMap(java.util.HashMap) BasePath(org.apache.servicecomb.serviceregistry.api.registry.BasePath) Test(org.junit.Test)

Example 3 with BasePath

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);
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) BasePath(org.apache.servicecomb.serviceregistry.api.registry.BasePath)

Aggregations

BasePath (org.apache.servicecomb.serviceregistry.api.registry.BasePath)3 HashMap (java.util.HashMap)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Configuration (org.apache.commons.configuration.Configuration)1 Microservice (org.apache.servicecomb.serviceregistry.api.registry.Microservice)1 Test (org.junit.Test)1