public class HttpHandlerConnector extends java.lang.Object implements ClientHttpConnector
HttpHandler
rather
than making actual requests to a network socket.
Internally the connector uses and adapts
MockClientHttpRequest
and MockClientHttpResponse
to
MockServerHttpRequest
and MockServerHttpResponse
.
Modifier and Type | Field and Description |
---|---|
private HttpHandler |
handler |
private static Log |
logger |
Constructor and Description |
---|
HttpHandlerConnector(HttpHandler handler)
Constructor with the
HttpHandler to handle requests with. |
Modifier and Type | Method and Description |
---|---|
private ServerHttpRequest |
adaptRequest(MockClientHttpRequest request,
<any> body) |
private ClientHttpResponse |
adaptResponse(MockServerHttpResponse response,
<any> body) |
<any> |
connect(HttpMethod httpMethod,
java.net.URI uri,
java.util.function.Function<? super ClientHttpRequest,<any>> requestCallback)
Connect to the origin server using the given
HttpMethod and
URI , then apply the given requestCallback on the
ClientHttpRequest once the connection has been established. |
private void |
log(java.lang.String message,
HttpMethod httpMethod,
java.net.URI uri) |
private ServerHttpResponse |
prepareResponse(ServerHttpResponse response,
ServerHttpRequest request) |
private static Log logger
private final HttpHandler handler
public HttpHandlerConnector(HttpHandler handler)
HttpHandler
to handle requests with.public <any> connect(HttpMethod httpMethod, java.net.URI uri, java.util.function.Function<? super ClientHttpRequest,<any>> requestCallback)
ClientHttpConnector
HttpMethod
and
URI
, then apply the given requestCallback
on the
ClientHttpRequest
once the connection has been established.
Return a publisher of the ClientHttpResponse
.
connect
in interface ClientHttpConnector
httpMethod
- the HTTP request methoduri
- the HTTP request URIrequestCallback
- a function that prepares and writes the request,
returning a publisher that signals when it's done interacting with the
request. Implementations should return a Mono<Void>
by calling
ReactiveHttpOutputMessage.writeWith(<any>)
or ReactiveHttpOutputMessage.setComplete()
.ClientHttpResponse
private void log(java.lang.String message, HttpMethod httpMethod, java.net.URI uri)
private ServerHttpRequest adaptRequest(MockClientHttpRequest request, <any> body)
private ServerHttpResponse prepareResponse(ServerHttpResponse response, ServerHttpRequest request)
private ClientHttpResponse adaptResponse(MockServerHttpResponse response, <any> body)