001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.server.connection;
030:
031: import com.caucho.util.NullEnumeration;
032: import com.caucho.vfs.ReadStream;
033:
034: import javax.servlet.RequestDispatcher;
035: import javax.servlet.ServletInputStream;
036: import java.io.BufferedReader;
037: import java.util.Collections;
038: import java.util.Enumeration;
039: import java.util.HashMap;
040: import java.util.Locale;
041: import java.util.Map;
042:
043: /**
044: * Used when there isn't any actual request object, e.g. for calling
045: * run-at servlets.
046: */
047: public class StubServletRequest extends AbstractHttpRequest {
048: private HashMap _attributes;
049:
050: public StubServletRequest() {
051: super (null, null);
052:
053: try {
054: start();
055: } catch (Throwable e) {
056: }
057: }
058:
059: public Object getAttribute(String name) {
060: if (_attributes != null)
061: return _attributes.get(name);
062: else
063: return null;
064: }
065:
066: public Enumeration<String> getAttributeNames() {
067: if (_attributes != null)
068: return Collections.enumeration(_attributes.keySet());
069: else
070: return (Enumeration) NullEnumeration.create();
071: }
072:
073: public void setAttribute(String name, Object value) {
074: if (_attributes == null)
075: _attributes = new HashMap();
076:
077: _attributes.put(name, value);
078: }
079:
080: public void removeAttribute(String name) {
081: if (_attributes != null)
082: _attributes.remove(name);
083: }
084:
085: public boolean initStream(ReadStream rawStream,
086: ReadStream realStream) {
087: return false;
088: }
089:
090: public String getCharacterEncoding() {
091: return "UTF-8";
092: }
093:
094: public void setCharacterEncoding(String encoding) {
095: }
096:
097: public int getContentLength() {
098: return -1;
099: }
100:
101: public String getContentType() {
102: return "application/octet-stream";
103: }
104:
105: public ServletInputStream getInputStream() {
106: throw new IllegalStateException();
107: }
108:
109: public String getParameter(String name) {
110: return null;
111: }
112:
113: public Enumeration<String> getParameterNames() {
114: return (Enumeration) NullEnumeration.create();
115: }
116:
117: public String[] getParameterValues(String name) {
118: return null;
119: }
120:
121: public Map<String, String[]> getParameterMap() {
122: return null;
123: }
124:
125: public String getProtocol() {
126: return "none";
127: }
128:
129: public BufferedReader getReader() {
130: throw new IllegalStateException();
131: }
132:
133: public String getRemoteAddr() {
134: return "127.0.0.1";
135: }
136:
137: public String getRemoteHost() {
138: return "127.0.0.1";
139: }
140:
141: public String getScheme() {
142: return "cron";
143: }
144:
145: public String getServerName() {
146: return "127.0.0.1";
147: }
148:
149: public int getServerPort() {
150: return 0;
151: }
152:
153: public String getRealPath(String path) {
154: return null;
155: }
156:
157: public Locale getLocale() {
158: return null;
159: }
160:
161: public Enumeration<Locale> getLocales() {
162: return (Enumeration) NullEnumeration.create();
163: }
164:
165: public boolean isSecure() {
166: return true;
167: }
168:
169: public RequestDispatcher getRequestDispatcher(String uri) {
170: return null;
171: }
172:
173: public String getMethod() {
174: return "GET";
175: }
176:
177: public String getServletPath() {
178: return null;
179: }
180:
181: public String getContextPath() {
182: return null;
183: }
184:
185: public String getPathInfo() {
186: return null;
187: }
188:
189: public String getPathTranslated() {
190: return null;
191: }
192:
193: public String getRequestURI() {
194: return null;
195: }
196:
197: public StringBuffer getRequestURL() {
198: return new StringBuffer("http://localhost");
199: }
200:
201: public int getUriLength() {
202: return 0;
203: }
204:
205: public byte[] getUriBuffer() {
206: return null;
207: }
208:
209: public String getQueryString() {
210: return null;
211: }
212:
213: public String getHeader(String header) {
214: return null;
215: }
216:
217: public int getIntHeader(String header) {
218: return 0;
219: }
220:
221: public long getDateHeader(String header) {
222: return 0;
223: }
224:
225: public Enumeration getHeaders(String header) {
226: return null;
227: }
228:
229: public Enumeration getHeaderNames() {
230: return null;
231: }
232:
233: public String getAuthType() {
234: return null;
235: }
236:
237: public String getRemoteUser() {
238: return null;
239: }
240:
241: public java.security.Principal getUserPrincipal() {
242: return null;
243: }
244:
245: public boolean isUserInRole(String str) {
246: return false;
247: }
248: }
|