1.定义 RestTemplateConfig 配置类
@Configuration
public class RestTemplateConfig
{
@Bean
public RestTemplate restTemplate(ClientHttpRequestFactory factory)
{
return new RestTemplate(factory);
}
@Bean
public ClientHttpRequestFactory simpleClientHttpRequestFactory()
{
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
factory.setReadTimeout(10000);//单位为ms
factory.setConnectTimeout(10000);//单位为ms
return factory;
}
}
2.
@Autowired
private RestTemplate restTemplate;
3. 接口调用,数据解析
String url = zipKinUrl + "/zipkin/api/v1/traces?annotationQuery=&endTs="+currentTime
+"&limit=1000&lookback="+lookbackTime
+"&minDuration=&serviceName=twasp-gateway&sortOrder=duration-desc&spanName=all";
System.out.println("url = " + url);
//get json数据
JSONArray array = restTemplate.getForEntity(url, JSONArray.class).getBody();