Running with Spring Boot v2.4.0, Spring v5.3.1
Currently InterceptingHttpAccessor
(extended by RestTemplate
) allows setting the ClientHttpRequestInterceptor
interceptors. In particular, it performs sorting with AnnotationAwareOrderComparator
.
From the other side, when we construct RestTemplate
via RestTemplateBuilder
, the interceptors are just added into the list, but not sorted. Does it make sense to add something like AnnotationAwareOrderComparator.sort(restTemplate.getInterceptors())
here?
Comment From: rstoyanchev
By here you mean in in RestTemplateBuilder
I presume. That would be a change to consider on the Spring Boot side. @spring-projects/spring-boot, could you please transfer?
Comment From: wilkinsona
Does it make sense to add something like
AnnotationAwareOrderComparator.sort(restTemplate.getInterceptors())
here?
I'm not sure that it does, unfortunately.
The current implementation honours the order of the interceptors as configured by the user. If we started sorting them via AnnotationAwareOrderComparator
it could change this ordering and break existing code.
If you want the interceptors to be sorted in a particular way, I think that sorting them prior to calling RestTemplateBuilder.interceptors(Collection<ClientHttpRequestInterceptor>)
is your best option.
I'll flag this for team attention so that we can consider making a breaking change and use AnnotationAwareOrderComparator.sort
for the default ordering rather than preserving the order provided by the user.
Comment From: wilkinsona
We discussed this and decided that we want to retain the flexibility of using the user-provided ordering. That allows us to keep the current behavior while also supporting your requirement as you can order the interceptors using AnnotationAwareOrderComparator.sort
prior to passing them to the builder. Thanks anyway for the suggestion.