Java 类org.springframework.http.client.AsyncClientHttpRequestInterceptor 实例源码

项目:haven-platform    文件:DockerServiceFactory.java   
private AsyncRestTemplate createNewRestTemplate(String addr) {
    // we use async client because usual client does not allow to interruption in some cases
    NettyRequestFactory factory = new NettyRequestFactory();
    if(AddressUtils.isHttps(addr)) {
        try {
            initSsl(addr, factory);
        } catch (Exception e) {
            log.error("", e);
        }
    }
    final AsyncRestTemplate restTemplate = new AsyncRestTemplate(factory);
    List<AsyncClientHttpRequestInterceptor> interceptors = new ArrayList<>();
    interceptors.add(new HttpAuthInterceptor(registryRepository));
    if(!StringUtils.isEmpty(agentPassword)) {
        interceptors.add(new BasicAuthAsyncInterceptor("admin", agentPassword));
    }
    restTemplate.setInterceptors(interceptors);
    return restTemplate;
}
项目:java-spring-web    文件:TracingAsyncRestTemplateTest.java   
public TracingAsyncRestTemplateTest() {
    final AsyncRestTemplate restTemplate = new AsyncRestTemplate();
    restTemplate.setInterceptors(Collections.<AsyncClientHttpRequestInterceptor>singletonList(
            new TracingAsyncRestTemplateInterceptor(mockTracer,
                    Collections.<RestTemplateSpanDecorator>singletonList(new RestTemplateSpanDecorator.StandardTags()))));

    client = new Client<AsyncRestTemplate>() {
        @Override
        public <T> ResponseEntity<T> getForEntity(String url, Class<T> clazz) {
            ListenableFuture<ResponseEntity<T>> forEntity = restTemplate.getForEntity(url, clazz);
            try {
                return forEntity.get();
            } catch (InterruptedException | ExecutionException e) {
                e.printStackTrace();
                Assert.fail();
            }
            return null;
        }

        @Override
        public AsyncRestTemplate template() {
            return restTemplate;
        }
    };

    mockServer = MockRestServiceServer.bindTo(client.template()).ignoreExpectOrder(true).build();
}
项目:java-spring-web    文件:AsyncRestTemplateAutoConfiguration.java   
private void registerTracingInterceptor(AsyncRestTemplate restTemplate) {
    List<AsyncClientHttpRequestInterceptor> interceptors = restTemplate.getInterceptors();

    for (AsyncClientHttpRequestInterceptor interceptor: interceptors) {
        if (interceptor instanceof TracingAsyncRestTemplateInterceptor) {
            return;
        }
    }

    log.info("Adding " + TracingAsyncRestTemplateInterceptor.class.getSimpleName() + " to async rest template");
    interceptors = new ArrayList<>(interceptors);
    interceptors.add(new TracingAsyncRestTemplateInterceptor(tracer));
    restTemplate.setInterceptors(interceptors);
}
项目:spring-cloud-commons    文件:AsyncLoadBalancerAutoConfiguration.java   
@Bean
public AsyncRestTemplateCustomizer asyncRestTemplateCustomizer(
        final AsyncLoadBalancerInterceptor loadBalancerInterceptor) {
    return new AsyncRestTemplateCustomizer() {
        @Override
        public void customize(AsyncRestTemplate restTemplate) {
            List<AsyncClientHttpRequestInterceptor> list = new ArrayList<>(
                    restTemplate.getInterceptors());
            list.add(loadBalancerInterceptor);
            restTemplate.setInterceptors(list);
        }
    };
}
项目:spring-cloud-commons    文件:AsyncLoadBalancerAutoConfigurationTests.java   
private void assertLoadBalanced(AsyncRestTemplate restTemplate) {
    List<AsyncClientHttpRequestInterceptor> interceptors = restTemplate.getInterceptors();
    MatcherAssert.assertThat(interceptors, hasSize(1));
    AsyncClientHttpRequestInterceptor interceptor = interceptors.get(0);
    MatcherAssert.assertThat(interceptor, is(instanceOf(AsyncLoadBalancerInterceptor.class)));
}