portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r348855 - in /portals/jetspeed-2/trunk: commons/src/java/org/apache/jetspeed/container/ commons/src/java/org/apache/jetspeed/dispatcher/ components/portal/src/java/org/apache/jetspeed/engine/servlet/
Date Fri, 25 Nov 2005 02:36:37 GMT
Author: ate
Date: Thu Nov 24 18:36:22 2005
New Revision: 348855

URL: http://svn.apache.org/viewcvs?rev=348855&view=rev
Log:
Correction to the PLT.16.3.3 compliance solution which only need, and should, be enforced
during an PortletRequestDispatcher.include call.
This should fix the reported FileUpload problems using the ActionRequest.getContentType().
I've used almost the same solution as in Pluto, and its JSR-168 TCK compliant (all tests passed).

Added:
    portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/container/PortletDispatcherIncludeAware.java
Modified:
    portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/dispatcher/JetspeedRequestDispatcher.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/servlet/ServletResponseImpl.java

Added: portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/container/PortletDispatcherIncludeAware.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/container/PortletDispatcherIncludeAware.java?rev=348855&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/container/PortletDispatcherIncludeAware.java
(added)
+++ portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/container/PortletDispatcherIncludeAware.java
Thu Nov 24 18:36:22 2005
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.container;
+
+/**
+ * Interface to communicate to HttpServleRequest and HttpServletResponse implementations
if they
+ * are currently dispatched from PortletDispatcher so that they can enforce the JSR-168 PLT.16.3.3
restrictions.
+ *
+ * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
+ * @version $Id$
+ */
+public interface PortletDispatcherIncludeAware
+{
+    public void setPortletDispatcherIncluded(boolean included);
+}

Modified: portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/dispatcher/JetspeedRequestDispatcher.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/dispatcher/JetspeedRequestDispatcher.java?rev=348855&r1=348854&r2=348855&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/dispatcher/JetspeedRequestDispatcher.java
(original)
+++ portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/dispatcher/JetspeedRequestDispatcher.java
Thu Nov 24 18:36:22 2005
@@ -26,6 +26,7 @@
 import javax.portlet.RenderRequest;
 import javax.portlet.PortletException;
 
+import org.apache.jetspeed.container.PortletDispatcherIncludeAware;
 import org.apache.pluto.core.impl.RenderRequestImpl;
 import org.apache.pluto.core.impl.RenderResponseImpl;
 
@@ -52,12 +53,22 @@
 
     public void include(RenderRequest request, RenderResponse response) throws PortletException,
java.io.IOException
     {
+        HttpServletRequest servletRequest = null;
         HttpServletResponse servletResponse = null;
         try
         {
-            HttpServletRequest servletRequest = (HttpServletRequest) ((RenderRequestImpl)
request).getRequest();
+            servletRequest = (HttpServletRequest) ((RenderRequestImpl) request).getRequest();
             servletResponse = (HttpServletResponse) ((RenderResponseImpl) response).getResponse();
-
+            
+            if ( servletRequest instanceof PortletDispatcherIncludeAware )
+            {
+                ((PortletDispatcherIncludeAware)servletRequest).setPortletDispatcherIncluded(true);
+            }
+            if ( servletResponse instanceof PortletDispatcherIncludeAware )
+            {
+                ((PortletDispatcherIncludeAware)servletResponse).setPortletDispatcherIncluded(true);
+            }
+            
             this.requestDispatcher.include(servletRequest, servletResponse);
 
         }
@@ -89,6 +100,18 @@
                 rootCause = e.getCause();
             }
             throw new PortletException(rootCause != null ? rootCause : e);
+        }
+        finally
+        {
+            if ( servletRequest != null && servletRequest instanceof PortletDispatcherIncludeAware
)
+            {
+                ((PortletDispatcherIncludeAware)servletRequest).setPortletDispatcherIncluded(true);
+            }
+            if ( servletResponse != null && servletResponse instanceof PortletDispatcherIncludeAware
)
+            {
+                ((PortletDispatcherIncludeAware)servletResponse).setPortletDispatcherIncluded(true);
+            }
+            
         }
     }
 }

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java?rev=348855&r1=348854&r2=348855&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java
Thu Nov 24 18:36:22 2005
@@ -36,6 +36,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.Jetspeed;
 import org.apache.jetspeed.PortalReservedParameters;
