protected FullHttpResponse executeHttpRequest(final FullHttpRequest request)
throws InterruptedException, ConnectException {
ThreadContext.put(KEY_TEST_STEP_ID, stepId);
ThreadContext.put(KEY_CLASS_NAME, CLS_NAME);
final Channel channel = getUnpooledConnection();
try {
final ChannelPipeline pipeline = channel.pipeline();
Loggers.MSG.debug(
"{}: execute the HTTP request using the channel {} w/ pipeline: {}", stepId,
channel.hashCode(), pipeline
);
pipeline.removeLast(); // remove the API specific handler
final SynchronousQueue<FullHttpResponse> fullRespSync = new SynchronousQueue<>();
pipeline.addLast(new HttpObjectAggregator(Integer.MAX_VALUE));
pipeline.addLast(
new SimpleChannelInboundHandler<HttpObject>() {
@Override
protected final void channelRead0(
final ChannelHandlerContext ctx, final HttpObject msg
) throws Exception {
if(msg instanceof FullHttpResponse) {
fullRespSync.put(((FullHttpResponse) msg).retain());
}
}
}
);
channel.writeAndFlush(request).sync();
return fullRespSync.take();
} finally {
channel.close();
}
}
HttpStorageDriverBase.java 文件源码
java
阅读 19
收藏 0
点赞 0
评论 0
项目:mongoose-base
作者:
评论列表
文章目录