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/14 14:29:03 UTC
[23/50] [abbrv] portals-pluto git commit: progress on async support.
Modifications to portlet container and portal driver servlet
progress on async support. Modifications to portlet container and portal driver servlet
Project: http://git-wip-us.apache.org/repos/asf/portals-pluto/repo
Commit: http://git-wip-us.apache.org/repos/asf/portals-pluto/commit/ae198fe2
Tree: http://git-wip-us.apache.org/repos/asf/portals-pluto/tree/ae198fe2
Diff: http://git-wip-us.apache.org/repos/asf/portals-pluto/diff/ae198fe2
Branch: refs/heads/master
Commit: ae198fe2959f446f0966e7af31c6d2d09f919b72
Parents: 49ca2dd
Author: Scott Nicklous <ms...@apache.org>
Authored: Tue Mar 22 16:18:30 2016 +0100
Committer: Scott Nicklous <ms...@apache.org>
Committed: Tue Mar 22 16:18:30 2016 +0100
----------------------------------------------------------------------
.../portals/samples/AsyncHackPortlet.java | 32 +++++++++++---
.../container/impl/PortletContainerImpl.java | 27 ++++++------
.../pluto/driver/PortalDriverServlet.java | 45 --------------------
.../container/DefaultPortletInvokerService.java | 17 ++++----
4 files changed, 45 insertions(+), 76 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/ae198fe2/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/AsyncHackPortlet.java
----------------------------------------------------------------------
diff --git a/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/AsyncHackPortlet.java b/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/AsyncHackPortlet.java
index 9e2c243..80eba8c 100644
--- a/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/AsyncHackPortlet.java
+++ b/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/AsyncHackPortlet.java
@@ -44,6 +44,26 @@ public class AsyncHackPortlet {
public static final String RESPARAM_DISPLAY = "display";
+ private AsyncContext context;
+ private static final String jsp = "/WEB-INF/jsp/pathinfo.jsp";
+// private static final String jsp = "/ais";
+
+
+ private class AsyncHackRunnable implements Runnable {
+
+ @Override
+ public void run() {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {}
+ LOGGER.fine("Slept, now dispatching.");
+ HttpServletRequest hreq = (HttpServletRequest) context.getRequest();
+ context.dispatch(hreq.getServletContext(), jsp);
+// context.dispatch(jsp);
+ }
+
+ }
+
// Injecting the namespace & URLFactory
@Inject
@Namespace
@@ -114,8 +134,6 @@ public class AsyncHackPortlet {
StringBuilder txt = new StringBuilder(128);
txt.append("Trying to start async. Servlet context: ").append(hreq.getServletContext().getContextPath());
- String jsp = "/WEB-INF/jsp/pathinfo.jsp";
-// String jsp = "/ais";
// RequestDispatcher rd = null;
// rd = hreq.getRequestDispatcher(jsp);
// txt.append("Request dispatcher: ").append(rd);
@@ -125,14 +143,14 @@ public class AsyncHackPortlet {
if (hreq != null && hresp != null) {
try {
- AsyncContext context = hreq.startAsync(hreq, hresp);
- context.setTimeout(1000);
+ context = hreq.startAsync(hreq, hresp);
+ context.setTimeout(4000);
txt.append("Async context: ").append((context == null) ? "null." : "not null.");
- txt.append(" Now dispatching ... ");
+ txt.append(" Now starting thread ... ");
-// context.dispatch(hreq.getServletContext(), jsp);
- context.dispatch(jsp);
+ AsyncHackRunnable ahr = new AsyncHackRunnable();
+ context.start(ahr);
txt.append(" done. ");
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/ae198fe2/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletContainerImpl.java
----------------------------------------------------------------------
diff --git a/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletContainerImpl.java b/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletContainerImpl.java
index dc17d7f..44f2035 100644
--- a/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletContainerImpl.java
+++ b/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletContainerImpl.java
@@ -268,22 +268,19 @@ public class PortletContainerImpl implements PortletContainer
FilterManager filterManager = filterInitialisation(portletWindow,PortletRequest.RESOURCE_PHASE);
- if (portletWindow.getPortletDefinition().isAsyncSupported()) {
- LOG.debug("invoking for async ... no resource release");
+ try
+ {
invoker.serveResource(requestContext, portletRequest, portletResponse, filterManager);
-
- } else {
- LOG.debug("invocation through request dispatcher.");
- try
- {
- invoker.serveResource(requestContext, portletRequest, portletResponse, filterManager);
- // Mark portlet interaction is completed: backend implementation can flush response state now
- responseContext.close();
- }
- finally
- {
- responseContext.release();
- }
+ }
+ finally
+ {
+ if (!request.isAsyncSupported() || !request.isAsyncStarted()) {
+ // Mark portlet interaction is completed: backend implementation can flush response state now
+ responseContext.close();
+ responseContext.release();
+ } else {
+ LOG.debug("Async started for resource request. responseContext not released.");
+ }
}
debugWithName("Portlet resource done for: " + portletWindow.getPortletDefinition().getPortletName());
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/ae198fe2/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalDriverServlet.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalDriverServlet.java b/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalDriverServlet.java
index 722b037..81ec5e9 100644
--- a/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalDriverServlet.java
+++ b/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalDriverServlet.java
@@ -145,51 +145,6 @@ public class PortalDriverServlet extends HttpServlet {
LOG.debug("Processing " + reqType + " request for window: " + portletWindow.getId().getStringId());
}
-
-// String portletName = portletWindow.getPortletName();
-// if (portletName.equals("AsyncHackPortlet")
-// && portalURL.getType() == URLType.Resource) {
-//
-// String uri = PortletInvokerService.URIPREFIX + portletWindow.getPortletDefinition().getPortletName();
-// String ctxpath = "/PortletV3AnnotatedDemo";
-// String jsp = "/WEB-INF/jsp/pathinfo.jsp";
-//
-// // LOG.debug("Directly doing async dispatch to JSP. uri: " + uri + ", jsp: " + jsp);
-// LOG.debug("Directly dispatching to portlet servlet. uri: " + uri);
-//
-// ServletContext ctx = request.getServletContext().getContext(ctxpath);
-// RequestDispatcher rd = ctx.getRequestDispatcher(uri);
-// rd.forward(request, response);
-// LOG.debug("Completed the dispatch.");
-// return;
-//
-// // ServletContext ctx = request.getServletContext().getContext(ctxpath);
-// // if (ctx == null) {
-// // LOG.debug("couldn't get context for uri.");
-// // } else {
-// // LOG.debug("Got context, path: >>>" + ctx.getContextPath() + "<<<");
-// //
-// // AsyncContext context = request.startAsync();
-// // context.dispatch(ctx, jsp);
-// //
-// // LOG.debug("Completed the dispatch.");
-// // return;
-// //
-// //
-// // RequestDispatcher rd = ctx.getRequestDispatcher(jsp);
-// // if (rd == null) {
-// // LOG.debug("couldn't get request dispatcher for context.");
-// // } else {
-// // LOG.debug("Got the request dispatcher.");
-// // // PrintWriter writer = response.getWriter();
-// // // writer.append("<h5>Greetings from portal driver servlet!</h5>");
-// // rd.include(request, response);
-// // LOG.debug("Dispatch seemed to go OK.");
-// // return;
-// // }
-// // }
-// }
-
try {
PageState ps;
String jsondata;
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/ae198fe2/pluto-portal-driver/src/main/java/org/apache/pluto/driver/container/DefaultPortletInvokerService.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver/src/main/java/org/apache/pluto/driver/container/DefaultPortletInvokerService.java b/pluto-portal-driver/src/main/java/org/apache/pluto/driver/container/DefaultPortletInvokerService.java
index 3d1e4ea..20d8a8b 100644
--- a/pluto-portal-driver/src/main/java/org/apache/pluto/driver/container/DefaultPortletInvokerService.java
+++ b/pluto-portal-driver/src/main/java/org/apache/pluto/driver/container/DefaultPortletInvokerService.java
@@ -17,6 +17,8 @@
package org.apache.pluto.driver.container;
import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
@@ -240,14 +242,8 @@ public class DefaultPortletInvokerService implements PortletInvokerService {
if (methodID.equals(PortletInvokerService.METHOD_RESOURCE))
{
- if (portletWindow.getPortletDefinition().isAsyncSupported()) {
- LOG.debug("Async dispatching resource request to portlet servlet.");
- AsyncContext actx = containerRequest.startAsync(containerRequest, containerResponse);
- actx.dispatch(servletContext, uri);
- } else {
- LOG.debug("Request dispatcher forward resource request to portlet servlet.");
- dispatcher.forward(containerRequest, containerResponse);
- }
+ LOG.debug("Request dispatcher forward resource request to portlet servlet.");
+ dispatcher.forward(containerRequest, containerResponse);
LOG.debug("Dispatch complete.");
}
else
@@ -284,11 +280,14 @@ public class DefaultPortletInvokerService implements PortletInvokerService {
}
} finally {
- if (!portletWindow.getPortletDefinition().isAsyncSupported()) {
+ if (!containerRequest.isAsyncSupported() || !containerRequest.isAsyncStarted()) {
+ LOG.debug("After invocation, removing attributes.");
containerRequest.removeAttribute(PortletInvokerService.METHOD_ID);
containerRequest.removeAttribute(PortletInvokerService.PORTLET_REQUEST);
containerRequest.removeAttribute(PortletInvokerService.PORTLET_RESPONSE);
containerRequest.removeAttribute(PortletInvokerService.FILTER_MANAGER);
+ } else {
+ LOG.debug("After invocation, async started for resource request. attributes not removed.");
}
}
} else {