public final class MockServerHttpRequest extends AbstractServerHttpRequest
AbstractServerHttpRequest
for use in tests without
an actual server. Use the static methods to obtain a builder.Modifier and Type | Class and Description |
---|---|
static interface |
MockServerHttpRequest.BaseBuilder<B extends MockServerHttpRequest.BaseBuilder<B>>
Request builder exposing properties not related to the body.
|
static interface |
MockServerHttpRequest.BodyBuilder
A builder that adds a body to the request.
|
ServerHttpRequest.Builder
logger
Modifier and Type | Method and Description |
---|---|
static MockServerHttpRequest.BaseBuilder<?> |
delete(java.lang.String urlTemplate,
java.lang.Object... uriVars)
HTTP DELETE variant.
|
static MockServerHttpRequest.BaseBuilder<?> |
get(java.lang.String urlTemplate,
java.lang.Object... uriVars)
Create an HTTP GET builder with the given URI template.
|
reactor.core.publisher.Flux<DataBuffer> |
getBody()
Return the body of the message as a
Publisher . |
HttpMethod |
getMethod()
Return the HTTP method of the request.
|
java.lang.String |
getMethodValue()
Return the HTTP method of the request as a String value.
|
<T> T |
getNativeRequest()
Return the underlying server response.
|
java.net.InetSocketAddress |
getRemoteAddress()
Return the remote address where this request is connected to, if available.
|
static MockServerHttpRequest.BaseBuilder<?> |
head(java.lang.String urlTemplate,
java.lang.Object... uriVars)
HTTP HEAD variant.
|
protected MultiValueMap<java.lang.String,HttpCookie> |
initCookies()
Obtain the cookies from the underlying "native" request and adapt those to
an
HttpCookie map. |
protected SslInfo |
initSslInfo()
Obtain SSL session information from the underlying "native" request.
|
static MockServerHttpRequest.BodyBuilder |
method(HttpMethod method,
java.lang.String urlTemplate,
java.lang.Object... vars)
Alternative to
method(HttpMethod, URI) that accepts a URI template. |
static MockServerHttpRequest.BodyBuilder |
method(HttpMethod method,
java.net.URI url)
Create a builder with the given HTTP method and a
URI . |
static MockServerHttpRequest.BaseBuilder<?> |
options(java.lang.String urlTemplate,
java.lang.Object... uriVars)
HTTP OPTIONS variant.
|
static MockServerHttpRequest.BodyBuilder |
patch(java.lang.String urlTemplate,
java.lang.Object... uriVars)
HTTP PATCH variant.
|
static MockServerHttpRequest.BodyBuilder |
post(java.lang.String urlTemplate,
java.lang.Object... uriVars)
HTTP POST variant.
|
static MockServerHttpRequest.BodyBuilder |
put(java.lang.String urlTemplate,
java.lang.Object... uriVars)
HTTP PUT variant.
|
getCookies, getHeaders, getId, getPath, getQueryParams, getSslInfo, getURI, initId, initQueryParams
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
mutate
public HttpMethod getMethod()
HttpRequest
null
if not resolvable (e.g. in case of a non-standard HTTP method)HttpRequest.getMethodValue()
,
HttpMethod.resolve(String)
public java.lang.String getMethodValue()
HttpRequest
HttpRequest.getMethod()
@Nullable public java.net.InetSocketAddress getRemoteAddress()
ServerHttpRequest
@Nullable protected SslInfo initSslInfo()
AbstractServerHttpRequest
initSslInfo
in class AbstractServerHttpRequest
null
if none availablepublic reactor.core.publisher.Flux<DataBuffer> getBody()
ReactiveHttpInputMessage
Publisher
.protected MultiValueMap<java.lang.String,HttpCookie> initCookies()
AbstractServerHttpRequest
HttpCookie
map. The return value is turned into an immutable
map and cached.
Note that this method is invoked lazily on access to
AbstractServerHttpRequest.getCookies()
. Sub-classes should synchronize cookie
initialization if the underlying "native" request does not provide
thread-safe access to cookie data.
initCookies
in class AbstractServerHttpRequest
public <T> T getNativeRequest()
AbstractServerHttpRequest
Note: This is exposed mainly for internal framework use such as WebSocket upgrades in the spring-webflux module.
getNativeRequest
in class AbstractServerHttpRequest
public static MockServerHttpRequest.BodyBuilder method(HttpMethod method, java.net.URI url)
URI
.method
- the HTTP method (GET, POST, etc)url
- the URLpublic static MockServerHttpRequest.BodyBuilder method(HttpMethod method, java.lang.String urlTemplate, java.lang.Object... vars)
method(HttpMethod, URI)
that accepts a URI template.
The given URI may contain query parameters, or those may be added later via
queryParam
builder methods.method
- the HTTP method (GET, POST, etc)urlTemplate
- the URL templatevars
- variables to expand into the templatepublic static MockServerHttpRequest.BaseBuilder<?> get(java.lang.String urlTemplate, java.lang.Object... uriVars)
queryParam
builder methods.urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variablespublic static MockServerHttpRequest.BaseBuilder<?> head(java.lang.String urlTemplate, java.lang.Object... uriVars)
get(String, Object...)
for general info.urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variablespublic static MockServerHttpRequest.BodyBuilder post(java.lang.String urlTemplate, java.lang.Object... uriVars)
get(String, Object...)
for general info.urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variablespublic static MockServerHttpRequest.BodyBuilder put(java.lang.String urlTemplate, java.lang.Object... uriVars)
get(String, Object...)
for general info.
queryParam
builder methods.urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variablespublic static MockServerHttpRequest.BodyBuilder patch(java.lang.String urlTemplate, java.lang.Object... uriVars)
get(String, Object...)
for general info.urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variablespublic static MockServerHttpRequest.BaseBuilder<?> delete(java.lang.String urlTemplate, java.lang.Object... uriVars)
get(String, Object...)
for general info.urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variablespublic static MockServerHttpRequest.BaseBuilder<?> options(java.lang.String urlTemplate, java.lang.Object... uriVars)
get(String, Object...)
for general info.urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variables