use of pro.tools.http.netty.handler.HttpClientHandler in project protools by SeanDragon.
the class DefaultClientPool method request.
public HttpReceive request(HttpSend httpSend, long timeout, TimeUnit timeUnit) {
final HttpReceive httpReceive = new HttpReceive();
Future<Channel> fch = channelPool.acquire();
Channel channel = null;
try {
channel = fch.get(timeout, timeUnit);
ChannelPipeline p = channel.pipeline();
p.addLast(new HttpClientHandler(httpSend, httpReceive));
final FullHttpRequest fullHttpRequest = convertRequest(httpSend);
p.writeAndFlush(fullHttpRequest);
channel.closeFuture().await(timeout, timeUnit);
if (!httpReceive.getIsDone()) {
httpReceive.setHaveError(true);
httpReceive.setErrMsg("请求已经超时");
}
} catch (Exception e) {
if (log.isWarnEnabled()) {
log.warn(e.getMessage(), e);
}
httpReceive.setHaveError(true).setErrMsg(e.getMessage()).setThrowable(e).setIsDone(true);
} finally {
if (channel != null) {
channelPool.release(channel);
}
}
return httpReceive;
}
Aggregations