Class MockServerRequest
- java.lang.Object
- org.springframework.mock.web.reactive.function.server.MockServerRequest
- All Implemented Interfaces:
ServerRequest
public final class MockServerRequest extends Object implements ServerRequest
Mock implementation ofServerRequest.- Since:
- 5.0
- Author:
- Arjen Poutsma
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceMockServerRequest.BuilderBuilder forMockServerRequest.Nested classes/interfaces inherited from interface org.springframework.web.reactive.function.server.ServerRequest
ServerRequest.Headers
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,Object>attributes()Get a mutable map of request attributes.<S> Sbody(BodyExtractor<S,? super ServerHttpRequest> extractor)Extract the body with the givenBodyExtractor.<S> Sbody(BodyExtractor<S,? super ServerHttpRequest> extractor, Map<String,Object> hints)Extract the body with the givenBodyExtractorand hints.<S> reactor.core.publisher.Flux<S>bodyToFlux(Class<? extends S> elementClass)Extract the body to aFlux.<S> reactor.core.publisher.Flux<S>bodyToFlux(ParameterizedTypeReference<S> typeReference)Extract the body to aFlux.<S> reactor.core.publisher.Mono<S>bodyToMono(Class<? extends S> elementClass)Extract the body to aMono.<S> reactor.core.publisher.Mono<S>bodyToMono(ParameterizedTypeReference<S> typeReference)Extract the body to aMono.static MockServerRequest.Builderbuilder()MultiValueMap<String,HttpCookie>cookies()Get the cookies of this request.ServerWebExchangeexchange()Get the web exchange that this request is based on.reactor.core.publisher.Mono<MultiValueMap<String,String>>formData()Get 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.Headersheaders()Get the headers of this request.Optional<InetSocketAddress>localAddress()Get the local address to which this request is connected, if available.List<HttpMessageReader<?>>messageReaders()Get the readers used to convert the body of this request.HttpMethodmethod()Get the HTTP method.StringmethodName()Get the name of the HTTP method.reactor.core.publisher.Mono<MultiValueMap<String,Part>>multipartData()Get the parts of a multipart request if the Content-Type is"multipart/form-data"or an empty map otherwise.PathContainerpathContainer()Get the request path as aPathContainer.Map<String,String>pathVariables()Get all path variables for this request.reactor.core.publisher.Mono<? extends Principal>principal()Get the authenticated user for the request, if any.MultiValueMap<String,String>queryParams()Get all query parameters for this request.Optional<InetSocketAddress>remoteAddress()Get the remote address to which this request is connected, if available.reactor.core.publisher.Mono<WebSession>session()Get the web session for this request.URIuri()Get the request URI.UriBuilderuriBuilder()Get aUriBuilderComponentsfrom the URI associated with thisServerRequest.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.web.reactive.function.server.ServerRequest
attribute, checkNotModified, checkNotModified, checkNotModified, path, pathVariable, queryParam
Method Detail
method
public HttpMethod method()
Description copied from interface:ServerRequestGet the HTTP method.- Specified by:
methodin interfaceServerRequest- Returns:
- the HTTP method as an HttpMethod enum value, or
nullif not resolvable (e.g. in case of a non-standard HTTP method)
methodName
public String methodName()
Description copied from interface:ServerRequestGet the name of the HTTP method.- Specified by:
methodNamein interfaceServerRequest- Returns:
- the HTTP method as a String
uri
public URI uri()
Description copied from interface:ServerRequestGet the request URI.- Specified by:
uriin interfaceServerRequest
uriBuilder
public UriBuilder uriBuilder()
Description copied from interface:ServerRequestGet aUriBuilderComponentsfrom the URI associated with thisServerRequest.Note: as of 5.1 this method ignores
"Forwarded"and"X-Forwarded-*"headers that specify the client-originated address. Consider using theForwardedHeaderFilterto extract and use, or to discard such headers.- Specified by:
uriBuilderin interfaceServerRequest- Returns:
- a URI builder
pathContainer
public PathContainer pathContainer()
Description copied from interface:ServerRequestGet the request path as aPathContainer.- Specified by:
pathContainerin interfaceServerRequest
headers
public ServerRequest.Headers headers()
Description copied from interface:ServerRequestGet the headers of this request.- Specified by:
headersin interfaceServerRequest
cookies
public MultiValueMap<String,HttpCookie> cookies()
Description copied from interface:ServerRequestGet the cookies of this request.- Specified by:
cookiesin interfaceServerRequest
remoteAddress
public Optional<InetSocketAddress> remoteAddress()
Description copied from interface:ServerRequestGet the remote address to which this request is connected, if available.- Specified by:
remoteAddressin interfaceServerRequest
localAddress
public Optional<InetSocketAddress> localAddress()
Description copied from interface:ServerRequestGet the local address to which this request is connected, if available.- Specified by:
localAddressin interfaceServerRequest
messageReaders
public List<HttpMessageReader<?>> messageReaders()
Description copied from interface:ServerRequestGet the readers used to convert the body of this request.- Specified by:
messageReadersin interfaceServerRequest
body
public <S> S body(BodyExtractor<S,? super ServerHttpRequest> extractor)
Description copied from interface:ServerRequestExtract the body with the givenBodyExtractor.- Specified by:
bodyin interfaceServerRequest- Type Parameters:
S- the type of the body returned- Parameters:
extractor- theBodyExtractorthat reads from the request- Returns:
- the extracted body
- See Also:
ServerRequest.body(BodyExtractor, Map)
body
public <S> S body(BodyExtractor<S,? super ServerHttpRequest> extractor, Map<String,Object> hints)
Description copied from interface:ServerRequestExtract the body with the givenBodyExtractorand hints.- Specified by:
bodyin interfaceServerRequest- Type Parameters:
S- the type of the body returned- Parameters:
extractor- theBodyExtractorthat reads from the requesthints- the map of hints likeJackson2CodecSupport.JSON_VIEW_HINTto use to customize body extraction- Returns:
- the extracted body
bodyToMono
public <S> reactor.core.publisher.Mono<S> bodyToMono(Class<? extends S> elementClass)
Description copied from interface:ServerRequestExtract the body to aMono.- Specified by:
bodyToMonoin interfaceServerRequest- Type Parameters:
S- the element type- Parameters:
elementClass- the class of element in theMono- Returns:
- the body as a mono
bodyToMono
public <S> reactor.core.publisher.Mono<S> bodyToMono(ParameterizedTypeReference<S> typeReference)
Description copied from interface:ServerRequestExtract the body to aMono.- Specified by:
bodyToMonoin interfaceServerRequest- Type Parameters:
S- the element type- Parameters:
typeReference- a type reference describing the expected response request type- Returns:
- a mono containing the body of the given type
T
bodyToFlux
public <S> reactor.core.publisher.Flux<S> bodyToFlux(Class<? extends S> elementClass)
Description copied from interface:ServerRequestExtract the body to aFlux.- Specified by:
bodyToFluxin interfaceServerRequest- Type Parameters:
S- the element type- Parameters:
elementClass- the class of element in theFlux- Returns:
- the body as a flux
bodyToFlux
public <S> reactor.core.publisher.Flux<S> bodyToFlux(ParameterizedTypeReference<S> typeReference)
Description copied from interface:ServerRequestExtract the body to aFlux.- Specified by:
bodyToFluxin interfaceServerRequest- Type Parameters:
S- the element type- Parameters:
typeReference- a type reference describing the expected request body type- Returns:
- a flux containing the body of the given type
T
attributes
public Map<String,Object> attributes()
Description copied from interface:ServerRequestGet a mutable map of request attributes.- Specified by:
attributesin interfaceServerRequest- Returns:
- the request attributes
queryParams
public MultiValueMap<String,String> queryParams()
Description copied from interface:ServerRequestGet all query parameters for this request.- Specified by:
queryParamsin interfaceServerRequest
pathVariables
public Map<String,String> pathVariables()
Description copied from interface:ServerRequestGet all path variables for this request.- Specified by:
pathVariablesin interfaceServerRequest
session
public reactor.core.publisher.Mono<WebSession> session()
Description copied from interface:ServerRequestGet the web session for this request.Always guaranteed to return an instance either matching the session id requested by the client, or with a new session id either because the client did not specify one or because the underlying session had expired.
Use of this method does not automatically create a session.
- Specified by:
sessionin interfaceServerRequest
principal
public reactor.core.publisher.Mono<? extends Principal> principal()
Description copied from interface:ServerRequestGet the authenticated user for the request, if any.- Specified by:
principalin interfaceServerRequest
formData
public reactor.core.publisher.Mono<MultiValueMap<String,String>> formData()
Description copied from interface:ServerRequestGet the form data from the body of the request if the Content-Type is"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
MultiValueMapis cached so that this method is safe to call more than once.- Specified by:
formDatain interfaceServerRequest
multipartData
public reactor.core.publisher.Mono<MultiValueMap<String,Part>> multipartData()
Description copied from interface:ServerRequestGet the parts of a multipart request if the Content-Type is"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
MultiValueMapis cached so that this method is safe to call more than once.- Specified by:
multipartDatain interfaceServerRequest
exchange
public ServerWebExchange exchange()
Description copied from interface:ServerRequestGet the web exchange that this request is based on.Note: Manipulating the exchange directly (instead of using the methods provided on
ServerRequestandServerResponse) can lead to irregular results.- Specified by:
exchangein interfaceServerRequest
builder
public static MockServerRequest.Builder builder()