本文整理汇总了Java中org.springframework.web.client.RestTemplate.getInterceptors方法的典型用法代码示例。如果您正苦于以下问题:Java RestTemplate.getInterceptors方法的具体用法?Java RestTemplate.getInterceptors怎么用?Java RestTemplate.getInterceptors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.client.RestTemplate
的用法示例。
在下文中一共展示了RestTemplate.getInterceptors方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
private void init(ApplicationContext ctx) {
loadBalancedRestTemplate = new RestTemplate();
SpringClientFactory springClientFactory = springClientFactory();
springClientFactory.setApplicationContext(ctx);
loadBalancerClient = new RibbonLoadBalancerClient(springClientFactory);
//custom restTemplate
LoadBalancerRequestFactory requestFactory = new LoadBalancerRequestFactory(loadBalancerClient, Collections.emptyList());
LoadBalancerInterceptor interceptor = new LoadBalancerInterceptor(loadBalancerClient, requestFactory);
List<ClientHttpRequestInterceptor> interceptors = loadBalancedRestTemplate.getInterceptors();
ArrayList<ClientHttpRequestInterceptor> customedInterceptors = new ArrayList<>(interceptors.size() + 1);
customedInterceptors.addAll(interceptors);
customedInterceptors.add(interceptor);
loadBalancedRestTemplate.setInterceptors(customedInterceptors);
}
示例2: restTemplate
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
@Bean
public RestTemplate restTemplate(OmegaContext context) {
RestTemplate template = new RestTemplate();
List<ClientHttpRequestInterceptor> interceptors = template.getInterceptors();
interceptors.add(new TransactionClientHttpRequestInterceptor(context));
template.setInterceptors(interceptors);
return template;
}
示例3: registerTracingInterceptor
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
private void registerTracingInterceptor(RestTemplate restTemplate) {
List<ClientHttpRequestInterceptor> interceptors = restTemplate.getInterceptors();
for (ClientHttpRequestInterceptor interceptor: interceptors) {
if (interceptor instanceof TracingRestTemplateInterceptor) {
return;
}
}
log.info("Adding " + TracingRestTemplateInterceptor.class.getSimpleName() + " to rest template");
interceptors = new ArrayList<>(interceptors);
interceptors.add(new TracingRestTemplateInterceptor(tracer));
restTemplate.setInterceptors(interceptors);
}
示例4: before
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
@Before
public void before() {
reset(restTemplateBuilder);
final RestTemplate restTemplate = Mockito.mock(RestTemplate.class);
restTemplate.getInterceptors();
when(restTemplateBuilder.build())
.thenReturn(restTemplate);
}