FacesRequestAttributes (as used by RequestContextHolder) can access global Portlet session (SPR-5637)
This commit is contained in:
parent
e93bf49268
commit
2524ca33d5
|
|
@ -22,6 +22,7 @@
|
|||
<classpathentry kind="var" path="IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.httpclient/3.1.0/com.springsource.org.apache.commons.httpclient-3.1.0.jar" sourcepath="/IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.httpclient/3.1.0/com.springsource.org.apache.commons.httpclient-sources-3.1.0.jar"/>
|
||||
<classpathentry kind="var" path="IVY_CACHE/javax.servlet/com.springsource.javax.servlet/2.5.0/com.springsource.javax.servlet-2.5.0.jar" sourcepath="/IVY_CACHE/javax.servlet/com.springsource.javax.servlet/2.5.0/com.springsource.javax.servlet-sources-2.5.0.jar"/>
|
||||
<classpathentry kind="var" path="IVY_CACHE/javax.faces/com.springsource.javax.faces/1.2.0.08/com.springsource.javax.faces-1.2.0.08.jar" sourcepath="/IVY_CACHE/javax.faces/com.springsource.javax.faces/1.2.0.08/com.springsource.javax.faces-sources-1.2.0.08.jar"/>
|
||||
<classpathentry kind="var" path="IVY_CACHE/javax.portlet/com.springsource.javax.portlet/2.0.0/com.springsource.javax.portlet-2.0.0.jar"/>
|
||||
<classpathentry kind="var" path="IVY_CACHE/org.easymock/com.springsource.org.easymock/2.3.0/com.springsource.org.easymock-2.3.0.jar" sourcepath="/IVY_CACHE/org.easymock/com.springsource.org.easymock/2.3.0/com.springsource.org.easymock-sources-2.3.0.jar"/>
|
||||
<classpathentry kind="var" path="IVY_CACHE/javax.xml.soap/com.springsource.javax.xml.soap/1.3.0/com.springsource.javax.xml.soap-1.3.0.jar" sourcepath="/IVY_CACHE/javax.xml.soap/com.springsource.javax.xml.soap/1.3.0/com.springsource.javax.xml.soap-sources-1.3.0.jar"/>
|
||||
<classpathentry kind="var" path="IVY_CACHE/org.mortbay.jetty/com.springsource.org.mortbay.jetty.server/6.1.9/com.springsource.org.mortbay.jetty.server-6.1.9.jar" sourcepath="/IVY_CACHE/org.mortbay.jetty/com.springsource.org.mortbay.jetty.server/6.1.9/com.springsource.org.mortbay.jetty.server-sources-6.1.9.jar"/>
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@
|
|||
<dependency org="javax.el" name="com.springsource.javax.el" rev="1.0.0" conf="provided, el->compile"/>
|
||||
<dependency org="javax.faces" name="com.springsource.javax.faces" rev="1.2.0.08"
|
||||
conf="provided, faces->compile"/>
|
||||
<dependency org="javax.portlet" name="com.springsource.javax.portlet" rev="2.0.0" conf="provided->compile"/>
|
||||
<dependency org="javax.servlet" name="com.springsource.javax.servlet" rev="2.5.0" conf="provided->compile"/>
|
||||
<dependency org="javax.servlet" name="com.springsource.javax.servlet.jsp" rev="2.1.0"
|
||||
conf="provided, jsp->compile"/>
|
||||
|
|
|
|||
|
|
@ -35,6 +35,12 @@
|
|||
<version>1.2_08</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.portlet</groupId>
|
||||
<artifactId>portlet-api</artifactId>
|
||||
<version>2.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
|
|
@ -45,7 +51,7 @@
|
|||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>jsp-api</artifactId>
|
||||
<version>2.1</version>
|
||||
<optional>provided</optional>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.xml</groupId>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 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.
|
||||
|
|
@ -20,11 +20,13 @@ import java.lang.reflect.Method;
|
|||
import java.util.Map;
|
||||
import javax.faces.context.ExternalContext;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.portlet.PortletSession;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.util.WebUtils;
|
||||
|
|
@ -48,6 +50,9 @@ import org.springframework.web.util.WebUtils;
|
|||
*/
|
||||
public class FacesRequestAttributes implements RequestAttributes {
|
||||
|
||||
private static final boolean portletApiPresent =
|
||||
ClassUtils.isPresent("javax.portlet.PortletSession", FacesRequestAttributes.class.getClassLoader());
|
||||
|
||||
/**
|
||||
* We'll create a lot of these objects, so we don't want a new logger every time.
|
||||
*/
|
||||
|
|
@ -93,6 +98,9 @@ public class FacesRequestAttributes implements RequestAttributes {
|
|||
if (scope == SCOPE_REQUEST) {
|
||||
return getExternalContext().getRequestMap();
|
||||
}
|
||||
else if (scope == SCOPE_GLOBAL_SESSION && portletApiPresent) {
|
||||
return PortletSessionAccessor.getGlobalSessionMapIfPossible(getExternalContext());
|
||||
}
|
||||
else {
|
||||
return getExternalContext().getSessionMap();
|
||||
}
|
||||
|
|
@ -193,4 +201,21 @@ public class FacesRequestAttributes implements RequestAttributes {
|
|||
return mutex;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class to avoid hard-coded Portlet API dependency.
|
||||
*/
|
||||
private static class PortletSessionAccessor {
|
||||
|
||||
public static Map<String, Object> getGlobalSessionMapIfPossible(ExternalContext externalContext) {
|
||||
Object session = externalContext.getSession(true);
|
||||
if (session instanceof PortletSession) {
|
||||
return ((PortletSession) session).getAttributeMap(PortletSession.APPLICATION_SCOPE);
|
||||
}
|
||||
else {
|
||||
return externalContext.getSessionMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ Import-Template:
|
|||
javax.el.*;version="[1.0.0, 2.0.0)";resolution:=optional,
|
||||
javax.faces.*;version="[1.1.0, 3.0.0)";resolution:=optional,
|
||||
javax.jws.*;resolution:=optional,
|
||||
javax.portlet.*;version="[2.0.0, 3.0.0)";resolution:=optional,
|
||||
javax.servlet;version="[2.4.0, 4.0.0)",
|
||||
javax.servlet.http;version="[2.4.0, 4.0.0)",
|
||||
javax.servlet.jsp.*;version="[2.0.0, 3.0.0)";resolution:=optional,
|
||||
|
|
|
|||
|
|
@ -146,6 +146,17 @@
|
|||
</SOURCES>
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$IVY_CACHE$/javax.portlet/com.springsource.javax.portlet/2.0.0/com.springsource.javax.portlet-2.0.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$IVY_CACHE$/javax.portlet/com.springsource.javax.portlet/2.0.0/com.springsource.javax.portlet-sources-2.0.0.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
|
|
|
|||
Loading…
Reference in New Issue