本文整理匯總了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);
}