com.vaadin.flow.server.
Interface VaadinRequest
All Known Implementing Classes:
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 TypeMethodDescriptiongetAttribute
(String name) 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 ornull
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.static VaadinRequest
Gets the currently processed Vaadin request.
long
getDateHeader
(String name) Returns the value of the specified request header as a long value that represents a Date object.
Gets the value of a request header, e.g.
Returns an enumeration of all the header names this request contains.
getHeaders
(String name) 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
isSecure()
Checks whether the request was made using a secure channel, e.g.
boolean
isUserInRole
(String role) Returns a boolean indicating whether the authenticated user is included in the specified logical "role".
void
removeAttribute
(String name) Removes an attribute from this request.
void
setAttribute
(String name, Object value) Defines a request attribute.
-
Method Details
-
getParameter
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.
ServletRequest.getParameter(String)
Parameters:
parameter
- the name of the parameterReturns:
The parameter value, or
null
if no parameter with the given name is presentSee Also:
-
getParameterMap
Gets all the parameters of the request.
getParameter(String)
ServletRequest.getParameterMap()
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()
.ServletRequest.getContentLength()
Returns:
content length in bytes
See Also:
-
getContentLengthLong
default long getContentLengthLong()Returns the length of the request content that can be read from the input stream returned by
getInputStream()
.ServletRequest.getContentLengthLong()
Returns:
a long containing the length of the request body or -1L if the length is not known
See Also:
-
getInputStream
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.ServletRequest.getInputStream()
Returns:
the input stream from which the contents of the request can be read
Throws:
IOException
- if the input stream can not be openedSee Also:
-
getAttribute
Gets a request attribute.
ServletRequest.getAttribute(String)
Parameters:
name
- the name of the attributeReturns:
the value of the attribute, or
null
if there is no attribute with the given nameSee Also:
-
setAttribute
Defines a request attribute.
ServletRequest.setAttribute(String, Object)
Parameters:
name
- the name of the attributevalue
- the attribute valueSee Also:
-
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'tnull
.HttpServletRequest.getPathInfo()
Returns:
a string with the path relative to the application.
See Also:
-
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.
HttpServletRequest.getContextPath()
Returns:
a String specifying the portion of the request URI that indicates the context of the request
See Also:
-
getWrappedSession
WrappedSession getWrappedSession()Gets the session associated with this request, creating a new if there is no session.
WrappedSession
HttpServletRequest.getSession()
Returns:
the wrapped session for this request
See Also:
-
getWrappedSession
Gets the session associated with this request, optionally creating a new if there is no session.
WrappedSession
HttpServletRequest.getSession(boolean)
Parameters:
allowSessionCreation
-true
to create a new session for this request if necessary;false
to returnnull
if there's no current sessionReturns:
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.
ServletRequest.getContentType()
Returns:
a string containing the name of the MIME type of the request, or null if the type is not known
See Also:
-
getLocale
Locale getLocale()Gets locale information from the query, e.g. using the Accept-Language header.
ServletRequest.getLocale()
Returns:
the preferred Locale
See Also:
-
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.
ServletRequest.getRemoteAddr()
Returns:
a string containing the IP address, or
null
if the address is not availableSee Also:
-
isSecure
boolean isSecure()Checks whether the request was made using a secure channel, e.g. using https.
ServletRequest.isSecure()
Returns:
a boolean indicating if the request is secure
See Also:
-
getHeader
Gets the value of a request header, e.g. a http header for a
HttpServletRequest
.HttpServletRequest.getHeader(String)
Parameters:
headerName
- the name of the headerReturns:
the header value, or
null
if the header is not present in the requestSee Also:
-
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 returnsnull
if no cookies were sent.HttpServletRequest.getCookies()
Returns:
an array of all the
Cookies
included with this request, ornull
if the request has no cookiesSee Also:
-
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 ornull
if there was no authentication.HttpServletRequest.getAuthType()
Returns:
a string indicating the authentication scheme, or
null
if the request was not authenticated.See Also:
-
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.
HttpServletRequest.getRemoteUser()
Returns:
a String specifying the login of the user making this request, or
null
if the user login is not known.See Also:
-
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 returnsnull
.HttpServletRequest.getUserPrincipal()
Returns:
a
java.security.Principal
containing the name of the user making this request;null
if the user has not been authenticatedSee Also:
-
isUserInRole
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
.HttpServletRequest.isUserInRole(String)
Parameters:
role
- a String specifying the name of the roleReturns:
a boolean indicating whether the user making this request belongs to a given role;
false
if the user has not been authenticatedSee Also:
-
removeAttribute
Removes an attribute from this request. This method is not generally needed as attributes only persist as long as the request is being handled.
ServletRequest.removeAttribute(String)
Parameters:
name
- a String specifying the name of the attribute to removeSee Also:
-
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.
ServletRequest.getAttributeNames()
Returns:
an Enumeration of strings containing the names of the request's attributes
See Also:
-
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.
ServletRequest.getLocales()
Returns:
an Enumeration of preferred Locale objects for the client
See Also:
-
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.
ServletRequest.getRemoteHost()
Returns:
a String containing the fully qualified name of the client, or
null
if the information is not available.See Also:
-
getRemotePort
int getRemotePort()Returns the Internet Protocol (IP) source port of the client or last proxy that sent the request.
ServletRequest.getRemotePort()
Returns:
an integer specifying the port number, or -1 if the information is not available.
See Also:
-
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.ServletRequest.getCharacterEncoding()
Returns:
a String containing the name of the character encoding, or null if the request does not specify a character encoding
See Also:
-
getReader
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 orgetInputStream()
may be called to read the body, not both.ServletRequest.getReader()
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 decodedIllegalStateException
- - ifgetInputStream()
method has been called on this requestIOException
- if an input or output exception occurredSee Also:
-
getMethod
String getMethod()Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.
HttpServletRequest.getMethod()
Returns:
a String specifying the name of the method with which this request was made
See Also:
-
getDateHeader
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.
HttpServletRequest.getDateHeader(String)
Parameters:
name
- a String specifying the name of the headerReturns:
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 dateSee Also:
-
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
HttpServletRequest.getHeaderNames()
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:
-
getHeaders
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.
HttpServletRequest.getHeaders(String)
Parameters:
name
- a String specifying the header nameReturns:
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:
-
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
-