portals-pluto-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msnickl...@apache.org
Subject [36/38] portals-pluto git commit: Completed implementation of header phase demo portlet. Fixed some bugs in the pluto header phase implementation.
Date Fri, 27 Nov 2015 12:38:17 GMT
Completed implementation of header phase demo portlet. Fixed some bugs in
the pluto header phase implementation.


Project: http://git-wip-us.apache.org/repos/asf/portals-pluto/repo
Commit: http://git-wip-us.apache.org/repos/asf/portals-pluto/commit/6dd6b872
Tree: http://git-wip-us.apache.org/repos/asf/portals-pluto/tree/6dd6b872
Diff: http://git-wip-us.apache.org/repos/asf/portals-pluto/diff/6dd6b872

Branch: refs/heads/V3Prototype
Commit: 6dd6b87226de02f4a4f06e877ad9249bb07e5a34
Parents: d11dcc5
Author: Scott Nicklous <msnicklous@apache.org>
Authored: Thu Nov 26 17:50:53 2015 +0100
Committer: Scott Nicklous <msnicklous@apache.org>
Committed: Thu Nov 26 17:50:53 2015 +0100

----------------------------------------------------------------------
 PortletHubDemo/pom.xml                          |  26 +-
 PortletHubDemo/src/main/webapp/WEB-INF/web.xml  |   2 +-
 PortletV3Demo/pom.xml                           |  22 -
 .../main/java/basic/portlet/HeaderPortlet.java  |  14 +-
 .../webapp/WEB-INF/jsp/headSectionMarkup.jsp    |  57 ++
 .../src/main/webapp/WEB-INF/jsp/view-hdp.jsp    |   5 +
 .../org/apache/pluto/container/HeaderData.java  |  40 +-
 .../impl/HttpServletPortletResponseWrapper.java |   8 +-
 .../impl/PortletRequestDispatcherImpl.java      | 550 ++++++++++---------
 .../PortletMimeResponseContextImpl.java         |  16 +-
 .../container/PortletResponseContextImpl.java   |  12 +
 11 files changed, 415 insertions(+), 337 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/6dd6b872/PortletHubDemo/pom.xml
----------------------------------------------------------------------
diff --git a/PortletHubDemo/pom.xml b/PortletHubDemo/pom.xml
index 60b0379..b64acf1 100644
--- a/PortletHubDemo/pom.xml
+++ b/PortletHubDemo/pom.xml
@@ -60,8 +60,8 @@
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-compiler-plugin</artifactId>
             <configuration>
-               <source>1.6</source>
-               <target>1.6</target>
+               <source>1.7</source>
+               <target>1.7</target>
             </configuration>
          </plugin>
          <plugin>
@@ -106,30 +106,8 @@
                  <artifactId>maven-war-plugin</artifactId>
                  <configuration>
                    <archiveClasses>false</archiveClasses>
-                   <webXml>${project.build.directory}/pluto-resources/web.xml</webXml>
                  </configuration>
                </plugin>
-               <!-- bind 'pluto:assemble' goal to 'generate-resources' lifecycle -->
-               <plugin>
-                  <groupId>org.apache.portals.pluto</groupId>
-                  <artifactId>maven-pluto-plugin</artifactId>
-                  <dependencies>
-                     <dependency>
-                        <groupId>org.apache.portals.pluto</groupId>
-                        <artifactId>pluto-util</artifactId>
-                        <version>${project.version}</version>
-                        <scope>runtime</scope>
-                     </dependency>
-                  </dependencies>
-                  <executions>
-                     <execution>
-                        <phase>generate-resources</phase>
-                        <goals>
-                           <goal>assemble</goal>
-                        </goals>
-                     </execution>
-                  </executions>
-               </plugin>
                <!-- workaround for war processing of m-r-r-plugin causing the generated
NOTICE and LICENSE file to be put under WEB-INF/classes/META-INF -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/6dd6b872/PortletHubDemo/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/webapp/WEB-INF/web.xml b/PortletHubDemo/src/main/webapp/WEB-INF/web.xml
index 5cf9329..ae832b5 100644
--- a/PortletHubDemo/src/main/webapp/WEB-INF/web.xml
+++ b/PortletHubDemo/src/main/webapp/WEB-INF/web.xml
@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
-	<display-name>PRP Resource Portlet</display-name>
+	<display-name>V3 Portlet Hub Demo Portlet</display-name>
 </web-app>

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/6dd6b872/PortletV3Demo/pom.xml
----------------------------------------------------------------------
diff --git a/PortletV3Demo/pom.xml b/PortletV3Demo/pom.xml
index a957244..3c23fdc 100644
--- a/PortletV3Demo/pom.xml
+++ b/PortletV3Demo/pom.xml
@@ -106,30 +106,8 @@
                  <artifactId>maven-war-plugin</artifactId>
                  <configuration>
                    <archiveClasses>false</archiveClasses>
