Repository: portals-pluto
Updated Branches:
refs/heads/master b925769ba -> 7d92d190b
Fixed an issue in which calls to PortletRequest.getPortletSession(true) returned different
a value each time (within the scope of a request). The JSR 378 TCK (inherited from JSR 329)
assumes it will be the same value.
Project: http://git-wip-us.apache.org/repos/asf/portals-pluto/repo
Commit: http://git-wip-us.apache.org/repos/asf/portals-pluto/commit/7d92d190
Tree: http://git-wip-us.apache.org/repos/asf/portals-pluto/tree/7d92d190
Diff: http://git-wip-us.apache.org/repos/asf/portals-pluto/diff/7d92d190
Branch: refs/heads/master
Commit: 7d92d190b86427fce7cf12fe543548e24815f89d
Parents: b925769
Author: Neil Griffin <neil.griffin.scm@gmail.com>
Authored: Wed Dec 14 18:14:52 2016 -0500
Committer: Neil Griffin <neil.griffin.scm@gmail.com>
Committed: Wed Dec 14 18:14:52 2016 -0500
----------------------------------------------------------------------
.../container/CachedPortletSession.java | 24 +++++
.../container/CachedPortletSessionImpl.java | 40 +++++++
.../container/PortletRequestContextImpl.java | 107 ++++++++++---------
3 files changed, 120 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/7d92d190/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/CachedPortletSession.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/CachedPortletSession.java
b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/CachedPortletSession.java
new file mode 100644
index 0000000..a7131f5
--- /dev/null
+++ b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/CachedPortletSession.java
@@ -0,0 +1,24 @@
+/*
+ * 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.driver.services.container;
+
+import javax.portlet.PortletSession;
+
+public interface CachedPortletSession extends PortletSession {
+
+ boolean isInvalidated();
+}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/7d92d190/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/CachedPortletSessionImpl.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/CachedPortletSessionImpl.java
b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/CachedPortletSessionImpl.java
new file mode 100644
index 0000000..ea7f69d
--- /dev/null
+++ b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/CachedPortletSessionImpl.java
@@ -0,0 +1,40 @@
+/*
+ * 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.driver.services.container;
+
+import javax.portlet.PortletSession;
+import javax.portlet.filter.PortletSessionWrapper;
+
+public class CachedPortletSessionImpl extends PortletSessionWrapper implements CachedPortletSession
{
+
+ private boolean invalidated;
+
+ public CachedPortletSessionImpl(PortletSession wrapped) {
+ super(wrapped);
+ }
+
+ @Override
+ public boolean isInvalidated() {
+ return invalidated;
+ }
+
+ @Override
+ public void invalidate() {
+ invalidated = true;
+ super.invalidate();
+ }
+}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/7d92d190/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletRequestContextImpl.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletRequestContextImpl.java
b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletRequestContextImpl.java
index f2f6e5e..1b01a45 100644
--- a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletRequestContextImpl.java
+++ b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletRequestContextImpl.java
@@ -93,6 +93,7 @@ public class PortletRequestContextImpl implements PortletRequestContext
{
private PortalURL url;
private PortletConfig portletConfig;
private ServletContext servletContext;
+ private CachedPortletSession cachedPortletSession;
private Cookie cookies[];
private String renderHeaders = null;
private boolean executingRequestBody = false;
@@ -352,68 +353,72 @@ public class PortletRequestContextImpl implements PortletRequestContext
{
LOG.debug("Retrieving portlet session (create=" + create + ")");
}
- //
- // It is critical that we don't retrieve the portlet session until the
- // cross context dispatch has been completed. If we do then we risk
- // having a cached version which is invalid for the context within
- // which it exists.
- //
+ if ((cachedPortletSession == null) || cachedPortletSession.isInvalidated()) {
+
+ //
+ // It is critical that we don't retrieve the portlet session until the
+ // cross context dispatch has been completed. If we do then we risk
+ // having a cached version which is invalid for the context within
+ // which it exists.
+ //
- if (portletConfig == null) {
- throw new IllegalStateException(EXCEPTIONS.getString("error.session.illegalState"));
- }
+ if (portletConfig == null) {
+ throw new IllegalStateException(EXCEPTIONS.getString("error.session.illegalState"));
+ }
- //
- // We must make sure that if the session has been invalidated (perhaps
- // through setMaxIntervalTimeout()) and the underlying request
- // returns null that we no longer use the cached version.
- // We have to check (ourselves) if the session has exceeded its max
- // inactive interval. If so, we should invalidate the underlying
- // HttpSession and recreate a new one (if the create flag is set to
- // true) -- We just cannot depend on the implementation of
- // javax.servlet.http.HttpSession!
- //
+ //
+ // We must make sure that if the session has been invalidated (perhaps
+ // through setMaxIntervalTimeout()) and the underlying request
+ // returns null that we no longer use the cached version.
+ // We have to check (ourselves) if the session has exceeded its max
+ // inactive interval. If so, we should invalidate the underlying
+ // HttpSession and recreate a new one (if the create flag is set to
+ // true) -- We just cannot depend on the implementation of
+ // javax.servlet.http.HttpSession!
+ //
- HttpSession httpSession = getServletRequest().getSession(create);
- if (httpSession != null) {
- // HttpSession is not null does NOT mean that it is valid.
- int maxInactiveInterval = httpSession.getMaxInactiveInterval();
- long lastAccesstime = httpSession.getLastAccessedTime();// lastAccesstime checks
added for PLUTO-436
- if (maxInactiveInterval >= 0 && lastAccesstime > 0) { // < 0 =>
Never expires.
- long maxInactiveTime = httpSession.getMaxInactiveInterval() * 1000L;
- long currentInactiveTime = System.currentTimeMillis() - lastAccesstime;
- if (currentInactiveTime > maxInactiveTime) {
- if (isDebug) {
- LOG.debug("The underlying HttpSession is expired and " + "should be invalidated.");
+ HttpSession httpSession = getServletRequest().getSession(create);
+ if (httpSession != null) {
+ // HttpSession is not null does NOT mean that it is valid.
+ int maxInactiveInterval = httpSession.getMaxInactiveInterval();
+ long lastAccesstime = httpSession.getLastAccessedTime();// lastAccesstime checks
added for PLUTO-436
+ if (maxInactiveInterval >= 0 && lastAccesstime > 0) { // < 0
=> Never expires.
+ long maxInactiveTime = httpSession.getMaxInactiveInterval() * 1000L;
+ long currentInactiveTime = System.currentTimeMillis() - lastAccesstime;
+ if (currentInactiveTime > maxInactiveTime) {
+ if (isDebug) {
+ LOG.debug("The underlying HttpSession is expired and " + "should be
invalidated.");
+ }
+ httpSession.invalidate();
+ httpSession = getServletRequest().getSession(create);
+ // Added for PLUTO-436
+ // a cached portletSession is no longer useable.
+ // a new one will be created below.
}
- httpSession.invalidate();
- httpSession = getServletRequest().getSession(create);
- // Added for PLUTO-436
- // a cached portletSession is no longer useable.
- // a new one will be created below.
}
}
- }
- if (httpSession == null) {
- if (isDebug) {
- LOG.debug("The underlying HttpSession is not available: " + "no session will
be returned.");
+ if (httpSession == null) {
+ if (isDebug) {
+ LOG.debug("The underlying HttpSession is not available: " + "no session will
be returned.");
+ }
+ return null;
}
- return null;
- }
- //
- // If we reach here, we are sure that the underlying HttpSession is
- // available. If we haven't created and cached a portlet session
- // instance, we will create and cache one now.
- //
+ //
+ // If we reach here, we are sure that the underlying HttpSession is
+ // available. If we haven't created and cached a portlet session
+ // instance, we will create and cache one now.
+ //
- final ContainerServices containerServices = container.getContainerServices();
- final PortletEnvironmentService portletEnvironmentService = containerServices.getPortletEnvironmentService();
+ final ContainerServices containerServices = container.getContainerServices();
+ final PortletEnvironmentService portletEnvironmentService = containerServices.getPortletEnvironmentService();
+
+ cachedPortletSession = new CachedPortletSessionImpl(portletEnvironmentService.createPortletSession(
+ portletConfig.getPortletContext(), getPortletWindow(), httpSession));
+ }
- PortletSession portletSession = portletEnvironmentService.createPortletSession(portletConfig.getPortletContext(),
- getPortletWindow(), httpSession);
- return portletSession;
+ return cachedPortletSession;
}
@Override
|