Interface VaadinRequest

All Known Implementing Classes:
VaadinServletRequest

public interface VaadinRequest
A generic request to the server, wrapping a more specific request type, e.g. HttpServletRequest.
Since:
1.0
Author:
Vaadin Ltd
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets a request attribute.
    Returns an Enumeration containing the names of the attributes available to this request.
    Returns the name of the authentication scheme used for the connection between client and server, for example, BASIC_AUTH, CLIENT_CERT_AUTH, a custom one or null if there was no authentication.
    Returns the name of the character encoding used in the body of this request.
    int
    Returns the length of the request content that can be read from the input stream returned by getInputStream().
    default long
    Returns the length of the request content that can be read from the input stream returned by getInputStream().
    Returns the MIME type of the body of the request, or null if the type is not known.
    Returns the portion of the request URI that indicates the context of the request.
    jakarta.servlet.http.Cookie[]
    Returns an array containing all of the Cookie objects the client sent with this request.
    Gets the currently processed Vaadin request.
    long
    Returns the value of the specified request header as a long value that represents a Date object.
    getHeader(String headerName)
    Gets the value of a request header, e.g.
    Returns an enumeration of all the header names this request contains.
    Returns all the values of the specified request header as an Enumeration of String objects.
    Returns an input stream from which the request content can be read.
    Gets locale information from the query, e.g.
    Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header.
    Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.
    getParameter(String parameter)
    Gets the named request parameter This is typically a HTTP GET or POST parameter, though other request types might have other ways of representing parameters.
    Gets all the parameters of the request.
    Gets the path of the requested resource relative to the application.
    Retrieves the body of the request as character data using a BufferedReader.
    Returns the IP address from which the request came.
    Returns the fully qualified name of the client or the last proxy that sent the request.
    int
    Returns the Internet Protocol (IP) source port of the client or last proxy that sent the request.
    Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated.
    Gets the vaadin service for the context of this request.
    Returns a java.security.Principal object containing the name of the current authenticated user.
    Gets the session associated with this request, creating a new if there is no session.
    getWrappedSession(boolean allowSessionCreation)
    Gets the session associated with this request, optionally creating a new if there is no session.
    boolean
    Checks whether the request was made using a secure channel, e.g.
    boolean
    Returns a boolean indicating whether the authenticated user is included in the specified logical "role".
    void
    Removes an attribute from this request.
    void
    setAttribute(String name, Object value)
    Defines a request attribute.
  • Method Details

    • getParameter

      String getParameter(String parameter)
      Gets the named request parameter This is typically a HTTP GET or POST parameter, though other request types might have other ways of representing parameters.
      Parameters:
      parameter - the name of the parameter
      Returns:
      The parameter value, or null if no parameter with the given name is present
      See Also:
      • ServletRequest.getParameter(String)
    • getParameterMap

      Map<String,String[]> getParameterMap()
      Gets all the parameters of the request.
      Returns:
      A mapping of parameter names to arrays of parameter values
      See Also:
    • getContentLength

      int getContentLength()
      Returns the length of the request content that can be read from the input stream returned by getInputStream().
      Returns:
      content length in bytes
      See Also:
      • ServletRequest.getContentLength()
    • getContentLengthLong

      default long getContentLengthLong()
      Returns the length of the request content that can be read from the input stream returned by getInputStream().
      Returns:
      a long containing the length of the request body or -1L if the length is not known
      See Also:
      • ServletRequest.getContentLengthLong()
    • getInputStream

      InputStream getInputStream() throws IOException
      Returns an input stream from which the request content can be read. The request content length can be obtained with getContentLength() without reading the full stream contents.
      Returns:
      the input stream from which the contents of the request can be read
      Throws:
      IOException - if the input stream can not be opened
      See Also:
      • ServletRequest.getInputStream()
    • getAttribute

      Object getAttribute(String name)
      Gets a request attribute.
      Parameters:
      name - the name of the attribute
      Returns:
      the value of the attribute, or null if there is no attribute with the given name
      See Also:
      • ServletRequest.getAttribute(String)
    • setAttribute

      void setAttribute(String name, Object value)
      Defines a request attribute.
      Parameters:
      name - the name of the attribute
      value - the attribute value
      See Also:
      • ServletRequest.setAttribute(String, Object)
    • getPathInfo

      String getPathInfo()
      Gets the path of the requested resource relative to the application. The path is null if no path information is available. Does always start with / if the path isn't null.
      Returns:
      a string with the path relative to the application.
      See Also:
      • HttpServletRequest.getPathInfo()
    • getContextPath

      String getContextPath()
      Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI.
      Returns:
      a String specifying the portion of the request URI that indicates the context of the request
      See Also:
      • HttpServletRequest.getContextPath()
    • getWrappedSession

      WrappedSession getWrappedSession()
      Gets the session associated with this request, creating a new if there is no session.
      Returns:
      the wrapped session for this request
      See Also:
    • getWrappedSession

      WrappedSession getWrappedSession(boolean allowSessionCreation)
      Gets the session associated with this request, optionally creating a new if there is no session.
      Parameters:
      allowSessionCreation - true to create a new session for this request if necessary; false to return null if there's no current session
      Returns:
      the wrapped session for this request
      See Also:
    • getContentType

      String getContentType()
      Returns the MIME type of the body of the request, or null if the type is not known.
      Returns:
      a string containing the name of the MIME type of the request, or null if the type is not known
      See Also:
      • ServletRequest.getContentType()
    • getLocale

      Locale getLocale()
      Gets locale information from the query, e.g. using the Accept-Language header.
      Returns:
      the preferred Locale
      See Also:
      • ServletRequest.getLocale()
    • getRemoteAddr

      String getRemoteAddr()
      Returns the IP address from which the request came. This might also be the address of a proxy between the server and the original requester.
      Returns:
      a string containing the IP address, or null if the address is not available
      See Also:
      • ServletRequest.getRemoteAddr()
    • isSecure

      boolean isSecure()
      Checks whether the request was made using a secure channel, e.g. using https.
      Returns:
      a boolean indicating if the request is secure
      See Also:
      • ServletRequest.isSecure()
    • getHeader

      String getHeader(String headerName)
      Gets the value of a request header, e.g. a http header for a HttpServletRequest.
      Parameters:
      headerName - the name of the header
      Returns:
      the header value, or null if the header is not present in the request
      See Also:
      • HttpServletRequest.getHeader(String)
    • getService

      VaadinService getService()
      Gets the vaadin service for the context of this request.
      Returns:
      the vaadin service
      See Also:
    • getCookies

      jakarta.servlet.http.Cookie[] getCookies()
      Returns an array containing all of the Cookie objects the client sent with this request. This method returns null if no cookies were sent.
      Returns:
      an array of all the Cookies included with this request, or null if the request has no cookies
      See Also:
      • HttpServletRequest.getCookies()
    • getAuthType

      String getAuthType()
      Returns the name of the authentication scheme used for the connection between client and server, for example, BASIC_AUTH, CLIENT_CERT_AUTH, a custom one or null if there was no authentication.
      Returns:
      a string indicating the authentication scheme, or null if the request was not authenticated.
      See Also:
      • HttpServletRequest.getAuthType()
    • getRemoteUser

      String getRemoteUser()
      Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated. Whether the user name is sent with each subsequent request depends on the browser and type of authentication.
      Returns:
      a String specifying the login of the user making this request, or null if the user login is not known.
      See Also:
      • HttpServletRequest.getRemoteUser()
    • getUserPrincipal

      Principal getUserPrincipal()
      Returns a java.security.Principal object containing the name of the current authenticated user. If the user has not been authenticated, the method returns null.
      Returns:
      a java.security.Principal containing the name of the user making this request; null if the user has not been authenticated
      See Also:
      • HttpServletRequest.getUserPrincipal()
    • isUserInRole

      boolean isUserInRole(String role)
      Returns a boolean indicating whether the authenticated user is included in the specified logical "role". Roles and role membership can be defined using deployment descriptors. If the user has not been authenticated, the method returns false.
      Parameters:
      role - a String specifying the name of the role
      Returns:
      a boolean indicating whether the user making this request belongs to a given role; false if the user has not been authenticated
      See Also:
      • HttpServletRequest.isUserInRole(String)
    • removeAttribute

      void removeAttribute(String name)
      Removes an attribute from this request. This method is not generally needed as attributes only persist as long as the request is being handled.
      Parameters:
      name - a String specifying the name of the attribute to remove
      See Also:
      • ServletRequest.removeAttribute(String)
    • getAttributeNames

      Enumeration<String> getAttributeNames()
      Returns an Enumeration containing the names of the attributes available to this request. This method returns an empty Enumeration if the request has no attributes available to it.
      Returns:
      an Enumeration of strings containing the names of the request's attributes
      See Also:
      • ServletRequest.getAttributeNames()
    • getLocales

      Enumeration<Locale> getLocales()
      Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header. If the client request doesn't provide an Accept-Language header, this method returns an Enumeration containing one Locale, the default locale for the server.
      Returns:
      an Enumeration of preferred Locale objects for the client
      See Also:
      • ServletRequest.getLocales()
    • getRemoteHost

      String getRemoteHost()
      Returns the fully qualified name of the client or the last proxy that sent the request. If the engine cannot or chooses not to resolve the hostname (to improve performance), this method returns the dotted-string form of the IP address.
      Returns:
      a String containing the fully qualified name of the client, or null if the information is not available.
      See Also:
      • ServletRequest.getRemoteHost()
    • getRemotePort

      int getRemotePort()
      Returns the Internet Protocol (IP) source port of the client or last proxy that sent the request.
      Returns:
      an integer specifying the port number, or -1 if the information is not available.
      See Also:
      • ServletRequest.getRemotePort()
    • getCharacterEncoding

      String getCharacterEncoding()
      Returns the name of the character encoding used in the body of this request. This method returns null if the request does not specify a character encoding.
      Returns:
      a String containing the name of the character encoding, or null if the request does not specify a character encoding
      See Also:
      • ServletRequest.getCharacterEncoding()
    • getReader

      BufferedReader getReader() throws IOException
      Retrieves the body of the request as character data using a BufferedReader. The reader translates the character data according to the character encoding used on the body. Either this method or getInputStream() may be called to read the body, not both.
      Returns:
      a BufferedReader containing the body of the request
      Throws:
      UnsupportedEncodingException - - if the character set encoding used is not supported and the text cannot be decoded
      IllegalStateException - - if getInputStream() method has been called on this request
      IOException - if an input or output exception occurred
      See Also:
      • ServletRequest.getReader()
    • getMethod

      String getMethod()
      Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.
      Returns:
      a String specifying the name of the method with which this request was made
      See Also:
      • HttpServletRequest.getMethod()
    • getDateHeader

      long getDateHeader(String name)
      Returns the value of the specified request header as a long value that represents a Date object. Use this method with headers that contain dates, such as If-Modified-Since.

      The date is returned as the number of milliseconds since January 1, 1970 GMT. The header name is case insensitive.

      If the request did not have a header of the specified name, this method returns -1. If the header can't be converted to a date, the method throws an IllegalArgumentException.

      Parameters:
      name - a String specifying the name of the header
      Returns:
      a long value representing the date specified in the header expressed as the number of milliseconds since January 1, 1970 GMT, or -1 if the named header was not included with the request
      Throws:
      IllegalArgumentException - If the header value can't be converted to a date
      See Also:
      • HttpServletRequest.getDateHeader(String)
    • getHeaderNames

      Enumeration<String> getHeaderNames()
      Returns an enumeration of all the header names this request contains. If the request has no headers, this method returns an empty enumeration.

      Some implementations do not allow access headers using this method, in which case this method returns null

      Returns:
      an enumeration of all the header names sent with this request; if the request has no headers, an empty enumeration; if the implementation does not allow this method, null
      See Also:
      • HttpServletRequest.getHeaderNames()
    • getHeaders

      Enumeration<String> getHeaders(String name)
      Returns all the values of the specified request header as an Enumeration of String objects.

      Some headers, such as Accept-Language can be sent by clients as several headers each with a different value rather than sending the header as a comma separated list.

      If the request did not include any headers of the specified name, this method returns an empty Enumeration. If the request does not support accessing headers, this method returns null.

      The header name is case insensitive. You can use this method with any request header.

      Parameters:
      name - a String specifying the header name
      Returns:
      an Enumeration containing the values of the requested header. If the request does not have any headers of that name return an empty enumeration. If the header information is not available, return null
      See Also:
      • HttpServletRequest.getHeaders(String)
    • getCurrent

      static VaadinRequest getCurrent()
      Gets the currently processed Vaadin request. The current request is automatically defined when the request is started. The current request can not be used in e.g. background threads because of the way server implementations reuse request instances.
      Returns:
      the current Vaadin request instance if available, otherwise null