-                   <webXml>${project.build.directory}/pluto-resources/web.xml</webXml>
                  </configuration>
                </plugin>
-               <!-- bind 'pluto:assemble' goal to 'generate-resources' lifecycle -->
-               <plugin>
-                  <groupId>org.apache.portals.pluto</groupId>
-                  <artifactId>maven-pluto-plugin</artifactId>
-                  <dependencies>
-                     <dependency>
-                        <groupId>org.apache.portals.pluto</groupId>
-                        <artifactId>pluto-util</artifactId>
-                        <version>${project.version}</version>
-                        <scope>runtime</scope>
-                     </dependency>
-                  </dependencies>
-                  <executions>
-                     <execution>
-                        <phase>generate-resources</phase>
-                        <goals>
-                           <goal>assemble</goal>
-                        </goals>
-                     </execution>
-                  </executions>
-               </plugin>
                <!-- workaround for war processing of m-r-r-plugin causing the generated
NOTICE and LICENSE file to be put under WEB-INF/classes/META-INF -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/6dd6b872/PortletV3Demo/src/main/java/basic/portlet/HeaderPortlet.java
----------------------------------------------------------------------
diff --git a/PortletV3Demo/src/main/java/basic/portlet/HeaderPortlet.java b/PortletV3Demo/src/main/java/basic/portlet/HeaderPortlet.java
index 03cb0bc..95df1af 100644
--- a/PortletV3Demo/src/main/java/basic/portlet/HeaderPortlet.java
+++ b/PortletV3Demo/src/main/java/basic/portlet/HeaderPortlet.java
@@ -19,14 +19,13 @@
 package basic.portlet;
 
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.Collections;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import javax.portlet.ActionParameters;
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
-import javax.portlet.ActionURL;
 import javax.portlet.GenericPortlet;
 import javax.portlet.HeaderRequest;
 import javax.portlet.HeaderResponse;
@@ -35,19 +34,14 @@ import javax.portlet.PortalContext;
 import javax.portlet.PortletException;
 import javax.portlet.PortletRequest;
 import javax.portlet.PortletRequestDispatcher;
-import javax.portlet.RenderParameters;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
-import javax.portlet.RenderURL;
 import javax.portlet.ResourceRequest;
 import javax.portlet.ResourceResponse;
 import javax.servlet.http.Cookie;
 
 import org.w3c.dom.Element;
 
-import static javax.portlet.MimeResponse.Copy.*;
-import static basic.portlet.Constants.*;
-
 /**
  * Portlet for testing the redirect funtionality, including the new getRedirectURL API.
  */
@@ -91,6 +85,12 @@ public class HeaderPortlet extends GenericPortlet {
       resp.setProperty("Portlet", this.getPortletName());
       resp.setProperty("Portal", "Pluto");
 
+      PrintWriter writer = resp.getWriter();
+      writer.println("<!-- before JSP include -->");
+      PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/headSectionMarkup.jsp");
+      rd.include(req, resp);
+      writer.println("<!-- after JSP include -->");
+
    }
 
    @Override

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/6dd6b872/PortletV3Demo/src/main/webapp/WEB-INF/jsp/headSectionMarkup.jsp
----------------------------------------------------------------------
diff --git a/PortletV3Demo/src/main/webapp/WEB-INF/jsp/headSectionMarkup.jsp b/PortletV3Demo/src/main/webapp/WEB-INF/jsp/headSectionMarkup.jsp
new file mode 100644
index 0000000..d15ad53
--- /dev/null
+++ b/PortletV3Demo/src/main/webapp/WEB-INF/jsp/headSectionMarkup.jsp
@@ -0,0 +1,57 @@
+<%--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You 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.
+--%>
+<%@ page session="false" %>
+<%@ taglib uri="http://xmlns.jcp.org/portlet_3_0"  prefix="portlet" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+
+<portlet:defineObjects />
+
+<!-- This jsp generates markup for the document head section -->
+   
+<meta name="description" content="Portlet Hub Demo Portlet">
+<style>
+<!--
+.markupSection {
+   padding: 5px;
+   background-color: #DDFFDD;
+   border: thin solid #22EE88;
+}
+-->
+</style>
+   
+<script type="text/javascript">
+(function () {
+   'use strict';
+   var cdiv = '<portlet:namespace/>cookieDiv',
+
+bootstrap = function () {
+   var cookies = document.cookie.split(';'), ii, markup;
+   markup = '<p>Current Cookies:</p>';
+   for (ii = 0; ii < cookies.length; ii++) {
+      markup += cookies[ii] + '<br/>';
+   }
+   document.getElementById(cdiv).innerHTML=markup;
+};
+   
+// execute when document has been loaded 
+window.addEventListener('load', bootstrap, false);
+}());
+</script>
+
+<p>Hi</p>

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/6dd6b872/PortletV3Demo/src/main/webapp/WEB-INF/jsp/view-hdp.jsp
----------------------------------------------------------------------
diff --git a/PortletV3Demo/src/main/webapp/WEB-INF/jsp/view-hdp.jsp b/PortletV3Demo/src/main/webapp/WEB-INF/jsp/view-hdp.jsp
index 71deb87..d78f9b4 100644
--- a/PortletV3Demo/src/main/webapp/WEB-INF/jsp/view-hdp.jsp
+++ b/PortletV3Demo/src/main/webapp/WEB-INF/jsp/view-hdp.jsp
@@ -34,4 +34,9 @@ method.
 Character encoding: <%=renderResponse.getCharacterEncoding() %>, 
 Content type: <%=renderResponse.getContentType() %>
 </p>
