Class MockServerHttpRequest
java.lang.Object
org.springframework.http.server.reactive.AbstractServerHttpRequest
org.springframework.mock.http.server.reactive.MockServerHttpRequest
- All Implemented Interfaces:
HttpMessage
,HttpRequest
,ReactiveHttpInputMessage
,ServerHttpRequest
Mock extension of
AbstractServerHttpRequest
for use in tests without
an actual server. Use the static methods to obtain a builder.- Since:
- 5.0
- Author:
- Rossen Stoyanchev
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Request builder exposing properties not related to the body.static interface
A builder that adds a body to the request.Nested classes/interfaces inherited from interface org.springframework.http.server.reactive.ServerHttpRequest
ServerHttpRequest.Builder
-
Method Summary
Modifier and TypeMethodDescriptionstatic MockServerHttpRequest.BaseBuilder<?>
HTTP DELETE variant.static MockServerHttpRequest.BaseBuilder<?>
Create an HTTP GET builder with the given URI template.reactor.core.publisher.Flux<DataBuffer>
getBody()
Return the body of the message as aPublisher
.Return the local address the request was accepted on, if available.Return the HTTP method of the request.Deprecated.<T> T
Return the underlying server response.Return the remote address where this request is connected to, if available.static MockServerHttpRequest.BaseBuilder<?>
HTTP HEAD variant.protected MultiValueMap<String,
HttpCookie> Obtain the cookies from the underlying "native" request and adapt those to anHttpCookie
map.protected SslInfo
Obtain SSL session information from the underlying "native" request.Deprecated.method
(HttpMethod method, String uri, Object... vars) Alternative tomethod(HttpMethod, URI)
that accepts a URI template.method
(HttpMethod method, URI url) Create a builder with the given HTTP method and aURI
.static MockServerHttpRequest.BaseBuilder<?>
HTTP OPTIONS variant.HTTP PATCH variant.HTTP POST variant.HTTP PUT variant.Methods inherited from class org.springframework.http.server.reactive.AbstractServerHttpRequest
getCookies, getHeaders, getId, getPath, getQueryParams, getSslInfo, getURI, initId, initLogPrefix, initQueryParams
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.http.server.reactive.ServerHttpRequest
mutate
-
Method Details
-
getMethod
Description copied from interface:HttpRequest
Return the HTTP method of the request.- Returns:
- the HTTP method as an HttpMethod value
- See Also:
-
getMethodValue
Deprecated.Description copied from interface:HttpRequest
Return the HTTP method of the request as a String value.- Returns:
- the HTTP method as a plain String
- See Also:
-
getLocalAddress
Description copied from interface:ServerHttpRequest
Return the local address the request was accepted on, if available. -
getRemoteAddress
Description copied from interface:ServerHttpRequest
Return the remote address where this request is connected to, if available. -
initSslInfo
Description copied from class:AbstractServerHttpRequest
Obtain SSL session information from the underlying "native" request.- Specified by:
initSslInfo
in classAbstractServerHttpRequest
- Returns:
- the session information, or
null
if none available
-
getBody
Description copied from interface:ReactiveHttpInputMessage
Return the body of the message as aPublisher
.- Returns:
- the body content publisher
-
initCookies
Description copied from class:AbstractServerHttpRequest
Obtain the cookies from the underlying "native" request and adapt those to anHttpCookie
map. The return value is turned into an immutable map and cached.Note that this method is invoked lazily on access to
AbstractServerHttpRequest.getCookies()
. Subclasses should synchronize cookie initialization if the underlying "native" request does not provide thread-safe access to cookie data.- Specified by:
initCookies
in classAbstractServerHttpRequest
-
getNativeRequest
public <T> T getNativeRequest()Description copied from class:AbstractServerHttpRequest
Return the underlying server response.Note: This is exposed mainly for internal framework use such as WebSocket upgrades in the spring-webflux module.
- Specified by:
getNativeRequest
in classAbstractServerHttpRequest
-
get
Create an HTTP GET builder with the given URI template. The given URI may contain query parameters, or those may be added later viaqueryParam
builder methods.- Parameters:
urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variables- Returns:
- the created builder
-
head
HTTP HEAD variant. Seeget(String, Object...)
for general info.- Parameters:
urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variables- Returns:
- the created builder
-
post
HTTP POST variant. Seeget(String, Object...)
for general info.- Parameters:
urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variables- Returns:
- the created builder
-
put
HTTP PUT variant. Seeget(String, Object...)
for general info.queryParam
builder methods.- Parameters:
urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variables- Returns:
- the created builder
-
patch
HTTP PATCH variant. Seeget(String, Object...)
for general info.- Parameters:
urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variables- Returns:
- the created builder
-
delete
HTTP DELETE variant. Seeget(String, Object...)
for general info.- Parameters:
urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variables- Returns:
- the created builder
-
options
HTTP OPTIONS variant. Seeget(String, Object...)
for general info.- Parameters:
urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variables- Returns:
- the created builder
-
method
Create a builder with the given HTTP method and aURI
.- Parameters:
method
- the HTTP method (GET, POST, etc)url
- the URL- Returns:
- the created builder
-
method
public static MockServerHttpRequest.BodyBuilder method(HttpMethod method, String uri, Object... vars) Alternative tomethod(HttpMethod, URI)
that accepts a URI template. The given URI may contain query parameters, or those may be added later viaqueryParam
builder methods.- Parameters:
method
- the HTTP method (GET, POST, etc)uri
- the URI template for the target URLvars
- variables to expand into the template- Returns:
- the created builder
-
method
@Deprecated(since="6.0") public static MockServerHttpRequest.BodyBuilder method(String httpMethod, String uri, Object... vars) Deprecated.as of Spring Framework 6.0 in favor ofmethod(HttpMethod, String, Object...)
Create a builder with a raw HTTP method value that is outside the range ofHttpMethod
enum values.- Parameters:
httpMethod
- the HTTP methodValue valueuri
- the URI template for target the URLvars
- variables to expand into the template- Returns:
- the created builder
- Since:
- 5.2.7
-
method(HttpMethod, String, Object...)