blob: 68c77cccf12f587f88917dcc598f409bf7d3476f [file] [log] [blame]
Michael E. Rodriguezd8af66f2005-12-08 20:55:55 +00001/*
2 * Copyright 1999,2005 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18package javax.servlet.http;
19
20import javax.servlet.ServletRequest;
21import java.util.Enumeration;
22
23/**
24 *
25 * Extends the {@link javax.servlet.ServletRequest} interface
26 * to provide request information for HTTP servlets.
27 *
28 * <p>The servlet container creates an <code>HttpServletRequest</code>
29 * object and passes it as an argument to the servlet's service
30 * methods (<code>doGet</code>, <code>doPost</code>, etc).
31 *
32 *
33 * @author Various
34 * @version $Version$
35 *
36 *
37 */
38
39public interface HttpServletRequest extends ServletRequest {
40
41 /**
42 * Returns the name of the authentication scheme used to protect
43 * the servlet, for example, "BASIC" or "SSL".
44 * If the servlet is not authenticated <code>null</code> is returned.
45 *
46 * <p>Same as the value of the CGI variable AUTH_TYPE.
47 *
48 *
49 * @return a <code>String</code> specifying the name of
50 * the authentication scheme, or
51 * <code>null</code> if the request was not
52 * authenticated
53 *
54 */
55
56 public String getAuthType();
57
58
59
60
61 /**
62 *
63 * Returns an array containing all of the <code>Cookie</code>
64 * objects the client sent with this request.
65 * This method returns <code>null</code> if no cookies were sent.
66 *
67 * @return an array of all the <code>Cookies</code>
68 * included with this request, or <code>null</code>
69 * if the request has no cookies
70 *
71 *
72 */
73
74 public Cookie[] getCookies();
75
76
77
78
79 /**
80 *
81 * Returns the value of the specified request header
82 * as a <code>long</code> value that represents a
83 * <code>Date</code> object. Use this method with
84 * headers that contain dates, such as
85 * <code>If-Modified-Since</code>.
86 *
87 * <p>The date is returned as
88 * the number of milliseconds since January 1, 1970 GMT.
89 * The header name is case insensitive.
90 *
91 * <p>If the request did not have a header of the
92 * specified name, this method returns -1. If the header
93 * can't be converted to a date, the method throws
94 * an <code>IllegalArgumentException</code>.
95 *
96 * @param name a <code>String</code> specifying the
97 * name of the header
98 *
99 * @return a <code>long</code> value
100 * representing the date specified
101 * in the header expressed as
102 * the number of milliseconds
103 * since January 1, 1970 GMT,
104 * or -1 if the named header
105 * was not included with the
106 * reqest
107 *
108 * @exception IllegalArgumentException If the header value
109 * can't be converted
110 * to a date
111 *
112 */
113
114 public long getDateHeader(String name);
115
116
117
118
119 /**
120 *
121 * Returns the value of the specified request header
122 * as a <code>String</code>. If the request did not include a header
123 * of the specified name, this method returns <code>null</code>.
124 * The header name is case insensitive. You can use
125 * this method with any request header.
126 *
127 * @param name a <code>String</code> specifying the
128 * header name
129 *
130 * @return a <code>String</code> containing the
131 * value of the requested
132 * header, or <code>null</code>
133 * if the request does not
134 * have a header of that name
135 *
136 */
137
138 public String getHeader(String name);
139
140
141
142
143 /**
144 *
145 * Returns an enumeration of all the header names
146 * this request contains. If the request has no
147 * headers, this method returns an empty enumeration.
148 *
149 * <p>Some servlet containers do not allow do not allow
150 * servlets to access headers using this method, in
151 * which case this method returns <code>null</code>
152 *
153 * @return an enumeration of all the
154 * header names sent with this
155 * request; if the request has
156 * no headers, an empty enumeration;
157 * if the servlet container does not
158 * allow servlets to use this method,
159 * <code>null</code>
160 *
161 *
162 */
163
164 public Enumeration getHeaderNames();
165
166
167
168
169 /**
170 *
171 * Returns the value of the specified request header
172 * as an <code>int</code>. If the request does not have a header
173 * of the specified name, this method returns -1. If the
174 * header cannot be converted to an integer, this method
175 * throws a <code>NumberFormatException</code>.
176 *
177 * <p>The header name is case insensitive.
178 *
179 * @param name a <code>String</code> specifying the name
180 * of a request header
181 *
182 * @return an integer expressing the value
183 * of the request header or -1
184 * if the request doesn't have a
185 * header of this name
186 *
187 * @exception NumberFormatException If the header value
188 * can't be converted
189 * to an <code>int</code>
190 */
191
192 public int getIntHeader(String name);
193
194
195
196
197 /**
198 *
199 * Returns the name of the HTTP method with which this
200 * request was made, for example, GET, POST, or PUT.
201 * Same as the value of the CGI variable REQUEST_METHOD.
202 *
203 * @return a <code>String</code>
204 * specifying the name
205 * of the method with which
206 * this request was made
207 *
208 */
209
210 public String getMethod();
211
212
213
214
215 /**
216 *
217 * Returns any extra path information associated with
218 * the URL the client sent when it made this request.
219 * The extra path information follows the servlet path
220 * but precedes the query string.
221 * This method returns <code>null</code> if there
222 * was no extra path information.
223 *
224 * <p>Same as the value of the CGI variable PATH_INFO.
225 *
226 *
227 * @return a <code>String</code>, decoded by the
228 * web container, specifying
229 * extra path information that comes
230 * after the servlet path but before
231 * the query string in the request URL;
232 * or <code>null</code> if the URL does not have
233 * any extra path information
234 *
235 */
236
237 public String getPathInfo();
238
239
240
241
242 /**
243 *
244 * Returns any extra path information after the servlet name
245 * but before the query string, and translates it to a real
246 * path. Same as the value of the CGI variable PATH_TRANSLATED.
247 *
248 * <p>If the URL does not have any extra path information,
249 * this method returns <code>null</code>.
250 *
251 * The web container does not decode this string.
252 *
253 *
254 * @return a <code>String</code> specifying the
255 * real path, or <code>null</code> if
256 * the URL does not have any extra path
257 * information
258 *
259 *
260 */
261
262 public String getPathTranslated();
263
264
265
266
267 /**
268 *
269 * Returns the query string that is contained in the request
270 * URL after the path. This method returns <code>null</code>
271 * if the URL does not have a query string. Same as the value
272 * of the CGI variable QUERY_STRING.
273 *
274 * @return a <code>String</code> containing the query
275 * string or <code>null</code> if the URL
276 * contains no query string. The value is not
277 * decoded by the container.
278 *
279 */
280
281 public String getQueryString();
282
283
284
285
286 /**
287 *
288 * Returns the login of the user making this request, if the
289 * user has been authenticated, or <code>null</code> if the user
290 * has not been authenticated.
291 * Whether the user name is sent with each subsequent request
292 * depends on the browser and type of authentication. Same as the
293 * value of the CGI variable REMOTE_USER.
294 *
295 * @return a <code>String</code> specifying the login
296 * of the user making this request, or <code>null</code
297 * if the user login is not known
298 *
299 */
300
301 public String getRemoteUser();
302
303
304
305
306 /**
307 *
308 * Returns the session ID specified by the client. This may
309 * not be the same as the ID of the actual session in use.
310 * For example, if the request specified an old (expired)
311 * session ID and the server has started a new session, this
312 * method gets a new session with a new ID. If the request
313 * did not specify a session ID, this method returns
314 * <code>null</code>.
315 *
316 *
317 * @return a <code>String</code> specifying the session
318 * ID, or <code>null</code> if the request did
319 * not specify a session ID
320 *
321 * @see #isRequestedSessionIdValid
322 *
323 */
324
325 public String getRequestedSessionId();
326
327
328
329
330 /**
331 *
332 * Returns the part of this request's URL from the protocol
333 * name up to the query string in the first line of the HTTP request.
334 * The web container does not decode this String.
335 * For example:
336 *
337 *
338
339 * <table>
340 * <tr align=left><th>First line of HTTP request </th>
341 * <th> Returned Value</th>
342 * <tr><td>POST /some/path.html HTTP/1.1<td><td>/some/path.html
343 * <tr><td>GET http://foo.bar/a.html HTTP/1.0
344 * <td><td>/a.html
345 * <tr><td>HEAD /xyz?a=b HTTP/1.1<td><td>/xyz
346 * </table>
347 *
348 * <p>To reconstruct an URL with a scheme and host, use
349 * {@link HttpUtils#getRequestURL}.
350 *
351 * @return a <code>String</code> containing
352 * the part of the URL from the
353 * protocol name up to the query string
354 *
355 * @see HttpUtils#getRequestURL
356 *
357 */
358
359 public String getRequestURI();
360
361 /**
362 *
363 * Returns the part of this request's URL that calls
364 * the servlet. This includes either the servlet name or
365 * a path to the servlet, but does not include any extra
366 * path information or a query string. Same as the value
367 * of the CGI variable SCRIPT_NAME.
368 *
369 *
370 * @return a <code>String</code> containing
371 * the name or path of the servlet being
372 * called, as specified in the request URL,
373 * decoded.
374 *
375 *
376 */
377
378 public String getServletPath();
379
380
381
382
383 /**
384 *
385 * Returns the current <code>HttpSession</code>
386 * associated with this request or, if if there is no
387 * current session and <code>create</code> is true, returns
388 * a new session.
389 *
390 * <p>If <code>create</code> is <code>false</code>
391 * and the request has no valid <code>HttpSession</code>,
392 * this method returns <code>null</code>.
393 *
394 * <p>To make sure the session is properly maintained,
395 * you must call this method before
396 * the response is committed. If the container is using cookies
397 * to maintain session integrity and is asked to create a new session
398 * when the response is committed, an IllegalStateException is thrown.
399 *
400 *
401 *
402 *
403 * @param create <code>true</code> to create
404 * a new session for this request if necessary;
405 * <code>false</code> to return <code>null</code>
406 * if there's no current session
407 *
408 *
409 * @return the <code>HttpSession</code> associated
410 * with this request or <code>null</code> if
411 * <code>create</code> is <code>false</code>
412 * and the request has no valid session
413 *
414 * @see #getSession()
415 *
416 *
417 */
418
419 public HttpSession getSession(boolean create);
420
421
422
423
424
425 /**
426 *
427 * Returns the current session associated with this request,
428 * or if the request does not have a session, creates one.
429 *
430 * @return the <code>HttpSession</code> associated
431 * with this request
432 *
433 * @see #getSession(boolean)
434 *
435 */
436
437 public HttpSession getSession();
438
439
440
441
442
443
444 /**
445 *
446 * Checks whether the requested session ID is still valid.
447 *
448 * @return <code>true</code> if this
449 * request has an id for a valid session
450 * in the current session context;
451 * <code>false</code> otherwise
452 *
453 * @see #getRequestedSessionId
454 * @see #getSession(boolean)
455 * @see HttpSessionContext
456 *
457 */
458
459 public boolean isRequestedSessionIdValid();
460
461
462
463
464 /**
465 *
466 * Checks whether the requested session ID came in as a cookie.
467 *
468 * @return <code>true</code> if the session ID
469 * came in as a
470 * cookie; otherwise, <code>false</code>
471 *
472 *
473 * @see #getSession(boolean)
474 *
475 */
476
477 public boolean isRequestedSessionIdFromCookie();
478
479
480
481
482 /**
483 *
484 * Checks whether the requested session ID came in as part of the
485 * request URL.
486 *
487 * @return <code>true</code> if the session ID
488 * came in as part of a URL; otherwise,
489 * <code>false</code>
490 *
491 *
492 * @see #getSession(boolean)
493 *
494 */
495
496 public boolean isRequestedSessionIdFromURL();
497
498
499
500
501
502 /**
503 *
504 * @deprecated As of Version 2.1 of the Java Servlet
505 * API, use {@link #isRequestedSessionIdFromURL}
506 * instead.
507 *
508 */
509
510 public boolean isRequestedSessionIdFromUrl();
511
512
513
514}