Search in sources :

Example 1 with ConfigurationManagerImpl

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

the class RootContainer method createPortalContainer.

/**
 * Create the portal container
 * @param context the servlet context
 */
public synchronized void createPortalContainer(ServletContext context) {
    SecurityManager security = System.getSecurityManager();
    if (security != null)
        security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
    // Keep the old ClassLoader
    final ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
    boolean hasChanged = false;
    final String portalContainerName = ContainerUtil.getServletContextName(context);
    try {
        LOG.info("Trying to create the portal container '" + portalContainerName + "'");
        PortalContainer pcontainer = new PortalContainer(this, context);
        PortalContainer.setInstance(pcontainer);
        executeInitTasks(pcontainer, PortalContainerPreInitTask.TYPE);
        // Set the full classloader of the portal container
        Thread.currentThread().setContextClassLoader(pcontainer.getPortalClassLoader());
        hasChanged = true;
        ConfigurationManagerImpl cService = new ConfigurationManagerImpl(pcontainer.getPortalContext(), profiles);
        if (ConfigurationManager.LOG_DEBUG) {
            showDependencies(portalContainerName);
        }
        // add configs from services
        try {
            cService.addConfiguration(ContainerUtil.getConfigurationURL("conf/portal/configuration.xml"));
        } catch (Exception ex) {
            LOG.error("Cannot add configuration conf/portal/configuration.xml. ServletContext: " + context, ex);
        }
        // Add configuration that depends on the environment
        String uri;
        if (serverenv_.isJBoss()) {
            uri = "conf/portal/jboss-configuration.xml";
        } else {
            uri = "conf/portal/generic-configuration.xml";
        }
        Collection<URL> envConf = ContainerUtil.getConfigurationURL(uri);
        try {
            cService.addConfiguration(envConf);
        } catch (Exception ex) {
            LOG.error("Cannot add configuration " + uri + ". ServletContext: " + context, ex);
        }
        // add configs from web apps
        Set<WebAppInitContext> contexts = pcontainer.getWebAppInitContexts();
        for (WebAppInitContext webappctx : contexts) {
            ServletContext ctx = webappctx.getServletContext();
            try {
                cService.addConfiguration(ctx, "war:/conf/configuration.xml");
            } catch (Exception ex) {
                LOG.error("Cannot add configuration war:/conf/configuration.xml. ServletContext: " + ctx, ex);
            }
        }
        // add config from application server,
        // $AH_HOME/exo-conf/portal/configuration.xml
        String overrideConfig = getServerEnvironment().getExoConfigurationDirectory() + "/portal/" + portalContainerName + "/configuration.xml";
        try {
            File file = new File(overrideConfig);
            if (file.exists())
                cService.addConfiguration(file.toURI().toURL());
        } catch (Exception ex) {
            LOG.error("Cannot add configuration " + overrideConfig + ". ServletContext: " + context, ex);
        }
        cService.processRemoveConfiguration();
        pcontainer.registerComponentInstance(ConfigurationManager.class, cService);
        registerComponentInstance(portalContainerName, pcontainer);
        pcontainer.start(true);
        // Register the portal as an mbean
        getManagementContext().register(pcontainer);
        // 
        executeInitTasks(pcontainer, PortalContainerPostInitTask.TYPE);
        executeInitTasks(pcontainer, PortalContainerPostCreateTask.TYPE);
        LOG.info("The portal container '" + portalContainerName + "' has been created successfully");
    } catch (Exception ex) {
        LOG.error("Cannot create the portal container '" + portalContainerName + "' . ServletContext: " + context, ex);
    } finally {
        if (hasChanged) {
            // Re-set the old classloader
            Thread.currentThread().setContextClassLoader(currentClassLoader);
        }
        try {
            PortalContainer.setInstance(null);
        } catch (Exception e) {
            LOG.warn("An error occured while cleaning the ThreadLocal", e);
        }
    }
}
Also used : ConfigurationManagerImpl(org.exoplatform.container.configuration.ConfigurationManagerImpl) MockConfigurationManagerImpl(org.exoplatform.test.MockConfigurationManagerImpl) ContainerException(org.exoplatform.container.spi.ContainerException) PrivilegedActionException(java.security.PrivilegedActionException) URL(java.net.URL) MockServletContext(org.exoplatform.test.MockServletContext) ServletContext(javax.servlet.ServletContext) File(java.io.File)

