- Revision
- 370
- Author
- mauro
- Date
- 2007-11-13 14:44:44 -0600 (Tue, 13 Nov 2007)
Log Message
Added ServletMonitor
Modified Paths
- trunk/core/src/main/java/org/codehaus/waffle/ComponentRegistry.java
- trunk/core/src/main/java/org/codehaus/waffle/context/pico/PicoComponentRegistry.java
- trunk/core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java
- trunk/core/src/main/java/org/codehaus/waffle/servlet/WaffleServlet.java
- trunk/core/src/test/java/org/codehaus/waffle/context/pico/PicoComponentRegistryTest.java
- trunk/core/src/test/java/org/codehaus/waffle/servlet/WaffleServletTest.java
- trunk/core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java
Added Paths
Diff
Modified: trunk/core/src/main/java/org/codehaus/waffle/ComponentRegistry.java (369 => 370)
--- trunk/core/src/main/java/org/codehaus/waffle/ComponentRegistry.java 2007-11-13 15:04:17 UTC (rev 369) +++ trunk/core/src/main/java/org/codehaus/waffle/ComponentRegistry.java 2007-11-13 20:44:44 UTC (rev 370) @@ -26,6 +26,7 @@ import org.codehaus.waffle.i18n.MessageResources; import org.codehaus.waffle.monitor.ActionMonitor; import org.codehaus.waffle.monitor.BindMonitor; +import org.codehaus.waffle.monitor.ServletMonitor; import org.codehaus.waffle.validation.Validator; import org.codehaus.waffle.view.ViewDispatcher; import org.codehaus.waffle.view.ViewResolver; @@ -76,5 +77,7 @@ ViewDispatcher getViewDispatcher(); ViewResolver getViewResolver(); + + ServletMonitor getServletMonitor(); }
Modified: trunk/core/src/main/java/org/codehaus/waffle/context/pico/PicoComponentRegistry.java (369 => 370)
--- trunk/core/src/main/java/org/codehaus/waffle/context/pico/PicoComponentRegistry.java 2007-11-13 15:04:17 UTC (rev 369) +++ trunk/core/src/main/java/org/codehaus/waffle/context/pico/PicoComponentRegistry.java 2007-11-13 20:44:44 UTC (rev 370) @@ -44,6 +44,7 @@ import org.codehaus.waffle.i18n.MessageResources; import org.codehaus.waffle.monitor.ActionMonitor; import org.codehaus.waffle.monitor.BindMonitor; +import org.codehaus.waffle.monitor.ServletMonitor; import org.codehaus.waffle.monitor.SilentMonitor; import org.codehaus.waffle.validation.DefaultValidator; import org.codehaus.waffle.validation.Validator; @@ -89,6 +90,7 @@ register(MethodDefinitionFinder.class, AnnotatedMethodDefinitionFinder.class, servletContext); register(MethodNameResolver.class, RequestParameterMethodNameResolver.class, servletContext); register(TypeConverter.class, OgnlTypeConverter.class, servletContext); + register(ServletMonitor.class, SilentMonitor.class, servletContext); register(Validator.class, DefaultValidator.class, servletContext); register(ViewDispatcher.class, DefaultViewDispatcher.class, servletContext); register(ViewResolver.class, DefaultViewResolver.class, servletContext); @@ -263,4 +265,8 @@ return locateByType(ViewResolver.class); } + public ServletMonitor getServletMonitor() { + return locateByType(ServletMonitor.class); + } + }
Modified: trunk/core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java (369 => 370)
--- trunk/core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java 2007-11-13 15:04:17 UTC (rev 369) +++ trunk/core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java 2007-11-13 20:44:44 UTC (rev 370) @@ -37,7 +37,7 @@ * * @author Mauro Talevi */ -public abstract class AbstractWritingMonitor implements ActionMonitor, BindMonitor { +public abstract class AbstractWritingMonitor implements ActionMonitor, BindMonitor, ServletMonitor { private Map<String, Level> levels; private Map<String, String> templates; @@ -63,6 +63,7 @@ levels.put("bindFailedForController", INFO); levels.put("responseIsCommitted", INFO); levels.put("viewDispatched", INFO); + levels.put("servletServiceFailed", WARN); return levels; } @@ -82,6 +83,7 @@ templates.put("bindFailedForController", "Bind failed for controller ''{0}'': {1}"); templates.put("responseIsCommitted", "Response is committed for response: {0}"); templates.put("viewDispatched", "View dispatched: {0}"); + templates.put("servletServiceFailed", "Servlet service failed: {0}"); return templates; } @@ -176,6 +178,10 @@ public void viewDispatched(View view) { write("viewDispatched", view); } + + public void servletServiceFailed(Exception cause){ + write("servletServiceFailed", cause); + } /** * Writes message for a given level. Concrete implementations should provide writing functionality.
Added: trunk/core/src/main/java/org/codehaus/waffle/monitor/ServletMonitor.java (0 => 370)
--- trunk/core/src/main/java/org/codehaus/waffle/monitor/ServletMonitor.java (rev 0) +++ trunk/core/src/main/java/org/codehaus/waffle/monitor/ServletMonitor.java 2007-11-13 20:44:44 UTC (rev 370) @@ -0,0 +1,24 @@ +/***************************************************************************** + * Copyright (C) 2005,2006 Michael Ward * + * All rights reserved. * + * ------------------------------------------------------------------------- * + * The software in this package is published under the terms of the BSD * + * style license a copy of which has been included with this distribution in * + * the LICENSE.txt file. * + * * + * Original code by: Mauro Talevi * + *****************************************************************************/ +package org.codehaus.waffle.monitor; + + + +/** + * A monitor for servlet-related events + * + * @author Mauro Talevi + */ +public interface ServletMonitor extends Monitor { + + void servletServiceFailed(Exception cause); + +}
Modified: trunk/core/src/main/java/org/codehaus/waffle/servlet/WaffleServlet.java (369 => 370)
--- trunk/core/src/main/java/org/codehaus/waffle/servlet/WaffleServlet.java 2007-11-13 15:04:17 UTC (rev 369) +++ trunk/core/src/main/java/org/codehaus/waffle/servlet/WaffleServlet.java 2007-11-13 20:44:44 UTC (rev 370) @@ -31,7 +31,7 @@ import org.codehaus.waffle.bind.RequestAttributeBinder; import org.codehaus.waffle.controller.ControllerDefinition; import org.codehaus.waffle.controller.ControllerDefinitionFactory; -import org.codehaus.waffle.monitor.ActionMonitor; +import org.codehaus.waffle.monitor.ServletMonitor; import org.codehaus.waffle.validation.DefaultErrorsContext; import org.codehaus.waffle.validation.ErrorsContext; import org.codehaus.waffle.validation.Validator; @@ -52,7 +52,7 @@ private static final String EMPTY = ""; private ActionMethodExecutor actionMethodExecutor; private ActionMethodResponseHandler actionMethodResponseHandler; - private ActionMonitor actionMonitor; + private ServletMonitor servletMonitor; private DataBinder dataBinder; private RequestAttributeBinder requestAttributeBinder; private ControllerDefinitionFactory controllerDefinitionFactory; @@ -73,7 +73,7 @@ * * @param actionMethodExecutor * @param actionMethodResponseHandler - * @param actionMonitor + * @param servletMonitor * @param dataBinder * @param requestAttributeBinder * @param controllerDefinitionFactory @@ -81,14 +81,14 @@ */ public WaffleServlet(ActionMethodExecutor actionMethodExecutor, ActionMethodResponseHandler actionMethodResponseHandler, - ActionMonitor actionMonitor, + ServletMonitor servletMonitor, DataBinder dataBinder, RequestAttributeBinder requestAttributeBinder, ControllerDefinitionFactory controllerDefinitionFactory, Validator validator) { this.actionMethodExecutor = actionMethodExecutor; this.actionMethodResponseHandler = actionMethodResponseHandler; - this.actionMonitor = actionMonitor; + this.servletMonitor = servletMonitor; this.dataBinder = dataBinder; this.requestAttributeBinder = requestAttributeBinder; this.controllerDefinitionFactory = controllerDefinitionFactory; @@ -113,7 +113,7 @@ .getComponentRegistry(getServletContext()); actionMethodExecutor = componentRegistry.getActionMethodExecutor(); actionMethodResponseHandler = componentRegistry.getActionMethodResponseHandler(); - actionMonitor = componentRegistry.getActionMonitor(); + servletMonitor = componentRegistry.getServletMonitor(); dataBinder = componentRegistry.getDataBinder(); requestAttributeBinder = componentRegistry.getRequestAttributeBinder(); controllerDefinitionFactory = componentRegistry.getControllerDefinitionFactory(); @@ -182,7 +182,7 @@ requestAttributeBinder.bind(request, controllerDefinition.getController()); actionMethodResponseHandler.handle(request, response, actionMethodResponse); } catch (ActionMethodInvocationException e) { - actionMonitor.actionMethodExecutionFailed(e); + servletMonitor.servletServiceFailed(e); log("ERROR: " + e.getMessage()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); }
Modified: trunk/core/src/test/java/org/codehaus/waffle/context/pico/PicoComponentRegistryTest.java (369 => 370)
--- trunk/core/src/test/java/org/codehaus/waffle/context/pico/PicoComponentRegistryTest.java 2007-11-13 15:04:17 UTC (rev 369) +++ trunk/core/src/test/java/org/codehaus/waffle/context/pico/PicoComponentRegistryTest.java 2007-11-13 20:44:44 UTC (rev 370) @@ -45,6 +45,7 @@ import org.codehaus.waffle.monitor.AbstractWritingMonitor; import org.codehaus.waffle.monitor.ActionMonitor; import org.codehaus.waffle.monitor.BindMonitor; +import org.codehaus.waffle.monitor.ServletMonitor; import org.codehaus.waffle.testmodel.StubActionMethodExecutor; import org.codehaus.waffle.testmodel.StubActionMethodResponseHandler; import org.codehaus.waffle.testmodel.StubArgumentResolver; @@ -127,7 +128,7 @@ { one(servletContext).getInitParameterNames(); will(returnValue(EMPTY_ENUMERATION)); - exactly(18).of(servletContext).getInitParameter(with(any(String.class))); + exactly(19).of(servletContext).getInitParameter(with(any(String.class))); } }); @@ -148,6 +149,7 @@ assertTrue(componentRegistry.getTypeConverter() instanceof OgnlTypeConverter); assertTrue(componentRegistry.getViewResolver() instanceof DefaultViewResolver); assertTrue(componentRegistry.getValidator() instanceof DefaultValidator); + assertTrue(componentRegistry.getServletMonitor() instanceof AbstractWritingMonitor); } @Test @@ -194,6 +196,8 @@ will(returnValue(StubControllerDefinitionFactory.class.getName())); one(servletContext).getInitParameter(ContextContainerFactory.class.getName()); will(returnValue(StubContextContainerFactory.class.getName())); + one(servletContext).getInitParameter(ServletMonitor.class.getName()); + will(returnValue(StubMonitor.class.getName())); } }); ComponentRegistry componentRegistry = new PicoComponentRegistry(servletContext);
Modified: trunk/core/src/test/java/org/codehaus/waffle/servlet/WaffleServletTest.java (369 => 370)
--- trunk/core/src/test/java/org/codehaus/waffle/servlet/WaffleServletTest.java 2007-11-13 15:04:17 UTC (rev 369) +++ trunk/core/src/test/java/org/codehaus/waffle/servlet/WaffleServletTest.java 2007-11-13 20:44:44 UTC (rev 370) @@ -41,7 +41,7 @@ import org.codehaus.waffle.context.pico.PicoContextContainer; import org.codehaus.waffle.controller.ControllerDefinition; import org.codehaus.waffle.controller.ControllerDefinitionFactory; -import org.codehaus.waffle.monitor.ActionMonitor; +import org.codehaus.waffle.monitor.ServletMonitor; import org.codehaus.waffle.monitor.SilentMonitor; import org.codehaus.waffle.validation.ErrorsContext; import org.codehaus.waffle.validation.Validator; @@ -81,7 +81,7 @@ // Component Registry... one(componentRegistry).getActionMethodExecutor(); one(componentRegistry).getActionMethodResponseHandler(); - one(componentRegistry).getActionMonitor(); + one(componentRegistry).getServletMonitor(); one(componentRegistry).getDataBinder(); one(componentRegistry).getRequestAttributeBinder(); one(componentRegistry).getControllerDefinitionFactory(); @@ -351,10 +351,10 @@ will(throwException(actionMethodInvocationException)); }}); - // Mock ActionMonitor - final ActionMonitor actionMonitor = mockery.mock(ActionMonitor.class); + // Mock ServletMonitor + final ServletMonitor servletMonitor = mockery.mock(ServletMonitor.class); mockery.checking(new Expectations() {{ - allowing(actionMonitor).actionMethodExecutionFailed(actionMethodInvocationException); + allowing(servletMonitor).servletServiceFailed(actionMethodInvocationException); }}); // Mock Validator @@ -372,9 +372,9 @@ mockMethodExecutorField.setAccessible(true); mockMethodExecutorField.set(waffleServlet, actionMethodExecutor); - Field mockMonitorField = WaffleServlet.class.getDeclaredField("actionMonitor"); + Field mockMonitorField = WaffleServlet.class.getDeclaredField("servletMonitor"); mockMonitorField.setAccessible(true); - mockMonitorField.set(waffleServlet, actionMonitor); + mockMonitorField.set(waffleServlet, servletMonitor); Field validatorFactoryField = WaffleServlet.class.getDeclaredField("validator"); validatorFactoryField.setAccessible(true);
Modified: trunk/core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java (369 => 370)
--- trunk/core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java 2007-11-13 15:04:17 UTC (rev 369) +++ trunk/core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java 2007-11-13 20:44:44 UTC (rev 370) @@ -10,10 +10,11 @@ import org.codehaus.waffle.action.HierarchicalArgumentResolver.Scope; import org.codehaus.waffle.monitor.ActionMonitor; import org.codehaus.waffle.monitor.BindMonitor; +import org.codehaus.waffle.monitor.ServletMonitor; import org.codehaus.waffle.validation.BindErrorMessage; import org.codehaus.waffle.view.View; -public class StubMonitor implements ActionMonitor, BindMonitor { +public class StubMonitor implements ActionMonitor, BindMonitor, ServletMonitor { public void defaultActionMethodFound(MethodDefinition methodDefinition) { } @@ -57,4 +58,7 @@ public void viewDispatched(View view) { } + public void servletServiceFailed(Exception cause) { + } + }
To unsubscribe from this list please visit:
