-
Notifications
You must be signed in to change notification settings - Fork 23
/
BlockCallHttpServletRequest.java
538 lines (457 loc) · 14.9 KB
/
BlockCallHttpServletRequest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cocoon.blocks.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.security.Principal;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletInputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionContext;
/**
* Create a HttpServletRequest from an URL, that is used while calling e.g. a block.
*
* @version $Id$
*/
public class BlockCallHttpServletRequest implements HttpServletRequest{
private URI uri;
private Hashtable attributes = new Hashtable();
private RequestParameters parameters;
private String encoding;
public BlockCallHttpServletRequest(URI uri) {
this.uri = uri;
this.parameters = new RequestParameters(this.uri.getQuery());
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequestWrapper#getAttribute(java.lang.String)
*/
public Object getAttribute(String name) {
return this.attributes.get(name);
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequestWrapper#getAttributeNames()
*/
public Enumeration getAttributeNames() {
return this.attributes.keys();
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequest#getAuthType()
*/
public String getAuthType() {
return null;
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getCharacterEncoding()
*/
public String getCharacterEncoding() {
return this.encoding;
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getContentLength()
*/
public int getContentLength() {
// TODO Doesn't handle input streams yet
return -1;
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getContentType()
*/
public String getContentType() {
// TODO Doesn't handle input streams yet
return null;
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequestWrapper#getContextPath()
*/
public String getContextPath() {
return "";
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequest#getCookies()
*/
public Cookie[] getCookies() {
return null;
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequest#getDateHeader(java.lang.String)
*/
public long getDateHeader(String name) {
return -1;
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequest#getHeader(java.lang.String)
*/
public String getHeader(String name) {
return null;
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequest#getHeaderNames()
*/
public Enumeration getHeaderNames() {
return null;
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String)
*/
public Enumeration getHeaders(String name) {
return null;
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getInputStream()
*/
public ServletInputStream getInputStream() throws IOException {
// TODO Doesn't handle input streams yet
throw new UnsupportedOperationException();
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequest#getIntHeader(java.lang.String)
*/
public int getIntHeader(String name) {
return -1;
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getLocale()
*/
public Locale getLocale() {
// TODO Implement this
throw new UnsupportedOperationException();
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getLocales()
*/
public Enumeration getLocales() {
// TODO Implement this
throw new UnsupportedOperationException();
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequest#getMethod()
*/
public String getMethod() {
// TODO Only implements GET yet
return "GET";
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequestWrapper#getParameter(java.lang.String)
*/
public String getParameter(String name) {
return this.parameters.getParameter(name);
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequestWrapper#getParameterMap()
*/
public Map getParameterMap() {
// TODO Implement this
throw new UnsupportedOperationException();
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequestWrapper#getParameterNames()
*/
public Enumeration getParameterNames() {
return this.parameters.getParameterNames();
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequestWrapper#getParameterValues(java.lang.String)
*/
public String[] getParameterValues(String name) {
return this.parameters.getParameterValues(name);
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequestWrapper#getPathInfo()
*/
public String getPathInfo() {
return this.uri.getPath();
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequest#getPathTranslated()
*/
public String getPathTranslated() {
// TODO This is legal but more info might be possible
return null;
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getProtocol()
*/
public String getProtocol() {
// TODO Implement this
throw new UnsupportedOperationException();
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequestWrapper#getQueryString()
*/
public String getQueryString() {
return this.uri.getQuery();
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getReader()
*/
public BufferedReader getReader() throws IOException {
// TODO No input handling yet
throw new UnsupportedOperationException();
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getRealPath(java.lang.String)
*/
public String getRealPath(String path) {
// Deprecated
return null;
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getRemoteAddr()
*/
public String getRemoteAddr() {
// TODO The URI of the current block might be an appropriate choice.
throw new UnsupportedOperationException();
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getRemoteHost()
*/
public String getRemoteHost() {
// TODO Local host might be an appropriate choice
throw new UnsupportedOperationException();
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequest#getRemoteUser()
*/
public String getRemoteUser() {
return null;
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getRequestDispatcher(java.lang.String)
*/
public RequestDispatcher getRequestDispatcher(String path) {
return null;
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequest#getRequestedSessionId()
*/
public String getRequestedSessionId() {
return null;
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequestWrapper#getRequestURI()
*/
public String getRequestURI() {
return this.getContextPath() + this.getServletPath() + this.getPathInfo();
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequestWrapper#getRequestURL()
*/
public StringBuffer getRequestURL() {
return new StringBuffer(this.getScheme()).append(':').append(this.getRequestURI());
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getScheme()
*/
public String getScheme() {
return this.uri.getScheme();
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getServerName()
*/
public String getServerName() {
// TODO implement this
return "";
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#getServerPort()
*/
public int getServerPort() {
// TODO implement this
return 80;
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequestWrapper#getServletPath()
*/
public String getServletPath() {
return "";
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequest#getSession()
*/
public HttpSession getSession() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequest#getSession(boolean)
*/
public HttpSession getSession(boolean create) {
// TODO Auto-generated method stub
if (create) {
return new HttpSession() {
public Object getAttribute(String name) {
// TODO Auto-generated method stub
return null;
}
public Enumeration getAttributeNames() {
// TODO Auto-generated method stub
return null;
}
public long getCreationTime() {
// TODO Auto-generated method stub
return 0;
}
public String getId() {
// TODO Auto-generated method stub
return null;
}
public long getLastAccessedTime() {
// TODO Auto-generated method stub
return 0;
}
public int getMaxInactiveInterval() {
// TODO Auto-generated method stub
return 0;
}
public ServletContext getServletContext() {
// TODO Auto-generated method stub
return null;
}
public HttpSessionContext getSessionContext() {
// TODO Auto-generated method stub
return null;
}
public Object getValue(String name) {
// TODO Auto-generated method stub
return null;
}
public String[] getValueNames() {
// TODO Auto-generated method stub
return null;
}
public void invalidate() {
// TODO Auto-generated method stub
}
public boolean isNew() {
// TODO Auto-generated method stub
return false;
}
public void putValue(String name, Object value) {
// TODO Auto-generated method stub
}
public void removeAttribute(String name) {
// TODO Auto-generated method stub
}
public void removeValue(String name) {
// TODO Auto-generated method stub
}
public void setAttribute(String name, Object value) {
// TODO Auto-generated method stub
}
public void setMaxInactiveInterval(int interval) {
// TODO Auto-generated method stub
}
};
}
return null;
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequest#getUserPrincipal()
*/
public Principal getUserPrincipal() {
// TODO No authentication handling between blocks yet
return null;
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromCookie()
*/
public boolean isRequestedSessionIdFromCookie() {
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromUrl()
*/
public boolean isRequestedSessionIdFromUrl() {
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromURL()
*/
public boolean isRequestedSessionIdFromURL() {
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdValid()
*/
public boolean isRequestedSessionIdValid() {
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#isSecure()
*/
public boolean isSecure() {
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequest#isUserInRole(java.lang.String)
*/
public boolean isUserInRole(String role) {
// TODO No authentication handling between blocks yet
return false;
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequestWrapper#removeAttribute(java.lang.String)
*/
public void removeAttribute(String name) {
this.attributes.remove(name);
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequestWrapper#setAttribute(java.lang.String, java.lang.Object)
*/
public void setAttribute(String name, Object value) {
if (value != null)
this.attributes.put(name, value);
else
this.removeAttribute(name);
}
/* (non-Javadoc)
* @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String)
*/
public void setCharacterEncoding(String encoding) throws UnsupportedEncodingException {
this.encoding = encoding;
}
public String getLocalAddr() {
// TODO Auto-generated method stub
return null;
}
public String getLocalName() {
// TODO Auto-generated method stub
return null;
}
public int getLocalPort() {
// TODO Auto-generated method stub
return 0;
}
public int getRemotePort() {
// TODO Auto-generated method stub
return 0;
}
}