Example 2 with ConfigurationManagerImpl

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

the class RootContainer method getPortalContainer.

public PortalContainer getPortalContainer(final String name) {
    PortalContainer pcontainer = getComponentInstance(name, PortalContainer.class);
    if (pcontainer == null) {
        J2EEServerInfo senv = getServerEnvironment();
        if ("standalone".equals(senv.getServerName()) || "test".equals(senv.getServerName())) {
            try {
                MockServletContext scontext = new MockServletContext(name);
                pcontainer = new PortalContainer(this, scontext);
                final PortalContainer currentPortalContainer = pcontainer;
                SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>() {

                    public Void run() {
                        PortalContainer.setInstance(currentPortalContainer);
                        return null;
                    }
                });
                final ConfigurationManagerImpl cService = new MockConfigurationManagerImpl(scontext);
                cService.addConfiguration(ContainerUtil.getConfigurationURL("conf/portal/configuration.xml"));
                cService.addConfiguration(ContainerUtil.getConfigurationURL("conf/portal/test-configuration.xml"));
                cService.processRemoveConfiguration();
                SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>() {

                    public Void run() {
                        currentPortalContainer.registerComponentInstance(ConfigurationManager.class, cService);
                        registerComponentInstance(name, currentPortalContainer);
                        currentPortalContainer.start(true);
                        onStartupComplete();
                        return null;
                    }
                });
            } catch (Exception ex) {
                LOG.error(ex.getLocalizedMessage(), ex);
            }
        }
    }
    return pcontainer;
}
Also used : J2EEServerInfo(org.exoplatform.container.monitor.jvm.J2EEServerInfo) MockConfigurationManagerImpl(org.exoplatform.test.MockConfigurationManagerImpl) ConfigurationManagerImpl(org.exoplatform.container.configuration.ConfigurationManagerImpl) MockConfigurationManagerImpl(org.exoplatform.test.MockConfigurationManagerImpl) ConfigurationManager(org.exoplatform.container.configuration.ConfigurationManager) MockServletContext(org.exoplatform.test.MockServletContext) ContainerException(org.exoplatform.container.spi.ContainerException) PrivilegedActionException(java.security.PrivilegedActionException)

Example 3 with ConfigurationManagerImpl

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

the class TestPropertyManagerConfigurator method testFromProperties.

public void testFromProperties() throws Exception {
    reset();
    URL propertiesURL = TestPropertyManagerConfigurator.class.getResource("property-configurator.properties");
    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 4 with ConfigurationManagerImpl

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

the class TestPropertyManagerConfigurator method testSimple.

public void testSimple() {
    reset();
    PropertiesParam propertiesParam = new PropertiesParam();
    propertiesParam.setProperty("property_1", "property_value_1");
    InitParams params = new InitParams();
    params.put("properties", propertiesParam);
    new PropertyConfigurator(params, new ConfigurationManagerImpl(new HashSet<String>()));
    Map<String, String> additions = reset();
    assertEquals(Collections.singletonMap("property_1", "property_value_1"), additions);
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) PropertiesParam(org.exoplatform.container.xml.PropertiesParam) ConfigurationManagerImpl(org.exoplatform.container.configuration.ConfigurationManagerImpl) HashSet(java.util.HashSet)

Example 5 with ConfigurationManagerImpl

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

the class TestPropertyManagerConfigurator method testFromPropertiesSkipBracket.

public void testFromPropertiesSkipBracket() throws Exception {
    reset();
    URL propertiesURL = TestPropertyManagerConfigurator.class.getResource("property-configurator.properties");
    assertNotNull(propertiesURL);
    System.setProperty(PropertyManager.PROPERTIES_URL, propertiesURL.toString());
    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 {0} value {1}", additions.get("property_5"));
    assertEquals("property_value_1-property {0} value {1}", additions.get("property_6"));
}
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)

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