001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.providers.jsp;
006:
007: import java.util.Hashtable;
008: import java.util.Map;
009: import java.util.Set;
010: import java.util.Vector;
011: import java.util.Enumeration;
012: import java.util.Locale;
013:
014: import java.io.BufferedReader;
015: import java.io.IOException;
016: import java.io.UnsupportedEncodingException;
017:
018: import javax.servlet.ServletInputStream;
019: import javax.servlet.RequestDispatcher;
020:
021: import javax.servlet.http.HttpServletRequestWrapper;
022: import javax.servlet.http.HttpServletRequest;
023: import javax.servlet.http.HttpSession;
024: import javax.servlet.http.Cookie;
025:
026: /*
027: * The Request is an internal representation for the request that is
028: * used by the JSP servlet.
029: **/
030:
031: class Request implements HttpServletRequest {
032: private Cookie[] cookies = null;
033: private Map attrs = null;
034: private String requestURI;
035: private HttpSession httpSession;
036: private HttpServletRequest origRequest;
037: private Hashtable parameters;
038: private String pathInfo;
039: private String servletPath;
040: private String contextPath;
041:
042: //mjm Session pssess as second arg
043: public Request(HttpServletRequest req, HttpSession jspsess,
044: Hashtable params, Cookie ca[], Map attributes, String uri) {
045:
046: origRequest = req;
047: //mjm psSession = pssess;
048: httpSession = jspsess;
049: parameters = params;
050: cookies = ca;
051: attrs = attributes;
052: requestURI = uri;
053: pathInfo = req.getPathInfo();
054: servletPath = req.getServletPath();
055: contextPath = req.getContextPath();
056: }
057:
058: public Map getAttributes() {
059: return attrs;
060: }
061:
062: public HttpSession getSession() {
063: return httpSession;
064: }
065:
066: public HttpSession getSession(boolean create) {
067: return httpSession;
068: }
069:
070: public Object getAttribute(String name) {
071: Object o = getAttributes().get(name);
072: if (o != null) {
073: return o;
074: }
075:
076: if (name.equals("javax.servlet.include.servlet_path")) {
077: // Desktop JSP Engine is a sand-box environment with its own file lookup
078: return null;
079: }
080:
081: return origRequest.getAttribute(name);
082: }
083:
084: public void setAttribute(String name, Object value) {
085: getAttributes().put(name, value);
086: }
087:
088: public void removeAttribute(String name) {
089: getAttributes().remove(name);
090: }
091:
092: public Enumeration getAttributeNames() {
093: Vector names = new Vector();
094:
095: for (Enumeration en = origRequest.getAttributeNames(); en
096: .hasMoreElements();) {
097: String key = (String) en.nextElement();
098: names.add(key);
099: }
100:
101: Set this Names = getAttributes().keySet();
102: names.addAll(this Names);
103:
104: return names.elements();
105: }
106:
107: public String getAuthType() {
108: checkRequest();
109: return origRequest.getAuthType();
110: }
111:
112: public String getCharacterEncoding() {
113: checkRequest();
114: return origRequest.getCharacterEncoding();
115: }
116:
117: public int getContentLength() {
118: checkRequest();
119: return origRequest.getContentLength();
120: }
121:
122: public String getContentType() {
123: checkRequest();
124: return origRequest.getContentType();
125: }
126:
127: public Cookie[] getCookies() {
128: return cookies;
129: }
130:
131: public long getDateHeader(String name) {
132: checkRequest();
133: return origRequest.getDateHeader(name);
134: }
135:
136: public String getHeader(String name) {
137: checkRequest();
138: return origRequest.getHeader(name);
139: }
140:
141: public Enumeration getHeaders(String name) {
142: checkRequest();
143: return origRequest.getHeaders(name);
144: }
145:
146: public Enumeration getHeaderNames() {
147: checkRequest();
148: return origRequest.getHeaderNames();
149: }
150:
151: public int getIntHeader(String name) {
152: checkRequest();
153: return origRequest.getIntHeader(name);
154: }
155:
156: public String getMethod() {
157: checkRequest();
158: return origRequest.getMethod();
159: }
160:
161: public String getParameter(String name) {
162: String[] values = getParameterValues(name);
163: if (values != null) {
164: return values[0];
165: } else {
166: return null;
167: }
168: }
169:
170: public String[] getParameterValues(String name) {
171: return (String[]) parameters.get(name);
172: }
173:
174: public Enumeration getParameterNames() {
175: return parameters.keys();
176: }
177:
178: public String getPathInfo() {
179: checkRequest();
180: return pathInfo;
181: }
182:
183: public String getPathTranslated() {
184: checkRequest();
185: return origRequest.getPathTranslated();
186: }
187:
188: public String getProtocol() {
189: checkRequest();
190: return origRequest.getProtocol();
191: }
192:
193: public String getQueryString() {
194: checkRequest();
195: return origRequest.getQueryString();
196: }
197:
198: public String getRemoteUser() {
199: return origRequest.getRemoteUser();
200: //mjm return psSession.getClientID();
201: }
202:
203: public String getScheme() {
204: checkRequest();
205: return origRequest.getScheme();
206: }
207:
208: public String getServerName() {
209: checkRequest();
210: return origRequest.getServerName();
211: }
212:
213: public int getServerPort() {
214: checkRequest();
215: return origRequest.getServerPort();
216: }
217:
218: public String getRemoteAddr() {
219: checkRequest();
220: return origRequest.getRemoteAddr();
221: }
222:
223: public String getRemoteHost() {
224: checkRequest();
225: return origRequest.getRemoteHost();
226: }
227:
228: public ServletInputStream getInputStream() throws IOException {
229: checkRequest();
230: return origRequest.getInputStream();
231: }
232:
233: public BufferedReader getReader() throws IOException {
234: throw new UnsupportedOperationException(
235: "Reader in JSPProvider is not available. Use getParameter method to get parameters.");
236: }
237:
238: public String getRequestedSessionId() {
239: //mjm return psSession.getID().toString();
240: return origRequest.getRequestedSessionId();
241: }
242:
243: public String getRequestURI() {
244: return requestURI;
245: }
246:
247: public RequestDispatcher getRequestDispatcher(String path) {
248: throw new UnsupportedOperationException(
249: "RequestDispatcher is not available to providers");
250: }
251:
252: public boolean isSecure() {
253: checkRequest();
254: return origRequest.isSecure();
255: }
256:
257: public Locale getLocale() {
258: checkRequest();
259: return origRequest.getLocale();
260: }
261:
262: public Enumeration getLocales() {
263: checkRequest();
264: return origRequest.getLocales();
265: }
266:
267: public String getContextPath() {
268: checkRequest();
269: return contextPath;
270: }
271:
272: public boolean isUserInRole(String role) {
273: return origRequest.isUserInRole(role);
274: }
275:
276: public java.security.Principal getUserPrincipal() {
277: return origRequest.getUserPrincipal();
278: }
279:
280: public String getServletPath() {
281: checkRequest();
282: return servletPath;
283: }
284:
285: /**
286: * @deprecated
287: */
288:
289: public String getRealPath(String name) {
290: return name;
291: }
292:
293: public boolean isRequestedSessionIdValid() {
294: return origRequest.isRequestedSessionIdValid();
295: }
296:
297: public boolean isRequestedSessionIdFromCookie() {
298: // yes, this is always true for now as cookies are all we use.
299: return true;
300: }
301:
302: /**
303: * @deprecated
304: */
305: public boolean isRequestedSessionIdFromUrl() {
306: return false;
307: }
308:
309: public boolean isRequestedSessionIdFromURL() {
310: return false;
311: }
312:
313: private void checkRequest() throws UnsupportedOperationException {
314: if (origRequest == null) {
315: throw new UnsupportedOperationException(
316: "Request information unavailable in this mode.");
317:
318: }
319: }
320:
321: /*
322: * Added as part of upgradation to servlet2.3 spec
323: */
324:
325: public StringBuffer getRequestURL() {
326: checkRequest();
327: return origRequest.getRequestURL();
328: }
329:
330: public Map getParameterMap() {
331: checkRequest();
332: return origRequest.getParameterMap();
333: }
334:
335: public void setCharacterEncoding(String env)
336: throws UnsupportedEncodingException {
337: checkRequest();
338: origRequest.setCharacterEncoding(env);
339: }
340:
341: }
|