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-94f89814c4dfpull/2/head
parent
5c2e18e51d
commit
5e1e1d1d77
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -47,26 +47,26 @@ import static org.junit.Assert.*;
|
||||||
@RunWith(Arquillian.class)
|
@RunWith(Arquillian.class)
|
||||||
@Category(IntegrationTest.class)
|
@Category(IntegrationTest.class)
|
||||||
public class KernelConfigTest {
|
public class KernelConfigTest {
|
||||||
|
|
||||||
public KernelConfigTest() {
|
public KernelConfigTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpClass() {
|
public static void setUpClass() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void tearDownClass() {
|
public static void tearDownClass() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deployment
|
@Deployment
|
||||||
public static WebArchive createDeployment() {
|
public static WebArchive createDeployment() {
|
||||||
final PomEquippedResolveStage pom = Maven
|
final PomEquippedResolveStage pom = Maven
|
||||||
|
|
@ -75,15 +75,15 @@ public class KernelConfigTest {
|
||||||
final PomEquippedResolveStage dependencies = pom
|
final PomEquippedResolveStage dependencies = pom
|
||||||
.importCompileAndRuntimeDependencies();
|
.importCompileAndRuntimeDependencies();
|
||||||
final File[] libs = dependencies.resolve().withTransitivity().asFile();
|
final File[] libs = dependencies.resolve().withTransitivity().asFile();
|
||||||
|
|
||||||
for (File lib : libs) {
|
for (File lib : libs) {
|
||||||
System.err.printf("Adding file '%s' to test archive...%n",
|
System.err.printf("Adding file '%s' to test archive...%n",
|
||||||
lib.getName());
|
lib.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return ShrinkWrap
|
return ShrinkWrap
|
||||||
.create(WebArchive.class,
|
.create(WebArchive.class,
|
||||||
"LibreCCM-org.libreccm.core.KernelConfigTest.war")
|
"LibreCCM-com.arsdigita.kernel.KernelConfigTest.war")
|
||||||
//.addPackage(CcmObject.class.getPackage())
|
//.addPackage(CcmObject.class.getPackage())
|
||||||
.addPackage(com.arsdigita.kernel.KernelConfig.class.getPackage())
|
.addPackage(com.arsdigita.kernel.KernelConfig.class.getPackage())
|
||||||
.addPackage(com.arsdigita.runtime.AbstractConfig.class.getPackage())
|
.addPackage(com.arsdigita.runtime.AbstractConfig.class.getPackage())
|
||||||
|
|
@ -91,10 +91,14 @@ public class KernelConfigTest {
|
||||||
getPackage())
|
getPackage())
|
||||||
.addPackage(com.arsdigita.util.JavaPropertyReader.class.
|
.addPackage(com.arsdigita.util.JavaPropertyReader.class.
|
||||||
getPackage())
|
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
|
.addPackage(org.libreccm.tests.categories.IntegrationTest.class
|
||||||
.getPackage())
|
.getPackage())
|
||||||
.addAsLibraries(libs)
|
.addAsLibraries(libs)
|
||||||
.addAsWebInfResource(
|
.addAsResource(
|
||||||
"configtests/com/arsdigita/kernel/KernelConfigTest/ccm-core.config",
|
"configtests/com/arsdigita/kernel/KernelConfigTest/ccm-core.config",
|
||||||
"ccm-core.config")
|
"ccm-core.config")
|
||||||
.addAsWebInfResource(
|
.addAsWebInfResource(
|
||||||
|
|
@ -106,13 +110,13 @@ public class KernelConfigTest {
|
||||||
.addAsResource(
|
.addAsResource(
|
||||||
"com/arsdigita/kernel/KernelConfig_parameter.properties",
|
"com/arsdigita/kernel/KernelConfig_parameter.properties",
|
||||||
"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
|
@Test
|
||||||
public void verifyKernelConfig() {
|
public void verifyKernelConfig() {
|
||||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
||||||
|
|
||||||
assertThat(kernelConfig.isDebugEnabled(),
|
assertThat(kernelConfig.isDebugEnabled(),
|
||||||
is(true));
|
is(true));
|
||||||
assertThat(kernelConfig.isDataPermissionCheckEnabled(),
|
assertThat(kernelConfig.isDataPermissionCheckEnabled(),
|
||||||
|
|
@ -132,5 +136,5 @@ public class KernelConfigTest {
|
||||||
assertThat(kernelConfig.getLanguagesIndependentCode(),
|
assertThat(kernelConfig.getLanguagesIndependentCode(),
|
||||||
is(equalTo("--")));
|
is(equalTo("--")));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
waf.config.packages=ccm-core
|
||||||
Loading…
Reference in New Issue