[portal-commits] JBoss Portal SVN: r9032 - in branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server: servlet and 1 other directory.

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Mon Nov 19 19:14:29 EST 2007


Author: julien at jboss.com
Date: 2007-11-19 19:14:29 -0500 (Mon, 19 Nov 2007)
New Revision: 9032

Modified:
   branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/impl/ServerInvocationContextImpl.java
   branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/servlet/PortalServlet.java
Log:
make 2.6 delegate parameter parsing to WebRequest from web module

Modified: branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/impl/ServerInvocationContextImpl.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/impl/ServerInvocationContextImpl.java	2007-11-20 00:12:45 UTC (rev 9031)
+++ branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/impl/ServerInvocationContextImpl.java	2007-11-20 00:14:29 UTC (rev 9032)
@@ -35,6 +35,8 @@
 import org.jboss.portal.server.ServerURL;
 import org.jboss.portal.server.request.URLContext;
 import org.jboss.portal.server.request.URLFormat;
+import org.jboss.portal.web.WebRequest;
+import org.jboss.portal.web.Body;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -54,6 +56,9 @@
    /** The client request. */
    private final HttpServletRequest req;
 
+   /** The client request. */
+   private final WebRequest webReq;
+
    /** The client response. */
    private final HttpServletResponse resp;
 
@@ -66,15 +71,6 @@
    /** The portal host. */
    private String portalHost;
 
-   /** . */
-   private String mediaType;
-
-   /** The query parameter map. */
-   private ParameterMap queryParameterMap;
-
-   /** The body parameter map or null. */
-   private ParameterMap bodyParameterMap;
-
    /** The url context. */
    private URLContext urlContext;
 
