【发布时间】:2016-03-17 20:38:14
【问题描述】:
在这段代码中sn -p
public <T extends JestResult> T execute(Action<T> clientRequest) throws IOException {
HttpUriRequest request = prepareRequest(clientRequest);
HttpResponse response = httpClient.execute(request);
return deserializeResponse(response, request, clientRequest);
}
private <T extends JestResult> T deserializeResponse(HttpResponse response, Action<T> clientRequest) throws IOException {
StatusLine statusLine = response.getStatusLine();
return clientRequest.createNewElasticSearchResult(
response.getEntity() == null ? null : EntityUtils.toString(response.getEntity()),
statusLine.getStatusCode(),
statusLine.getReasonPhrase(),
gson
);
}
收到回复后,我们不应该做类似的事情
response.close()
这个特定的堆栈溢出线程HttpClient 4.0.1 - how to release connection? 提到了使用响应实体
EntityUtils.consume(HttpEntity)
只做EntityUtils.toString(response.getEntity()) 就够了吗?
【问题讨论】:
标签: java apache-httpclient-4.x elasticsearch-jest