CCM NG: KernelConfig now seems to work in a Java EE application container.

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3519 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2015-07-04 08:16:49 +00:00
parent 5c2e18e51d
commit 5e1e1d1d77
3 changed files with 106 additions and 14 deletions

View File

@ -0,0 +1,87 @@
/*
* Copyright (C) 2015 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.web;
import com.arsdigita.runtime.CCMResourceManager;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
/**
* Listener used to initialise several parameters for legacy CCM classes. This
* class is not identical with the class with same name in old versions. It has
* been modified so that only those things are done which necessary to get the
* legacy classes, for instance the classes derived from
* {@link com.arsdigita.runtime.AbstractConfig} working. Also it is not longer
* necessary to include an entry in the {@code web.xml} for this class because
* this can be done using {@link @WebListener} annotation in the Servlet API
* 3.0.
*
* The following is the documentation from the original class which is provided
* here for reference. The information is outdated!
*
* Web application lifecycle listener, used to perform central initialisation
* tasks at CCM startup in a Servlet container / web application server,
* expecially setting the runtime context (file locations) and (in the future)
* the database connection.
*
* The methods of this classes are by definition only invoked by the Servlet
* container / web application server, not by any Servlet or java class of the
* application itself! Invocation is managed by the deployment descriptor.
*
* Note! Don't forget to configure it in web.xml deployment descriptor!
* <listener>
* <listener-class>
* com.arsdigita.runtime.CCMApplicationContextListener
* </listener-class>
* </listener>
* According to the 2.3 specification these tags must be placed after the filter
* tags and before the Servlet tags!
*
* @author pboy
* @author Jens Pelzetter <a href="mailto:jens.pelzetter@googlemail.com">Jens
* Pelzetter</a>
*/
@WebListener
public class CCMApplicationContextListener implements ServletContextListener {
public static final Logger logger = LogManager.getLogger(
CCMApplicationContextListener.class);
@Override
public void contextInitialized(final ServletContextEvent event) {
final ServletContext context = event.getServletContext();
final String appBase = context.getRealPath("/");
logger.info(String.format("Setting base directory to %s", appBase));
CCMResourceManager.setBaseDirectory(appBase);
}
@Override
public void contextDestroyed(final ServletContextEvent event) {
//Nothing yet
}
}

View File

@ -47,26 +47,26 @@ import static org.junit.Assert.*;
@RunWith(Arquillian.class)
@Category(IntegrationTest.class)
public class KernelConfigTest {
public KernelConfigTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Deployment
public static WebArchive createDeployment() {
final PomEquippedResolveStage pom = Maven
@ -75,15 +75,15 @@ public class KernelConfigTest {
final PomEquippedResolveStage dependencies = pom
.importCompileAndRuntimeDependencies();
final File[] libs = dependencies.resolve().withTransitivity().asFile();
for (File lib : libs) {
System.err.printf("Adding file '%s' to test archive...%n",
lib.getName());
}
return ShrinkWrap
.create(WebArchive.class,
"LibreCCM-org.libreccm.core.KernelConfigTest.war")
"LibreCCM-com.arsdigita.kernel.KernelConfigTest.war")
//.addPackage(CcmObject.class.getPackage())
.addPackage(com.arsdigita.kernel.KernelConfig.class.getPackage())
.addPackage(com.arsdigita.runtime.AbstractConfig.class.getPackage())
@ -91,10 +91,14 @@ public class KernelConfigTest {
getPackage())
.addPackage(com.arsdigita.util.JavaPropertyReader.class.
getPackage())
.addPackage(com.arsdigita.web.CCMApplicationContextListener.class
.getPackage())
.addPackage(com.arsdigita.xml.XML.class.getPackage())
.addPackage(com.arsdigita.xml.formatters.DateFormatter.class.getPackage())
.addPackage(org.libreccm.tests.categories.IntegrationTest.class
.getPackage())
.addAsLibraries(libs)
.addAsWebInfResource(
.addAsResource(
"configtests/com/arsdigita/kernel/KernelConfigTest/ccm-core.config",
"ccm-core.config")
.addAsWebInfResource(
@ -106,13 +110,13 @@ public class KernelConfigTest {
.addAsResource(
"com/arsdigita/kernel/KernelConfig_parameter.properties",
"com/arsdigita/kernel/KernelConfig_parameter.properties")
.addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}
@Test
public void verifyKernelConfig() {
final KernelConfig kernelConfig = KernelConfig.getConfig();
assertThat(kernelConfig.isDebugEnabled(),
is(true));
assertThat(kernelConfig.isDataPermissionCheckEnabled(),
@ -132,5 +136,5 @@ public class KernelConfigTest {
assertThat(kernelConfig.getLanguagesIndependentCode(),
is(equalTo("--")));
}
}