diff --git a/source/java/org/alfresco/web/app/ContextListener.java b/source/java/org/alfresco/web/app/ContextListener.java
index 69763287bc..6bc4ea5a67 100644
--- a/source/java/org/alfresco/web/app/ContextListener.java
+++ b/source/java/org/alfresco/web/app/ContextListener.java
@@ -26,7 +26,6 @@ import javax.servlet.http.HttpSessionListener;
import javax.transaction.UserTransaction;
import org.alfresco.error.AlfrescoRuntimeException;
-import org.alfresco.repo.cache.InternalEhCacheManagerFactoryBean;
import org.alfresco.repo.security.authentication.AuthenticationContext;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -54,6 +53,8 @@ public class ContextListener implements ServletContextListener, HttpSessionListe
private static Log logger = LogFactory.getLog(ContextListener.class);
private ServletContext servletContext;
+ private ServletContextListener enterpriseListener;
+ private String enterpriseListenerClass = "org.alfresco.enterprise.repo.EnterpriseContextListener";
/**
* @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
@@ -123,16 +124,51 @@ public class ContextListener implements ServletContextListener, HttpSessionListe
}
catch (Exception ex) {}
}
+ synchronized(this)
+ {
+ findEnterpriseListener();
+ if (enterpriseListener != null)
+ {
+ // Perform any extra context initialisation required for enterprise.
+ enterpriseListener.contextInitialized(event);
+ }
+ }
}
+ protected void findEnterpriseListener()
+ {
+ try
+ {
+ Class> c = Class.forName(enterpriseListenerClass);
+ enterpriseListener = (ServletContextListener) c.newInstance();
+ }
+ catch (ClassNotFoundException e)
+ {
+ // It's OK not to have the enterprise context destroyer available.
+ }
+ catch (InstantiationException e)
+ {
+ logger.error("Failed to instantiate enterprise ServletContextListener.", e);
+ }
+ catch (IllegalAccessException e)
+ {
+ logger.error("Failed to instantiate enterprise ServletContextListener.", e);
+ }
+ }
+
/**
* {@inheritDoc}
- *
- * Forcibly kills Alfresco's EHCache CacheManager
*/
public void contextDestroyed(ServletContextEvent event)
{
- InternalEhCacheManagerFactoryBean.getInstance().shutdown();
+ synchronized(this)
+ {
+ if (enterpriseListener != null)
+ {
+ // Perform any extra destruction required for enterprise.
+ enterpriseListener.contextDestroyed(event);
+ }
+ }
}
/**
@@ -152,4 +188,16 @@ public class ContextListener implements ServletContextListener, HttpSessionListe
if (logger.isDebugEnabled())
logger.debug("HTTP session destroyed: " + event.getSession().getId());
}
+
+ /**
+ * Inject a different class name (from the default) for the enterprise ServletContextListener.
+ *
+ * Useful for testing.
+ *
+ * @param listenerClass Class name to use.
+ */
+ protected void setEnterpriseListenerClass(String listenerClass)
+ {
+ this.enterpriseListenerClass = listenerClass;
+ }
}
diff --git a/source/java/org/alfresco/web/app/ContextListenerTest.java b/source/java/org/alfresco/web/app/ContextListenerTest.java
new file mode 100644
index 0000000000..bc06ac112b
--- /dev/null
+++ b/source/java/org/alfresco/web/app/ContextListenerTest.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2005-2012 Alfresco Software Limited.
+ *
+ * This file is part of Alfresco
+ *
+ * Alfresco 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco 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 Alfresco. If not, see .
+ */
+package org.alfresco.web.app;
+
+import static org.junit.Assert.*;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+/**
+ * Tests for the ContextListener class.
+ *
+ * @author Matt Ward
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class ContextListenerTest
+{
+ private ContextListener contextListener;
+ private @Mock ServletContextEvent event;
+
+
+ @Before
+ public void setUp() throws Exception
+ {
+ contextListener = new ContextListener();
+ contextListener.setEnterpriseListenerClass("org.alfresco.web.app.ContextListenerTest$StubEnterpriseListener");
+ StubEnterpriseListener.enterpriseDestroyed = false;
+ }
+
+ @Test
+ public void testContextDestroyed()
+ {
+ contextListener.findEnterpriseListener();
+ contextListener.contextDestroyed(event);
+
+ assertTrue("Enterprise contextDestroyed() not executed.", StubEnterpriseListener.enterpriseDestroyed);
+ }
+
+
+ /**
+ * ServletContextListener to simulate an enterprise-specific context listener.
+ */
+ protected static class StubEnterpriseListener implements ServletContextListener
+ {
+ static boolean enterpriseDestroyed;
+
+ @Override
+ public void contextDestroyed(ServletContextEvent arg0)
+ {
+ enterpriseDestroyed = true;
+ }
+
+ @Override
+ public void contextInitialized(ServletContextEvent arg0)
+ {
+ // Noop
+ }
+ }
+}