1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 1999 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if
  20. * any, must include the following acknowlegement:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowlegement may appear in the software itself,
  24. * if and wherever such third-party acknowlegements normally appear.
  25. *
  26. * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
  27. * Foundation" must not be used to endorse or promote products derived
  28. * from this software without prior written permission. For written
  29. * permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache"
  32. * nor may "Apache" appear in their names without prior written
  33. * permission of the Apache Group.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation. For more
  51. * information on the Apache Software Foundation, please see
  52. * <http://www.apache.org/>.
  53. *
  54. * ====================================================================
  55. *
  56. * This source code implements specifications defined by the Java
  57. * Community Process. In order to remain compliant with the specification
  58. * DO NOT add / change / or delete method signatures!
  59. */
  60. package javax.servlet.http;
  61. import javax.servlet.ServletRequest;
  62. import java.util.Enumeration;
  63. /**
  64. *
  65. * Extends the {@link javax.servlet.ServletRequest} interface
  66. * to provide request information for HTTP servlets.
  67. *
  68. * <p>The servlet container creates an <code>HttpServletRequest</code>
  69. * object and passes it as an argument to the servlet's service
  70. * methods (<code>doGet</code>, <code>doPost</code>, etc).
  71. *
  72. *
  73. * @author Various
  74. * @version $Version$
  75. *
  76. *
  77. */
  78. public interface HttpServletRequest extends ServletRequest {
  79. /**
  80. * String identifier for Basic authentication. Value "BASIC"
  81. */
  82. public static final String BASIC_AUTH = "BASIC";
  83. /**
  84. * String identifier for Basic authentication. Value "FORM"
  85. */
  86. public static final String FORM_AUTH = "FORM";
  87. /**
  88. * String identifier for Basic authentication. Value "CLIENT_CERT"
  89. */
  90. public static final String CLIENT_CERT_AUTH = "CLIENT_CERT";
  91. /**
  92. * String identifier for Basic authentication. Value "DIGEST"
  93. */
  94. public static final String DIGEST_AUTH = "DIGEST";
  95. /**
  96. * Returns the name of the authentication scheme used to protect
  97. * the servlet. All servlet containers support basic, form and client
  98. * certificate authentication, and may additionally support digest
  99. * authentication.
  100. * If the servlet is not authenticated <code>null</code> is returned.
  101. *
  102. * <p>Same as the value of the CGI variable AUTH_TYPE.
  103. *
  104. *
  105. * @return one of the static members BASIC_AUTH,
  106. * FORM_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH
  107. * (suitable for == comparison)
  108. * indicating the authentication scheme, or
  109. * <code>null</code> if the request was
  110. * not authenticated.
  111. *
  112. */
  113. public String getAuthType();
  114. /**
  115. *
  116. * Returns an array containing all of the <code>Cookie</code>
  117. * objects the client sent with this request.
  118. * This method returns <code>null</code> if no cookies were sent.
  119. *
  120. * @return an array of all the <code>Cookies</code>
  121. * included with this request, or <code>null</code>
  122. * if the request has no cookies
  123. *
  124. *
  125. */
  126. public Cookie[] getCookies();
  127. /**
  128. *
  129. * Returns the value of the specified request header
  130. * as a <code>long</code> value that represents a
  131. * <code>Date</code> object. Use this method with
  132. * headers that contain dates, such as
  133. * <code>If-Modified-Since</code>.
  134. *
  135. * <p>The date is returned as
  136. * the number of milliseconds since January 1, 1970 GMT.
  137. * The header name is case insensitive.
  138. *
  139. * <p>If the request did not have a header of the
  140. * specified name, this method returns -1. If the header
  141. * can't be converted to a date, the method throws
  142. * an <code>IllegalArgumentException</code>.
  143. *
  144. * @param name a <code>String</code> specifying the
  145. * name of the header
  146. *
  147. * @return a <code>long</code> value
  148. * representing the date specified
  149. * in the header expressed as
  150. * the number of milliseconds
  151. * since January 1, 1970 GMT,
  152. * or -1 if the named header
  153. * was not included with the
  154. * reqest
  155. *
  156. * @exception IllegalArgumentException If the header value
  157. * can't be converted
  158. * to a date
  159. *
  160. */
  161. public long getDateHeader(String name);
  162. /**
  163. *
  164. * Returns the value of the specified request header
  165. * as a <code>String</code>. If the request did not include a header
  166. * of the specified name, this method returns <code>null</code>.
  167. * The header name is case insensitive. You can use
  168. * this method with any request header.
  169. *
  170. * @param name a <code>String</code> specifying the
  171. * header name
  172. *
  173. * @return a <code>String</code> containing the
  174. * value of the requested
  175. * header, or <code>null</code>
  176. * if the request does not
  177. * have a header of that name
  178. *
  179. */
  180. public String getHeader(String name);
  181. /**
  182. *
  183. * Returns all the values of the specified request header
  184. * as an <code>Enumeration</code> of <code>String</code> objects.
  185. *
  186. * <p>Some headers, such as <code>Accept-Language</code> can be sent
  187. * by clients as several headers each with a different value rather than
  188. * sending the header as a comma separated list.
  189. *
  190. * <p>If the request did not include any headers
  191. * of the specified name, this method returns an empty
  192. * <code>Enumeration</code>.
  193. * The header name is case insensitive. You can use
  194. * this method with any request header.
  195. *
  196. * @param name a <code>String</code> specifying the
  197. * header name
  198. *
  199. * @return an <code>Enumeration</code> containing
  200. * the values of the requested header. If
  201. * the request does not have any headers of
  202. * that name return an empty
  203. * enumeration. If
  204. * the container does not allow access to
  205. * header information, return null
  206. *
  207. */
  208. public Enumeration getHeaders(String name);
  209. /**
  210. *
  211. * Returns an enumeration of all the header names
  212. * this request contains. If the request has no
  213. * headers, this method returns an empty enumeration.
  214. *
  215. * <p>Some servlet containers do not allow do not allow
  216. * servlets to access headers using this method, in
  217. * which case this method returns <code>null</code>
  218. *
  219. * @return an enumeration of all the
  220. * header names sent with this
  221. * request; if the request has
  222. * no headers, an empty enumeration;
  223. * if the servlet container does not
  224. * allow servlets to use this method,
  225. * <code>null</code>
  226. *
  227. *
  228. */
  229. public Enumeration getHeaderNames();
  230. /**
  231. *
  232. * Returns the value of the specified request header
  233. * as an <code>int</code>. If the request does not have a header
  234. * of the specified name, this method returns -1. If the
  235. * header cannot be converted to an integer, this method
  236. * throws a <code>NumberFormatException</code>.
  237. *
  238. * <p>The header name is case insensitive.
  239. *
  240. * @param name a <code>String</code> specifying the name
  241. * of a request header
  242. *
  243. * @return an integer expressing the value
  244. * of the request header or -1
  245. * if the request doesn't have a
  246. * header of this name
  247. *
  248. * @exception NumberFormatException If the header value
  249. * can't be converted
  250. * to an <code>int</code>
  251. */
  252. public int getIntHeader(String name);
  253. /**
  254. *
  255. * Returns the name of the HTTP method with which this
  256. * request was made, for example, GET, POST, or PUT.
  257. * Same as the value of the CGI variable REQUEST_METHOD.
  258. *
  259. * @return a <code>String</code>
  260. * specifying the name
  261. * of the method with which
  262. * this request was made
  263. *
  264. */
  265. public String getMethod();
  266. /**
  267. *
  268. * Returns any extra path information associated with
  269. * the URL the client sent when it made this request.
  270. * The extra path information follows the servlet path
  271. * but precedes the query string.
  272. * This method returns <code>null</code> if there
  273. * was no extra path information.
  274. *
  275. * <p>Same as the value of the CGI variable PATH_INFO.
  276. *
  277. *
  278. * @return a <code>String</code>, decoded by the
  279. * web container, specifying
  280. * extra path information that comes
  281. * after the servlet path but before
  282. * the query string in the request URL;
  283. * or <code>null</code> if the URL does not have
  284. * any extra path information
  285. *
  286. */
  287. public String getPathInfo();
  288. /**
  289. *
  290. * Returns any extra path information after the servlet name
  291. * but before the query string, and translates it to a real
  292. * path. Same as the value of the CGI variable PATH_TRANSLATED.
  293. *
  294. * <p>If the URL does not have any extra path information,
  295. * this method returns <code>null</code>.
  296. *
  297. * The web container does not decode thins string.
  298. *
  299. *
  300. * @return a <code>String</code> specifying the
  301. * real path, or <code>null</code> if
  302. * the URL does not have any extra path
  303. * information
  304. *
  305. *
  306. */
  307. public String getPathTranslated();
  308. /**
  309. *
  310. * Returns the portion of the request URI that indicates the context
  311. * of the request. The context path always comes first in a request
  312. * URI. The path starts with a "/" character but does not end with a "/"
  313. * character. For servlets in the default (root) context, this method
  314. * returns "". The container does not decode this string.
  315. *
  316. *
  317. * @return a <code>String</code> specifying the
  318. * portion of the request URI that indicates the context
  319. * of the request
  320. *
  321. *
  322. */
  323. public String getContextPath();
  324. /**
  325. *
  326. * Returns the query string that is contained in the request
  327. * URL after the path. This method returns <code>null</code>
  328. * if the URL does not have a query string. Same as the value
  329. * of the CGI variable QUERY_STRING.
  330. *
  331. * @return a <code>String</code> containing the query
  332. * string or <code>null</code> if the URL
  333. * contains no query string. The value is not
  334. * decoded by the container.
  335. *
  336. */
  337. public String getQueryString();
  338. /**
  339. *
  340. * Returns the login of the user making this request, if the
  341. * user has been authenticated, or <code>null</code> if the user
  342. * has not been authenticated.
  343. * Whether the user name is sent with each subsequent request
  344. * depends on the browser and type of authentication. Same as the
  345. * value of the CGI variable REMOTE_USER.
  346. *
  347. * @return a <code>String</code> specifying the login
  348. * of the user making this request, or <code>null</code
  349. * if the user login is not known
  350. *
  351. */
  352. public String getRemoteUser();
  353. /**
  354. *
  355. * Returns a boolean indicating whether the authenticated user is included
  356. * in the specified logical "role". Roles and role membership can be
  357. * defined using deployment descriptors. If the user has not been
  358. * authenticated, the method returns <code>false</code>.
  359. *
  360. * @param role a <code>String</code> specifying the name
  361. * of the role
  362. *
  363. * @return a <code>boolean</code> indicating whether
  364. * the user making this request belongs to a given role;
  365. * <code>false</code> if the user has not been
  366. * authenticated
  367. *
  368. */
  369. public boolean isUserInRole(String role);
  370. /**
  371. *
  372. * Returns a <code>java.security.Principal</code> object containing
  373. * the name of the current authenticated user. If the user has not been
  374. * authenticated, the method returns <code>null</code>.
  375. *
  376. * @return a <code>java.security.Principal</code> containing
  377. * the name of the user making this request;
  378. * <code>null</code> if the user has not been
  379. * authenticated
  380. *
  381. */
  382. public java.security.Principal getUserPrincipal();
  383. /**
  384. *
  385. * Returns the session ID specified by the client. This may
  386. * not be the same as the ID of the actual session in use.
  387. * For example, if the request specified an old (expired)
  388. * session ID and the server has started a new session, this
  389. * method gets a new session with a new ID. If the request
  390. * did not specify a session ID, this method returns
  391. * <code>null</code>.
  392. *
  393. *
  394. * @return a <code>String</code> specifying the session
  395. * ID, or <code>null</code> if the request did
  396. * not specify a session ID
  397. *
  398. * @see #isRequestedSessionIdValid
  399. *
  400. */
  401. public String getRequestedSessionId();
  402. /**
  403. *
  404. * Returns the part of this request's URL from the protocol
  405. * name up to the query string in the first line of the HTTP request.
  406. * The web container does not decode this String.
  407. * For example:
  408. *
  409. *
  410. * <table>
  411. * <tr align=left><th>First line of HTTP request </th>
  412. * <th> Returned Value</th>
  413. * <tr><td>POST /some/path.html HTTP/1.1<td><td>/some/path.html
  414. * <tr><td>GET http://foo.bar/a.html HTTP/1.0
  415. * <td><td>/a.html
  416. * <tr><td>HEAD /xyz?a=b HTTP/1.1<td><td>/xyz
  417. * </table>
  418. *
  419. * <p>To reconstruct an URL with a scheme and host, use
  420. * {@link HttpUtils#getRequestURL}.
  421. *
  422. * @return a <code>String</code> containing
  423. * the part of the URL from the
  424. * protocol name up to the query string
  425. *
  426. * @see HttpUtils#getRequestURL
  427. *
  428. */
  429. public String getRequestURI();
  430. /**
  431. *
  432. * Reconstructs the URL the client used to make the request.
  433. * The returned URL contains a protocol, server name, port
  434. * number, and server path, but it does not include query
  435. * string parameters.
  436. *
  437. * <p>Because this method returns a <code>StringBuffer</code>,
  438. * not a string, you can modify the URL easily, for example,
  439. * to append query parameters.
  440. *
  441. * <p>This method is useful for creating redirect messages
  442. * and for reporting errors.
  443. *
  444. * @return a <code>StringBuffer</code> object containing
  445. * the reconstructed URL
  446. *
  447. */
  448. public StringBuffer getRequestURL();
  449. /**
  450. *
  451. * Returns the part of this request's URL that calls
  452. * the servlet. This includes either the servlet name or
  453. * a path to the servlet, but does not include any extra
  454. * path information or a query string. Same as the value
  455. * of the CGI variable SCRIPT_NAME.
  456. *
  457. *
  458. * @return a <code>String</code> containing
  459. * the name or path of the servlet being
  460. * called, as specified in the request URL,
  461. * decoded.
  462. *
  463. *
  464. */
  465. public String getServletPath();
  466. /**
  467. *
  468. * Returns the current <code>HttpSession</code>
  469. * associated with this request or, if if there is no
  470. * current session and <code>create</code> is true, returns
  471. * a new session.
  472. *
  473. * <p>If <code>create</code> is <code>false</code>
  474. * and the request has no valid <code>HttpSession</code>,
  475. * this method returns <code>null</code>.
  476. *
  477. * <p>To make sure the session is properly maintained,
  478. * you must call this method before
  479. * the response is committed. If the container is using cookies
  480. * to maintain session integrity and is asked to create a new session
  481. * when the response is committed, an IllegalStateException is thrown.
  482. *
  483. *
  484. *
  485. *
  486. * @param <code>true</code> to create
  487. * a new session for this request if necessary;
  488. * <code>false</code> to return <code>null</code>
  489. * if there's no current session
  490. *
  491. *
  492. * @return the <code>HttpSession</code> associated
  493. * with this request or <code>null</code> if
  494. * <code>create</code> is <code>false</code>
  495. * and the request has no valid session
  496. *
  497. * @see #getSession()
  498. *
  499. *
  500. */
  501. public HttpSession getSession(boolean create);
  502. /**
  503. *
  504. * Returns the current session associated with this request,
  505. * or if the request does not have a session, creates one.
  506. *
  507. * @return the <code>HttpSession</code> associated
  508. * with this request
  509. *
  510. * @see #getSession(boolean)
  511. *
  512. */
  513. public HttpSession getSession();
  514. /**
  515. *
  516. * Checks whether the requested session ID is still valid.
  517. *
  518. * @return <code>true</code> if this
  519. * request has an id for a valid session
  520. * in the current session context;
  521. * <code>false</code> otherwise
  522. *
  523. * @see #getRequestedSessionId
  524. * @see #getSession
  525. * @see HttpSessionContext
  526. *
  527. */
  528. public boolean isRequestedSessionIdValid();
  529. /**
  530. *
  531. * Checks whether the requested session ID came in as a cookie.
  532. *
  533. * @return <code>true</code> if the session ID
  534. * came in as a
  535. * cookie; otherwise, <code>false</code>
  536. *
  537. *
  538. * @see #getSession
  539. *
  540. */
  541. public boolean isRequestedSessionIdFromCookie();
  542. /**
  543. *
  544. * Checks whether the requested session ID came in as part of the
  545. * request URL.
  546. *
  547. * @return <code>true</code> if the session ID
  548. * came in as part of a URL; otherwise,
  549. * <code>false</code>
  550. *
  551. *
  552. * @see #getSession
  553. *
  554. */
  555. public boolean isRequestedSessionIdFromURL();
  556. /**
  557. *
  558. * @deprecated As of Version 2.1 of the Java Servlet
  559. * API, use {@link #isRequestedSessionIdFromURL}
  560. * instead.
  561. *
  562. */
  563. public boolean isRequestedSessionIdFromUrl();
  564. }