From 21f61e3680a1f15cfde12a75f4e0fcdc32591234 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 2 Dec 2011 12:03:35 +0000 Subject: [PATCH] Portlet session mutex uses global session attribute to be shared among all portlets in the session (SPR-8888) --- .../springframework/web/portlet/util/PortletUtils.java | 4 ++-- .../web/portlet/util/PortletUtilsTests.java | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/util/PortletUtils.java b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/util/PortletUtils.java index 968229c7538..2beb0352b86 100644 --- a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/util/PortletUtils.java +++ b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/util/PortletUtils.java @@ -29,10 +29,10 @@ import javax.portlet.PortletContext; import javax.portlet.PortletException; import javax.portlet.PortletRequest; import javax.portlet.PortletRequestDispatcher; +import javax.portlet.PortletResponse; import javax.portlet.PortletSession; import javax.portlet.ResourceRequest; import javax.portlet.ResourceResponse; -import javax.portlet.PortletResponse; import javax.portlet.filter.PortletRequestWrapper; import javax.portlet.filter.PortletResponseWrapper; import javax.servlet.http.Cookie; @@ -271,7 +271,7 @@ public abstract class PortletUtils { */ public static Object getSessionMutex(PortletSession session) { Assert.notNull(session, "Session must not be null"); - Object mutex = session.getAttribute(WebUtils.SESSION_MUTEX_ATTRIBUTE); + Object mutex = session.getAttribute(WebUtils.SESSION_MUTEX_ATTRIBUTE, PortletSession.APPLICATION_SCOPE); if (mutex == null) { mutex = session; } diff --git a/org.springframework.web.portlet/src/test/java/org/springframework/web/portlet/util/PortletUtilsTests.java b/org.springframework.web.portlet/src/test/java/org/springframework/web/portlet/util/PortletUtilsTests.java index d37bb93da3a..a55e0d8e964 100644 --- a/org.springframework.web.portlet/src/test/java/org/springframework/web/portlet/util/PortletUtilsTests.java +++ b/org.springframework.web.portlet/src/test/java/org/springframework/web/portlet/util/PortletUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-20011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +25,6 @@ import javax.portlet.PortletContext; import javax.portlet.PortletRequest; import javax.portlet.PortletSession; -import static org.easymock.EasyMock.*; -import static org.junit.Assert.*; import org.junit.Test; import org.springframework.beans.ITestBean; @@ -38,6 +36,9 @@ import org.springframework.mock.web.portlet.MockPortletRequest; import org.springframework.mock.web.portlet.MockPortletSession; import org.springframework.web.util.WebUtils; +import static org.easymock.EasyMock.*; +import static org.junit.Assert.*; + /** * @author Rick Evans * @author Chris Beams @@ -374,7 +375,7 @@ public final class PortletUtilsTests { public void testGetSessionMutexWithExistingSessionMutexReturnsTheExistingSessionMutex() throws Exception { MockPortletSession session = new MockPortletSession(); Object expectSessionMutex = new Object(); - session.setAttribute(WebUtils.SESSION_MUTEX_ATTRIBUTE, expectSessionMutex); + session.setAttribute(WebUtils.SESSION_MUTEX_ATTRIBUTE, expectSessionMutex, PortletSession.APPLICATION_SCOPE); Object actualSessionMutex = PortletUtils.getSessionMutex(session); assertNotNull("PortletUtils.getSessionMutex(..) must never return a null mutex", actualSessionMutex); assertSame("PortletUtils.getSessionMutex(..) must return the bound mutex attribute if a mutex has been bound as a Session attribute beforehand",