You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WrappedRequest.java 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Copyright 2011 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * 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, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.server;
  17. import java.io.IOException;
  18. import java.io.InputStream;
  19. import java.io.Serializable;
  20. import java.util.Locale;
  21. import java.util.Map;
  22. import javax.portlet.PortletRequest;
  23. import javax.servlet.ServletRequest;
  24. import javax.servlet.http.HttpServletRequest;
  25. import com.vaadin.Application;
  26. import com.vaadin.UIRequiresMoreInformationException;
  27. import com.vaadin.annotations.EagerInit;
  28. import com.vaadin.ui.UI;
  29. /**
  30. * A generic request to the server, wrapping a more specific request type, e.g.
  31. * HttpServletReqest or PortletRequest.
  32. *
  33. * @since 7.0
  34. */
  35. public interface WrappedRequest extends Serializable {
  36. /**
  37. * Detailed information extracted from the browser.
  38. *
  39. * @see WrappedRequest#getBrowserDetails()
  40. */
  41. public interface BrowserDetails extends Serializable {
  42. /**
  43. * Gets the URI hash fragment for the request. This is typically used to
  44. * encode navigation within an application.
  45. *
  46. * @return the URI hash fragment
  47. */
  48. public String getUriFragment();
  49. /**
  50. * Gets the value of window.name from the browser. This can be used to
  51. * keep track of the specific window between browser reloads.
  52. *
  53. * @return the string value of window.name in the browser
  54. */
  55. public String getWindowName();
  56. /**
  57. * Gets a reference to the {@link WebBrowser} object containing
  58. * additional information, e.g. screen size and the time zone offset.
  59. *
  60. * @return the web browser object
  61. */
  62. public WebBrowser getWebBrowser();
  63. }
  64. /**
  65. * Gets the named request parameter This is typically a HTTP GET or POST
  66. * parameter, though other request types might have other ways of
  67. * representing parameters.
  68. *
  69. * @see javax.servlet.ServletRequest#getParameter(String)
  70. * @see javax.portlet.PortletRequest#getParameter(String)
  71. *
  72. * @param parameter
  73. * the name of the parameter
  74. * @return The paramter value, or <code>null</code> if no parameter with the
  75. * given name is present
  76. */
  77. public String getParameter(String parameter);
  78. /**
  79. * Gets all the parameters of the request.
  80. *
  81. * @see #getParameter(String)
  82. *
  83. * @see javax.servlet.ServletRequest#getParameterMap()
  84. * @see javax.portlet.PortletRequest#getParameter(String)
  85. *
  86. * @return A mapping of parameter names to arrays of parameter values
  87. */
  88. public Map<String, String[]> getParameterMap();
  89. /**
  90. * Returns the length of the request content that can be read from the input
  91. * stream returned by {@link #getInputStream()}.
  92. *
  93. * @see javax.servlet.ServletRequest#getContentLength()
  94. * @see javax.portlet.ClientDataRequest#getContentLength()
  95. *
  96. * @return content length in bytes
  97. */
  98. public int getContentLength();
  99. /**
  100. * Returns an input stream from which the request content can be read. The
  101. * request content length can be obtained with {@link #getContentLength()}
  102. * without reading the full stream contents.
  103. *
  104. * @see javax.servlet.ServletRequest#getInputStream()
  105. * @see javax.portlet.ClientDataRequest#getPortletInputStream()
  106. *
  107. * @return the input stream from which the contents of the request can be
  108. * read
  109. * @throws IOException
  110. * if the input stream can not be opened
  111. */
  112. public InputStream getInputStream() throws IOException;
  113. /**
  114. * Gets a request attribute.
  115. *
  116. * @param name
  117. * the name of the attribute
  118. * @return the value of the attribute, or <code>null</code> if there is no
  119. * attribute with the given name
  120. *
  121. * @see javax.servlet.ServletRequest#getAttribute(String)
  122. * @see javax.portlet.PortletRequest#getAttribute(String)
  123. */
  124. public Object getAttribute(String name);
  125. /**
  126. * Defines a request attribute.
  127. *
  128. * @param name
  129. * the name of the attribute
  130. * @param value
  131. * the attribute value
  132. *
  133. * @see javax.servlet.ServletRequest#setAttribute(String, Object)
  134. * @see javax.portlet.PortletRequest#setAttribute(String, Object)
  135. */
  136. public void setAttribute(String name, Object value);
  137. /**
  138. * Gets the path of the requested resource relative to the application. The
  139. * path be <code>null</code> if no path information is available. Does
  140. * always start with / if the path isn't <code>null</code>.
  141. *
  142. * @return a string with the path relative to the application.
  143. *
  144. * @see javax.servlet.http.HttpServletRequest#getPathInfo()
  145. */
  146. public String getRequestPathInfo();
  147. /**
  148. * Returns the maximum time interval, in seconds, that the session
  149. * associated with this request will be kept open between client accesses.
  150. *
  151. * @return an integer specifying the number of seconds the session
  152. * associated with this request remains open between client requests
  153. *
  154. * @see javax.servlet.http.HttpSession#getMaxInactiveInterval()
  155. * @see javax.portlet.PortletSession#getMaxInactiveInterval()
  156. */
  157. public int getSessionMaxInactiveInterval();
  158. /**
  159. * Gets an attribute from the session associated with this request.
  160. *
  161. * @param name
  162. * the name of the attribute
  163. * @return the attribute value, or <code>null</code> if the attribute is not
  164. * defined in the session
  165. *
  166. * @see javax.servlet.http.HttpSession#getAttribute(String)
  167. * @see javax.portlet.PortletSession#getAttribute(String)
  168. */
  169. public Object getSessionAttribute(String name);
  170. /**
  171. * Saves an attribute value in the session associated with this request.
  172. *
  173. * @param name
  174. * the name of the attribute
  175. * @param attribute
  176. * the attribute value
  177. *
  178. * @see javax.servlet.http.HttpSession#setAttribute(String, Object)
  179. * @see javax.portlet.PortletSession#setAttribute(String, Object)
  180. */
  181. public void setSessionAttribute(String name, Object attribute);
  182. /**
  183. * Returns the MIME type of the body of the request, or null if the type is
  184. * not known.
  185. *
  186. * @return a string containing the name of the MIME type of the request, or
  187. * null if the type is not known
  188. *
  189. * @see javax.servlet.ServletRequest#getContentType()
  190. * @see javax.portlet.ResourceRequest#getContentType()
  191. *
  192. */
  193. public String getContentType();
  194. /**
  195. * Gets detailed information about the browser from which the request
  196. * originated. This consists of information that is not available from
  197. * normal HTTP requests, but requires additional information to be extracted
  198. * for instance using javascript in the browser.
  199. *
  200. * This information is only guaranteed to be available in some special
  201. * cases, for instance when
  202. * {@link Application#getUIForRequest(WrappedRequest)} is called again after
  203. * throwing {@link UIRequiresMoreInformationException} or in
  204. * {@link UI#init(WrappedRequest)} for a UI class not annotated with
  205. * {@link EagerInit}
  206. *
  207. * @return the browser details, or <code>null</code> if details are not
  208. * available
  209. *
  210. * @see BrowserDetails
  211. */
  212. public BrowserDetails getBrowserDetails();
  213. /**
  214. * Gets locale information from the query, e.g. using the Accept-Language
  215. * header.
  216. *
  217. * @return the preferred Locale
  218. *
  219. * @see ServletRequest#getLocale()
  220. * @see PortletRequest#getLocale()
  221. */
  222. public Locale getLocale();
  223. /**
  224. * Returns the IP address from which the request came. This might also be
  225. * the address of a proxy between the server and the original requester.
  226. *
  227. * @return a string containing the IP address, or <code>null</code> if the
  228. * address is not available
  229. *
  230. * @see ServletRequest#getRemoteAddr()
  231. */
  232. public String getRemoteAddr();
  233. /**
  234. * Checks whether the request was made using a secure channel, e.g. using
  235. * https.
  236. *
  237. * @return a boolean indicating if the request is secure
  238. *
  239. * @see ServletRequest#isSecure()
  240. * @see PortletRequest#isSecure()
  241. */
  242. public boolean isSecure();
  243. /**
  244. * Gets the value of a request header, e.g. a http header for a
  245. * {@link HttpServletRequest}.
  246. *
  247. * @param headerName
  248. * the name of the header
  249. * @return the header value, or <code>null</code> if the header is not
  250. * present in the request
  251. *
  252. * @see HttpServletRequest#getHeader(String)
  253. */
  254. public String getHeader(String headerName);
  255. /**
  256. * Gets the deployment configuration for the context of this request.
  257. *
  258. * @return the deployment configuration
  259. *
  260. * @see DeploymentConfiguration
  261. */
  262. public DeploymentConfiguration getDeploymentConfiguration();
  263. }