public 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.
|
private static class |
MockServerHttpRequest.DefaultBodyBuilder |
ServerHttpRequest.Builder
Modifier and Type | Field and Description |
---|---|
private <any> |
body |
private MultiValueMap<java.lang.String,HttpCookie> |
cookies |
private HttpMethod |
httpMethod |
private java.net.InetSocketAddress |
remoteAddress |
private SslInfo |
sslInfo |
Modifier | Constructor and Description |
---|---|
private |
MockServerHttpRequest(HttpMethod httpMethod,
java.net.URI uri,
java.lang.String contextPath,
HttpHeaders headers,
MultiValueMap<java.lang.String,HttpCookie> cookies,
java.net.InetSocketAddress remoteAddress,
SslInfo sslInfo,
<any> body) |
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.
|
<any> |
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
|
<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, getPath, getQueryParams, getSslInfo, getURI, initQueryParams
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
mutate
private final HttpMethod httpMethod
private final MultiValueMap<java.lang.String,HttpCookie> cookies
@Nullable private final java.net.InetSocketAddress remoteAddress
private final <any> body
private MockServerHttpRequest(HttpMethod httpMethod, java.net.URI uri, @Nullable java.lang.String contextPath, HttpHeaders headers, MultiValueMap<java.lang.String,HttpCookie> cookies, @Nullable java.net.InetSocketAddress remoteAddress, @Nullable SslInfo sslInfo, <any> body)
public HttpMethod getMethod()
HttpRequest
null
if not resolvable (e.g. in case of a non-standard HTTP method)public java.lang.String getMethodValue()
HttpRequest
@Nullable public java.net.InetSocketAddress getRemoteAddress()
ServerHttpRequest
@Nullable protected SslInfo initSslInfo()
AbstractServerHttpRequest
initSslInfo
in class AbstractServerHttpRequest
null
if none availablepublic <any> 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