You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by ms...@apache.org on 2016/04/08 15:40:18 UTC

[06/34] portals-pluto git commit: Activated async mode in portal driver servlet. activated async mode for the servlets representing portlets that are configured for async"

Activated async mode in portal driver servlet. activated async mode for
the servlets representing portlets that are configured for async"


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

Branch: refs/heads/V3Prototype
Commit: 45fb2a6ff36870ff752386522a7d6ff0909a5663
Parents: 914a968
Author: Scott Nicklous <ms...@apache.org>
Authored: Sun Mar 20 21:39:52 2016 +0100
Committer: Scott Nicklous <ms...@apache.org>
Committed: Sun Mar 20 21:39:52 2016 +0100

----------------------------------------------------------------------
 .../org/apache/portals/samples/PathDisplay.java |  5 +
 .../apache/portals/samples/PathInfoPortlet.java | 97 ++++++++++++++------
 .../src/main/webapp/WEB-INF/jsp/pathinfo.jsp    |  2 +-
 .../driver/PortletContainerInitializer.java     |  1 +
 .../container/impl/PortletRequestImpl.java      |  8 ++
 pluto-portal/src/main/webapp/WEB-INF/web.xml    |  3 +
 6 files changed, 89 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/45fb2a6f/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/PathDisplay.java
