001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.granite.gravity.tomcat;
018
019 import java.io.BufferedReader;
020 import java.io.IOException;
021 import java.io.UnsupportedEncodingException;
022 import java.security.Principal;
023 import java.util.Collection;
024 import java.util.Enumeration;
025 import java.util.Locale;
026 import java.util.Map;
027
028 import javax.servlet.AsyncContext;
029 import javax.servlet.DispatcherType;
030 import javax.servlet.RequestDispatcher;
031 import javax.servlet.ServletContext;
032 import javax.servlet.ServletException;
033 import javax.servlet.ServletInputStream;
034 import javax.servlet.ServletRequest;
035 import javax.servlet.ServletResponse;
036 import javax.servlet.http.Cookie;
037 import javax.servlet.http.HttpServletRequest;
038 import javax.servlet.http.HttpServletResponse;
039 import javax.servlet.http.HttpSession;
040 import javax.servlet.http.Part;
041
042 import org.apache.catalina.websocket.Constants;
043 import org.apache.tomcat.util.res.StringManager;
044
045 /**
046 * Wrapper for the HttpServletRequest object that allows the underlying request
047 * object to be invalidated.
048 */
049 public class WsHttpServletRequestWrapper implements HttpServletRequest {
050
051 private static final StringManager sm = StringManager.getManager(Constants.Package);
052
053 private HttpServletRequest request;
054
055 public WsHttpServletRequestWrapper(HttpServletRequest request) {
056 this.request = request;
057 }
058
059 private HttpServletRequest getRequest() {
060 if (request == null) {
061 throw new IllegalStateException(sm.getString("wrapper.invalid"));
062 }
063 return request;
064 }
065
066 protected void invalidate() {
067 request = null;
068 }
069
070 public Object getAttribute(String name) {
071 return getRequest().getAttribute(name);
072 }
073
074 public Enumeration<String> getAttributeNames() {
075 return getRequest().getAttributeNames();
076 }
077
078 public String getCharacterEncoding() {
079 return getRequest().getCharacterEncoding();
080 }
081
082 public void setCharacterEncoding(String env)
083 throws UnsupportedEncodingException {
084 getRequest().setCharacterEncoding(env);
085 }
086
087 public int getContentLength() {
088 return getRequest().getContentLength();
089 }
090
091 public String getContentType() {
092 return getRequest().getContentType();
093 }
094
095 public ServletInputStream getInputStream() throws IOException {
096 return getRequest().getInputStream();
097 }
098
099 public String getParameter(String name) {
100 return getRequest().getParameter(name);
101 }
102
103 public Enumeration<String> getParameterNames() {
104 return getRequest().getParameterNames();
105 }
106
107 public String[] getParameterValues(String name) {
108 return getRequest().getParameterValues(name);
109 }
110
111 public Map<String, String[]> getParameterMap() {
112 return getRequest().getParameterMap();
113 }
114
115 public String getProtocol() {
116 return getRequest().getProtocol();
117 }
118
119 public String getScheme() {
120 return getRequest().getScheme();
121 }
122
123 public String getServerName() {
124 return getRequest().getServerName();
125 }
126
127 public int getServerPort() {
128 return getRequest().getServerPort();
129 }
130
131 public BufferedReader getReader() throws IOException {
132 return getRequest().getReader();
133 }
134
135 public String getRemoteAddr() {
136 return getRequest().getRemoteAddr();
137 }
138
139 public String getRemoteHost() {
140 return getRequest().getRemoteHost();
141 }
142
143 public void setAttribute(String name, Object o) {
144 getRequest().setAttribute(name, o);
145 }
146
147 public void removeAttribute(String name) {
148 getRequest().removeAttribute(name);
149 }
150
151 public Locale getLocale() {
152 return getRequest().getLocale();
153 }
154
155 public Enumeration<Locale> getLocales() {
156 return getRequest().getLocales();
157 }
158
159 public boolean isSecure() {
160 return getRequest().isSecure();
161 }
162
163 public RequestDispatcher getRequestDispatcher(String path) {
164 return getRequest().getRequestDispatcher(path);
165 }
166
167 @Deprecated
168 public String getRealPath(String path) {
169 return getRequest().getRealPath(path);
170 }
171
172 public int getRemotePort() {
173 return getRequest().getRemotePort();
174 }
175
176 public String getLocalName() {
177 return getRequest().getLocalName();
178 }
179
180 public String getLocalAddr() {
181 return getRequest().getLocalAddr();
182 }
183
184 public int getLocalPort() {
185 return getRequest().getLocalPort();
186 }
187
188 public ServletContext getServletContext() {
189 return getRequest().getServletContext();
190 }
191
192 public AsyncContext startAsync() throws IllegalStateException {
193 return getRequest().startAsync();
194 }
195
196 public AsyncContext startAsync(ServletRequest servletRequest,
197 ServletResponse servletResponse) throws IllegalStateException {
198 return getRequest().startAsync(servletRequest, servletResponse);
199 }
200
201 public boolean isAsyncStarted() {
202 return getRequest().isAsyncStarted();
203 }
204
205 public boolean isAsyncSupported() {
206 return getRequest().isAsyncSupported();
207 }
208
209 public AsyncContext getAsyncContext() {
210 return getRequest().getAsyncContext();
211 }
212
213 public DispatcherType getDispatcherType() {
214 return getRequest().getDispatcherType();
215 }
216
217 public String getAuthType() {
218 return getRequest().getAuthType();
219 }
220
221 public Cookie[] getCookies() {
222 return getRequest().getCookies();
223 }
224
225 public long getDateHeader(String name) {
226 return getRequest().getDateHeader(name);
227 }
228
229 public String getHeader(String name) {
230 return getRequest().getHeader(name);
231 }
232
233 public Enumeration<String> getHeaders(String name) {
234 return getRequest().getHeaders(name);
235 }
236
237 public Enumeration<String> getHeaderNames() {
238 return getRequest().getHeaderNames();
239 }
240
241 public int getIntHeader(String name) {
242 return getRequest().getIntHeader(name);
243 }
244
245 public String getMethod() {
246 return getRequest().getMethod();
247 }
248
249 public String getPathInfo() {
250 return getRequest().getPathInfo();
251 }
252
253 public String getPathTranslated() {
254 return getRequest().getPathTranslated();
255 }
256
257 public String getContextPath() {
258 return getRequest().getContextPath();
259 }
260
261 public String getQueryString() {
262 return getRequest().getQueryString();
263 }
264
265 public String getRemoteUser() {
266 return getRequest().getRemoteUser();
267 }
268
269 public boolean isUserInRole(String role) {
270 return getRequest().isUserInRole(role);
271 }
272
273 public Principal getUserPrincipal() {
274 return getRequest().getUserPrincipal();
275 }
276
277 public String getRequestedSessionId() {
278 return getRequest().getRequestedSessionId();
279 }
280
281 public String getRequestURI() {
282 return getRequest().getRequestURI();
283 }
284
285 public StringBuffer getRequestURL() {
286 return getRequest().getRequestURL();
287 }
288
289 public String getServletPath() {
290 return getRequest().getServletPath();
291 }
292
293 public HttpSession getSession(boolean create) {
294 return getRequest().getSession(create);
295 }
296
297 public HttpSession getSession() {
298 return getRequest().getSession();
299 }
300
301 public boolean isRequestedSessionIdValid() {
302 return getRequest().isRequestedSessionIdValid();
303 }
304
305 public boolean isRequestedSessionIdFromCookie() {
306 return getRequest().isRequestedSessionIdFromCookie();
307 }
308
309 public boolean isRequestedSessionIdFromURL() {
310 return getRequest().isRequestedSessionIdFromURL();
311 }
312
313 @Deprecated
314 public boolean isRequestedSessionIdFromUrl() {
315 return getRequest().isRequestedSessionIdFromUrl();
316 }
317
318 public boolean authenticate(HttpServletResponse response)
319 throws IOException, ServletException {
320 return getRequest().authenticate(response);
321 }
322
323 public void login(String username, String password) throws ServletException {
324 getRequest().login(username, password);
325 }
326
327 public void logout() throws ServletException {
328 getRequest().logout();
329 }
330
331 public Collection<Part> getParts() throws IOException, ServletException {
332 return getRequest().getParts();
333 }
334
335 public Part getPart(String name) throws IOException, ServletException {
336 return getRequest().getPart(name);
337 }
338 }