1 /* 2 * Copyright 2019, OpenCensus Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package io.opencensus.examples.spring.servlet; 18 19 import org.springframework.context.annotation.Bean; 20 import org.springframework.context.annotation.Configuration; 21 import org.springframework.http.client.AsyncClientHttpRequestFactory; 22 import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory; 23 import org.springframework.web.client.AsyncRestTemplate; 24 25 @Configuration 26 public class ApplicationAutoConfiguration { 27 28 /* Instance of AsyncRestTemplate. */ 29 @Bean getAsyncRestTemplate(AsyncClientHttpRequestFactory factory)30 public AsyncRestTemplate getAsyncRestTemplate(AsyncClientHttpRequestFactory factory) { 31 return new AsyncRestTemplate(factory); 32 } 33 34 /** 35 * Factory for AsyncClientHttpRequest. 36 * 37 * @return AsyncClientHttpRequestFactory 38 */ 39 @Bean getAsyncClientHttpRequestFactory()40 public AsyncClientHttpRequestFactory getAsyncClientHttpRequestFactory() { 41 int timeout = 5000; 42 HttpComponentsAsyncClientHttpRequestFactory asyncClientHttpRequestFactory = 43 new HttpComponentsAsyncClientHttpRequestFactory(); 44 asyncClientHttpRequestFactory.setConnectTimeout(timeout); 45 return asyncClientHttpRequestFactory; 46 } 47 } 48