----------------------------------------------------------------------
diff --git a/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/PathDisplay.java b/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/PathDisplay.java
index dbf1cf4..ae0f61f 100644
--- a/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/PathDisplay.java
+++ b/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/PathDisplay.java
@@ -53,6 +53,7 @@ public class PathDisplay {
    
    private String type;
    private String caller;
+   private boolean isAsyncSupported = false;
 
    public PathDisplay(HttpServletRequest req, String caller) {
       this.caller = caller;
@@ -82,6 +83,7 @@ public class PathDisplay {
       method_query_string = req.getQueryString();
       
       type = req.getDispatcherType().name();
+      isAsyncSupported = req.isAsyncSupported();
 }
 
    public PathDisplay(PortletRequest req, String caller) {
@@ -137,6 +139,9 @@ public class PathDisplay {
          txt.append("</tr><tr>");
          txt.append("<td>async_query_string:</td><td>").append(async_query_string).append("</td>\n");
       }
+      txt.append("</tr><tr>");
+      txt.append("<td>isAsyncSupported:</td><td>").append(isAsyncSupported).append("</td>\n");
+
       txt.append("</tr><tr><td style='padding-top:8px;'/></tr><tr>");
 
       if ((forward_request_uri == null) && (forward_context_path == null) && (forward_servlet_path == null)

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/45fb2a6f/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/PathInfoPortlet.java
----------------------------------------------------------------------
diff --git a/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/PathInfoPortlet.java b/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/PathInfoPortlet.java
index 1f42b14..aa87980 100644
--- a/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/PathInfoPortlet.java
+++ b/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/PathInfoPortlet.java
@@ -16,20 +16,25 @@
  *  under the License.
  */
 
-
 package org.apache.portals.samples;
 
+import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.ArrayList;
 
 import javax.inject.Inject;
 import javax.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
 import javax.portlet.ResourceURL;
 import javax.portlet.annotations.Namespace;
 import javax.portlet.annotations.RenderMethod;
 import javax.portlet.annotations.ServeResourceMethod;
 import javax.portlet.annotations.URLFactory;
+import javax.servlet.AsyncContext;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
-
+import javax.servlet.http.HttpServletResponse;
 
 /**
  * Resource portlet for viewing path information.
@@ -37,26 +42,30 @@ import javax.servlet.http.HttpServletRequest;
 public class PathInfoPortlet {
 
    public static final String RESPARAM_DISPLAY = "display";
-   
+
    // Injecting the namespace & URLFactory
-   @Inject @Namespace private String pid;
-   @Inject private            URLFactory uf;
+   @Inject
+   @Namespace
+   private String             pid;
+   @Inject
+   private URLFactory         uf;
 
-   @RenderMethod(portletNames = {"PathInfoPortlet"}, ordinal=100)
+   @RenderMethod(portletNames = { "PathInfoPortlet" }, ordinal = 100)
    public String getImageInclude() {
-      
+
       StringBuilder txt = new StringBuilder(128);
       txt.append("<h3>Path Info Portlet</h3>");
-      
+
       ResourceURL resurl = uf.createResourceURL();
-      
+
       txt.append("<div class='infobox' id='").append(pid).append("-putResourceHere'></div>\n");
       txt.append("<script>\n");
       txt.append("(function () {\n");
       txt.append("   var xhr = new XMLHttpRequest();\n");
       txt.append("   xhr.onreadystatechange=function() {\n");
       txt.append("      if (xhr.readyState==4 && xhr.status==200) {\n");
-      txt.append("         document.getElementById('").append(pid).append("-putResourceHere').innerHTML=xhr.responseText;\n");
+      txt.append("         document.getElementById('").append(pid)
+            .append("-putResourceHere').innerHTML=xhr.responseText;\n");
       txt.append("      }\n");
       txt.append("   };\n");
       txt.append("   xhr.open(\"GET\",\"").append(resurl.toString()).append("\",true);\n");
@@ -66,34 +75,70 @@ public class PathInfoPortlet {
 
       return txt.toString();
    }
-   
-   @Inject private ResourceRequest resReq;
-   
+
    /**
-    *  This resource method generates some output directly, then includes output
-    *  from a JSP as specified in the annotation.
-    *  
-    * @return  The string for inclusion in the output.
+    * This resource method generates some output directly, then includes output
+    * from a JSP as specified in the annotation.
+    * 
+    * @return The string for inclusion in the output.
+    * @throws IOException
     */
-   @ServeResourceMethod(portletNames={"PathInfoPortlet"}, include="/WEB-INF/jsp/pathinfo.jsp")
-   public void getPathInfo() {
-      
+   @ServeResourceMethod(portletNames = { "PathInfoPortlet" }, asyncSupported = true)
+   public void getPathInfo(ResourceRequest req, ResourceResponse resp) throws IOException {
+
       @SuppressWarnings("unchecked")
-      ArrayList<String> pathInfo = (ArrayList<String>) resReq.getAttribute("pathInfo");
+      ArrayList<String> pathInfo = (ArrayList<String>) req.getAttribute("pathInfo");
       if (pathInfo == null) {
          pathInfo = new ArrayList<String>();
       }
-      
-      HttpServletRequest hreq = (HttpServletRequest) resReq.getAttribute("javax.portlet.debug.ServletRequest");
+
+      HttpServletRequest hreq = (HttpServletRequest) req.getAttribute("javax.portlet.debug.ServletRequest");
+      HttpServletResponse hresp = (HttpServletResponse) req.getAttribute("javax.portlet.debug.ServletResponse");
       PathDisplay pd;
       if (hreq != null) {
          pd = new PathDisplay(hreq, "Resource Method (Servlet)");
       } else {
-         pd = new PathDisplay(resReq, "Resource Method (Resource)");
+         pd = new PathDisplay(req, "Resource Method (Resource)");
       }
       pathInfo.add(pd.toMarkup());
-      
-      resReq.setAttribute("pathInfo", pathInfo);
+
+      req.setAttribute("pathInfo", pathInfo);
+
+      PrintWriter writer = resp.getWriter();
+      writer.append("<h5>Async Hack Resource Request</h5>");
+      writer.append("<p>");
+      writer.append("Trying to start async. Servlet context = ").append(hreq.getServletContext().getContextPath())
+            .append(". ");
+      resp.flushBuffer();
+
+      RequestDispatcher rd = null;
+      String jsp = "/WEB-INF/jsp/pathinfo.jsp";
+      rd = hreq.getRequestDispatcher(jsp);
+      if (hreq != null && hresp != null) {
+         try {
+            AsyncContext context = hreq.startAsync(hreq, hresp);
+            context.setTimeout(3000);
+            writer = context.getResponse().getWriter();
+            writer.append("worked. Async context: ").append((context == null) ? "null." : "not null.");
+            writer.append(" Now dispatching ... ");
+            resp.flushBuffer();
+            context.dispatch(jsp);
+            writer.append(" done. ");
+         } catch (Exception e) {
+            writer.append(" ... didn't work. Exception: ").append(e.toString());
+            resp.flushBuffer();
+         }
+      }
+
+      writer.append("</p><hr>");
+      resp.flushBuffer();
+      try {
+         writer.append("<p>Now doing request dispatcher include.</p>");
+         rd.include(hreq, hresp);
+      } catch (ServletException e) {
+         writer.append("<p>Exception including jsp. ").append(e.toString());
+         writer.append("</p>");
+      }
 
    }
 

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/45fb2a6f/PortletV3AnnotatedDemo/src/main/webapp/WEB-INF/jsp/pathinfo.jsp
----------------------------------------------------------------------
diff --git a/PortletV3AnnotatedDemo/src/main/webapp/WEB-INF/jsp/pathinfo.jsp b/PortletV3AnnotatedDemo/src/main/webapp/WEB-INF/jsp/pathinfo.jsp
index 099b153..b5d8e1a 100644
--- a/PortletV3AnnotatedDemo/src/main/webapp/WEB-INF/jsp/pathinfo.jsp
+++ b/PortletV3AnnotatedDemo/src/main/webapp/WEB-INF/jsp/pathinfo.jsp
@@ -4,7 +4,7 @@
 <%@ page import="org.apache.portals.samples.*" %>
 <%@ page import="java.util.*" %>
 
-<portlet:defineObjects />
+<!--   portlet:defineObjects /  -->
 
 <p>Message from included JSP.</p>
 <%

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/45fb2a6f/pluto-container-driver-api/src/main/java/org/apache/pluto/container/driver/PortletContainerInitializer.java
----------------------------------------------------------------------
diff --git a/pluto-container-driver-api/src/main/java/org/apache/pluto/container/driver/PortletContainerInitializer.java b/pluto-container-driver-api/src/main/java/org/apache/pluto/container/driver/PortletContainerInitializer.java
index 7b5e8fc..0fb20a6 100644
--- a/pluto-container-driver-api/src/main/java/org/apache/pluto/container/driver/PortletContainerInitializer.java
+++ b/pluto-container-driver-api/src/main/java/org/apache/pluto/container/driver/PortletContainerInitializer.java
@@ -160,6 +160,7 @@ public class PortletContainerInitializer implements ServletContainerInitializer
                ServletRegistration.Dynamic sr = ctx.addServlet(servletName, PortletServlet3.class);
                sr.addMapping(mapping);
                sr.setInitParameter(PortletServlet3.PORTLET_NAME, pn);
+               sr.setAsyncSupported(pd.isAsyncSupported());
                sr.setLoadOnStartup(100);
 
             }

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/45fb2a6f/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletRequestImpl.java
----------------------------------------------------------------------
diff --git a/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletRequestImpl.java b/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletRequestImpl.java
index c25b437..af3dbb4 100644
--- a/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletRequestImpl.java
+++ b/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletRequestImpl.java
@@ -261,6 +261,14 @@ public abstract class PortletRequestImpl implements PortletRequest
         {
             return requestContext.getServletRequest();
         }
+        else if (name.equals("javax.portlet.debug.ServletResponse"))
+        {
+            return requestContext.getServletResponse();
+        }
+        else if (name.equals("javax.portlet.debug.ServletContext"))
+        {
+            return requestContext.getServletContext();
+        }
         return requestContext.getAttribute(name);
     }
 

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/45fb2a6f/pluto-portal/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/pluto-portal/src/main/webapp/WEB-INF/web.xml b/pluto-portal/src/main/webapp/WEB-INF/web.xml
index 60fdba0..283560b 100644
--- a/pluto-portal/src/main/webapp/WEB-INF/web.xml
+++ b/pluto-portal/src/main/webapp/WEB-INF/web.xml
@@ -34,6 +34,7 @@ limitations under the License.
   <filter>
     <filter-name>plutoPortalDriver</filter-name>
     <filter-class>org.apache.pluto.driver.PortalDriverFilter</filter-class>
+    <async-supported>true</async-supported>
   </filter>
 
   <filter-mapping>
@@ -55,6 +56,7 @@ limitations under the License.
     <display-name>Pluto Portal Driver</display-name>
     <servlet-name>plutoPortalDriver</servlet-name>
     <servlet-class>org.apache.pluto.driver.PortalDriverServlet</servlet-class>
+    <async-supported>true</async-supported>
   </servlet>
 
   <servlet>
@@ -62,6 +64,7 @@ limitations under the License.
     <display-name>Pluto Portal Driver</display-name>
     <servlet-name>plutoPortalDriverLogout</servlet-name>
     <servlet-class>org.apache.pluto.driver.PortalDriverLogoutServlet</servlet-class>
+    <async-supported>true</async-supported>
   </servlet>
 
   <servlet>