|
From: <jt...@hy...> - 2007-03-26 23:28:50
|
Author: jtravis Date: 2007-03-26 15:28:44 -0800 (Mon, 26 Mar 2007) New Revision: 3911 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=3911 Modified: trunk/src/org/hyperic/hq/ui/rendit/InvocationBindings.java trunk/src/org/hyperic/hq/ui/rendit/RenditServer.java trunk/src/org/hyperic/hq/ui/rendit/servlet/RenditServlet.java trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy Log: Migrate path parsing to the groovy dispatcher Modified: trunk/src/org/hyperic/hq/ui/rendit/InvocationBindings.java =================================================================== --- trunk/src/org/hyperic/hq/ui/rendit/InvocationBindings.java 2007-03-26 21:17:40 UTC (rev 3910) +++ trunk/src/org/hyperic/hq/ui/rendit/InvocationBindings.java 2007-03-26 23:28:44 UTC (rev 3911) @@ -1,8 +1,6 @@ package org.hyperic.hq.ui.rendit; import java.io.File; -import java.util.Collections; -import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -12,24 +10,18 @@ * the groovy dispatcher. */ public class InvocationBindings { - private List _requestPath; private File _pluginDir; private HttpServletRequest _request; private HttpServletResponse _response; - InvocationBindings(List requestPath, File pluginDir, - HttpServletRequest request, HttpServletResponse response) + InvocationBindings(File pluginDir, HttpServletRequest request, + HttpServletResponse response) { - _requestPath = requestPath; _pluginDir = pluginDir; _request = request; _response = response; } - public List getRequestPath() { - return Collections.unmodifiableList(_requestPath); - } - public File getPluginDir() { return _pluginDir; } Modified: trunk/src/org/hyperic/hq/ui/rendit/RenditServer.java =================================================================== --- trunk/src/org/hyperic/hq/ui/rendit/RenditServer.java 2007-03-26 21:17:40 UTC (rev 3910) +++ trunk/src/org/hyperic/hq/ui/rendit/RenditServer.java 2007-03-26 23:28:44 UTC (rev 3911) @@ -75,11 +75,10 @@ } } - public void handleRequest(List path, HttpServletRequest req, + public void handleRequest(String pluginName, HttpServletRequest req, HttpServletResponse resp) throws Exception { - String pluginName = (String)path.get(0); PluginWrapper plugin; synchronized (CFG_LOCK) { @@ -93,7 +92,7 @@ Binding b = new Binding(); b.setVariable("invokeArgs", - new InvocationBindings(path, plugin.getPluginDir(), + new InvocationBindings(plugin.getPluginDir(), req, resp)); plugin.run("org/hyperic/hq/ui/rendit/dispatcher.groovy", b); } Modified: trunk/src/org/hyperic/hq/ui/rendit/servlet/RenditServlet.java =================================================================== --- trunk/src/org/hyperic/hq/ui/rendit/servlet/RenditServlet.java 2007-03-26 21:17:40 UTC (rev 3910) +++ trunk/src/org/hyperic/hq/ui/rendit/servlet/RenditServlet.java 2007-03-26 23:28:44 UTC (rev 3911) @@ -47,14 +47,16 @@ reqUri = reqUri.substring(servPath.length()); List path = StringUtil.explode(reqUri, "/"); - if (path.size() != 3) { + if (path.size() < 1) { throw new ServletException("Illegal request path"); } - _log.info("Request: " + req.getRequestURI() + "?" + - req.getQueryString()); + String plugin = (String)path.get(0); + _log.info("Request for [" + plugin + "]: " + req.getRequestURI() + + "?" + req.getQueryString()); + try { - RenditServer.getInstance().handleRequest(path, req, response); + RenditServer.getInstance().handleRequest(plugin, req, response); } catch(Exception e) { throw new ServletException(e); } Modified: trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy =================================================================== --- trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy 2007-03-26 21:17:40 UTC (rev 3910) +++ trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy 2007-03-26 23:28:44 UTC (rev 3911) @@ -6,7 +6,7 @@ /** * The Dispatcher is the direct invocation target called from the HQ * RenditServer. It has the responsibility of locating the controllers, - * setting up the environment, and invoking the request. + * setting up the environment, and invoking the request. */ class Dispatcher { private Log log = LogFactory.getLog(Dispatcher.class); @@ -22,9 +22,13 @@ return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase(); } - def Dispatcher(def invokeArgs) { - def path = invokeArgs.requestPath + def Dispatcher(invokeArgs) { + def req = invokeArgs.request + def servPath = req.servletPath + def reqUri = req.requestURI + List path = reqUri[(servPath.length() + 1)..-1].split('/') + if (path.size() < 3) { throw new IllegalArgumentException("Path must have at least 3 " + "components"); @@ -33,7 +37,7 @@ pluginDir = invokeArgs.pluginDir controllerName = capitalize(path[1]) + "Controller" action = path[2] - this.invokeArgs = invokeArgs + this.invokeArgs = invokeArgs } def invoke() { |