- Revision
- 798
- Author
- mauro
- Date
- 2008-08-28 19:45:20 -0500 (Thu, 28 Aug 2008)
Log Message
Added event to monitor context initialization failures.
Modified Paths
- trunk/waffle-core/src/main/java/org/codehaus/waffle/context/AbstractContextContainerFactory.java
- trunk/waffle-core/src/main/java/org/codehaus/waffle/context/WaffleContextListener.java
- trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java
- trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/ContextMonitor.java
- trunk/waffle-core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java
Diff
Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/context/AbstractContextContainerFactory.java (797 => 798)
--- trunk/waffle-core/src/main/java/org/codehaus/waffle/context/AbstractContextContainerFactory.java 2008-08-29 00:09:47 UTC (rev 797) +++ trunk/waffle-core/src/main/java/org/codehaus/waffle/context/AbstractContextContainerFactory.java 2008-08-29 00:45:20 UTC (rev 798) @@ -3,15 +3,16 @@ */ package org.codehaus.waffle.context; +import static java.text.MessageFormat.format; + +import javax.servlet.ServletContext; + import org.codehaus.waffle.WaffleException; import org.codehaus.waffle.i18n.MessageResources; import org.codehaus.waffle.monitor.ContextMonitor; import org.codehaus.waffle.registrar.Registrar; import org.codehaus.waffle.registrar.RegistrarAssistant; -import javax.servlet.ServletContext; -import static java.text.MessageFormat.format; - /** * @author Michael Ward * @author Mauro Talevi @@ -32,14 +33,19 @@ } public void initialize(ServletContext servletContext) throws WaffleException { - initializeRegistrar(servletContext); - servletContext.setAttribute(ContextContainerFactory.class.getName(), this); // register self to context - contextMonitor.contextInitialized(); + try { + initializeRegistrar(servletContext); + servletContext.setAttribute(ContextContainerFactory.class.getName(), this); // register self to context + contextMonitor.contextInitialized(); + } catch (WaffleException e) { + contextMonitor.contextInitializationFailed(e); + throw e; // re-throwing exception after failure event has been monitored + } } /** * Create the Registrar from the ServletContext's InitParameter. - * + * * @param servletContext */ private void initializeRegistrar(ServletContext servletContext) { @@ -52,7 +58,7 @@ } catch (ClassNotFoundException e) { contextMonitor.registrarNotFound(registrarClassName); String message = format("Unable to load the Registrar [{0}] defined as context-param in web.xml", - registrarClassName); + registrarClassName); throw new WaffleException(message, e); } @@ -84,12 +90,12 @@ return applicationContextContainer; } - protected ContextMonitor getContextMonitor(){ + protected ContextMonitor getContextMonitor() { return contextMonitor; } - + protected abstract ContextContainer buildApplicationContextContainer(); protected abstract Registrar createRegistrar(ContextContainer contextContainer); -} \ No newline at end of file +}
Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/context/WaffleContextListener.java (797 => 798)
--- trunk/waffle-core/src/main/java/org/codehaus/waffle/context/WaffleContextListener.java 2008-08-29 00:09:47 UTC (rev 797) +++ trunk/waffle-core/src/main/java/org/codehaus/waffle/context/WaffleContextListener.java 2008-08-29 00:45:20 UTC (rev 798) @@ -30,11 +30,9 @@ */ public void contextInitialized(ServletContextEvent servletContextEvent) { ServletContext servletContext = servletContextEvent.getServletContext(); - // build component registry instance and add it to the ServletContext ComponentRegistry componentRegistry = buildComponentRegistry(servletContext); servletContext.setAttribute(ComponentRegistry.class.getName(), componentRegistry); - contextContainerFactory = componentRegistry.getContextContainerFactory(); contextContainerFactory.initialize(servletContext); }
Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java (797 => 798)
--- trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java 2008-08-29 00:09:47 UTC (rev 797) +++ trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java 2008-08-29 00:45:20 UTC (rev 798) @@ -21,6 +21,7 @@ import javax.servlet.Servlet; import javax.servlet.http.HttpServletResponse; +import org.codehaus.waffle.WaffleException; import org.codehaus.waffle.action.ActionMethodResponse; import org.codehaus.waffle.action.MethodDefinition; import org.codehaus.waffle.action.HierarchicalArgumentResolver.Scope; @@ -82,6 +83,7 @@ levels.put("registrarCreated", INFO); levels.put("registrarNotFound", WARN); levels.put("contextInitialized", DEBUG); + levels.put("contextInitializationFailed", WARN); levels.put("applicationContextContainerStarted", DEBUG); levels.put("applicationContextContainerDestroyed", DEBUG); levels.put("sessionContextContainerCreated", DEBUG); @@ -141,6 +143,7 @@ messages.put("registrarCreated", "Registrar ''{0}'' created with monitor ''{1}''"); messages.put("registrarNotFound", "Registrar ''{0}'' not found"); messages.put("contextInitialized", "Context initialized"); + messages.put("contextInitializationFailed", "Context initialization failed: {0}"); messages.put("applicationContextContainerStarted", "Application context container started"); messages.put("applicationContextContainerDestroyed", "Application context container destroyed"); messages.put("sessionContextContainerCreated", "Session context container created with parent application container ''{0}''"); @@ -305,6 +308,10 @@ write("contextInitialized"); } + public void contextInitializationFailed(WaffleException cause){ + write("contextInitializationFailed", cause); + } + public void applicationContextContainerStarted() { write("applicationContextContainerStarted"); }
Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/ContextMonitor.java (797 => 798)
--- trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/ContextMonitor.java 2008-08-29 00:09:47 UTC (rev 797) +++ trunk/waffle-core/src/main/java/org/codehaus/waffle/monitor/ContextMonitor.java 2008-08-29 00:45:20 UTC (rev 798) @@ -3,6 +3,7 @@ */ package org.codehaus.waffle.monitor; +import org.codehaus.waffle.WaffleException; import org.codehaus.waffle.context.ContextContainer; import org.codehaus.waffle.registrar.Registrar; @@ -19,6 +20,8 @@ void contextInitialized(); + void contextInitializationFailed(WaffleException cause); + void applicationContextContainerStarted(); void applicationContextContainerDestroyed();
Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java (797 => 798)
--- trunk/waffle-core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java 2008-08-29 00:09:47 UTC (rev 797) +++ trunk/waffle-core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java 2008-08-29 00:45:20 UTC (rev 798) @@ -9,6 +9,7 @@ import javax.servlet.Servlet; import javax.servlet.http.HttpServletResponse; +import org.codehaus.waffle.WaffleException; import org.codehaus.waffle.action.ActionMethodResponse; import org.codehaus.waffle.action.MethodDefinition; import org.codehaus.waffle.action.HierarchicalArgumentResolver.Scope; @@ -95,6 +96,9 @@ public void contextInitialized() { } + public void contextInitializationFailed(WaffleException cause) { + } + public void applicationContextContainerDestroyed() { } @@ -136,10 +140,10 @@ public void actionMethodInvocationFailed(Exception cause) { } - + public void servletInitialized(Servlet servlet) { } - + public void servletServiceFailed(Exception cause) { } @@ -164,5 +168,4 @@ public void viewResponded(ResponderView responderView) { } - }
To unsubscribe from this list please visit:
