Author: julien_viet
Date: 2010-09-02 10:44:20 -0400 (Thu, 02 Sep 2010)
New Revision: 4034
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/WebAppController.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/WebRequestHandler.java
portal/branches/navcontroller/component/web/server/src/main/java/org/exoplatform/web/handler/DownloadHandler.java
portal/branches/navcontroller/component/web/server/src/main/java/org/exoplatform/web/handler/UploadHandler.java
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java
Log:
start to wire URL router with portal controller
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/WebAppController.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/WebAppController.java 2010-09-02
13:40:40 UTC (rev 4033)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/WebAppController.java 2010-09-02
14:44:20 UTC (rev 4034)
@@ -22,14 +22,18 @@
import org.exoplatform.container.ExoContainer;
import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.container.component.RequestLifeCycle;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
import org.exoplatform.web.application.Application;
+import org.exoplatform.web.controller.QualifiedName;
+import org.exoplatform.web.controller.metadata.RouteMetaData;
+import org.exoplatform.web.controller.metadata.RouterMetaData;
import org.exoplatform.web.controller.router.Router;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -46,14 +50,19 @@
public class WebAppController
{
- protected static Log log = ExoLogger.getLogger("portal:WebAppController");
+ /** . */
+ protected static Logger log = LoggerFactory.getLogger(WebAppController.class);
+ /** . */
private HashMap<String, Object> attributes_;
+ /** . */
private HashMap<String, Application> applications_;
- private HashMap<String, WebRequestHandler> handlers_;
+ /** . */
+ private HashMap<String, WebRequestHandler> handlers;
+ /** . */
private Router router;
/**
@@ -67,7 +76,8 @@
{
applications_ = new HashMap<String, Application>();
attributes_ = new HashMap<String, Object>();
- handlers_ = new HashMap<String, WebRequestHandler>();
+ this.handlers = new HashMap<String, WebRequestHandler>();
+ this.router = new Router(new RouterMetaData());
}
public Object getAttribute(String name, Object value)
@@ -102,18 +112,28 @@
applications_.put(app.getApplicationId(), app);
}
+ private static final QualifiedName HANDLER_PARAM = new QualifiedName("ctrl",
"handler");
+
public void register(WebRequestHandler handler) throws Exception
{
for (String path : handler.getPath())
- handlers_.put(path, handler);
+ {
+ RouteMetaData routeMetaData = new RouteMetaData(path);
+
+ //
+ String handlerKey = "" + System.identityHashCode(handler);
+
+ //
+ routeMetaData.addParameter(HANDLER_PARAM, handlerKey);
+
+ //
+ handlers.put(handlerKey, handler);
+
+ //
+ router.addRoute(routeMetaData);
+ }
}
- public void unregister(String[] paths)
- {
- for (String path : paths)
- handlers_.remove(path);
- }
-
/**
* This is the first method - in the eXo web framework - reached by incoming HTTP
request, it acts like a
* servlet service() method
@@ -127,24 +147,37 @@
*/
public void service(HttpServletRequest req, HttpServletResponse res) throws Exception
{
- WebRequestHandler handler = handlers_.get(req.getServletPath());
- if (log.isDebugEnabled())
+
+ String portalPath = req.getRequestURI().substring(req.getContextPath().length());
+ log.info("Portal path: " + portalPath);
+
+ //
+ Map<QualifiedName, String> parameters = router.process(portalPath);
+ log.info("Decoded parameters: " + parameters);
+
+ //
+ if (parameters != null)
{
- log.debug("Servlet Path: " + req.getServletPath());
- log.debug("Handler used for this path: " + handler);
- }
- if (handler != null)
- {
- ExoContainer portalContainer = ExoContainerContext.getCurrentContainer();
- RequestLifeCycle.begin(portalContainer);
- try
+ String handlerKey = parameters.get(HANDLER_PARAM);
+ if (handlerKey != null)
{
- handler.execute(this, req, res);
+ WebRequestHandler handler = handlers.get(handlerKey);
+ log.info("Handler used for this path: " + handler);
+
+ //
+ ExoContainer portalContainer = ExoContainerContext.getCurrentContainer();
+ RequestLifeCycle.begin(portalContainer);
+
+ //
+ try
+ {
+ handler.execute(this, req, res, parameters);
+ }
+ finally
+ {
+ RequestLifeCycle.end();
+ }
}
- finally
- {
- RequestLifeCycle.end();
- }
}
}
}
\ No newline at end of file
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/WebRequestHandler.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/WebRequestHandler.java 2010-09-02
13:40:40 UTC (rev 4033)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/WebRequestHandler.java 2010-09-02
14:44:20 UTC (rev 4034)
@@ -20,9 +20,11 @@
package org.exoplatform.web;
import org.exoplatform.container.component.BaseComponentPlugin;
+import org.exoplatform.web.controller.QualifiedName;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.util.Map;
/**
* Created by The eXo Platform SAS
@@ -45,7 +47,11 @@
abstract public String[] getPath();
- abstract public void execute(WebAppController app, HttpServletRequest req,
HttpServletResponse res) throws Exception;
+ abstract public void execute(
+ WebAppController app,
+ HttpServletRequest req,
+ HttpServletResponse res,
+ Map<QualifiedName, String> parameters) throws Exception;
public void onDestroy(WebAppController controler) throws Exception
{
Modified:
portal/branches/navcontroller/component/web/server/src/main/java/org/exoplatform/web/handler/DownloadHandler.java
===================================================================
---
portal/branches/navcontroller/component/web/server/src/main/java/org/exoplatform/web/handler/DownloadHandler.java 2010-09-02
13:40:40 UTC (rev 4033)
+++
portal/branches/navcontroller/component/web/server/src/main/java/org/exoplatform/web/handler/DownloadHandler.java 2010-09-02
14:44:20 UTC (rev 4034)
@@ -25,10 +25,12 @@
import org.exoplatform.download.DownloadService;
import org.exoplatform.web.WebAppController;
import org.exoplatform.web.WebRequestHandler;
+import org.exoplatform.web.controller.QualifiedName;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
+import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -48,7 +50,7 @@
return new String[]{"/download"};
}
- public void execute(WebAppController controller, HttpServletRequest req,
HttpServletResponse res) throws Exception
+ public void execute(WebAppController controller, HttpServletRequest req,
HttpServletResponse res, Map<QualifiedName, String> parameters) throws Exception
{
String resourceId = req.getParameter("resourceId");
res.setHeader("Cache-Control", "private max-age=600,
s-maxage=120");
Modified:
portal/branches/navcontroller/component/web/server/src/main/java/org/exoplatform/web/handler/UploadHandler.java
===================================================================
---
portal/branches/navcontroller/component/web/server/src/main/java/org/exoplatform/web/handler/UploadHandler.java 2010-09-02
13:40:40 UTC (rev 4033)
+++
portal/branches/navcontroller/component/web/server/src/main/java/org/exoplatform/web/handler/UploadHandler.java 2010-09-02
14:44:20 UTC (rev 4034)
@@ -26,9 +26,11 @@
import org.exoplatform.upload.UploadService;
import org.exoplatform.web.WebAppController;
import org.exoplatform.web.WebRequestHandler;
+import org.exoplatform.web.controller.QualifiedName;
import java.io.Writer;
import java.net.URLEncoder;
+import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -52,7 +54,7 @@
return new String[]{"/upload"};
}
- public void execute(WebAppController controller, HttpServletRequest req,
HttpServletResponse res) throws Exception
+ public void execute(WebAppController controller, HttpServletRequest req,
HttpServletResponse res, Map<QualifiedName, String> parameters) throws Exception
{
String action = req.getParameter("action");
String[] uploadIds = req.getParameterValues("uploadId");
Modified:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java
===================================================================
---
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java 2010-09-02
13:40:40 UTC (rev 4033)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java 2010-09-02
14:44:20 UTC (rev 4034)
@@ -29,12 +29,14 @@
import org.exoplatform.web.application.ApplicationRequestPhaseLifecycle;
import org.exoplatform.web.application.Phase;
import org.exoplatform.web.application.RequestFailure;
+import org.exoplatform.web.controller.QualifiedName;
import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.core.UIApplication;
import org.exoplatform.webui.core.UIComponent;
import org.exoplatform.webui.event.Event;
import java.util.List;
+import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -51,7 +53,7 @@
protected static Log log =
ExoLogger.getLogger("portal:PortalRequestHandler");
- private String[] PATHS = {"/public", "/private"};
+ private String[] PATHS = {"/public{gtn{path}:.*}",
"/private{gtn{path}:.*}"};
public String[] getPath()
{
@@ -82,7 +84,7 @@
*
*/
@SuppressWarnings("unchecked")
- public void execute(WebAppController controller, HttpServletRequest req,
HttpServletResponse res) throws Exception
+ public void execute(WebAppController controller, HttpServletRequest req,
HttpServletResponse res, Map<QualifiedName, String> parameters) throws Exception
{
log.debug("Session ID = " + req.getSession().getId());
res.setHeader("Cache-Control", "no-cache");