Example usage for org.springframework.web.reactive.function.client ClientResponse body

List of usage examples for org.springframework.web.reactive.function.client ClientResponse body

Introduction

In this page you can find the example usage for org.springframework.web.reactive.function.client ClientResponse body.

Prototype

<T> T body(BodyExtractor<T, ? super ClientHttpResponse> extractor);

Source Link

Document

Extract the body with the given BodyExtractor .

Usage

From source file:org.springframework.cloud.gateway.filter.WebClientWriteResponseFilter.java

@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
    // NOTICE: nothing in "pre" filter stage as CLIENT_RESPONSE_ATTR is not added
    // until the WebHandler is run
    return chain.filter(exchange).then(Mono.defer(() -> {
        ClientResponse clientResponse = exchange.getAttribute(CLIENT_RESPONSE_ATTR);
        if (clientResponse == null) {
            return Mono.empty();
        }/*from  w  w  w .  j  a v a2s  .co m*/
        log.trace("WebClientWriteResponseFilter start");
        ServerHttpResponse response = exchange.getResponse();

        return response.writeWith(clientResponse.body(BodyExtractors.toDataBuffers()))
                .log("webClient response");
    }));
}