KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > server > connection > StubServletRequest


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.server.connection;
30
31 import com.caucho.util.NullEnumeration;
32 import com.caucho.vfs.ReadStream;
33
34 import javax.servlet.RequestDispatcher JavaDoc;
35 import javax.servlet.ServletInputStream JavaDoc;
36 import java.io.BufferedReader JavaDoc;
37 import java.util.Collections JavaDoc;
38 import java.util.Enumeration JavaDoc;
39 import java.util.HashMap JavaDoc;
40 import java.util.Locale JavaDoc;
41 import java.util.Map JavaDoc;
42
43 /**
44  * Used when there isn't any actual request object, e.g. for calling
45  * run-at servlets.
46  */

47 public class StubServletRequest extends AbstractHttpRequest {
48   private HashMap JavaDoc _attributes;
49
50   public StubServletRequest()
51   {
52     super(null, null);
53
54     try {
55       start();
56     } catch (Throwable JavaDoc e) {
57     }
58   }
59   
60   public Object JavaDoc getAttribute(String JavaDoc name)
61   {
62     if (_attributes != null)
63       return _attributes.get(name);
64     else
65       return null;
66   }
67   
68   public Enumeration<String JavaDoc> getAttributeNames()
69   {
70     if (_attributes != null)
71       return Collections.enumeration(_attributes.keySet());
72     else
73       return (Enumeration) NullEnumeration.create();
74   }
75   
76   public void setAttribute(String JavaDoc name, Object JavaDoc value)
77   {
78     if (_attributes == null)
79       _attributes = new HashMap JavaDoc();
80
81     _attributes.put(name, value);
82   }
83   
84   public void removeAttribute(String JavaDoc name)
85   {
86     if (_attributes != null)
87       _attributes.remove(name);
88   }
89     
90   public boolean initStream(ReadStream rawStream, ReadStream realStream)
91   {
92     return false;
93   }
94   
95   public String JavaDoc getCharacterEncoding() { return "UTF-8"; }
96   public void setCharacterEncoding(String JavaDoc encoding) { }
97   public int getContentLength() { return -1; }
98   public String JavaDoc getContentType() { return "application/octet-stream"; }
99   public ServletInputStream JavaDoc getInputStream()
100   {
101     throw new IllegalStateException JavaDoc();
102   }
103   public String JavaDoc getParameter(String JavaDoc name) { return null; }
104   public Enumeration<String JavaDoc> getParameterNames()
105   {
106     return (Enumeration) NullEnumeration.create();
107   }
108   public String JavaDoc []getParameterValues(String JavaDoc name) { return null; }
109   public Map JavaDoc<String JavaDoc,String JavaDoc[]> getParameterMap() { return null; }
110   public String JavaDoc getProtocol() { return "none"; }
111   
112   public BufferedReader JavaDoc getReader()
113   {
114     throw new IllegalStateException JavaDoc();
115   }
116   public String JavaDoc getRemoteAddr() { return "127.0.0.1"; }
117   public String JavaDoc getRemoteHost() { return "127.0.0.1"; }
118   public String JavaDoc getScheme() { return "cron"; }
119   public String JavaDoc getServerName() { return "127.0.0.1"; }
120   public int getServerPort() { return 0; }
121     
122   public String JavaDoc getRealPath(String JavaDoc path) { return null; }
123   public Locale JavaDoc getLocale() { return null; }
124   public Enumeration<Locale JavaDoc> getLocales()
125   { return (Enumeration) NullEnumeration.create(); }
126   public boolean isSecure() { return true; }
127   public RequestDispatcher JavaDoc getRequestDispatcher(String JavaDoc uri) { return null; }
128
129   public String JavaDoc getMethod() { return "GET"; }
130   public String JavaDoc getServletPath() { return null; }
131   public String JavaDoc getContextPath() { return null; }
132   public String JavaDoc getPathInfo() { return null; }
133   public String JavaDoc getPathTranslated() { return null; }
134   public String JavaDoc getRequestURI () { return null; }
135   public StringBuffer JavaDoc getRequestURL ()
136   {
137     return new StringBuffer JavaDoc("http://localhost");
138   }
139   public int getUriLength() { return 0; }
140   public byte []getUriBuffer() { return null; }
141   
142   public String JavaDoc getQueryString() { return null; }
143
144   public String JavaDoc getHeader(String JavaDoc header) { return null; }
145   public int getIntHeader(String JavaDoc header) { return 0; }
146   public long getDateHeader(String JavaDoc header) { return 0; }
147   public Enumeration getHeaders(String JavaDoc header) { return null; }
148   public Enumeration getHeaderNames() { return null; }
149
150   public String JavaDoc getAuthType() { return null; }
151   public String JavaDoc getRemoteUser() { return null; }
152   public java.security.Principal JavaDoc getUserPrincipal() { return null; }
153
154   public boolean isUserInRole(String JavaDoc str) { return false; }
155 }
156   
157
Popular Tags