类 MockServerHttpRequest
- java.lang.Object
- org.springframework.http.server.reactive.AbstractServerHttpRequest
- org.springframework.mock.http.server.reactive.MockServerHttpRequest
public final class MockServerHttpRequest extends AbstractServerHttpRequest
Mock extension ofAbstractServerHttpRequestfor use in tests without an actual server. Use the static methods to obtain a builder.- 从以下版本开始:
- 5.0
- 作者:
- Rossen Stoyanchev
嵌套类概要
嵌套类 修饰符和类型 类 说明 static interfaceMockServerHttpRequest.BaseBuilder<B extends MockServerHttpRequest.BaseBuilder<B>>Request builder exposing properties not related to the body.static interfaceMockServerHttpRequest.BodyBuilderA builder that adds a body to the request.从接口继承的嵌套类/接口 org.springframework.http.server.reactive.ServerHttpRequest
ServerHttpRequest.Builder
字段概要
从类继承的字段 org.springframework.http.server.reactive.AbstractServerHttpRequest
logger
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 static MockServerHttpRequest.BaseBuilder<?>delete(String urlTemplate, Object... uriVars)HTTP DELETE variant.static MockServerHttpRequest.BaseBuilder<?>get(String urlTemplate, 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 aPublisher.InetSocketAddressgetLocalAddress()Return the local address the request was accepted on, if available.HttpMethodgetMethod()Return the HTTP method of the request.StringgetMethodValue()Return the HTTP method of the request as a String value.<T> TgetNativeRequest()Return the underlying server response.InetSocketAddressgetRemoteAddress()Return the remote address where this request is connected to, if available.static MockServerHttpRequest.BaseBuilder<?>head(String urlTemplate, Object... uriVars)HTTP HEAD variant.protected MultiValueMap<String,HttpCookie>initCookies()Obtain the cookies from the underlying "native" request and adapt those to anHttpCookiemap.protected SslInfoinitSslInfo()Obtain SSL session information from the underlying "native" request.static MockServerHttpRequest.BodyBuildermethod(String method, String urlTemplate, Object... vars)Create a builder with a raw HTTP method value that is outside the range ofHttpMethodenum values.static MockServerHttpRequest.BodyBuildermethod(HttpMethod method, String urlTemplate, Object... vars)Alternative tomethod(HttpMethod, URI)that accepts a URI template.static MockServerHttpRequest.BodyBuildermethod(HttpMethod method, URI url)Create a builder with the given HTTP method and aURI.static MockServerHttpRequest.BaseBuilder<?>options(String urlTemplate, Object... uriVars)HTTP OPTIONS variant.static MockServerHttpRequest.BodyBuilderpatch(String urlTemplate, Object... uriVars)HTTP PATCH variant.static MockServerHttpRequest.BodyBuilderpost(String urlTemplate, Object... uriVars)HTTP POST variant.static MockServerHttpRequest.BodyBuilderput(String urlTemplate, Object... uriVars)HTTP PUT variant.从类继承的方法 org.springframework.http.server.reactive.AbstractServerHttpRequest
getCookies, getHeaders, getId, getPath, getQueryParams, getSslInfo, getURI, initId, initQueryParams
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口继承的方法 org.springframework.http.server.reactive.ServerHttpRequest
mutate
方法详细资料
getMethod
public HttpMethod getMethod()
从接口复制的说明:HttpRequestReturn the HTTP method of the request.- 返回:
- the HTTP method as an HttpMethod enum value, or
nullif not resolvable (e.g. in case of a non-standard HTTP method) - 另请参阅:
HttpRequest.getMethodValue(),HttpMethod.resolve(String)
getMethodValue
public String getMethodValue()
从接口复制的说明:HttpRequestReturn the HTTP method of the request as a String value.- 返回:
- the HTTP method as a plain String
- 另请参阅:
HttpRequest.getMethod()
getLocalAddress
@Nullable public InetSocketAddress getLocalAddress()
从接口复制的说明:ServerHttpRequestReturn the local address the request was accepted on, if available.
getRemoteAddress
@Nullable public InetSocketAddress getRemoteAddress()
从接口复制的说明:ServerHttpRequestReturn the remote address where this request is connected to, if available.
initSslInfo
@Nullable protected SslInfo initSslInfo()
从类复制的说明:AbstractServerHttpRequestObtain SSL session information from the underlying "native" request.- 指定者:
initSslInfo在类中AbstractServerHttpRequest- 返回:
- the session information, or
nullif none available
getBody
public reactor.core.publisher.Flux<DataBuffer> getBody()
从接口复制的说明:ReactiveHttpInputMessageReturn the body of the message as aPublisher.- 返回:
- the body content publisher
initCookies
protected MultiValueMap<String,HttpCookie> initCookies()
从类复制的说明:AbstractServerHttpRequestObtain the cookies from the underlying "native" request and adapt those to anHttpCookiemap. 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在类中AbstractServerHttpRequest
getNativeRequest
public <T> T getNativeRequest()
从类复制的说明:AbstractServerHttpRequestReturn the underlying server response.Note: This is exposed mainly for internal framework use such as WebSocket upgrades in the spring-webflux module.
get
public static MockServerHttpRequest.BaseBuilder<?> get(String urlTemplate, Object... uriVars)
Create an HTTP GET builder with the given URI template. The given URI may contain query parameters, or those may be added later viaqueryParambuilder methods.- 参数:
urlTemplate- a URL template; the resulting URL will be encodeduriVars- zero or more URI variables- 返回:
- the created builder
head
public static MockServerHttpRequest.BaseBuilder<?> head(String urlTemplate, Object... uriVars)
HTTP HEAD variant. Seeget(String, Object...)for general info.- 参数:
urlTemplate- a URL template; the resulting URL will be encodeduriVars- zero or more URI variables- 返回:
- the created builder
post
public static MockServerHttpRequest.BodyBuilder post(String urlTemplate, Object... uriVars)
HTTP POST variant. Seeget(String, Object...)for general info.- 参数:
urlTemplate- a URL template; the resulting URL will be encodeduriVars- zero or more URI variables- 返回:
- the created builder
put
public static MockServerHttpRequest.BodyBuilder put(String urlTemplate, Object... uriVars)
HTTP PUT variant. Seeget(String, Object...)for general info.queryParambuilder methods.- 参数:
urlTemplate- a URL template; the resulting URL will be encodeduriVars- zero or more URI variables- 返回:
- the created builder
patch
public static MockServerHttpRequest.BodyBuilder patch(String urlTemplate, Object... uriVars)
HTTP PATCH variant. Seeget(String, Object...)for general info.- 参数:
urlTemplate- a URL template; the resulting URL will be encodeduriVars- zero or more URI variables- 返回:
- the created builder
delete
public static MockServerHttpRequest.BaseBuilder<?> delete(String urlTemplate, Object... uriVars)
HTTP DELETE variant. Seeget(String, Object...)for general info.- 参数:
urlTemplate- a URL template; the resulting URL will be encodeduriVars- zero or more URI variables- 返回:
- the created builder
options
public static MockServerHttpRequest.BaseBuilder<?> options(String urlTemplate, Object... uriVars)
HTTP OPTIONS variant. Seeget(String, Object...)for general info.- 参数:
urlTemplate- a URL template; the resulting URL will be encodeduriVars- zero or more URI variables- 返回:
- the created builder
method
public static MockServerHttpRequest.BodyBuilder method(HttpMethod method, URI url)
Create a builder with the given HTTP method and aURI.- 参数:
method- the HTTP method (GET, POST, etc)url- the URL- 返回:
- the created builder
method
public static MockServerHttpRequest.BodyBuilder method(HttpMethod method, String urlTemplate, Object... vars)
Alternative tomethod(HttpMethod, URI)that accepts a URI template. The given URI may contain query parameters, or those may be added later viaqueryParambuilder methods.- 参数:
method- the HTTP method (GET, POST, etc)urlTemplate- the URL templatevars- variables to expand into the template- 返回:
- the created builder
method
public static MockServerHttpRequest.BodyBuilder method(String method, String urlTemplate, Object... vars)
Create a builder with a raw HTTP method value that is outside the range ofHttpMethodenum values.- 参数:
method- the HTTP method valueurlTemplate- the URL templatevars- variables to expand into the template- 返回:
- the created builder
- 从以下版本开始:
- 5.2.7