@@ -90,13 +86,11 @@
    public ServerInvocationContextImpl(
       HttpServletRequest req,
       HttpServletResponse resp,
+      WebRequest webReq,
       String portalHost,
       String portalRequestPath,
       String portalContextPath,
-      Map queryParameterMap,
-      Map bodyParameterMap,
-      URLContext urlContext,
-      String mediaType)
+      URLContext urlContext)
    {
       if (req == null)
       {
@@ -109,14 +103,12 @@
 
       //
       this.req = req;
+      this.webReq = webReq;
       this.resp = resp;
       this.portalRequestPath = portalRequestPath;
       this.portalContextPath = portalContextPath;
       this.portalHost = portalHost;
-      this.queryParameterMap = new ParameterMap(queryParameterMap);
-      this.bodyParameterMap = bodyParameterMap != null ? new ParameterMap(bodyParameterMap) : null;
       this.urlContext = urlContext;
-      this.mediaType = mediaType;
       this.buffers = new Buffer[16];
 
       //
@@ -157,7 +149,7 @@
 
    public String getMediaType()
    {
-      return mediaType;
+      return webReq.getMediaType();
    }
 
    public URLContext getURLContext()
@@ -167,12 +159,21 @@
 
    public ParameterMap getQueryParameterMap()
    {
-      return queryParameterMap;
+      return webReq.getQueryParameterMap();
    }
 
    public ParameterMap getBodyParameterMap()
    {
-      return bodyParameterMap;
+      Body body = webReq.getBody();
+
+      //
+      if (body instanceof Body.Form)
+      {
+         return ((Body.Form)body).getParameters();
+      }
+
+      //
+      return null;
    }
 
    public String getPortalRequestPath()

Modified: branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/servlet/PortalServlet.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/servlet/PortalServlet.java	2007-11-20 00:12:45 UTC (rev 9031)
+++ branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/servlet/PortalServlet.java	2007-11-20 00:14:29 UTC (rev 9032)
@@ -25,12 +25,10 @@
 import org.apache.log4j.Logger;
 import org.jboss.mx.util.MBeanProxy;
 import org.jboss.mx.util.MBeanServerLocator;
-import org.jboss.portal.common.http.QueryStringParser;
 import org.jboss.portal.common.invocation.InterceptorStackFactory;
 import org.jboss.portal.common.invocation.InvocationException;
 import org.jboss.portal.common.net.URLTools;
 import org.jboss.portal.common.util.Exceptions;
-import org.jboss.portal.server.PortalConstants;
 import org.jboss.portal.server.RequestController;
 import org.jboss.portal.server.RequestControllerDispatcher;
 import org.jboss.portal.server.RequestControllerFactory;
@@ -42,6 +40,7 @@
 import org.jboss.portal.server.ServerResponse;
 import org.jboss.portal.server.impl.ServerInvocationContextImpl;
 import org.jboss.portal.server.request.URLContext;
+import org.jboss.portal.web.WebRequest;
 
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
@@ -51,11 +50,6 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
-import java.nio.charset.Charset;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
 
 /**
  * The main servlet of the portal. This servlet must be properly configured with the servlet mapping style it is
@@ -67,12 +61,6 @@
 public class PortalServlet extends HttpServlet
 {
 
-   /** . */
-   private static final int GET_METHOD = 0;
-
-   /** . */
-   private static final int POST_METHOD = 1;
-
    /** Describes a default servlet mapping. */
    private static final int DEFAULT_SERVLET_MAPPING = 0;
 
@@ -167,68 +155,8 @@
       return controllerFactory;
    }
 
-   private String retrieveMediaType(String contentType)
-   {
-      String mediaType = contentType;
-
-      //
-      if (mediaType != null)
-      {
-         // Remove any parameters
-         int index = mediaType.indexOf(';');
-         if (index != -1)
-         {
-            mediaType = contentType.substring(0, index);
-         }
-
-         // Trim
-         mediaType = mediaType.trim();
-
-         // Media type matching is case insensitive, so we convert to lower case
-         mediaType = mediaType.toLowerCase();
-      }
-      return mediaType;
-   }
-
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
-      int method;
-      if ("GET".equals(req.getMethod()))
-      {
-         method = GET_METHOD;
-      }
-      else if ("POST".equals(req.getMethod()))
-      {
-         method = POST_METHOD;
-      }
-      else
-      {
-         throw new ServletException();
-      }
-
-      // Compute the media type in the content type
-      String mediaType = retrieveMediaType(req.getContentType());
-
-      // Only affect the charset encoding if the servlet container will decode the request
-      if (method == POST_METHOD && PortalConstants.APPLICATION_X_WWW_FORM_URLENCODED.equals(mediaType))
-      {
-         // Now we must ensure that we have either an equals or a trailing space after the media-type
-         String characterEncoding = req.getCharacterEncoding();
-         if (characterEncoding == null)
-         {
-            // Set out charset for the portal request
-            req.setCharacterEncoding(PortalConstants.UTF_8.name());
-         }
-         else
-         {
-            Charset charset = Charset.forName(characterEncoding);
-            if (!PortalConstants.UTF_8.equals(charset))
-            {
-               throw new ServletException("Unaccepted charset " + characterEncoding);
-            }
-         }
-      }
-
       //
       String servletPath = req.getServletPath();
       String requestURI = req.getRequestURI();
@@ -277,65 +205,9 @@
       //
       URLContext urlContext = URLContext.newInstance(req.isSecure(), req.getRemoteUser() != null);
 
-      // ***************
-      // ***************
-      // ***************
-      // ***************
-
-      // Parse the query string to have the get parameters
-      // The resulting map has its parameters decoded from the x-www-form-url encoding
-      Map queryParameterMap = Collections.EMPTY_MAP;
-      String queryString = req.getQueryString();
-      if (queryString != null)
-      {
-         queryParameterMap = QueryStringParser.getInstance().parseQueryString(queryString);
-      }
-
       //
-      Map bodyParameterMap = null;
-      if (method == POST_METHOD && PortalConstants.APPLICATION_X_WWW_FORM_URLENCODED.equals(mediaType))
-      {
-         bodyParameterMap = Collections.EMPTY_MAP;
-         for (Iterator i = req.getParameterMap().entrySet().iterator(); i.hasNext();)
-         {
-            Map.Entry entry = (Map.Entry)i.next();
+      WebRequest webReq = new WebRequest(req);
 
-            // Get param name
-            String paramName = (String)entry.getKey();
-
-            // Values that are aggregated from the query string and the body
-            String[] paramValues = (String[])entry.getValue();
-
-            // Values decoded from the query string
-            String[] queryValues = (String[])queryParameterMap.get(paramName);
-            if (queryValues != null)
-            {
-               int bodyValuesLength = paramValues.length - queryValues.length;
-               if (bodyValuesLength > 0)
-               {
-                  String[] bodyValues = new String[bodyValuesLength];
-                  System.arraycopy(paramValues, queryValues.length, bodyValues, 0, bodyValuesLength);
-                  if (bodyParameterMap.isEmpty())
-                  {
-                     bodyParameterMap = new HashMap();
-                  }
-                  bodyParameterMap.put(paramName, bodyValues);
-               }
-            }
-            else
-            {
-               if (bodyParameterMap.isEmpty())
-               {
-                  bodyParameterMap = new HashMap();
-               }
-               bodyParameterMap.put(paramName, paramValues);
-            }
-         }
-
-         // Make the map unmodifiable
-         bodyParameterMap = bodyParameterMap.isEmpty() ? bodyParameterMap : Collections.unmodifiableMap(bodyParameterMap);
-      }
-
       // ***************
       // ***************
       // ***************
@@ -348,13 +220,11 @@
       ServerInvocationContext invocationCtx = new ServerInvocationContextImpl(
          req,
          resp,
+         webReq,
          portalHost,
          portalRequestPath,
          portalContextPath,
-         queryParameterMap,
-         bodyParameterMap,
-         urlContext,
-         mediaType);
+         urlContext);
 
       //
       ServerRequest request = new ServerRequest(invocationCtx);




More information about the portal-commits mailing list