|
|
@ -35,6 +35,7 @@ import com.tencent.cloud.polaris.router.interceptor.NearbyRouterRequestIntercept
|
|
|
|
import com.tencent.cloud.polaris.router.interceptor.RuleBasedRouterRequestInterceptor;
|
|
|
|
import com.tencent.cloud.polaris.router.interceptor.RuleBasedRouterRequestInterceptor;
|
|
|
|
import com.tencent.cloud.polaris.router.resttemplate.RouterLabelRestTemplateInterceptor;
|
|
|
|
import com.tencent.cloud.polaris.router.resttemplate.RouterLabelRestTemplateInterceptor;
|
|
|
|
import com.tencent.cloud.polaris.router.spi.SpringWebRouterLabelResolver;
|
|
|
|
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.SmartInitializingSingleton;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@ -117,7 +118,13 @@ public class RouterAutoConfiguration {
|
|
|
|
public SmartInitializingSingleton addRouterLabelInterceptorForRestTemplate(RouterLabelRestTemplateInterceptor interceptor) {
|
|
|
|
public SmartInitializingSingleton addRouterLabelInterceptorForRestTemplate(RouterLabelRestTemplateInterceptor interceptor) {
|
|
|
|
return () -> restTemplates.forEach(restTemplate -> {
|
|
|
|
return () -> restTemplates.forEach(restTemplate -> {
|
|
|
|
List<ClientHttpRequestInterceptor> list = new ArrayList<>(restTemplate.getInterceptors());
|
|
|
|
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);
|
|
|
|
restTemplate.setInterceptors(list);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|