+import org.apache.jetspeed.container.PortletDispatcherIncludeAware;
 import org.apache.jetspeed.container.namespace.JetspeedNamespaceMapper;
 import org.apache.jetspeed.container.namespace.JetspeedNamespaceMapperFactory;
 import org.apache.jetspeed.container.url.PortalURL;
@@ -56,7 +57,7 @@
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
  * @version $Id$
  */
-public class ServletRequestImpl extends HttpServletRequestWrapper
+public class ServletRequestImpl extends HttpServletRequestWrapper implements PortletDispatcherIncludeAware
 {
     public static final String ACCEPT_LANGUAGE = "Accept-Language";
     /** Logger */
@@ -68,6 +69,8 @@
 
     private Map portletParameters;
     private ObjectID webAppId;
+    
+    private boolean included;
 
     public ServletRequestImpl( HttpServletRequest servletRequest, PortletWindow window )
     {
@@ -379,158 +382,150 @@
         return super.getHeaderNames();
     }
     
+    /**
+     * @param included when true, JSR-168 PLT.16.3.3 rules need to be enforced
+     */
+    public void setPortletDispatcherIncluded(boolean included)
+    {
+        this.included = included;
+    }
+    
     /*
-     * JST-168 PLT.16.3.3 cxxix
+     * JSR-168 PLT.16.3.3 cxxix
      */
   	public String getProtocol()
   	{
-  			return null;
+        return (included ? null : super.getProtocol() );
   	}
 
     /*
-     * JST-168 PLT.16.3.3 cxxix
+     * JSR-168 PLT.16.3.3 cxxix
      */
   	public String getRemoteAddr()
   	{
-  			return null;
+        return (included ? null : super.getRemoteAddr() );
   	}
 
     /*
-     * JST-168 PLT.16.3.3 cxxix
+     * JSR-168 PLT.16.3.3 cxxix
      */
   	public String getRemoteHost()
   	{
-  			return null;
-  	}
-
-    /*
-     * JST-168 PLT.16.3.3 cxxix
-     */
-  	public String getRealPath()
-  	{
-  			return null;
+        return (included ? null : super.getRemoteHost() );
   	}
 
     /*
-     * JST-168 PLT.16.3.3 cxxix
+     * JSR-168 PLT.16.3.3 cxxix
      */
   	public StringBuffer getRequestURL()
   	{
-  			return null;
+        return (included ? null : super.getRequestURL());
   	}
 
     /*
-     * JST-168 PLT.16.3.3 cxxx
+     * JSR-168 PLT.16.3.3 cxxx
      */
     public String getPathInfo()
   	{
-  			String attr = (String)super.getAttribute("javax.servlet.include.path_info");
-  			return (attr != null) ? attr : super.getPathInfo();
+        return (included ? (String)super.getAttribute("javax.servlet.include.path_info")
: super.getPathInfo());
   	}
 
     /*
-     * JST-168 PLT.16.3.3 cxxx
+     * JSR-168 PLT.16.3.3 cxxx
      */
   	public String getPathTranslated()
   	{
-  	    // TODO: Don't know yet how to implement this. 
-  	    //       A null value is a valid value. 
-  			return null;
+        return (included ? null : super.getPathTranslated());
   	}
 
     /*
-     * JST-168 PLT.16.3.3 cxxx
+     * JSR-168 PLT.16.3.3 cxxx
      */
   	public String getQueryString()
   	{
-  			String attr = (String)super.getAttribute("javax.servlet.include.query_string");
-  			return (attr != null) ? attr : super.getQueryString();
+        return (included ? (String)super.getAttribute("javax.servlet.include.query_string")
: super.getQueryString());
   	}
 
     /*
-     * JST-168 PLT.16.3.3 cxxx
+     * JSR-168 PLT.16.3.3 cxxx
      */
   	public String getRequestURI()
   	{
-  			String attr = (String)super.getAttribute("javax.servlet.include.request_uri");
-  			return (attr != null) ? attr : super.getRequestURI();
+        return (included ? (String)super.getAttribute("javax.servlet.include.request_uri")
: super.getRequestURI());
   	}
 
     /*
-     * JST-168 PLT.16.3.3 cxxx
+     * JSR-168 PLT.16.3.3 cxxx
      */
   	public String getServletPath()
   	{
-  			String attr = (String)super.getAttribute("javax.servlet.include.servlet_path");
-  			return (attr != null) ? attr : super.getServletPath();
+        return (included ? (String)super.getAttribute("javax.servlet.include.servlet_path")
: super.getServletPath());
   	}
 
     /*
-     * JST-168 PLT.16.3.3 cxxxi
+     * JSR-168 PLT.16.3.3 cxxxi
      */
   	public String getContextPath() 
   	{
-       String attr = (String)super.getAttribute("javax.servlet.include.context_path");
-       return (attr != null) ? attr : super.getContextPath();
+        return (included ? (String)super.getAttribute("javax.servlet.include.context_path")
: super.getContextPath());
   	}
 
     /*
-     * JST-168 PLT.16.3.3 cxxxiv
+     * JSR-168 PLT.16.3.3 cxxxiv
      */
-/*
     public int getContentLength()
     {
-        return 0;
+        return (included ? 0 : super.getContentLength());
     }
-*/
+
     /*
-     * JST-168 PLT.16.3.3 cxxix
+     * JSR-168 PLT.16.3.3 cxxix
      */
     public String getRealPath(String arg0)
     {
-        return null;
+        return (included ? null : super.getRealPath(arg0));
     }
 
     /*
-     * JST-168 PLT.16.3.3 cxxxii
+     * JSR-168 PLT.16.3.3 cxxxii
      */
-/*
     public BufferedReader getReader() throws IOException
     {
-        return null;
+        return (included ? null : super.getReader());
     }
-*/
+
     /*
-     * JST-168 PLT.16.3.3 cxxxii
+     * JSR-168 PLT.16.3.3 cxxxii
      */
     public String getCharacterEncoding()
     {
-        return null;
+        return (included ? null : super.getCharacterEncoding());
     }
 
     /*
-     * JST-168 PLT.16.3.3 cxxxii
+     * JSR-168 PLT.16.3.3 cxxxii
      */
-/*
     public String getContentType()
     {
-        return null;
+        return (included ? null : super.getContentType());
     }
-*/
+
     /*
-     * JST-168 PLT.16.3.3 cxxxii
+     * JSR-168 PLT.16.3.3 cxxxii
      */
-/*
     public ServletInputStream getInputStream() throws IOException
     {
-        return null;
+        return (included ? null : super.getInputStream());
     }
-*/
+
     /*
-     * JST-168 PLT.16.3.3 cxxxii
+     * JSR-168 PLT.16.3.3 cxxxii
      */
     public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException
     {
+        if ( !included )
+        {
+            super.setCharacterEncoding(arg0);
+        }
     }
-
 }

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/servlet/ServletResponseImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/servlet/ServletResponseImpl.java?rev=348855&r1=348854&r2=348855&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/servlet/ServletResponseImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/servlet/ServletResponseImpl.java
Thu Nov 24 18:36:22 2005
@@ -15,30 +15,219 @@
  */
 package org.apache.jetspeed.engine.servlet;
 
