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