Вопрос по перехватчикам. Как я могу перехватить HTTP-ответ с помощью одного перехватчика до того, как его перехватит Logbook? Цель — очистить JSON от ненужных полей до того, как Logbook его перехватит. То есть первый перехватчик удаляет ненужные поля и только потом передает очищенную модель в Logbook. Как это можно реализовать? И возможно ли это вообще?
Я пробовал написать перехватчик, но при вызове Execute.execute(request, body) Logbook сразу видит ответ и перехватывает его, прежде чем я успею что-либо изменить. Что мне делать?
У меня такая конфигурация:
@Configuration
public class ClientConfiguration {
@Bean
public SomeApiClient apiClient(RestClient.Builder restClientBuilder,
Logbook logbook,
@Value("${api.external.service.url}") String url,
ObjectMapper objectMapper,
LogbookRegistry logbookRegistry) {
var restClient = restClientBuilder.clone()
.baseUrl(url)
.requestInterceptor(new CustomJsonInterceptor(objectMapper, logbookRegistry))
.requestInterceptor(new LogbookClientHttpRequestInterceptor(logbook))
.defaultStatusHandler(new CustomHttpErrorHandler())
.build();
RestClientAdapter adapter = RestClientAdapter.create(restClient);
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(adapter).build();
return factory.createClient(SomeApiClient.class);
}
}
А вот мой класс-перехватчик:
public class CustomJsonInterceptor implements ClientHttpRequestInterceptor {
...
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
ClientHttpRequestExecution execution) throws IOException {
ClientHttpResponse response = execution.execute(request, body); // This executes the logbook interceptor
...
}
}