Search in sources :

Example 6 with ConfigurationManagerImpl

use of org.exoplatform.container.configuration.ConfigurationManagerImpl in project kernel by exoplatform.

the class RootContainer method loadConfigurationManager.

/**
 * @param rootContainer
 * @return
 * @throws Exception
 */
private static ConfigurationManager loadConfigurationManager(RootContainer rootContainer, boolean logEnabled) throws Exception {
    final ConfigurationManagerImpl service = new ConfigurationManagerImpl(rootContainer.profiles, logEnabled);
    service.addConfiguration(ContainerUtil.getConfigurationURL("conf/configuration.xml"));
    if (System.getProperty("maven.exoplatform.dir") != null) {
        service.addConfiguration(ContainerUtil.getConfigurationURL("conf/test-configuration.xml"));
    }
    J2EEServerInfo serverEnv = rootContainer.getServerEnvironment();
    service.addConfiguration(Archive.getConfigurationURL(serverEnv.getApplicationDeployDirectories(), serverEnv.getApplicationDeployArchives(), "META-INF/exo-conf/configuration.xml"));
    String confDir = serverEnv.getExoConfigurationDirectory();
    String overrideConf = confDir + "/configuration.xml";
    File file = new File(overrideConf);
    if (PrivilegedFileHelper.exists(file)) {
        service.addConfiguration("file:" + overrideConf);
    }
    service.processRemoveConfiguration();
    if (PropertyManager.isDevelopping()) {
        Configuration conf = service.getConfiguration();
        if (conf != null) {
            conf.keepCurrentState();
        }
    }
    return service;
}
Also used : Configuration(org.exoplatform.container.xml.Configuration) J2EEServerInfo(org.exoplatform.container.monitor.jvm.J2EEServerInfo) ConfigurationManagerImpl(org.exoplatform.container.configuration.ConfigurationManagerImpl) MockConfigurationManagerImpl(org.exoplatform.test.MockConfigurationManagerImpl) File(java.io.File)

Example 7 with ConfigurationManagerImpl

use of org.exoplatform.container.configuration.ConfigurationManagerImpl in project kernel by exoplatform.

the class TestPropertyManagerConfigurator method testFromXML.

public void testFromXML() throws Exception {
    reset();
    URL propertiesURL = TestPropertyManagerConfigurator.class.getResource("property-configurator.xml");
    assertNotNull(propertiesURL);
    System.setProperty(PropertyManager.PROPERTIES_URL, propertiesURL.toString());
    System.setProperty("property_2", "property_value_2");
    PropertiesParam propertiesParam = new PropertiesParam();
    InitParams params = new InitParams();
    params.put("properties", propertiesParam);
    new PropertyConfigurator(params, new ConfigurationManagerImpl(new HashSet<String>()));
    Map<String, String> additions = reset();
    assertEquals("property_value_1", additions.get("property_1"));
    assertEquals("property_value_2", additions.get("property_2"));
    assertEquals("${property_3}", additions.get("property_3"));
    assertEquals("property_value_1-property_value_2", additions.get("property_4"));
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) PropertiesParam(org.exoplatform.container.xml.PropertiesParam) ConfigurationManagerImpl(org.exoplatform.container.configuration.ConfigurationManagerImpl) URL(java.net.URL) HashSet(java.util.HashSet)

Example 8 with ConfigurationManagerImpl

use of org.exoplatform.container.configuration.ConfigurationManagerImpl in project kernel by exoplatform.

the class TestPropertyManagerConfigurator method testFromPropertiesByParam.

