PLUTO-600 Add method to PortletRequestContext SPI that allows the portal to have complete control over request attribute resolution for portlets and servlets that portlets delegate to
git-svn-id: https://svn.apache.org/repos/asf/portals/pluto/trunk@1053938 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pluto-container-api/src/main/java/org/apache/pluto/container/PortletRequestContext.java b/pluto-container-api/src/main/java/org/apache/pluto/container/PortletRequestContext.java
index 3ba0753..8dd441f 100644
--- a/pluto-container-api/src/main/java/org/apache/pluto/container/PortletRequestContext.java
+++ b/pluto-container-api/src/main/java/org/apache/pluto/container/PortletRequestContext.java
@@ -22,6 +22,7 @@
import javax.portlet.PortletConfig;
import javax.servlet.ServletContext;
+import javax.servlet.ServletRequest;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -45,6 +46,14 @@
Enumeration<String> getAttributeNames();
Object getAttribute(String name);
+ /**
+ * Get the attribute from the request. Generally only called by servlet code that has been dispatched
+ * to by a portlet (such as rendering a JSP).
+ *
+ * @param name attribute name
+ * @param servletRequest The current servlet request
+ */
+ Object getAttribute(String name, ServletRequest servletRequest);
void setAttribute(String name, Object value);
Locale getPreferredLocale();
diff --git a/pluto-container/src/main/java/org/apache/pluto/container/impl/HttpServletPortletRequestWrapper.java b/pluto-container/src/main/java/org/apache/pluto/container/impl/HttpServletPortletRequestWrapper.java
index 0881739..e4baac5 100644
--- a/pluto-container/src/main/java/org/apache/pluto/container/impl/HttpServletPortletRequestWrapper.java
+++ b/pluto-container/src/main/java/org/apache/pluto/container/impl/HttpServletPortletRequestWrapper.java
@@ -42,6 +42,8 @@
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpSession;
+import org.apache.pluto.container.PortletInvokerService;
+import org.apache.pluto.container.PortletRequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -318,6 +320,7 @@
*/
protected Map<String, String[]> parameterMap;
+ protected final PortletRequestContext requestContext;
protected final ServletContext servletContext;
protected final PortletRequest portletRequest;
protected final ClientDataRequest clientDataRequest;
@@ -353,6 +356,7 @@
lifecyclePhase = (String)portletRequest.getAttribute(PortletRequest.LIFECYCLE_PHASE);
clientDataRequest = PortletRequest.ACTION_PHASE.equals(lifecyclePhase) || PortletRequest.RESOURCE_PHASE.equals(lifecyclePhase) ? (ClientDataRequest)portletRequest : null;
renderPhase = PortletRequest.RENDER_PHASE.equals(lifecyclePhase);
+ requestContext = (PortletRequestContext )portletRequest.getAttribute(PortletInvokerService.REQUEST_CONTEXT);
this.forwarded = !included;
this.namedDispatch = namedDispatch;
origParameterMap = new HashMap<String,String[]>(request.getParameterMap());
@@ -1109,7 +1113,7 @@
// except for servlet container injected (managed) attributes which cannot reliably be retrieved from the portletRequest
Object value = servletContainerManagedAttributes.contains(name) ? null : portletRequest.getAttribute(name);
// if null, fall back to retrieve the attribute from the web container itself
- return value != null ? value : getRequest().getAttribute(name);
+ return value != null ? value : requestContext.getAttribute(name, getRequest());
}
@Override
diff --git a/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletRequestImpl.java b/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletRequestImpl.java
index 84d998b..87ff0c0 100644
--- a/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletRequestImpl.java
+++ b/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletRequestImpl.java
@@ -76,10 +76,10 @@
// Private Member Variables ------------------------------------------------
/** The PortalContext within which this request is occuring. */
- private PortalContext portalContext;
+ private final PortalContext portalContext;
- private PortletRequestContext requestContext;
- private PortletResponseContext responseContext;
+ private final PortletRequestContext requestContext;
+ private final PortletResponseContext responseContext;
/** The portlet session. */
private PortletSession portletSession;
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 698d2d4..79ddd97 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
@@ -26,6 +26,7 @@
import javax.portlet.PortletConfig;
import javax.servlet.ServletContext;
+import javax.servlet.ServletRequest;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -119,6 +120,10 @@
Object value = servletRequest.getAttribute(encodeAttributeName(name));
return value != null ? value : servletRequest.getAttribute(name);
}
+
+ public Object getAttribute(String name, ServletRequest servletRequest) {
+ return servletRequest.getAttribute(name);
+ }
@SuppressWarnings("unchecked")
public Enumeration<String> getAttributeNames()