01: /*
02: * Copyright 2002 Sun Microsystems, Inc. All
03: * rights reserved. Use of this product is subject
04: * to license terms. Federal Acquisitions:
05: * Commercial Software -- Government Users
06: * Subject to Standard License Terms and
07: * Conditions.
08: *
09: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
10: * are trademarks or registered trademarks of Sun Microsystems,
11: * Inc. in the United States and other countries.
12: */
13:
14: package com.sun.portal.container.portlet.impl;
15:
16: import javax.servlet.http.HttpServletRequest;
17: import javax.servlet.http.HttpServletRequestWrapper;
18:
19: import com.sun.portal.portletcontainercommon.PortletContainerRequest;
20: import com.sun.portal.portletcontainercommon.PortletContainerResponse;
21:
22: /**
23: * The <code>PAERequestWrapper</code> is for wrapper the original
24: * HttpServletRequest before passing it to the RequestDispatcher.include().
25: * A wrapper is needed because the <code>PortletContainer</code> and the
26: * PortletApplicationEngine communicate with each other by setting the
27: * <code>PortletContainerRequest</code> and <code>PortletContainerResponse</code>
28: * to the request atributes. Without a wrapper, this mechanism for
29: * communicating does not work under multi-threaded environment since
30: * each RequestDispatcher.include() call overwrites the attributes of the
31: * previous call. This wrapper only wraps the <code>getAttribute()</code>
32: * and <code>setAttribute()</code> methods.
33: **/
34: public class PAERequestWrapper extends HttpServletRequestWrapper {
35:
36: private Object portletContainerRequest;
37: private Object portletContainerResponse;
38: private HttpServletRequest request;
39:
40: public PAERequestWrapper(HttpServletRequest req) {
41: super (req);
42: request = req;
43: }
44:
45: public Object getAttribute(String name) {
46: if (name
47: .equals(PortletContainerRequest.PORTLET_CONTAINER_REQUEST)) {
48: return portletContainerRequest;
49: } else if (name
50: .equals(PortletContainerResponse.PORTLET_CONTAINER_RESPONSE)) {
51: return portletContainerResponse;
52: } else {
53: return super .getAttribute(name);
54: }
55: }
56:
57: public void setAttribute(String name, Object o) {
58: if (name
59: .equals(PortletContainerRequest.PORTLET_CONTAINER_REQUEST)) {
60: portletContainerRequest = o;
61: } else if (name
62: .equals(PortletContainerResponse.PORTLET_CONTAINER_RESPONSE)) {
63: portletContainerResponse = o;
64: } else {
65: super.setAttribute(name, o);
66: }
67: }
68: }
|