分析传出 HTTP 调用 - AWS X-Ray
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

分析传出 HTTP 调用

用户工厂类演示应用程序如何使用X-Ray SDK for Java的 HTTPClientBuilder 版本来检测传出 HTTP 调用。

src/main/java/scorekeep/UserFactory.java – HTTPClient 分析

import com.amazonaws.xray.proxies.apache.http.HttpClientBuilder; public String randomName() throws IOException { CloseableHttpClient httpclient = HttpClientBuilder.create().build(); HttpGet httpGet = new HttpGet("http://uinames.com/api/"); CloseableHttpResponse response = httpclient.execute(httpGet); try { HttpEntity entity = response.getEntity(); InputStream inputStream = entity.getContent(); ObjectMapper mapper = new ObjectMapper(); Map<String, String> jsonMap = mapper.readValue(inputStream, Map.class); String name = jsonMap.get("name"); EntityUtils.consume(entity); return name; } finally { response.close(); } }

如果您当前使用 org.apache.http.impl.client.HttpClientBuilder,则只需使用 com.amazonaws.xray.proxies.apache.http.HttpClientBuilder 的语句换出该类的导出语句。