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);
}
}
}
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;
}
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"));
}
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);
}
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"));
}
Aggregations