001: /*
002: * DummyHTTPServletRequest.java
003: *
004: * Created on January 8, 2003, 3:43 PM
005: */
006:
007: package com.sun.portal.rproxy.configservlet;
008:
009: import java.util.ArrayList;
010: import java.util.Enumeration;
011: import java.util.Iterator;
012: import java.util.List;
013: import java.util.NoSuchElementException;
014: import java.util.StringTokenizer;
015: import java.util.Vector;
016:
017: import javax.servlet.RequestDispatcher;
018: import javax.servlet.ServletInputStream;
019: import javax.servlet.http.Cookie;
020: import javax.servlet.http.HttpServletRequest;
021: import javax.servlet.http.HttpSession;
022:
023: /**
024: *
025: * @author mm132998
026: * @version
027: */
028: public class DummyHTTPServletRequest implements HttpServletRequest {
029:
030: private String _crlf = new String(new byte[] { 13, 10 });
031:
032: private char lf = '\n';
033:
034: public String getAuthType() {
035: // return null;
036: throw new UnsupportedOperationException(
037: "getAuthType() not supported");
038: }
039:
040: public String getContextPath() {
041: // return null;
042: throw new UnsupportedOperationException(
043: "getContextPath() not supported");
044: }
045:
046: public Cookie[] getCookies() {
047: return null;
048: // throw new UnsupportedOperationException("getCookies() not
049: // supported");
050: }
051:
052: public long getDateHeader(String name) {
053: // return null;
054: throw new UnsupportedOperationException(
055: "getDateHeader() not supported");
056: }
057:
058: public String getHeader(String header) {
059: String s;
060: int headerLen = header.length();
061: int numHeaders = _headerLines.size();
062: for (int i = 0; i < numHeaders; ++i) {
063: s = (String) _headerLines.get(i);
064: if (s.regionMatches(true, 0, header, 0, headerLen)) {
065: return s;
066: }
067: }
068: return null;
069: }
070:
071: public Enumeration getHeaderNames() {
072: String s;
073: Vector headers = new Vector();
074: int headerOffset;
075: int numHeaders = _headerLines.size();
076: for (int i = 0; i < numHeaders; ++i) {
077: s = (String) _headerLines.get(i);
078: headerOffset = s.indexOf(':');
079: headers.add(headerOffset == -1 ? s : s.substring(0,
080: headerOffset).trim());
081: }
082: return headers.elements();
083: }
084:
085: public Enumeration getHeaders(String header) {
086: String s;
087: Vector headers = new Vector();
088: int headerLen = header.length();
089: int headerOffset;
090: int numHeaders = _headerLines.size();
091: for (int i = 0; i < numHeaders; ++i) {
092: s = (String) _headerLines.get(i);
093: if (s.regionMatches(true, 0, header, 0, headerLen)) {
094: headerOffset = s.indexOf(':');
095: headers.add(headerOffset == -1 ? s : s.substring(0,
096: headerOffset).trim());
097: }
098: }
099: return headers.elements();
100: }
101:
102: public int getIntHeader(String name) {
103: // return null;
104: throw new UnsupportedOperationException(
105: "getIntHeader() not supported");
106: }
107:
108: public String getMethod() {
109: // return null;
110: throw new UnsupportedOperationException(
111: "getMethod() not supported");
112: }
113:
114: public String getPathInfo() {
115: // return null;
116: throw new UnsupportedOperationException(
117: "getPathInfo() not supported");
118: }
119:
120: public String getPathTranslated() {
121: // return null;
122: throw new UnsupportedOperationException(
123: "getPathTranslated() not supported");
124: }
125:
126: public String getQueryString() {
127: // return null;
128: throw new UnsupportedOperationException(
129: "getQueryString() not supported");
130: }
131:
132: public String getRemoteUser() {
133: // return null;
134: throw new UnsupportedOperationException(
135: "getRemoteUser() not supported");
136: }
137:
138: public String getRequestedSessionId() {
139: // return null;
140: throw new UnsupportedOperationException(
141: "getRequestedSessionId() not supported");
142: }
143:
144: public String getRequestURI() {
145: // return null;
146: return _path;
147: }
148:
149: public String getServletPath() {
150: // return null;
151: throw new UnsupportedOperationException(
152: "getServletPath() not supported");
153: }
154:
155: public HttpSession getSession() {
156: // return null;
157: throw new UnsupportedOperationException(
158: "getSession() not supported");
159: }
160:
161: public HttpSession getSession(boolean create) {
162: // return null;
163: throw new UnsupportedOperationException(
164: "getSession() not supported");
165: }
166:
167: public java.security.Principal getUserPrincipal() {
168: // return null;
169: throw new UnsupportedOperationException(
170: "getUserPrincipal() not supported");
171: }
172:
173: public boolean isRequestedSessionIdFromCookie() {
174: // return null;
175: throw new UnsupportedOperationException(
176: "isRequestedSessionIdFromCookie() not supported");
177: }
178:
179: public boolean isRequestedSessionIdFromUrl() {
180: // return null;
181: throw new UnsupportedOperationException(
182: "isRequestedSessionIdFromUrl() not supported");
183: }
184:
185: public boolean isRequestedSessionIdFromURL() {
186: // return null;
187: throw new UnsupportedOperationException(
188: "isRequestedSessionIdFromURL() not supported");
189: }
190:
191: public boolean isRequestedSessionIdValid() {
192: // return null;
193: throw new UnsupportedOperationException(
194: "isRequestedSessionIdValid() not supported");
195: }
196:
197: public boolean isUserInRole(String role) {
198: // return null;
199: throw new UnsupportedOperationException(
200: "isUserInRole() not supported");
201: }
202:
203: public Object getAttribute(String name) {
204: return null;
205: }
206:
207: public Enumeration getAttributeNames() {
208: return null;
209: }
210:
211: public String getCharacterEncoding() {
212: return null;
213: }
214:
215: public int getContentLength() {
216: return 0;
217: }
218:
219: public ServletInputStream getInputStream() {
220: // return null;
221: throw new UnsupportedOperationException(
222: "getInputStream() not supported");
223: }
224:
225: public java.util.Locale getLocale() {
226: return null;
227: }
228:
229: public Enumeration getLocales() {
230: return new Vector().elements();
231: }
232:
233: public String getParameter(String name) {
234: return null;
235: }
236:
237: public Enumeration getParameterNames() {
238: return new Vector().elements();
239: }
240:
241: public String[] getParameterValues(String name) {
242: return null;
243: }
244:
245: public String getProtocol() {
246: return _httpVersion;
247: }
248:
249: public java.io.BufferedReader getReader() {
250: return null;
251: }
252:
253: public String getRealPath(String path) {
254: return null;
255: }
256:
257: public String getRemoteAddr() {
258: return null;
259: }
260:
261: public String getRemoteHost() {
262: return null;
263: }
264:
265: public RequestDispatcher getRequestDispatcher(String path) {
266: return null;
267: }
268:
269: public String getScheme() {
270: return null;
271: }
272:
273: public String getServerName() {
274: return null;
275: }
276:
277: public int getServerPort() {
278: return -1;
279: }
280:
281: public boolean isSecure() {
282: throw new UnsupportedOperationException(
283: "isSecure() not supported");
284: }
285:
286: public String getContentType() {
287: return null;
288: }
289:
290: public void removeAttribute(String name) {
291: }
292:
293: public void setAttribute(String name, Object value) {
294: }
295:
296: private boolean _firstLine = true;
297:
298: private boolean _headerComplete = false;
299:
300: private List _headerLines = new ArrayList();
301:
302: private String _httpVersion = "";
303:
304: private String _method = null;
305:
306: private String _path = "";
307:
308: public void addHeaderLine(String s) {
309: if (_firstLine) {
310:
311: if (s.equals(_crlf)) {
312: return;
313: }
314:
315: int strLength = s.length();
316: if (strLength > 0 && s.charAt(strLength - 1) == lf) {
317: if (!s.endsWith(_crlf)) {
318: s = s.substring(0, strLength - 1) + _crlf;
319: }
320:
321: if (s.startsWith(_crlf)) {
322: s = s.substring(2);
323: } else if (s.charAt(0) == lf) {
324: s = s.substring(1);
325: }
326: if (s.equals(_crlf)) {
327: return;
328: }
329: _firstLine = false;
330: StringTokenizer st = new StringTokenizer(s);
331: _method = st.nextToken();
332: _path = st.nextToken();
333:
334: try {
335: _httpVersion = st.nextToken();
336: } catch (NoSuchElementException ex) {
337: _httpVersion = "HTTP/0.9";
338: _headerComplete = true;
339: }
340: }
341: } else {
342:
343: int strLength = s.length();
344: if (!s.endsWith(_crlf) && strLength > 0) {
345: s = s.substring(0, strLength - 1) + _crlf;
346: }
347:
348: if (s.equals(_crlf)) {
349: _headerComplete = true;
350: } else {
351: _headerLines.add(s);
352: }
353: }
354: }
355:
356: public String toString() {
357: StringBuffer sb = new StringBuffer();
358: Iterator iter = _headerLines.iterator();
359:
360: sb.append(_method).append(" ").append(_path).append(" ")
361: .append(_httpVersion).append("\r\n");
362: while (iter.hasNext()) {
363: sb.append(iter.next().toString());
364: }
365: return sb.toString();
366: }
367: }
|