Interface RequestAccess

All Known Implementing Classes:
AbstractLesscController, AbstractLoggingFilter, AbstractSASSController, AppController, AppControllerFilter, ConfirmationTag, CSRFFilter, CSRFTokenTag, DBConnectionFilter, DebugTag, FormTag, FreeMarkerTag, HeadersLogFilter, HttpSupport, HttpSupportFilter, LinkToTag, MessageTag, RequestParamsLogFilter, RequestPropertiesLogFilter, SelectTag, SimpleController, StatisticsFilter, YieldTag

public interface RequestAccess
Provides access to request values.
Author:
igor, on 6/16/14.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static org.slf4j.Logger
     
  • Method Summary

    Modifier and Type
    Method
    Description
    default AppContext
    Returns instance of AppContext.
    default String
    Provides a context of the request - usually an app name (as seen on URL of request).
    default Cookie
    cookie​(String name)
    Returns a cookie by name, null if not found.
    default List<Cookie>
    Returns collection of all cookies browser sent.
    default String
    Convenience method, returns cookie value.
    default boolean
    exists​(String name)
    Tests if a request parameter exists.
    default String
    Returns a format part of the URI, or null if URI does not have a format part.
    default String
    Returns value of ID if one is present on a URL.
    default Locale
    Same as locale().
    default String
    This method returns a host name of a web server if this container is fronted by one, such that it sets a header X-Forwarded-Host on the request and forwards it to the Java container.
    default int
    This method returns a port of a web server if this Java container is fronted by one, such that it sets a header X-Forwarded-Port on the request and forwards it to the Java container.
    default String
     
    default String
    This method returns a protocol of a request to web server if this container is fronted by one, such that it sets a header X-Forwarded-Proto on the request and forwards it to the Java container.
    default Route
    Returns instance of Route to be used for potential conditional logic inside controller filters.
    default String
    header​(String name)
    Returns a request header by name.
    default Map<String,​String>
    Returns all headers from a request keyed by header name.
    default String
    Returns local host name on which request was received.
    default String
    Returns local IP address on which request was received.
    default String
    Returns IP address that the web server forwarded request for.
    default boolean
    True if this request uses HTTP DELETE method, false otherwise.
    default boolean
    True if this request uses HTTP GET method, false otherwise.
    default boolean
    True if this request uses HTTP HEAD method, false otherwise.
    default boolean
    isMethod​(String method)
     
    default boolean
     
    default boolean
    True if this request uses HTTP POST method, false otherwise.
    default boolean
    True if this request uses HTTP PUT method, false otherwise.
    default boolean
    Returns true if this request is Ajax.
    default Locale
    Returns locale of request.
    default String
    Returns an HTTP method from the request.
    default String
    param​(String name)
    Returns value of routing user segment, or route wild card value, or request parameter.
    default String
    param​(String name, List<FormItem> formItems)
    Convenience method to get a parameter value in case multipart/form-data request was used.
    default Map<String,​String[]>
    Returns an instance of java.util.Map containing parameter names as keys and parameter values as map values.
    default List<String>
    params​(String name)
    Returns multiple request values for a name.
    default List<String>
    params​(String name, List<FormItem> formItems)
    Convenience method to get parameter values in case multipart/form-data request was used.
    default Map<String,​String>
    Returns a map where keys are names of all parameters, while values are the first value for each parameter, even if such parameter has more than one value submitted.
    default Map<String,​String>
    params1st​(List<FormItem> formItems)
    Convenience method to get parameters in case multipart/form-data request was used.
    default String
    Returns a path of the request.
    default int
    Returns port on which the of the server received current request.
    default String
    Returns protocol of request, for example: HTTP/1.1.
    default String
    Returns query string of the request.
    default String
    IP address of the requesting client.
    default String
    Host name of the requesting client.
    default boolean
    requestHas​(String name)
    Synonym of exists(String).
    default String
     
    default Object
    session​(String name)
     
    default void
    session​(String name, Object value)
    Sets an object on a current session.
    default String
    uri()
    Returns URI, or a full path of request.
    default String
    url()
    Returns a full URL of the request, all except a query string.
    default String
    Helper method, returns user-agent header of the request.
    default boolean
    xhr()
    Synonym for isXhr().
  • Field Details

    • LOGGER

      static final org.slf4j.Logger LOGGER
  • Method Details

    • isMultipartContent

      default boolean isMultipartContent()
    • param

      default String param(String name)
      Returns value of routing user segment, or route wild card value, or request parameter. If this name represents multiple values, this call will result in IllegalArgumentException.
      Parameters:
      name - name of parameter.
      Returns:
      value of routing user segment, or route wild card value, or request parameter.
    • param

      default String param(String name, List<FormItem> formItems)
      Convenience method to get a parameter value in case multipart/form-data request was used. Returns a value of one named parameter from request. Will only return form fields, and not files.
      Parameters:
      name - name of parameter.
      formItems - form items retrieved from multipart/form-data request.
      Returns:
      value of request parameter from multipart/form-data request or null if not found.
    • getId

      default String getId()
      Returns value of ID if one is present on a URL. Id is usually a part of a URI, such as: /controller/action/id. This depends on a type of a URI, and whether controller is RESTful or not.
      Returns:
      ID value from URI is one exists, null if not.
    • format

      default String format()
      Returns a format part of the URI, or null if URI does not have a format part. A format part is defined as part of URI that is trailing after a last dot, as in: /books.xml, here "xml" is a format.
      Returns:
      format part of the URI, or nul if URI does not have it.
    • appContext

      default AppContext appContext()
      Returns instance of AppContext.
      Returns:
      instance of AppContext.
    • isXhr

      default boolean isXhr()
      Returns true if this request is Ajax.
      Returns:
      true if this request is Ajax.
      See Also:
      List_of_HTTP_header_fields
    • userAgent

      default String userAgent()
      Helper method, returns user-agent header of the request.
      Returns:
      user-agent header of the request.
    • xhr

      default boolean xhr()
      Synonym for isXhr().
    • getRoute

      default Route getRoute()
      Returns instance of Route to be used for potential conditional logic inside controller filters.
      Returns:
      instance of Route
    • exists

      default boolean exists(String name)
      Tests if a request parameter exists. Disregards the value completely - this can be empty string, but as long as parameter does exist, this method returns true.
      Parameters:
      name - name of request parameter to test.
      Returns:
      true if parameter exists, false if not.
    • requestHas

      default boolean requestHas(String name)
      Synonym of exists(String).
      Parameters:
      name - name of request parameter to test.
      Returns:
      true if parameter exists, false if not.
    • host

      default String host()
      Returns local host name on which request was received.
      Returns:
      local host name on which request was received.
    • ipAddress

      default String ipAddress()
      Returns local IP address on which request was received.
      Returns:
      local IP address on which request was received.
    • getRequestProtocol

      default String getRequestProtocol()
      This method returns a protocol of a request to web server if this container is fronted by one, such that it sets a header X-Forwarded-Proto on the request and forwards it to the Java container. If such header is not present, than the protocol() method is used.
      Returns:
      protocol of web server request if X-Forwarded-Proto header is found, otherwise current protocol.
    • getRequestPort

      default int getRequestPort()
      This method returns a port of a web server if this Java container is fronted by one, such that it sets a header X-Forwarded-Port on the request and forwards it to the Java container. If such header is not present, than the port() method is used.
      Returns:
      port of web server request if X-Forwarded-Port header is found, otherwise port of the Java container.
    • port

      default int port()
      Returns port on which the of the server received current request.
      Returns:
      port on which the of the server received current request.
    • protocol

      default String protocol()
      Returns protocol of request, for example: HTTP/1.1.
      Returns:
      protocol of request
    • getRequestHost

      default String getRequestHost()
      This method returns a host name of a web server if this container is fronted by one, such that it sets a header X-Forwarded-Host on the request and forwards it to the Java container. If such header is not present, than the host() method is used.
      Returns:
      host name of web server if X-Forwarded-Host header is found, otherwise local host name.
    • ipForwardedFor

      default String ipForwardedFor()
      Returns IP address that the web server forwarded request for.
      Returns:
      IP address that the web server forwarded request for.
    • params

      default List<String> params(String name)
      Returns multiple request values for a name.
      Parameters:
      name - name of multiple values from request.
      Returns:
      multiple request values for a name.
    • params

      default List<String> params(String name, List<FormItem> formItems)
      Convenience method to get parameter values in case multipart/form-data request was used. Returns multiple request values for a name.
      Parameters:
      name - name of multiple values from request.
      formItems - form items retrieved from multipart/form-data request.
      Returns:
      multiple request values for a name. Will ignore files, and only return form fields.
    • params1st

      default Map<String,​String> params1st()
      Returns a map where keys are names of all parameters, while values are the first value for each parameter, even if such parameter has more than one value submitted.
      Returns:
      a map where keys are names of all parameters, while values are first value for each parameter, even if such parameter has more than one value submitted.
    • params1st

      default Map<String,​String> params1st(List<FormItem> formItems)
      Convenience method to get parameters in case multipart/form-data request was used. Returns a map where keys are names of all parameters, while values are the first value for each parameter, even if such parameter has more than one value submitted.
      Parameters:
      formItems - form items retrieved from multipart/form-data request.
      Returns:
      a map where keys are names of all parameters, while values are first value for each parameter, even if such parameter has more than one value submitted.
    • params

      default Map<String,​String[]> params()
      Returns an instance of java.util.Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array.
      Returns:
      an instance java.util.Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array.
    • locale

      default Locale locale()
      Returns locale of request.
      Returns:
      locale of request.
    • getLocale

      default Locale getLocale()
      Same as locale().
      Returns:
      locale of request.
    • cookies

      default List<Cookie> cookies()
      Returns collection of all cookies browser sent.
      Returns:
      collection of all cookies browser sent.
    • cookie

      default Cookie cookie(String name)
      Returns a cookie by name, null if not found.
      Parameters:
      name - name of a cookie.
      Returns:
      a cookie by name, null if not found.
    • cookieValue

      default String cookieValue(String name)
      Convenience method, returns cookie value.
      Parameters:
      name - name of cookie.
      Returns:
      cookie value.
    • path

      default String path()
      Returns a path of the request. It does not include protocol, host, port or context. Just a path. Example: /controller/action/id
      Returns:
      a path of the request.
    • url

      default String url()
      Returns a full URL of the request, all except a query string.
      Returns:
      a full URL of the request, all except a query string.
    • queryString

      default String queryString()
      Returns query string of the request.
      Returns:
      query string of the request.
    • method

      default String method()
      Returns an HTTP method from the request.
      Returns:
      an HTTP method from the request.
    • isGet

      default boolean isGet()
      True if this request uses HTTP GET method, false otherwise.
      Returns:
      True if this request uses HTTP GET method, false otherwise.
    • isPost

      default boolean isPost()
      True if this request uses HTTP POST method, false otherwise.
      Returns:
      True if this request uses HTTP POST method, false otherwise.
    • isPut

      default boolean isPut()
      True if this request uses HTTP PUT method, false otherwise.
      Returns:
      True if this request uses HTTP PUT method, false otherwise.
    • isDelete

      default boolean isDelete()
      True if this request uses HTTP DELETE method, false otherwise.
      Returns:
      True if this request uses HTTP DELETE method, false otherwise.
    • isMethod

      default boolean isMethod(String method)
    • isHead

      default boolean isHead()
      True if this request uses HTTP HEAD method, false otherwise.
      Returns:
      True if this request uses HTTP HEAD method, false otherwise.
    • context

      default String context()
      Provides a context of the request - usually an app name (as seen on URL of request). Example: /mywebapp
      Returns:
      a context of the request - usually an app name (as seen on URL of request).
    • uri

      default String uri()
      Returns URI, or a full path of request. This does not include protocol, host or port. Just context and path. Examlpe: /mywebapp/controller/action/id
      Returns:
      URI, or a full path of request.
    • remoteHost

      default String remoteHost()
      Host name of the requesting client.
      Returns:
      host name of the requesting client.
    • remoteAddress

      default String remoteAddress()
      IP address of the requesting client.
      Returns:
      IP address of the requesting client.
    • header

      default String header(String name)
      Returns a request header by name.
      Parameters:
      name - name of header
      Returns:
      header value.
    • headers

      default Map<String,​String> headers()
      Returns all headers from a request keyed by header name.
      Returns:
      all headers from a request keyed by header name.
    • session

      default Object session(String name)
      Parameters:
      name - name of an object in session
      Returns:
      object in session, or null.
    • session

      default void session(String name, Object value)
      Sets an object on a current session.
      Parameters:
      name - name of object
      value - value of object
    • getRequestProperties

      default String getRequestProperties()
    • servletPath

      default String servletPath()