private void init() {
#Reactor
ioReactorConfig = IOReactorConfig.custom()
.setIoThreadCount(Runtime.getRuntime().availableProcessors())
.setConnectTimeout(30000)
.setSoTimeout(30000)
.build();
try {
ioReactor = new DefaultConnectingIOReactor(ioReactorConfig);
} catch (IOReactorException e) {
e.printStackTrace();
//TODO handle exception
}
connManager = new PoolingNHttpClientConnectionManager(ioReactor);
httpClient = HttpAsyncClients.custom().setConnectionManager(connManager).build();
}
private ZCResponse httPost(URI uri, Object object,List<NameValuePair> params, Map<String,String> headers) {
HttpPost postRequest = new HttpPost(uri);
HttpResponse httpResponse = null;
try {
addHeaders(postRequest,headers);
addPostParams(postRequest,object,params);
Future<HttpResponse> futureResponse = httpClient.execute(postRequest, null);
httpResponse = futureResponse.get();
response = **readResponse(httpResponse);**
}
private String readResponse(HttpResponse response) throws IOException {
BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
rd.close();
return result.toString();
}
我对使用Apache Http Async客户端的代码有以下疑问