Как зарегистрировать весенний запрос веб-клиента и тело ответа? - PullRequest
0 голосов
/ 11 ноября 2019

добавил функцию ExchangeFilterFunction в WebClient, которая регистрирует запрос и ответ, но во время регистрации не смогла зарегистрировать тело запроса и ответа в виде строки или JSON. Он печатает как объект

Пробовал разные отливки и извлекает тело как строку, используя bodyToMono, toEntity, но они возвращают объект, а не строку точно.

        logRequest(clientRequest.url(), clientRequest.method(), clientRequest.headers(), clientRequest.body());
        Mono<ClientResponse> response = exchangeFunction.exchange(clientRequest);
        ClientResponse clientResponse = response.block();

      logResponse(clientResponse.statusCode(), clientResponse.headers(), clientResponse.toString(), clientResponse);

        return response;
    }```

```private void logRequest(URI uri, HttpMethod method, HttpHeaders httpHeaders, BodyInserter<?, ? super ClientHttpRequest> body) {

        log.info("Request: {}", 
                 LogVar.with("Body", body)
        );
    }

    private void logResponse(HttpStatus statusCode, Headers headers, String body, ClientResponse extractor) {
        log.info("Response: {}", 
                 , LogVar.with("Body", extractor.bodyToMono(String.class))
        );
    }```

Expecting Json OR XML whatever the request/response is, to be logged as a string.
...