Portlet session mutex uses global session attribute to be shared among all portlets in the session (SPR-8888)

This commit is contained in:
Juergen Hoeller 2011-12-02 12:03:35 +00:00
parent 53cb529162
commit 21f61e3680
2 changed files with 7 additions and 6 deletions

View File

@ -29,10 +29,10 @@ import javax.portlet.PortletContext;
import javax.portlet.PortletException; import javax.portlet.PortletException;
import javax.portlet.PortletRequest; import javax.portlet.PortletRequest;
import javax.portlet.PortletRequestDispatcher; import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletResponse;
import javax.portlet.PortletSession; import javax.portlet.PortletSession;
import javax.portlet.ResourceRequest; import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse; import javax.portlet.ResourceResponse;
import javax.portlet.PortletResponse;
import javax.portlet.filter.PortletRequestWrapper; import javax.portlet.filter.PortletRequestWrapper;
import javax.portlet.filter.PortletResponseWrapper; import javax.portlet.filter.PortletResponseWrapper;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
@ -271,7 +271,7 @@ public abstract class PortletUtils {
*/ */
public static Object getSessionMutex(PortletSession session) { public static Object getSessionMutex(PortletSession session) {
Assert.notNull(session, "Session must not be null"); 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) { if (mutex == null) {
mutex = session; mutex = session;
} }

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.PortletRequest;
import javax.portlet.PortletSession; import javax.portlet.PortletSession;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.ITestBean; 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.mock.web.portlet.MockPortletSession;
import org.springframework.web.util.WebUtils; import org.springframework.web.util.WebUtils;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
/** /**
* @author Rick Evans * @author Rick Evans
* @author Chris Beams * @author Chris Beams
@ -374,7 +375,7 @@ public final class PortletUtilsTests {
public void testGetSessionMutexWithExistingSessionMutexReturnsTheExistingSessionMutex() throws Exception { public void testGetSessionMutexWithExistingSessionMutexReturnsTheExistingSessionMutex() throws Exception {
MockPortletSession session = new MockPortletSession(); MockPortletSession session = new MockPortletSession();
Object expectSessionMutex = new Object(); 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); Object actualSessionMutex = PortletUtils.getSessionMutex(session);
assertNotNull("PortletUtils.getSessionMutex(..) must never return a null mutex", actualSessionMutex); 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", assertSame("PortletUtils.getSessionMutex(..) must return the bound mutex attribute if a mutex has been bound as a Session attribute beforehand",