public final class MockServerRequest extends java.lang.Object implements ServerRequest
ServerRequest
.Modifier and Type | Class and Description |
---|---|
static interface |
MockServerRequest.Builder
Builder for
MockServerRequest . |
private static class |
MockServerRequest.BuilderImpl |
private static class |
MockServerRequest.MockHeaders |
ServerRequest.Headers
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.String,java.lang.Object> |
attributes |
private java.lang.Object |
body |
private MultiValueMap<java.lang.String,HttpCookie> |
cookies |
private ServerWebExchange |
exchange |
private MockServerRequest.MockHeaders |
headers |
private java.util.List<HttpMessageReader<?>> |
messageReaders |
private HttpMethod |
method |
private RequestPath |
pathContainer |
private java.util.Map<java.lang.String,java.lang.String> |
pathVariables |
private java.security.Principal |
principal |
private MultiValueMap<java.lang.String,java.lang.String> |
queryParams |
private java.net.InetSocketAddress |
remoteAddress |
private WebSession |
session |
private java.net.URI |
uri |
Modifier | Constructor and Description |
---|---|
private |
MockServerRequest(HttpMethod method,
java.net.URI uri,
java.lang.String contextPath,
MockServerRequest.MockHeaders headers,
MultiValueMap<java.lang.String,HttpCookie> cookies,
java.lang.Object body,
java.util.Map<java.lang.String,java.lang.Object> attributes,
MultiValueMap<java.lang.String,java.lang.String> queryParams,
java.util.Map<java.lang.String,java.lang.String> pathVariables,
WebSession session,
java.security.Principal principal,
java.net.InetSocketAddress remoteAddress,
java.util.List<HttpMessageReader<?>> messageReaders,
ServerWebExchange exchange) |
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.String,java.lang.Object> |
attributes()
Return a mutable map of request attributes.
|
<S> S |
body(BodyExtractor<S,? super ServerHttpRequest> extractor)
Extract the body with the given
BodyExtractor . |
<S> S |
body(BodyExtractor<S,? super ServerHttpRequest> extractor,
java.util.Map<java.lang.String,java.lang.Object> hints)
Extract the body with the given
BodyExtractor and hints. |
<S> <any> |
bodyToFlux(java.lang.Class<? extends S> elementClass)
Extract the body to a
Flux . |
<S> <any> |
bodyToFlux(ParameterizedTypeReference<S> typeReference)
Extract the body to a
Flux . |
<S> <any> |
bodyToMono(java.lang.Class<? extends S> elementClass)
Extract the body to a
Mono . |
<S> <any> |
bodyToMono(ParameterizedTypeReference<S> typeReference)
Extract the body to a
Mono . |
static MockServerRequest.Builder |
builder() |
MultiValueMap<java.lang.String,HttpCookie> |
cookies()
Return the cookies of this request.
|
ServerWebExchange |
exchange()
Return the web exchange that this request is based on.
|
<any> |
formData()
Return the form data from the body of the request if the Content-Type is
"application/x-www-form-urlencoded" or an empty map otherwise. |
ServerRequest.Headers |
headers()
Return the headers of this request.
|
java.util.List<HttpMessageReader<?>> |
messageReaders()
Return the readers used to convert the body of this request.
|
HttpMethod |
method()
Return the HTTP method.
|
java.lang.String |
methodName()
Return the name of the HTTP method.
|
<any> |
multipartData()
Return the parts of a multipart request if the Content-Type is
"multipart/form-data" or an empty map otherwise. |
PathContainer |
pathContainer()
Return the request path as
PathContainer . |
java.util.Map<java.lang.String,java.lang.String> |
pathVariables()
Return all path variables for this request.
|
<any> |
principal()
Return the authenticated user for the request, if any.
|
MultiValueMap<java.lang.String,java.lang.String> |
queryParams()
Return all query parameters for this request.
|
java.util.Optional<java.net.InetSocketAddress> |
remoteAddress()
Return the remote address where this request is connected to, if available.
|
<any> |
session()
Return the web session for this request.
|
java.net.URI |
uri()
Return the request URI.
|
UriBuilder |
uriBuilder()
Return a
UriBuilderComponents from the URI associated with this
ServerRequest . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
attribute, create, from, path, pathVariable, queryParam
private final HttpMethod method
private final java.net.URI uri
private final RequestPath pathContainer
private final MockServerRequest.MockHeaders headers
private final MultiValueMap<java.lang.String,HttpCookie> cookies
@Nullable private final java.lang.Object body
private final java.util.Map<java.lang.String,java.lang.Object> attributes
private final MultiValueMap<java.lang.String,java.lang.String> queryParams
private final java.util.Map<java.lang.String,java.lang.String> pathVariables
@Nullable private final WebSession session
@Nullable private java.security.Principal principal
@Nullable private final java.net.InetSocketAddress remoteAddress
private final java.util.List<HttpMessageReader<?>> messageReaders
@Nullable private final ServerWebExchange exchange
private MockServerRequest(HttpMethod method, java.net.URI uri, java.lang.String contextPath, MockServerRequest.MockHeaders headers, MultiValueMap<java.lang.String,HttpCookie> cookies, @Nullable java.lang.Object body, java.util.Map<java.lang.String,java.lang.Object> attributes, MultiValueMap<java.lang.String,java.lang.String> queryParams, java.util.Map<java.lang.String,java.lang.String> pathVariables, @Nullable WebSession session, @Nullable java.security.Principal principal, @Nullable java.net.InetSocketAddress remoteAddress, java.util.List<HttpMessageReader<?>> messageReaders, @Nullable ServerWebExchange exchange)
public HttpMethod method()
ServerRequest
method
in interface ServerRequest
null
if not resolvable (e.g. in case of a non-standard HTTP method)public java.lang.String methodName()
ServerRequest
methodName
in interface ServerRequest
public java.net.URI uri()
ServerRequest
uri
in interface ServerRequest
public UriBuilder uriBuilder()
ServerRequest
UriBuilderComponents
from the URI associated with this
ServerRequest
.
Note: as of 5.1 this method ignores
"Forwarded"
and "X-Forwarded-*"
headers that specify the
client-originated address. Consider using the ForwardedHeaderFilter
to extract and use, or to discard such headers.
uriBuilder
in interface ServerRequest
public PathContainer pathContainer()
ServerRequest
PathContainer
.pathContainer
in interface ServerRequest
public ServerRequest.Headers headers()
ServerRequest
headers
in interface ServerRequest
public MultiValueMap<java.lang.String,HttpCookie> cookies()
ServerRequest
cookies
in interface ServerRequest
public java.util.Optional<java.net.InetSocketAddress> remoteAddress()
ServerRequest
remoteAddress
in interface ServerRequest
public java.util.List<HttpMessageReader<?>> messageReaders()
ServerRequest
messageReaders
in interface ServerRequest
public <S> S body(BodyExtractor<S,? super ServerHttpRequest> extractor)
ServerRequest
BodyExtractor
.body
in interface ServerRequest
S
- the type of the body returnedextractor
- the BodyExtractor
that reads from the requestServerRequest.body(BodyExtractor, Map)
public <S> S body(BodyExtractor<S,? super ServerHttpRequest> extractor, java.util.Map<java.lang.String,java.lang.Object> hints)
ServerRequest
BodyExtractor
and hints.body
in interface ServerRequest
S
- the type of the body returnedextractor
- the BodyExtractor
that reads from the requesthints
- the map of hints like Jackson2CodecSupport.JSON_VIEW_HINT
to use to customize body extractionpublic <S> <any> bodyToMono(java.lang.Class<? extends S> elementClass)
ServerRequest
Mono
.bodyToMono
in interface ServerRequest
S
- the element typeelementClass
- the class of element in the Mono
public <S> <any> bodyToMono(ParameterizedTypeReference<S> typeReference)
ServerRequest
Mono
.bodyToMono
in interface ServerRequest
S
- the element typetypeReference
- a type reference describing the expected response request typeT
public <S> <any> bodyToFlux(java.lang.Class<? extends S> elementClass)
ServerRequest
Flux
.bodyToFlux
in interface ServerRequest
S
- the element typeelementClass
- the class of element in the Flux
public <S> <any> bodyToFlux(ParameterizedTypeReference<S> typeReference)
ServerRequest
Flux
.bodyToFlux
in interface ServerRequest
S
- the element typetypeReference
- a type reference describing the expected request body typeT
public java.util.Map<java.lang.String,java.lang.Object> attributes()
ServerRequest
attributes
in interface ServerRequest
public MultiValueMap<java.lang.String,java.lang.String> queryParams()
ServerRequest
queryParams
in interface ServerRequest
public java.util.Map<java.lang.String,java.lang.String> pathVariables()
ServerRequest
pathVariables
in interface ServerRequest
public <any> session()
ServerRequest
session
in interface ServerRequest
public <any> principal()
ServerRequest
principal
in interface ServerRequest
public <any> formData()
ServerRequest
"application/x-www-form-urlencoded"
or an empty map otherwise.
Note: calling this method causes the request body to
be read and parsed in full and the resulting MultiValueMap
is
cached so that this method is safe to call more than once.
formData
in interface ServerRequest
public <any> multipartData()
ServerRequest
"multipart/form-data"
or an empty map otherwise.
Note: calling this method causes the request body to
be read and parsed in full and the resulting MultiValueMap
is
cached so that this method is safe to call more than once.
multipartData
in interface ServerRequest
public ServerWebExchange exchange()
ServerRequest
Note: Manipulating the exchange directly (instead of using the methods provided on
ServerRequest
and ServerResponse
) can lead to irregular results.
exchange
in interface ServerRequest
public static MockServerRequest.Builder builder()