Author: hoang_to
Date: 2011-09-14 23:47:43 -0400 (Wed, 14 Sep 2011)
New Revision: 7433
Modified:
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/WebAppController.java
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/WebRequestHandler.java
portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/DownloadHandler.java
portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/UploadHandler.java
portal/trunk/packaging/jboss-as5/pkg/src/main/resources/jboss/server/default/conf/gatein/controller.xml
portal/trunk/packaging/jboss-as6/pkg/src/main/resources/jboss/server/default/conf/gatein/controller.xml
portal/trunk/packaging/jetty/pkg/src/main/resources/jetty/gatein/conf/controller.xml
portal/trunk/packaging/tomcat/pkg/src/main/resources/tomcat/gatein/conf/controller.xml
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/DefaultRequestHandler.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/LegacyRequestHandler.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/StaticResourceRequestHandler.java
Log:
GTNPORTAL-2099: WebRequestHandler could relay request handling work to another
requesthandler
Modified:
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/WebAppController.java
===================================================================
---
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/WebAppController.java 2011-09-15
03:39:16 UTC (rev 7432)
+++
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/WebAppController.java 2011-09-15
03:47:43 UTC (rev 7433)
@@ -35,14 +35,13 @@
import org.exoplatform.management.rest.annotations.RESTEndpoint;
import org.exoplatform.web.application.Application;
import org.exoplatform.web.controller.QualifiedName;
+import org.exoplatform.web.controller.metadata.ControllerDescriptor;
import org.exoplatform.web.controller.metadata.DescriptorBuilder;
-import org.exoplatform.web.controller.metadata.ControllerDescriptor;
+import org.exoplatform.web.controller.router.Router;
import org.exoplatform.web.controller.router.RouterConfigException;
-import org.exoplatform.web.controller.router.Router;
import org.gatein.common.http.QueryStringParser;
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
-
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -56,7 +55,6 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
-
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -320,51 +318,57 @@
Iterator<Map<QualifiedName, String>> matcher =
router.matcher(portalPath, req.getParameterMap());
//
- Map<QualifiedName, String> parameters = null;
- if (matcher.hasNext())
- {
- parameters = matcher.next();
- }
+ boolean started = false;
+ boolean processed = false;
//
- if (parameters != null)
+ try
{
- String handlerKey = parameters.get(HANDLER_PARAM);
- if (handlerKey != null)
+ while (matcher.hasNext() && !processed)
{
- WebRequestHandler handler = handlers.get(handlerKey);
- if (handler != null)
+ if (!started)
{
- if (debug)
- {
- log.debug("Serving request path=" + portalPath + ",
parameters=" + parameters + " with handler " + handler);
- }
-
- //
RequestLifeCycle.begin(ExoContainerContext.getCurrentContainer());
+ started = true;
+ }
- //
- try
+ //
+ Map<QualifiedName, String> parameters = matcher.next();
+ String handlerKey = parameters.get(HANDLER_PARAM);
+ if (handlerKey != null)
+ {
+ WebRequestHandler handler = handlers.get(handlerKey);
+ if (handler != null)
{
- handler.execute(new ControllerContext(this, router, req, res,
parameters));
+ if (debug)
+ {
+ log.debug("Serving request path=" + portalPath +
", parameters=" + parameters + " with handler " + handler);
+ }
+
+ //
+ processed = handler.execute(new ControllerContext(this, router, req,
res, parameters));
}
- finally
+ else
{
- RequestLifeCycle.end();
+ log.debug("No handler " + handlerKey + " for request
path=" + portalPath + ", parameters=" + parameters);
}
}
- else
- {
- log.error("Invalid handler " + handlerKey + " for
request path=" + portalPath + ", parameters=" + parameters);
- res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
}
}
- else
+ finally
{
- log.error("Could not associate the request path=" + portalPath +
", parameters=" + parameters + " with an handler");
- res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ if (started)
+ {
+ RequestLifeCycle.end();
+ }
}
+
+ //
+ if (!processed)
+ {
+ log.error("Could not associate the request path=" + portalPath +
" with an handler");
+ res.sendError(HttpServletResponse.SC_NOT_FOUND);
+ }
}
else
{
Modified:
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/WebRequestHandler.java
===================================================================
---
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/WebRequestHandler.java 2011-09-15
03:39:16 UTC (rev 7432)
+++
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/WebRequestHandler.java 2011-09-15
03:47:43 UTC (rev 7433)
@@ -20,10 +20,6 @@
package org.exoplatform.web;
import org.exoplatform.container.component.BaseComponentPlugin;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.Map;
import javax.servlet.ServletConfig;
/**
@@ -55,8 +51,9 @@
*
* @param context the controller context
* @throws Exception any exception
+ * @return true if the handler was able to handle the request
*/
- abstract public void execute(ControllerContext context) throws Exception;
+ abstract public boolean execute(ControllerContext context) throws Exception;
/**
* Destroy callback.
Modified:
portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/DownloadHandler.java
===================================================================
---
portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/DownloadHandler.java 2011-09-15
03:39:16 UTC (rev 7432)
+++
portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/DownloadHandler.java 2011-09-15
03:47:43 UTC (rev 7433)
@@ -49,9 +49,10 @@
}
@Override
- public void execute(ControllerContext context) throws Exception
+ public boolean execute(ControllerContext context) throws Exception
{
execute(context.getController(), context.getRequest(), context.getResponse());
+ return true;
}
public void execute(WebAppController controller, HttpServletRequest req,
HttpServletResponse res) throws Exception
Modified:
portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/UploadHandler.java
===================================================================
---
portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/UploadHandler.java 2011-09-15
03:39:16 UTC (rev 7432)
+++
portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/UploadHandler.java 2011-09-15
03:47:43 UTC (rev 7433)
@@ -53,9 +53,10 @@
}
@Override
- public void execute(ControllerContext context) throws Exception
+ public boolean execute(ControllerContext context) throws Exception
{
execute(context.getController(), context.getRequest(), context.getResponse());
+ return true;
}
public void execute(WebAppController controller, HttpServletRequest req,
HttpServletResponse res) throws Exception
Modified:
portal/trunk/packaging/jboss-as5/pkg/src/main/resources/jboss/server/default/conf/gatein/controller.xml
===================================================================
---
portal/trunk/packaging/jboss-as5/pkg/src/main/resources/jboss/server/default/conf/gatein/controller.xml 2011-09-15
03:39:16 UTC (rev 7432)
+++
portal/trunk/packaging/jboss-as5/pkg/src/main/resources/jboss/server/default/conf/gatein/controller.xml 2011-09-15
03:47:43 UTC (rev 7433)
@@ -67,15 +67,6 @@
</route>
</route>
- <route path="/{gtn:path}">
- <route-param qname="gtn:handler">
- <value>staticResource</value>
- </route-param>
- <path-param qname="gtn:path" encoding="preserve-path">
- <pattern>.*\.(jpg|png|gif|ico|css)</pattern>
- </path-param>
- </route>
-
<route path="/">
<!-- The portal handler -->
@@ -129,6 +120,15 @@
</route>
+ <route path="/{gtn:path}">
+ <route-param qname="gtn:handler">
+ <value>staticResource</value>
+ </route-param>
+ <path-param qname="gtn:path" encoding="preserve-path">
+ <pattern>.*\.(jpg|png|gif|ico|css)</pattern>
+ </path-param>
+ </route>
+
<!-- Default handler -->
<route path="/">
<route-param qname="gtn:handler">
Modified:
portal/trunk/packaging/jboss-as6/pkg/src/main/resources/jboss/server/default/conf/gatein/controller.xml
===================================================================
---
portal/trunk/packaging/jboss-as6/pkg/src/main/resources/jboss/server/default/conf/gatein/controller.xml 2011-09-15
03:39:16 UTC (rev 7432)
+++
portal/trunk/packaging/jboss-as6/pkg/src/main/resources/jboss/server/default/conf/gatein/controller.xml 2011-09-15
03:47:43 UTC (rev 7433)
@@ -67,15 +67,6 @@
</route>
</route>
- <route path="/{gtn:path}">
- <route-param qname="gtn:handler">
- <value>staticResource</value>
- </route-param>
- <path-param qname="gtn:path" encoding="preserve-path">
- <pattern>.*\.(jpg|png|gif|ico|css)</pattern>
- </path-param>
- </route>
-
<route path="/">
<!-- The portal handler -->
@@ -129,6 +120,15 @@
</route>
+ <route path="/{gtn:path}">
+ <route-param qname="gtn:handler">
+ <value>staticResource</value>
+ </route-param>
+ <path-param qname="gtn:path" encoding="preserve-path">
+ <pattern>.*\.(jpg|png|gif|ico|css)</pattern>
+ </path-param>
+ </route>
+
<!-- Default handler -->
<route path="/">
<route-param qname="gtn:handler">
Modified:
portal/trunk/packaging/jetty/pkg/src/main/resources/jetty/gatein/conf/controller.xml
===================================================================
---
portal/trunk/packaging/jetty/pkg/src/main/resources/jetty/gatein/conf/controller.xml 2011-09-15
03:39:16 UTC (rev 7432)
+++
portal/trunk/packaging/jetty/pkg/src/main/resources/jetty/gatein/conf/controller.xml 2011-09-15
03:47:43 UTC (rev 7433)
@@ -67,15 +67,6 @@
</route>
</route>
- <route path="/{gtn:path}">
- <route-param qname="gtn:handler">
- <value>staticResource</value>
- </route-param>
- <path-param qname="gtn:path" encoding="preserve-path">
- <pattern>.*\.(jpg|png|gif|ico|css)</pattern>
- </path-param>
- </route>
-
<route path="/">
<!-- The portal handler -->
@@ -129,6 +120,15 @@
</route>
+ <route path="/{gtn:path}">
+ <route-param qname="gtn:handler">
+ <value>staticResource</value>
+ </route-param>
+ <path-param qname="gtn:path" encoding="preserve-path">
+ <pattern>.*\.(jpg|png|gif|ico|css)</pattern>
+ </path-param>
+ </route>
+
<!-- Default handler -->
<route path="/">
<route-param qname="gtn:handler">
Modified:
portal/trunk/packaging/tomcat/pkg/src/main/resources/tomcat/gatein/conf/controller.xml
===================================================================
---
portal/trunk/packaging/tomcat/pkg/src/main/resources/tomcat/gatein/conf/controller.xml 2011-09-15
03:39:16 UTC (rev 7432)
+++
portal/trunk/packaging/tomcat/pkg/src/main/resources/tomcat/gatein/conf/controller.xml 2011-09-15
03:47:43 UTC (rev 7433)
@@ -67,15 +67,6 @@
</route>
</route>
- <route path="/{gtn:path}">
- <route-param qname="gtn:handler">
- <value>staticResource</value>
- </route-param>
- <path-param qname="gtn:path" encoding="preserve-path">
- <pattern>.*\.(jpg|png|gif|ico|css)</pattern>
- </path-param>
- </route>
-
<route path="/">
<!-- The portal handler -->
@@ -129,6 +120,15 @@
</route>
+ <route path="/{gtn:path}">
+ <route-param qname="gtn:handler">
+ <value>staticResource</value>
+ </route-param>
+ <path-param qname="gtn:path" encoding="preserve-path">
+ <pattern>.*\.(jpg|png|gif|ico|css)</pattern>
+ </path-param>
+ </route>
+
<!-- Default handler -->
<route path="/">
<route-param qname="gtn:handler">
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/DefaultRequestHandler.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/DefaultRequestHandler.java 2011-09-15
03:39:16 UTC (rev 7432)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/DefaultRequestHandler.java 2011-09-15
03:47:43 UTC (rev 7433)
@@ -56,7 +56,7 @@
}
@Override
- public void execute(ControllerContext context) throws Exception
+ public boolean execute(ControllerContext context) throws Exception
{
String defaultPortal = configService.getDefaultPortal();
PortalURLContext urlContext = new PortalURLContext(context,
SiteKey.portal(defaultPortal));
@@ -64,5 +64,6 @@
String s = url.setResource(new NavigationResource(SiteType.PORTAL, defaultPortal,
"")).toString();
HttpServletResponse resp = context.getResponse();
resp.sendRedirect(resp.encodeRedirectURL(s));
+ return true;
}
}
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/LegacyRequestHandler.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/LegacyRequestHandler.java 2011-09-15
03:39:16 UTC (rev 7432)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/LegacyRequestHandler.java 2011-09-15
03:47:43 UTC (rev 7433)
@@ -84,7 +84,7 @@
}
@Override
- public void execute(ControllerContext context) throws Exception
+ public boolean execute(ControllerContext context) throws Exception
{
String requestSiteName =
context.getParameter(PortalRequestHandler.REQUEST_SITE_NAME);
String requestPath = context.getParameter(PortalRequestHandler.REQUEST_PATH);
@@ -129,5 +129,6 @@
HttpServletResponse resp = context.getResponse();
resp.sendRedirect(resp.encodeRedirectURL(s));
+ return true;
}
}
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java 2011-09-15
03:39:16 UTC (rev 7432)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java 2011-09-15
03:47:43 UTC (rev 7433)
@@ -28,7 +28,6 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.web.ControllerContext;
-import org.exoplatform.web.WebAppController;
import org.exoplatform.web.WebRequestHandler;
import org.exoplatform.web.application.ApplicationLifecycle;
import org.exoplatform.web.application.ApplicationRequestPhaseLifecycle;
@@ -37,10 +36,8 @@
import org.exoplatform.web.controller.QualifiedName;
import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.core.UIApplication;
-
import java.util.List;
import java.util.Locale;
-
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -98,7 +95,7 @@
*/
@SuppressWarnings("unchecked")
@Override
- public void execute(ControllerContext controllerContext) throws Exception
+ public boolean execute(ControllerContext controllerContext) throws Exception
{
HttpServletRequest req = controllerContext.getRequest();
HttpServletResponse res = controllerContext.getResponse();
@@ -126,7 +123,7 @@
if (requestSiteName == null) {
res.sendRedirect(req.getContextPath());
- return;
+ return true;
}
PortalApplication app =
controllerContext.getController().getApplication(PortalApplication.PORTAL_APPLICATION_ID);
@@ -137,7 +134,7 @@
PortalConfig persistentPortalConfig = storage.getPortalConfig(requestSiteType,
requestSiteName);
if (persistentPortalConfig == null)
{
- context.sendError(HttpServletResponse.SC_NOT_FOUND);
+ return false;
}
else if(req.getRemoteUser() == null)
{
@@ -152,6 +149,7 @@
{
processRequest(context, app);
}
+ return true;
}
@SuppressWarnings("unchecked")
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/StaticResourceRequestHandler.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/StaticResourceRequestHandler.java 2011-09-15
03:39:16 UTC (rev 7432)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/StaticResourceRequestHandler.java 2011-09-15
03:47:43 UTC (rev 7433)
@@ -39,7 +39,7 @@
}
@Override
- public void execute(ControllerContext context) throws Exception
+ public boolean execute(ControllerContext context) throws Exception
{
PortalContainer portalContainer = PortalContainer.getInstance();
ServletContext mergedContext = portalContainer.getPortalContext();
@@ -47,5 +47,6 @@
HttpServletRequest req = context.getRequest();
HttpServletResponse res = context.getResponse();
mergedContext.getNamedDispatcher("default").forward(req, res);
+ return true;
}
}