public interface ServerRequest
HandlerFunction
.
Access to headers and body is offered by ServerRequest.Headers
and
body(Class)
, respectively.Modifier and Type | Interface and Description |
---|---|
static interface |
ServerRequest.Builder
Defines a builder for a request.
|
static interface |
ServerRequest.Headers
Represents the headers of the HTTP request.
|
Modifier and Type | Method and Description |
---|---|
default java.util.Optional<java.lang.Object> |
attribute(java.lang.String name)
Get the request attribute value if present.
|
java.util.Map<java.lang.String,java.lang.Object> |
attributes()
Get a mutable map of request attributes.
|
<T> T |
body(java.lang.Class<T> bodyType)
Extract the body as an object of the given type.
|
<T> T |
body(ParameterizedTypeReference<T> bodyType)
Extract the body as an object of the given type.
|
MultiValueMap<java.lang.String,Cookie> |
cookies()
Get the cookies of this request.
|
static ServerRequest |
create(HttpServletRequest servletRequest,
java.util.List<HttpMessageConverter<?>> messageReaders)
Create a new
ServerRequest based on the given HttpServletRequest and
message converters. |
static ServerRequest.Builder |
from(ServerRequest other)
Create a builder with the status, headers, and cookies of the given request.
|
ServerRequest.Headers |
headers()
Get the headers of this request.
|
java.util.List<HttpMessageConverter<?>> |
messageConverters()
Get the readers used to convert the body of this request.
|
default HttpMethod |
method()
Get the HTTP method.
|
java.lang.String |
methodName()
Get the name of the HTTP method.
|
default java.util.Optional<java.lang.String> |
param(java.lang.String name)
Get the first query parameter with the given name, if present.
|
MultiValueMap<java.lang.String,java.lang.String> |
params()
Get all query parameters for this request.
|
default java.lang.String |
path()
Get the request path.
|
default PathContainer |
pathContainer()
Get the request path as a
PathContainer . |
default java.lang.String |
pathVariable(java.lang.String name)
Get the path variable with the given name, if present.
|
java.util.Map<java.lang.String,java.lang.String> |
pathVariables()
Get all path variables for this request.
|
java.util.Optional<java.security.Principal> |
principal()
Get the authenticated user for the request, if any.
|
java.util.Optional<java.net.InetSocketAddress> |
remoteAddress()
Get the remote address to which this request is connected, if available.
|
HttpServletRequest |
servletRequest()
Get the servlet request that this request is based on.
|
HttpSession |
session()
Get the web session for this request.
|
java.net.URI |
uri()
Get the request URI.
|
UriBuilder |
uriBuilder()
Get a
UriBuilderComponents from the URI associated with this
ServerRequest . |
@Nullable default HttpMethod method()
null
if not resolvable (e.g. in case of a non-standard HTTP method)java.lang.String methodName()
java.net.URI uri()
UriBuilder uriBuilder()
UriBuilderComponents
from the URI associated with this
ServerRequest
.default java.lang.String path()
default PathContainer pathContainer()
PathContainer
.ServerRequest.Headers headers()
MultiValueMap<java.lang.String,Cookie> cookies()
java.util.Optional<java.net.InetSocketAddress> remoteAddress()
java.util.List<HttpMessageConverter<?>> messageConverters()
<T> T body(java.lang.Class<T> bodyType) throws ServletException, java.io.IOException
T
- the body typebodyType
- the type of return valueServletException
java.io.IOException
<T> T body(ParameterizedTypeReference<T> bodyType) throws ServletException, java.io.IOException
T
- the body typebodyType
- the type of return valueServletException
java.io.IOException
default java.util.Optional<java.lang.Object> attribute(java.lang.String name)
name
- the attribute namejava.util.Map<java.lang.String,java.lang.Object> attributes()
default java.util.Optional<java.lang.String> param(java.lang.String name)
name
- the parameter nameMultiValueMap<java.lang.String,java.lang.String> params()
default java.lang.String pathVariable(java.lang.String name)
name
- the variable namejava.lang.IllegalArgumentException
- if there is no path variable with the given namejava.util.Map<java.lang.String,java.lang.String> pathVariables()
HttpSession session()
java.util.Optional<java.security.Principal> principal()
HttpServletRequest servletRequest()
static ServerRequest create(HttpServletRequest servletRequest, java.util.List<HttpMessageConverter<?>> messageReaders)
ServerRequest
based on the given HttpServletRequest
and
message converters.servletRequest
- the requestmessageReaders
- the message readersServerRequest
static ServerRequest.Builder from(ServerRequest other)
other
- the response to copy the status, headers, and cookies from