public class MockServerHttpRequest extends AbstractServerHttpRequest
ServerHttpRequest
.
Note: this class extends the same
AbstractServerHttpRequest
base class as actual server-specific
implementation and is therefore read-only once created. Use static builder
methods in this class to build up request instances.
Modifier and Type | Class and Description |
---|---|
static interface |
MockServerHttpRequest.BaseBuilder<B extends MockServerHttpRequest.BaseBuilder<B>>
Defines a builder that adds headers to the request.
|
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 java.lang.String |
contextPath |
private MultiValueMap<java.lang.String,HttpCookie> |
cookies |
private HttpMethod |
httpMethod |
private java.net.InetSocketAddress |
remoteAddress |
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,
<any> body) |
Modifier and Type | Method and Description |
---|---|
static MockServerHttpRequest.BaseBuilder<?> |
delete(java.lang.String urlTemplate,
java.lang.Object... uriVars)
Create an HTTP DELETE builder with the given url.
|
static MockServerHttpRequest.BaseBuilder<?> |
get(java.lang.String urlTemplate,
java.lang.Object... uriVars)
Create an HTTP GET builder with the given url.
|
<any> |
getBody()
Return the body of the message as a
Publisher . |
java.lang.String |
getContextPath()
Returns the portion of the URL path that represents the context path for
the current
HttpHandler . |
HttpMethod |
getMethod()
Return the HTTP method of the request.
|
java.util.Optional<java.net.InetSocketAddress> |
getRemoteAddress()
Returns the remote address where this request is connected to.
|
static MockServerHttpRequest.BaseBuilder<?> |
head(java.lang.String urlTemplate,
java.lang.Object... uriVars)
Create an HTTP HEAD builder with the given url.
|
protected MultiValueMap<java.lang.String,HttpCookie> |
initCookies()
Obtain the cookies from the underlying "native" request and adapt those to
an
HttpCookie map. |
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)
Creates an HTTP OPTIONS builder with the given url.
|
static MockServerHttpRequest.BodyBuilder |
patch(java.lang.String urlTemplate,
java.lang.Object... uriVars)
Create an HTTP PATCH builder with the given url.
|
static MockServerHttpRequest.BodyBuilder |
post(java.lang.String urlTemplate,
java.lang.Object... uriVars)
Create an HTTP POST builder with the given url.
|
static MockServerHttpRequest.BodyBuilder |
put(java.lang.String urlTemplate,
java.lang.Object... uriVars)
Create an HTTP PUT builder with the given url.
|
getCookies, getHeaders, getQueryParams, getURI, initQueryParams
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
mutate
private final HttpMethod httpMethod
private final java.lang.String contextPath
private final MultiValueMap<java.lang.String,HttpCookie> cookies
private final java.net.InetSocketAddress remoteAddress
private final <any> body
private MockServerHttpRequest(HttpMethod httpMethod, java.net.URI uri, java.lang.String contextPath, HttpHeaders headers, MultiValueMap<java.lang.String,HttpCookie> cookies, java.net.InetSocketAddress remoteAddress, <any> body)
public HttpMethod getMethod()
HttpRequest
null
if not resolvable (e.g. in case of a non-standard HTTP method)public java.lang.String getContextPath()
ServerHttpRequest
HttpHandler
. The context path is always at the
beginning of the request path. It starts with "/" but but does not end
with "/". This method may return an empty string if no context path is
configured.public java.util.Optional<java.net.InetSocketAddress> getRemoteAddress()
ServerHttpRequest
public <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 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.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)
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)
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)
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)
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)
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)
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)
urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variables