geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r783899 - /geronimo/server/branches/2.1/plugins/console/console-portal-driver/src/main/java/org/apache/geronimo/console/servlet/GenericForwardServlet.java
Date Thu, 11 Jun 2009 20:45:45 GMT
Author: gawor
Date: Thu Jun 11 20:45:45 2009
New Revision: 783899

URL: http://svn.apache.org/viewvc?rev=783899&view=rev
Log:
handle servlet context restarts and improve error handling (GERONIMO-4638)

Modified:
    geronimo/server/branches/2.1/plugins/console/console-portal-driver/src/main/java/org/apache/geronimo/console/servlet/GenericForwardServlet.java

Modified: geronimo/server/branches/2.1/plugins/console/console-portal-driver/src/main/java/org/apache/geronimo/console/servlet/GenericForwardServlet.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/console/console-portal-driver/src/main/java/org/apache/geronimo/console/servlet/GenericForwardServlet.java?rev=783899&r1=783898&r2=783899&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/console/console-portal-driver/src/main/java/org/apache/geronimo/console/servlet/GenericForwardServlet.java
(original)
+++ geronimo/server/branches/2.1/plugins/console/console-portal-driver/src/main/java/org/apache/geronimo/console/servlet/GenericForwardServlet.java
Thu Jun 11 20:45:45 2009
@@ -98,8 +98,9 @@
 
     private void addGBean(AbstractName name) {
         ContextForward forward = (ContextForward) kernel.getProxyManager().createProxy(name,
ContextForward.class);
-        forwards.put(forward.getPortalPathPrefix(), new ForwardData(getServletContext().getContext(forward.getPortletContextPath()),
-                                                                    forward.getPortletServletPath(),
name));
+        forwards.put(forward.getPortalPathPrefix(), new ForwardData(forward.getPortletContextPath(),

+                                                                    forward.getPortletServletPath(),

+                                                                    name));
     }
 
     private void removeGBean(AbstractName name) {
@@ -123,7 +124,7 @@
         String path = req.getPathInfo();
         if(path == null) {
             log.error("Unable to forward request; no path information provided.  Path is
used to identify where to forward to.");
-            return;
+            throw new ServletException("Unable to forward request");
         }
         ForwardData forward = null;
         for (Iterator it = forwards.keySet().iterator(); it.hasNext();) {
@@ -131,11 +132,12 @@
             if(path.startsWith(prefix)) {
                 forward = (ForwardData) forwards.get(prefix);
                 path = path.substring(prefix.length());
+                break;
             }
         }
         if(forward == null) {
             log.error("Unable to forward URL "+path+"; does not match any known ContextForward
definitions.");
-            return;
+            throw new ServletException("Unable to forward request");
         }
         if(!path.equals("") && !path.startsWith("/")) path = "/"+path;
         String queryString = req.getQueryString();
@@ -143,23 +145,32 @@
             path += "?" + queryString;
         }
         path = forward.getServletPath()+path;
-        RequestDispatcher dispatcher = forward.getForwardContext().getRequestDispatcher(path);
+        ServletContext ctx = forward.getForwardContext(getServletContext());
+        if (ctx == null) {
+            log.error("Unable to forward URL " + path + ". Context not found: " + forward.getContextPath());
+            throw new ServletException("Unable to forward request");
+        }
+        RequestDispatcher dispatcher = ctx.getRequestDispatcher(path);
         dispatcher.forward(req, resp);
     }
 
     private static class ForwardData {
-        private ServletContext forwardContext;
+        private String contextPath;
         private String servletPath;
         private AbstractName gbean;
 
-        public ForwardData(ServletContext forwardContext, String servletPath, AbstractName
gbean) {
-            this.forwardContext = forwardContext;
+        public ForwardData(String contextPath, String servletPath, AbstractName gbean) {
+            this.contextPath = contextPath;
             this.servletPath = servletPath;
             this.gbean = gbean;
         }
 
-        public ServletContext getForwardContext() {
-            return forwardContext;
+        public ServletContext getForwardContext(ServletContext ctx) {
+            return ctx.getContext(contextPath);
+        }
+        
+        public String getContextPath() {
+            return contextPath;
         }
 
         public String getServletPath() {



Mime
View raw message