+<p>
+The following section shows cookie information inserted by JavaScript code that was added
to the 
+output stream during the header phase processing.
+</p>
+<div  class='markupSection' id='<portlet:namespace/>cookieDiv'></div>
 </div>

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/6dd6b872/pluto-container-api/src/main/java/org/apache/pluto/container/HeaderData.java
----------------------------------------------------------------------
diff --git a/pluto-container-api/src/main/java/org/apache/pluto/container/HeaderData.java
b/pluto-container-api/src/main/java/org/apache/pluto/container/HeaderData.java
index b7a7756..6209f5d 100644
--- a/pluto-container-api/src/main/java/org/apache/pluto/container/HeaderData.java
+++ b/pluto-container-api/src/main/java/org/apache/pluto/container/HeaderData.java
@@ -29,6 +29,8 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.servlet.http.Cookie;
 import javax.xml.parsers.DocumentBuilder;
@@ -72,8 +74,8 @@ public class HeaderData {
    private static final String       ROOT_ELEMENT_END   = "</rootElement>";
    private static final String       ROOT_ELEMENT_REGEX = "(?:\\s*)</{0,1}" + ROOT_ELEMENT
+ ">(?:\\s*)";
 
-   private static final Set<String>  allowedTags        = new HashSet<String>(Arrays.asList(new
String[] { "META",
-         "LINK", "STYLE", "SCRIPT", "NOSCRIPT"         }));
+   private static final Set<String>  allowedTags        = new HashSet<String>(Arrays.asList(new
String[] { 
+         "META", "LINK", "STYLE", "SCRIPT", "NOSCRIPT"         }));
 
    private List<Cookie>              cookies            = new ArrayList<Cookie>();
    private Map<String, List<String>> httpHeaders        = new HashMap<String,
List<String>>();
@@ -83,6 +85,9 @@ public class HeaderData {
    private PrintWriter               pWriter            = null;
 
    public void resetBuffer() {
+      if (isDebug) {
+         LOG.debug("Resetting buffer.");
+      }
       if (baoStream != null) {
          baoStream.reset();
       }
@@ -106,6 +111,9 @@ public class HeaderData {
          sWriter = new StringWriter(bufferSize);
          pWriter = new PrintWriter(sWriter);
       }
+      if (isDebug) {
+         LOG.debug("returning writer.");
+      }
       return pWriter;
    }
 
@@ -116,6 +124,9 @@ public class HeaderData {
       if (baoStream == null) {
          baoStream = new ByteArrayOutputStream(bufferSize);
       }
+      if (isDebug) {
+         LOG.debug("returning output stream.");
+      }
       return baoStream;
    }
 
@@ -143,10 +154,31 @@ public class HeaderData {
       }
 
       if (src != null) {
-         StringBuilder sb = new StringBuilder(128);
+         StringBuffer sb = new StringBuffer(128);
          sb.append(ROOT_ELEMENT_START);
-         sb.append(src);
+         
+         // need to do some preprocessing on the input text to avoid placing a burden on
the 
+         // portlet developer. Goals:
+         //    * allow meta and link tags with or without a closing slash
+         //    * allow use of unescaped angle brackets within script tag
+
+         // make the parser eat link & meta tags with or without closing slash.
+         src = src.replaceAll("(<(?:meta|link).*?[^/])>", "$1/>");
+         
+         // convert < brackets within script tags to corresponding entities
+         
+         Pattern pat = Pattern.compile("(?s)" +             // multiline mode 
+                                       "(?<=<script)" +     // 0-width lookbehind;
script start tag
+                                       "(.*?)" +            // non-greedy content of tag
+                                       "(?=</script)");     // 0-width lookahead: script
end tag
+         Matcher mat = pat.matcher(src);
+         while (mat.find()) {
+            mat.appendReplacement(sb, mat.group().replaceAll("<", "&lt;"));
+         }
+         mat.appendTail(sb);
+
          sb.append(ROOT_ELEMENT_END);
+         LOG.debug(sb.toString());
 
          StringReader sr = new StringReader(sb.toString());
          InputSource is = new InputSource(sr);

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/6dd6b872/pluto-container/src/main/java/org/apache/pluto/container/impl/HttpServletPortletResponseWrapper.java
----------------------------------------------------------------------
diff --git a/pluto-container/src/main/java/org/apache/pluto/container/impl/HttpServletPortletResponseWrapper.java
b/pluto-container/src/main/java/org/apache/pluto/container/impl/HttpServletPortletResponseWrapper.java
index 6b93fda..c5a269e 100644
--- a/pluto-container/src/main/java/org/apache/pluto/container/impl/HttpServletPortletResponseWrapper.java
+++ b/pluto-container/src/main/java/org/apache/pluto/container/impl/HttpServletPortletResponseWrapper.java
@@ -54,7 +54,13 @@ public class HttpServletPortletResponseWrapper extends HttpServletResponseWrappe
         super(response);
         this.portletResponse = portletResponse;
         this.lifecyclePhase = (String)portletRequest.getAttribute(PortletRequest.LIFECYCLE_PHASE);
-        this.mimeResponse = PortletRequest.RENDER_PHASE.equals(lifecyclePhase) || PortletRequest.RESOURCE_PHASE.equals(lifecyclePhase)
? (MimeResponse)portletResponse : null;
+        MimeResponse mr = null;
+        if (PortletRequest.RENDER_PHASE.equals(lifecyclePhase) || 
+            PortletRequest.RESOURCE_PHASE.equals(lifecyclePhase) ||
+            PortletRequest.HEADER_PHASE.equals(lifecyclePhase)) {
+           mr = (MimeResponse)portletResponse;
+        }
+        this.mimeResponse = mr;
         this.forwarded = !included;
         this.included = included;
     }

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/6dd6b872/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletRequestDispatcherImpl.java
----------------------------------------------------------------------
diff --git a/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletRequestDispatcherImpl.java
b/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletRequestDispatcherImpl.java
index 7261e70..2ef980c 100644
--- a/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletRequestDispatcherImpl.java
+++ b/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletRequestDispatcherImpl.java
@@ -1,270 +1,280 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.pluto.container.impl;
-
-import java.io.IOException;
-import java.util.Map;
-
-import javax.portlet.MimeResponse;
-import javax.portlet.PortletConfig;
-import javax.portlet.PortletException;
-import javax.portlet.PortletRequest;
-import javax.portlet.PortletRequestDispatcher;
-import javax.portlet.PortletResponse;
-import javax.portlet.RenderRequest;
-import javax.portlet.RenderResponse;
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequestWrapper;
-import javax.servlet.http.HttpServletResponseWrapper;
-import javax.servlet.http.HttpSession;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.pluto.container.PortletInvokerService;
-import org.apache.pluto.container.PortletRequestContext;
-
-/**
- * Implementation of the <code>PortletRequestDispatcher</code> interface.
- * The portlet request dispatcher is used to dispatch <b>PortletRequest</b> and
- * <b>PortletResponse</b> to a URI.
- * 
- */
-public class PortletRequestDispatcherImpl implements PortletRequestDispatcher, RequestDispatcher
-{	
-    /** Logger. */
-    private static final Logger LOG = LoggerFactory.getLogger(PortletRequestDispatcherImpl.class);
-    
-    // Private Member Variables ------------------------------------------------
-    
-    /** The nested servlet request dispatcher instance. */
-    private RequestDispatcher requestDispatcher;
-    private boolean namedDispatch;
-    
-    
-    // Constructors ------------------------------------------------------------
-    
-    /**
-     * Creates an instance. This constructor should be called to construct a
-     * portlet request dispatcher.
-     * @param requestDispatcher  the servlet request dispatcher.
-     * @param namedDispatch true if requestDispatcher is a named dispatcher 
-     * @see javax.portlet.PortletContext#getNamedDispatcher(String)
-     * @see javax.portlet.PortletContext#getRequestDispatcher(String)
-     */
-    public PortletRequestDispatcherImpl(RequestDispatcher requestDispatcher, boolean namedDispatch)
-    {
-        this.requestDispatcher = requestDispatcher;
-        this.namedDispatch = namedDispatch;
-    	
-        if (LOG.isDebugEnabled())
-        {
-        	LOG.debug("Request dispatcher created.");
-        }
-    }
-    
-    private static HttpServletPortletRequestWrapper getWrappedRequest(ServletRequest request)
-    {
-        HttpServletPortletRequestWrapper req = null;
-        
-        do
-        {
-            if (request instanceof HttpServletPortletRequestWrapper)
-            {
-                req = (HttpServletPortletRequestWrapper)request;
-            }
-            else if (request instanceof HttpServletRequestWrapper)
-            {
-                request = ((HttpServletRequestWrapper)request).getRequest();
-            }
-            else
-            {
-                request = null;
-            }                
-        }
-        while (request != null && req == null);
-        return req;
-    }
-
-    private static HttpServletPortletResponseWrapper getWrappedResponse(ServletResponse response)
-    {
-        HttpServletPortletResponseWrapper res = null;
-        
-        do
-        {
-            if (response instanceof HttpServletPortletResponseWrapper)
-            {
-                res = (HttpServletPortletResponseWrapper)response;
-            }
-            else if (response instanceof HttpServletResponseWrapper)
-            {
-                response = ((HttpServletResponseWrapper)response).getResponse();
-            }
-            else
-            {
-                response = null;
-            }                
-        }
-        while (response != null && res == null);
-        return res;
-    }
-    
-    private void doDispatch(PortletRequest request, PortletResponse response, boolean included)
throws PortletException, IOException
-    {
-        boolean needsFlushAfterForward = false;
-        if (!included)
-        {
-            String lifecyclePhase = (String)request.getAttribute(PortletRequest.LIFECYCLE_PHASE);
-            if (PortletRequest.RENDER_PHASE.equals(lifecyclePhase) || PortletRequest.RESOURCE_PHASE.equals(lifecyclePhase))
-            {
-                needsFlushAfterForward = true;
-                ((MimeResponse)response).resetBuffer();
-            }
-        }
-        
-        PortletRequestContext requestContext = (PortletRequestContext)request.getAttribute(PortletInvokerService.REQUEST_CONTEXT);
-        HttpSession session = null;
-        
-        // PLT.10.4.3. Proxied session is created and passed if javax.portlet.servletDefaultSessionScope
== PORTLET_SCOPE
-        if (isPortletScopeSessionConfigured(requestContext))
-        {
-            String portletWindowId = requestContext.getPortletWindow().getId().getStringId();
-            session = ServletPortletSessionProxy.createProxy(requestContext.getServletRequest(),
portletWindowId);
-        }
-        
-        HttpServletPortletRequestWrapper req = new HttpServletPortletRequestWrapper(requestContext.getServletRequest(),

-                                                                                    requestContext.getServletContext(),
-                                                                                    session,
-                                                                                    request,
-                                                                                    included,
-                                                                                    namedDispatch);
-        HttpServletPortletResponseWrapper res = new HttpServletPortletResponseWrapper(requestContext.getServletResponse(),
-                                                                                      request,
-                                                                                      response,
-                                                                                      included);
-        try
-        {
-            request.setAttribute(PortletInvokerService.PORTLET_CONFIG, requestContext.getPortletConfig());
-            request.setAttribute(PortletInvokerService.PORTLET_REQUEST, request);
-            request.setAttribute(PortletInvokerService.PORTLET_RESPONSE, response);
-            
-            if (!included && req.isForwardingPossible())
-            {
-                requestDispatcher.forward(req, res);
-            }
-            else
-            {
-                // need to "fake" the forward using an include
-                requestDispatcher.include(req, res);
-            }
-            if (needsFlushAfterForward)
-            {
-                ((MimeResponse)response).flushBuffer();
-            }
-        }
-        catch (ServletException sex)
-        {
-            if (sex.getRootCause() != null)
-            {
-                throw new PortletException(sex.getRootCause());
-            } 
-            throw new PortletException(sex);
-        }
-        finally
-        {
-            request.removeAttribute(PortletInvokerService.PORTLET_CONFIG);
-            request.removeAttribute(PortletInvokerService.PORTLET_REQUEST);
-            request.removeAttribute(PortletInvokerService.PORTLET_RESPONSE);
-        }
-    }
-    
-    private boolean isPortletScopeSessionConfigured(PortletRequestContext requestContext)
-    {
-        boolean portletScopeSessionConfigured = false;
-        
-        PortletConfig portletConfig = requestContext.getPortletConfig();
-        Map<String, String []> containerRuntimeOptions = portletConfig.getContainerRuntimeOptions();
-        String [] values = containerRuntimeOptions.get("javax.portlet.servletDefaultSessionScope");
-        
-        if (values != null && values.length > 0)
-        {
-            portletScopeSessionConfigured = "PORTLET_SCOPE".equals(values[0]);
-        }
-        
-        return portletScopeSessionConfigured;
-    }
-
-    // PortletRequestDispatcher Impl -------------------------------------------
-   
-    public void forward(PortletRequest request, PortletResponse response) throws PortletException,
IOException
-    {
-        doDispatch(request, response, false);
-    }
-    
-	public void include(PortletRequest request, PortletResponse response) throws PortletException,
IOException
-	{
-	    doDispatch(request, response, true);
-	}
-	
-	public void include(RenderRequest request, RenderResponse response) throws PortletException,
IOException
-	{
-	    doDispatch(request, response, true);
-    }
-	
-    // Nested RequestDispatcher Impl -------------------------------------------
-	
-    public void forward(ServletRequest request, ServletResponse response) throws ServletException,
IOException
-    {
-        HttpServletPortletRequestWrapper req = getWrappedRequest(request);
-        HttpServletPortletResponseWrapper res = getWrappedResponse(response);
-        res.resetBuffer();
-        
-        // cache the current dispatch state
-        boolean forwarded = req.isForwarded();
-        boolean namedDispatch = req.isNamedDispatch();
-        Map<String,Object> pathAttributeValues = req.getPathAttributeValues();
-        HttpServletPortletRequestWrapper.PathMethodValues pathMethodValues = req.getInitPathMethodValues();
-        
-        // (re)initialize the request wrapper to a nested forward
-        req.setNestedForward();
-        try
-        {
-            if (req.isForwardingPossible())
-            {
-                requestDispatcher.forward(request, response);
-            }
-            else
-            {
-                // need to "fake" the forward using an include
-                requestDispatcher.include(request, response);
-            }
-        }
-        finally
-        {
-            // restore the previously cached dispatch state
-            req.restoreFromNestedForward(forwarded, namedDispatch, pathMethodValues, pathAttributeValues);
-        }
-    }
-
-    public void include(ServletRequest request, ServletResponse response) throws ServletException,
IOException
-    {
-        // no need for special handling on a nested dispatcher include: just calling the
wrapped servlet dispatcher
-        requestDispatcher.include(request, response);
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.pluto.container.impl;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.portlet.MimeResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.PortletResponse;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponseWrapper;
+import javax.servlet.http.HttpSession;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.pluto.container.PortletInvokerService;
+import org.apache.pluto.container.PortletRequestContext;
+
+/**
+ * Implementation of the <code>PortletRequestDispatcher</code> interface.
+ * The portlet request dispatcher is used to dispatch <b>PortletRequest</b> and
+ * <b>PortletResponse</b> to a URI.
+ * 
+ */
+public class PortletRequestDispatcherImpl implements PortletRequestDispatcher, RequestDispatcher
+{	
+    /** Logger. */
+    private static final Logger LOG = LoggerFactory.getLogger(PortletRequestDispatcherImpl.class);
+    private final static boolean isDebug = LOG.isDebugEnabled();
+    
+    // Private Member Variables ------------------------------------------------
+    
+    /** The nested servlet request dispatcher instance. */
+    private RequestDispatcher requestDispatcher;
+    private boolean namedDispatch;
+    
+    
+    // Constructors ------------------------------------------------------------
+    
+    /**
+     * Creates an instance. This constructor should be called to construct a
+     * portlet request dispatcher.
+     * @param requestDispatcher  the servlet request dispatcher.
+     * @param namedDispatch true if requestDispatcher is a named dispatcher 
+     * @see javax.portlet.PortletContext#getNamedDispatcher(String)
+     * @see javax.portlet.PortletContext#getRequestDispatcher(String)
+     */
+    public PortletRequestDispatcherImpl(RequestDispatcher requestDispatcher, boolean namedDispatch)
+    {
+        this.requestDispatcher = requestDispatcher;
+        this.namedDispatch = namedDispatch;
+    	
+        if (LOG.isDebugEnabled())
+        {
+        	LOG.debug("Request dispatcher created.");
+        }
+    }
+    
+    private static HttpServletPortletRequestWrapper getWrappedRequest(ServletRequest request)
+    {
+        HttpServletPortletRequestWrapper req = null;
+        
+        do
+        {
+            if (request instanceof HttpServletPortletRequestWrapper)
+            {
+                req = (HttpServletPortletRequestWrapper)request;
+            }
+            else if (request instanceof HttpServletRequestWrapper)
+            {
+                request = ((HttpServletRequestWrapper)request).getRequest();
+            }
+            else
+            {
+                request = null;
+            }                
+        }
+        while (request != null && req == null);
+        return req;
+    }
+
+    private static HttpServletPortletResponseWrapper getWrappedResponse(ServletResponse response)
+    {
+        HttpServletPortletResponseWrapper res = null;
+        
+        do
+        {
+            if (response instanceof HttpServletPortletResponseWrapper)
+            {
+                res = (HttpServletPortletResponseWrapper)response;
+            }
+            else if (response instanceof HttpServletResponseWrapper)
+            {
+                response = ((HttpServletResponseWrapper)response).getResponse();
+            }
+            else
+            {
+                response = null;
+            }                
+        }
+        while (response != null && res == null);
+        return res;
+    }
+    
+    private void doDispatch(PortletRequest request, PortletResponse response, boolean included)
throws PortletException, IOException
+    {
+        boolean needsFlushAfterForward = false;
+        if (!included)
+        {
+            String lifecyclePhase = (String)request.getAttribute(PortletRequest.LIFECYCLE_PHASE);
+            if (PortletRequest.RENDER_PHASE.equals(lifecyclePhase) || PortletRequest.RESOURCE_PHASE.equals(lifecyclePhase))
+            {
+                needsFlushAfterForward = true;
+                ((MimeResponse)response).resetBuffer();
+            }
+        }
+        
+        PortletRequestContext requestContext = (PortletRequestContext)request.getAttribute(PortletInvokerService.REQUEST_CONTEXT);
+        HttpSession session = null;
+        
+        // PLT.10.4.3. Proxied session is created and passed if javax.portlet.servletDefaultSessionScope
== PORTLET_SCOPE
+        if (isPortletScopeSessionConfigured(requestContext))
+        {
+            String portletWindowId = requestContext.getPortletWindow().getId().getStringId();
+            session = ServletPortletSessionProxy.createProxy(requestContext.getServletRequest(),
portletWindowId);
+        }
+        
+        HttpServletPortletRequestWrapper req = new HttpServletPortletRequestWrapper(requestContext.getServletRequest(),

+                                                                                    requestContext.getServletContext(),
+                                                                                    session,
+                                                                                    request,
+                                                                                    included,
+                                                                                    namedDispatch);
+        HttpServletPortletResponseWrapper res = new HttpServletPortletResponseWrapper(requestContext.getServletResponse(),
+                                                                                      request,
+                                                                                      response,
+                                                                                      included);
+        try
+        {
+            request.setAttribute(PortletInvokerService.PORTLET_CONFIG, requestContext.getPortletConfig());
+            request.setAttribute(PortletInvokerService.PORTLET_REQUEST, request);
+            request.setAttribute(PortletInvokerService.PORTLET_RESPONSE, response);
+            
+            if (!included && req.isForwardingPossible())
+            {
+                requestDispatcher.forward(req, res);
+            }
+            else
+            {
+                // need to "fake" the forward using an include
+                requestDispatcher.include(req, res);
+            }
+            if (needsFlushAfterForward)
+            {
+                ((MimeResponse)response).flushBuffer();
+            }
+        }
+        catch (ServletException sex)
+        {
+            if (sex.getRootCause() != null)
+            {
+                throw new PortletException(sex.getRootCause());
+            } 
+            throw new PortletException(sex);
+        }
+        finally
+        {
+            request.removeAttribute(PortletInvokerService.PORTLET_CONFIG);
+            request.removeAttribute(PortletInvokerService.PORTLET_REQUEST);
+            request.removeAttribute(PortletInvokerService.PORTLET_RESPONSE);
+        }
+    }
+    
+    private boolean isPortletScopeSessionConfigured(PortletRequestContext requestContext)
+    {
+        boolean portletScopeSessionConfigured = false;
+        
+        PortletConfig portletConfig = requestContext.getPortletConfig();
+        Map<String, String []> containerRuntimeOptions = portletConfig.getContainerRuntimeOptions();
+        String [] values = containerRuntimeOptions.get("javax.portlet.servletDefaultSessionScope");
+        
+        if (values != null && values.length > 0)
+        {
+            portletScopeSessionConfigured = "PORTLET_SCOPE".equals(values[0]);
+        }
+        
+        return portletScopeSessionConfigured;
+    }
+
+    // PortletRequestDispatcher Impl -------------------------------------------
+   
+    public void forward(PortletRequest request, PortletResponse response) throws PortletException,
IOException
+    {
+       if (isDebug) {
+          LOG.debug("Doing request dispatcher forward for portlet request.");
+       }
+        doDispatch(request, response, false);
+    }
+    
+	public void include(PortletRequest request, PortletResponse response) throws PortletException,
IOException
+	{
+	   if (isDebug) {
+         LOG.debug("Doing request dispatcher include for portlet request.");
+      }
+	    doDispatch(request, response, true);
+	}
+	
+	public void include(RenderRequest request, RenderResponse response) throws PortletException,
IOException
+	{
+      if (isDebug) {
+         LOG.debug("Doing request dispatcher include for render request.");
+      }
+	    doDispatch(request, response, true);
+    }
+	
+    // Nested RequestDispatcher Impl -------------------------------------------
+	
+    public void forward(ServletRequest request, ServletResponse response) throws ServletException,
IOException
+    {
+        HttpServletPortletRequestWrapper req = getWrappedRequest(request);
+        HttpServletPortletResponseWrapper res = getWrappedResponse(response);
+        res.resetBuffer();
+        
+        // cache the current dispatch state
+        boolean forwarded = req.isForwarded();
+        boolean namedDispatch = req.isNamedDispatch();
+        Map<String,Object> pathAttributeValues = req.getPathAttributeValues();
+        HttpServletPortletRequestWrapper.PathMethodValues pathMethodValues = req.getInitPathMethodValues();
+        
+        // (re)initialize the request wrapper to a nested forward
+        req.setNestedForward();
+        try
+        {
+            if (req.isForwardingPossible())
+            {
+                requestDispatcher.forward(request, response);
+            }
+            else
+            {
+                // need to "fake" the forward using an include
+                requestDispatcher.include(request, response);
+            }
+        }
+        finally
+        {
+            // restore the previously cached dispatch state
+            req.restoreFromNestedForward(forwarded, namedDispatch, pathMethodValues, pathAttributeValues);
+        }
+    }
+
+    public void include(ServletRequest request, ServletResponse response) throws ServletException,
IOException
+    {
+        // no need for special handling on a nested dispatcher include: just calling the
wrapped servlet dispatcher
+        requestDispatcher.include(request, response);
+    }
+}

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/6dd6b872/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletMimeResponseContextImpl.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletMimeResponseContextImpl.java
b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletMimeResponseContextImpl.java
index 9e1a0d4..ffbdc2d 100644
--- a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletMimeResponseContextImpl.java
+++ b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletMimeResponseContextImpl.java
@@ -93,13 +93,13 @@ public abstract class PortletMimeResponseContextImpl extends PortletResponseCont
    }
 
    public void flushBuffer() throws IOException {
-      if (!isClosed() && !isSetPropsAllowed()) {
+      if (!isClosed() && !isHeaderBufferActive()) {
          getServletResponse().flushBuffer();
       }
    }
 
    public int getBufferSize() {
-      if (isSetPropsAllowed()) {
+      if (isHeaderBufferActive()) {
          // header request
          return headerData.getBufferSize();
       } else {
@@ -134,7 +134,7 @@ public abstract class PortletMimeResponseContextImpl extends PortletResponseCont
       if (isClosed()) {
          return null;
       }
-      if (isSetPropsAllowed()) {
+      if (isHeaderBufferActive()) {
          // header request
          return headerData.getBaoStream();
       } else {
@@ -157,7 +157,7 @@ public abstract class PortletMimeResponseContextImpl extends PortletResponseCont
       if (isClosed()) {
          return null;
       }
-      if (isSetPropsAllowed()) {
+      if (isHeaderBufferActive()) {
          // header request
          return headerData.getWriter();
       } else {
@@ -167,7 +167,7 @@ public abstract class PortletMimeResponseContextImpl extends PortletResponseCont
    }
 
    public boolean isCommitted() {
-      if (isSetPropsAllowed()) {
+      if (isHeaderBufferActive()) {
          // header request
          return false;
       } else {
@@ -177,7 +177,7 @@ public abstract class PortletMimeResponseContextImpl extends PortletResponseCont
 
    public void reset() {
       if (!isClosed()) {
-         if (isSetPropsAllowed()) {
+         if (isHeaderBufferActive()) {
             // header request
             headerData.reset();
          } else {
@@ -188,7 +188,7 @@ public abstract class PortletMimeResponseContextImpl extends PortletResponseCont
 
    public void resetBuffer() {
       if (!isClosed()) {
-         if (isSetPropsAllowed()) {
+         if (isHeaderBufferActive()) {
             // header request
             headerData.resetBuffer();
          } else {
@@ -199,7 +199,7 @@ public abstract class PortletMimeResponseContextImpl extends PortletResponseCont
 
    public void setBufferSize(int size) {
       if (!isClosed()) {
-         if (isSetPropsAllowed()) {
+         if (isHeaderBufferActive()) {
             // header request
             headerData.setBufferSize(size);
          } else {

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/6dd6b872/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletResponseContextImpl.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletResponseContextImpl.java
b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletResponseContextImpl.java
index 0e60f50..c59784b 100644
--- a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletResponseContextImpl.java
+++ b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletResponseContextImpl.java
@@ -18,6 +18,7 @@ package org.apache.pluto.driver.services.container;
 
 import static javax.portlet.PortletRequest.HEADER_PHASE;
 import static javax.portlet.PortletRequest.RENDER_PHASE;
+import static javax.portlet.PortletRequest.RESOURCE_PHASE;
 
 import java.util.Arrays;
 import java.util.HashSet;
@@ -102,6 +103,17 @@ public abstract class PortletResponseContextImpl implements PortletResponseConte
    public void setPropsAllowed(boolean isSetPropsAllowed) {
       this.isSetPropsAllowed = isSetPropsAllowed;
    }
+   
+   /**
+    * Returns <code>true</code> if markup written to the portlet output stream
should 
+    * land in the document head section.
+    *  
+    * @return  <code>true</code> if the header buffer is active
+    */
+   public boolean isHeaderBufferActive() {
+      return isSetPropsAllowed && !lifecycle.equals(RESOURCE_PHASE);
+   }
+
 
    /**
     * returns the header data provided by the portlet during header phase execution.


Mime
View raw message