Java Code Examples for org.springframework.web.client.RestTemplate.getInterceptors()

The following are Jave code examples for showing how to use getInterceptors() of the org.springframework.web.client.RestTemplate class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: EasyTransaction   File: RestRibbonEasyTransRpcConsumerImpl.java   Source Code and License Vote up 7 votes
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);
}
 
Example 2
Project: incubator-servicecomb-saga   File: RestTemplateConfig.java   Source Code and License Vote up 5 votes
@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;
}
 
Example 3
Project: java-spring-web   File: RestTemplateAutoConfiguration.java   Source Code and License Vote up 5 votes
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);
}
 
Example 4
Project: be.liege.cti.ged   File: AlfredServiceBuilderTest.java   Source Code and License Vote up 5 votes
@Before
public void before() {
    reset(restTemplateBuilder);
    final RestTemplate restTemplate = Mockito.mock(RestTemplate.class);
    restTemplate.getInterceptors();
    when(restTemplateBuilder.build())
            .thenReturn(restTemplate);
}