Spring WebClient的日志请求和响应时间

时间:2020-07-21 16:21:18

标签: java spring logging spring-webclient

我目前正尝试从RestTemplate转移,因为它已被剥离到Spring WebClient。目前,我对如何记录响应和执行时间的方法感到困惑。

  public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution){
    long startTime = System.currentTimeMillis();
    try {
        ClientHttpResponse clientHttpResponse = execution.execute(request, body);
        if (outboundMetrics != null) {
            int httpStatusCode = clientHttpResponse.getRawStatusCode();
            HttpOutboundMetrics.ResponseStatus responseStatus = null;
            if (httpStatusCode >= 200 && httpStatusCode < 300) {
                responseStatus = HttpOutboundMetrics.ResponseStatus.HTTP_2XX_RESPONSE;
            } 
            outboundMetrics.recordCallStatus(responseStatus, startTime, System.currentTimeMillis());
        }
        return clientHttpResponse;

}

我对Rest Template Intercept的原始代码是什么。 webclient筛选器是否具有与execute.execute等效的内容?

0 个答案:

没有答案