Support ordered interceptors in RestTemplate
This commit sorts `ClientHttpRequestInterceptor`s when those are set in `InterceptingHttpAccessor` (which `RestTemplate` extends from). Interceptors can now be annotated with `@Order` or implements `Ordered` to reflect their order of execution for each request. Issue: SPR-13971
This commit is contained in:
@@ -19,6 +19,7 @@ package org.springframework.http.client.support;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||
import org.springframework.http.client.ClientHttpRequestFactory;
|
||||
import org.springframework.http.client.ClientHttpRequestInterceptor;
|
||||
import org.springframework.http.client.InterceptingClientHttpRequestFactory;
|
||||
@@ -40,6 +41,7 @@ public abstract class InterceptingHttpAccessor extends HttpAccessor {
|
||||
* Sets the request interceptors that this accessor should use.
|
||||
*/
|
||||
public void setInterceptors(List<ClientHttpRequestInterceptor> interceptors) {
|
||||
AnnotationAwareOrderComparator.sort(interceptors);
|
||||
this.interceptors = interceptors;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user