From 626882318634addd6966266013e8e1fce288d45f Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 7 May 2013 07:26:39 -0700 Subject: [PATCH] Allow shenanigans (injection) when instantiating logic. --- .../velocity/DispatcherServlet.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/samskivert/velocity/DispatcherServlet.java b/src/main/java/com/samskivert/velocity/DispatcherServlet.java index fc0e8156..85c840ef 100644 --- a/src/main/java/com/samskivert/velocity/DispatcherServlet.java +++ b/src/main/java/com/samskivert/velocity/DispatcherServlet.java @@ -575,17 +575,7 @@ public class DispatcherServlet extends HttpServlet Logic logic = _logic.get(lclass); if (logic == null) { - try { - Class pcl = Class.forName(lclass); - logic = (Logic)pcl.newInstance(); - - } catch (ClassNotFoundException cnfe) { - // nothing interesting to report - - } catch (Throwable t) { - log.warning("Unable to instantiate logic for application", "path", path, - "lclass", lclass, t); - } + logic = instantiateLogic(path, lclass); // if something failed, use a dummy in it's place so that we don't sit around all day // freaking out about our inability to instantiate the proper logic class @@ -600,6 +590,23 @@ public class DispatcherServlet extends HttpServlet return logic; } + /** + * Instantiates a logic instance with the supplied class name. May return null if no such class + * exists. + */ + protected Logic instantiateLogic (String path, String lclass) { + try { + Class pcl = Class.forName(lclass); + return (Logic)pcl.newInstance(); + } catch (ClassNotFoundException cnfe) { + // nothing interesting to report + } catch (Throwable t) { + log.warning("Unable to instantiate logic for application", "path", path, + "lclass", lclass, t); + } + return null; + } + /** The application being served by this dispatcher servlet. */ protected Application _app;