+import java.io.IOException;
+import java.util.Locale;
+
+import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponseWrapper;
 
+import org.apache.jetspeed.container.PortletDispatcherIncludeAware;
+
 /**
  * Factory implementation for creating HTTP Response Wrappers
  *
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
  * @version $Id$
  */
-public class ServletResponseImpl
-    extends HttpServletResponseWrapper
+public class ServletResponseImpl extends HttpServletResponseWrapper implements PortletDispatcherIncludeAware
 {
+    private boolean included;
+    
     public ServletResponseImpl(HttpServletResponse response)
     {
         super(response);
     }
 
-    private javax.servlet.http.HttpServletResponse _getHttpServletResponse()
-    {
-        return(HttpServletResponse) super.getResponse();
-    }
-
     public void setResponse(HttpServletResponse response) 
     {
         super.setResponse(response);
     }   
+
+    /**
+     * @param included when true, JSR-168 PLT.16.3.3 rules need to be enforced
+     */
+    public void setPortletDispatcherIncluded(boolean included)
+    {
+        this.included = included;
+    }
+    
+    /*
+     * JSR-168 PLT.16.3.3 .cxxxviii
+     * @deprecated use encodeRedirectURL instead
+     */
+    public String encodeRedirectUrl(String url)
+    {
+        return (included ? null : super.encodeRedirectUrl(url));
+    }
+
+    /*
+     * JSR-168 PLT.16.3.3 .cxxxviii
+     */
+    public String encodeRedirectURL(String url)
+    {
+        return (included ? null : super.encodeRedirectURL(url));
+    }
+
+    /*
+     * JSR-168 PLT.16.3.3 .cxl
+     */
+    public void addCookie(Cookie arg0)
+    {
+        if (!included)
+        {
+            super.addCookie(arg0);
+        }
+    }
+
+    /*
+     * JSR-168 PLT.16.3.3 .cxl
+     */
+    public void addDateHeader(String arg0, long arg1)
+    {
+        if (!included)
+        {
+            super.addDateHeader(arg0, arg1);
+        }
+    }
+
+    /*
+     * JSR-168 PLT.16.3.3 .cxl
+     */
+    public void addHeader(String arg0, String arg1)
+    {
+        if (!included)
+        {
+            super.addHeader(arg0, arg1);
+        }
+    }
+
+    /*
+     * JSR-168 PLT.16.3.3 .cxl
+     */
+    public void addIntHeader(String arg0, int arg1)
+    {
+        if (!included)
+        {
+            super.addIntHeader(arg0, arg1);
+        }
+    }
+
+    /*
+     * JSR-168 PLT.16.3.3 .cxl
+     */
+    public boolean containsHeader(String arg0)
+    {
+        return (included ? false : super.containsHeader(arg0));
+    }
+
+    /*
+     * JSR-168 PLT.16.3.3 .cxl
+     */
+    public void sendError(int arg0, String arg1) throws IOException
+    {
+        if (!included)
+        {
+            super.sendError(arg0, arg1);
+        }
+    }
+
+    /*
+     * JSR-168 PLT.16.3.3 .cxl
+     */
+    public void sendRedirect(String arg0) throws IOException
+    {
+        if (!included)
+        {
+            super.sendRedirect(arg0);
+        }
+    }
+
+    /*
+     * JSR-168 PLT.16.3.3 .cxl
+     */
+    public void setDateHeader(String arg0, long arg1)
+    {
+        if (!included)
+        {
+            super.setDateHeader(arg0, arg1);
+        }
+    }
+
+    /*
+     * JSR-168 PLT.16.3.3 .cxl
+     */
+    public void setHeader(String arg0, String arg1)
+    {
+        if (!included)
+        {
+            super.setHeader(arg0, arg1);
+        }
+    }
+
+    /*
+     * JSR-168 PLT.16.3.3 .cxl
+     */
+    public void setIntHeader(String arg0, int arg1)
+    {
+        if (!included)
+        {
+            super.setIntHeader(arg0, arg1);
+        }
+    }
+
+    /*
+     * JSR-168 PLT.16.3.3 .cxl
+     */
+    public void setStatus(int arg0, String arg1)
+    {
+        if (!included)
+        {
+            super.setStatus(arg0, arg1);
+        }
+    }
+
+    /*
+     * JSR-168 PLT.16.3.3 .cxl
+     */
+    public void setStatus(int arg0)
+    {
+        if (!included)
+        {
+            super.setStatus(arg0);
+        }
+    }
+
+    /*
+     * JSR-168 PLT.16.3.3 .cxl
+     */
+    public void setContentLength(int arg0)
+    {
+        if (!included)
+        {
+            super.setContentLength(arg0);
+        }
+    }
+
+    /*
+     * JSR-168 PLT.16.3.3 .cxl
+     */
+    public void setContentType(String arg0)
+    {
+        if (!included)
+        {
+            super.setContentType(arg0);
+        }
+    }
+
+    /*
+     * JSR-168 PLT.16.3.3 .cxl
+     */
+    public void setLocale(Locale arg0)
+    {
+        if (!included)
+        {
+            super.setLocale(arg0);
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message