public void testFromPropertiesByParam() throws Exception {
    reset();
    URL propertiesURL = TestPropertyManagerConfigurator.class.getResource("property-configurator.properties");
    assertNotNull(propertiesURL);
    System.setProperty("property_2", "property_value_2");
    ValueParam propertiesPathParam = new ValueParam();
    propertiesPathParam.setName("properties.url");
    propertiesPathParam.setValue(propertiesURL.toString());
    InitParams params = new InitParams();
    params.put("properties.url", propertiesPathParam);
    new PropertyConfigurator(params, new ConfigurationManagerImpl(new HashSet<String>()));
    Map<String, String> additions = reset();
    assertEquals("property_value_1", additions.get("property_1"));
    assertEquals("property_value_2", additions.get("property_2"));
    assertEquals("${property_3}", additions.get("property_3"));
    assertEquals("property_value_1-property_value_2", additions.get("property_4"));
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) ValueParam(org.exoplatform.container.xml.ValueParam) ConfigurationManagerImpl(org.exoplatform.container.configuration.ConfigurationManagerImpl) URL(java.net.URL) HashSet(java.util.HashSet)

Example 9 with ConfigurationManagerImpl

use of org.exoplatform.container.configuration.ConfigurationManagerImpl in project kernel by exoplatform.

the class TestTemplateConfigurationHelper method testTemplating.

public void testTemplating() throws IOException {
    TemplateConfigurationHelper helper = new TemplateConfigurationHelper(new String[] { "^foo-.*", "^jgroups-configuration" }, new String[] { "^foo-configuration" }, new ConfigurationManagerImpl());
    String template = "configuration in any format, containing ${foo-template-variable} and many others";
    String expectedConfig = "configuration in any format, containing pretty good parameter and many others";
    InputStream templateStream = new ByteArrayInputStream(template.getBytes());
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("foo-template-variable", "pretty good parameter");
    InputStream configStream = helper.fillTemplate(templateStream, parameters);
    String config = Utils.readStream(configStream);
    assertTrue(expectedConfig.equals(config));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ConfigurationManagerImpl(org.exoplatform.container.configuration.ConfigurationManagerImpl)

Example 10 with ConfigurationManagerImpl

use of org.exoplatform.container.configuration.ConfigurationManagerImpl in project kernel by exoplatform.

the class TestTemplateConfigurationHelper method testFilters2.

public void testFilters2() {
    // create helper with predefined include and exclude patterns
    TemplateConfigurationHelper helper = new TemplateConfigurationHelper(new String[] { "^foo-.*", "^jgroups-configuration" }, new String[] { "^foo-configuration" }, new ConfigurationManagerImpl());
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("jgroups-configuration", "");
    parameters.put("foo-cache.loader", "");
    parameters.put("foo-clustername", "");
    parameters.put("max-volatile-size", "");
    Map<String, String> preparedParameters = helper.prepareParameters(parameters);
    assertEquals(3, preparedParameters.size());
    // "foo-configuration" and "max-volatile-size" should be excluded
    assertFalse(preparedParameters.containsKey("${max-volatile-size}"));
    assertTrue(preparedParameters.containsKey("${foo-cache.loader}"));
    assertTrue(preparedParameters.containsKey("${foo-clustername}"));
}
Also used : HashMap(java.util.HashMap) ConfigurationManagerImpl(org.exoplatform.container.configuration.ConfigurationManagerImpl)

Aggregations

ConfigurationManagerImpl (org.exoplatform.container.configuration.ConfigurationManagerImpl)11 URL (java.net.URL)5 HashSet (java.util.HashSet)5 InitParams (org.exoplatform.container.xml.InitParams)5 PropertiesParam (org.exoplatform.container.xml.PropertiesParam)4 HashMap (java.util.HashMap)3 MockConfigurationManagerImpl (org.exoplatform.test.MockConfigurationManagerImpl)3 File (java.io.File)2 PrivilegedActionException (java.security.PrivilegedActionException)2 J2EEServerInfo (org.exoplatform.container.monitor.jvm.J2EEServerInfo)2 ContainerException (org.exoplatform.container.spi.ContainerException)2 MockServletContext (org.exoplatform.test.MockServletContext)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ServletContext (javax.servlet.ServletContext)1 ConfigurationManager (org.exoplatform.container.configuration.ConfigurationManager)1 Configuration (org.exoplatform.container.xml.Configuration)1 ValueParam (org.exoplatform.container.xml.ValueParam)1