|
|
|
@ -36,6 +36,7 @@ import com.tencent.cloud.polaris.router.interceptor.NearbyRouterRequestIntercept
|
|
|
|
|
import com.tencent.cloud.polaris.router.interceptor.RuleBasedRouterRequestInterceptor;
|
|
|
|
|
import com.tencent.cloud.polaris.router.resttemplate.RouterLabelRestTemplateInterceptor;
|
|
|
|
|
import com.tencent.cloud.polaris.router.spi.SpringWebRouterLabelResolver;
|
|
|
|
|
import com.tencent.cloud.rpc.enhancement.resttemplate.EnhancedRestTemplateInterceptor;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.SmartInitializingSingleton;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
@ -125,7 +126,13 @@ public class RouterAutoConfiguration {
|
|
|
|
|
public SmartInitializingSingleton addRouterLabelInterceptorForRestTemplate(RouterLabelRestTemplateInterceptor interceptor) {
|
|
|
|
|
return () -> restTemplates.forEach(restTemplate -> {
|
|
|
|
|
List<ClientHttpRequestInterceptor> list = new ArrayList<>(restTemplate.getInterceptors());
|
|
|
|
|
list.add(interceptor);
|
|
|
|
|
int addIndex = list.size();
|
|
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
if (list.get(i) instanceof EnhancedRestTemplateInterceptor) {
|
|
|
|
|
addIndex = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
list.add(addIndex, interceptor);
|
|
|
|
|
restTemplate.setInterceptors(list);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|