You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by at...@apache.org on 2005/08/27 02:28:37 UTC

svn commit: r240364 - in /portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed: container/invoker/ request/

Author: ate
Date: Fri Aug 26 17:28:25 2005
New Revision: 240364

URL: http://svn.apache.org/viewcvs?rev=240364&view=rev
Log:
See: http://issues.apache.org/jira/browse/JS2-355

Added:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/PortalRequest.java   (with props)
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/PortalRequestFactory.java   (with props)
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/PortalRequestFactoryImpl.java   (with props)
Modified:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContext.java

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java?rev=240364&r1=240363&r2=240364&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java (original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java Fri Aug 26 17:28:25 2005
@@ -175,7 +175,7 @@
         String portletApplicationName = webApplicationDefinition.getContextRoot();
 
         // gather all required data from request and response
-        ServletRequest servletRequest = ((HttpServletRequestWrapper)((HttpServletRequestWrapper)portletRequest).getRequest()).getRequest();
+        ServletRequest servletRequest = ((HttpServletRequestWrapper)((HttpServletRequestWrapper)((HttpServletRequestWrapper)portletRequest).getRequest()).getRequest()).getRequest();
 
         ServletResponse servletResponse = ((HttpServletResponseWrapper) portletResponse).getResponse();
 

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContext.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContext.java?rev=240364&r1=240363&r2=240364&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContext.java (original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContext.java Fri Aug 26 17:28:25 2005
@@ -15,12 +15,9 @@
  */
 package org.apache.jetspeed.request;
 
-import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.WeakHashMap;
@@ -28,6 +25,7 @@
 import javax.security.auth.Subject;
 import javax.servlet.ServletConfig;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.jetspeed.Jetspeed;
@@ -41,7 +39,6 @@
 import org.apache.jetspeed.om.common.MutableLanguage;
 import org.apache.jetspeed.om.impl.LanguageImpl;
 import org.apache.jetspeed.om.page.ContentPage;
-import org.apache.jetspeed.om.page.Fragment;
 import org.apache.jetspeed.userinfo.UserInfoManager;
 import org.apache.pluto.om.common.Language;
 import org.apache.pluto.om.common.LanguageSet;
@@ -83,9 +80,6 @@
     private Map requestsForWindows;
     private Map responsesForWindows;
     
-    private Fragment rootFragment;
-    private Map fragments;
-    
     /**
      * Create a new Request Context
      * 
@@ -103,15 +97,34 @@
         this.userInfoMgr = userInfoMgr;
         this.requestsForWindows = new HashMap();
         this.responsesForWindows = new HashMap();
-        this.fragments = new LinkedHashMap();
 
         // set context in Request for later use
         if (null != this.request)
         {
             this.request.setAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE, this);
+            PortalRequestFactory prf = null;
+            try
+            {
+                prf = (PortalRequestFactory)Jetspeed.getComponentManager().getComponent(PortalRequestFactory.class);
+            }
+            catch (Throwable t)
+            {
+                // allow undefined
+            }
+            if ( prf != null )
+            {
+                this.request = prf.createPortalRequest(this.request);
+            }
+            else
+            {
+                // Simply wrap the current request so we maintain the same
+                // level of wrapping.
+                // This is needed in the ServletPortletInvoker to get back
+                // to the original request.
+                this.request = new HttpServletRequestWrapper(this.request);
+            }
         }
     }
-
 
     public HttpServletRequest getRequest()
     {

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/PortalRequest.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/PortalRequest.java?rev=240364&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/PortalRequest.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/PortalRequest.java Fri Aug 26 17:28:25 2005
@@ -0,0 +1,79 @@
+/*
+ * 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.request;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpSession;
+
+/**
+ * PortalRequest wraps the original request to the portal and keeps local
+ * references to properties like contextPath, servletPath and the Session
+ * when its created.
+ * <p>
+ * Some web servers like WebSphere don't store these properties inside the
+ * request but derive them dynamically based on the web application context
+ * in which they are invoked.
+ * </p>
+ * <p>
+ * For cross-context invoked portlet applications, getting access to the
+ * portal contextPath using requestContext.getRequest().getContextPath()
+ * this clearly is a problem. Also, access to the Portal Session is not
+ * possible this way.
+ * </p>
+ * <p>
+ * The requestContext.request is actually wrapped by this class which solves
+ * the problem by storing a reference to the actual properties at the time
+ * of creation and returning  
+ * </p>
+ * 
+ * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
+ * @version $Id$
+ */
+public class PortalRequest extends HttpServletRequestWrapper
+{
+    private final String      contextPath;
+    private final String      servletPath;
+    private final HttpSession session;
+    
+    public PortalRequest(HttpServletRequest request)
+    {
+        super(request);
+        contextPath = request.getContextPath();
+        servletPath = request.getServletPath();
+        session = request.getSession(true);
+    }
+
+    public String getContextPath()
+    {
+        return this.contextPath;
+    }
+
+    public String getServletPath()
+    {
+        return this.servletPath;
+    }
+
+    public HttpSession getSession()
+    {
+        return this.session;        
+    }
+
+    public HttpSession getSession(boolean create)
+    {
+        return this.session;
+    }    
+}

Propchange: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/PortalRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/PortalRequestFactory.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/PortalRequestFactory.java?rev=240364&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/PortalRequestFactory.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/PortalRequestFactory.java Fri Aug 26 17:28:25 2005
@@ -0,0 +1,38 @@
+/*
+ * 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.request;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * PortalRequestFactory allows specialized instantiation of a PortalRequest to be
+ * used for JetspeedRequestContext.request.
+ * <p>
+ * JetspeedRequestContext also implements this interface and simply returns the
+ * provided request as no wrapping is needed for Tomcat.
+ * </p>
+ * <p>
+ * To actually use a PortalRequest as wrapper (as needed for instance on WebSphere), 
+ * inject the PortalRequestFactoryImpl in JetspeedRequestContext.
+ * </p>
+ * 
+ * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
+ * @version $Id$
+ */
+public interface PortalRequestFactory
+{
+    HttpServletRequest createPortalRequest(HttpServletRequest request);
+}

Propchange: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/PortalRequestFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/PortalRequestFactoryImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/PortalRequestFactoryImpl.java?rev=240364&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/PortalRequestFactoryImpl.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/PortalRequestFactoryImpl.java Fri Aug 26 17:28:25 2005
@@ -0,0 +1,32 @@
+/*
+ * 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.request;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * PortalRequestFactoryImpl 
+ *  
+ * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
+ * @version $Id$
+ */
+public class PortalRequestFactoryImpl implements PortalRequestFactory
+{
+    public HttpServletRequest createPortalRequest(HttpServletRequest request)
+    {
+        return new PortalRequest(request);
+    }
+}

Propchange: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/PortalRequestFactoryImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native



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