@Test public void testPost() throws InterruptedException { while(true){ String post = http.post("http: System.out.println(post); Thread.sleep(100); } }
public String post(String url, String content) { try { Result<String> result = new AsynResult<String>(); ChannelFuture channelFuture = channelFuturePool.getResource(); DefaultFullHttpRequest request = createRequest(channelFuture,url,content); Channel channel = channelFuture.channel(); channel.attr(resultKey).set(result); channel.writeAndFlush(request); String resultContent = result.get(); channelFuturePool.returnResource(channelFuture); return resultContent; } catch (Exception e) { throw new NettyHttpException(e); } }
NettyHttp { public String post(String url, String content) { try { Result<String> result = new AsynResult<String>(); ChannelFuture channelFuture = channelFuturePool.getResource(); DefaultFullHttpRequest request = createRequest(channelFuture,url,content); Channel channel = channelFuture.channel(); channel.attr(resultKey).set(result); channel.writeAndFlush(request); String resultContent = result.get(); channelFuturePool.returnResource(channelFuture); return resultContent; } catch (Exception e) { throw new NettyHttpException(e); } } }
NettyHttp { public String post(String url, String content) { try { Result<String> result = new AsynResult<String>(); ChannelFuture channelFuture = channelFuturePool.getResource(); DefaultFullHttpRequest request = createRequest(channelFuture,url,content); Channel channel = channelFuture.channel(); channel.attr(resultKey).set(result); channel.writeAndFlush(request); String resultContent = result.get(); channelFuturePool.returnResource(channelFuture); return resultContent; } catch (Exception e) { throw new NettyHttpException(e); } } NettyHttp(ChannelFuturePool channelFuturePool); }
NettyHttp { public String post(String url, String content) { try { Result<String> result = new AsynResult<String>(); ChannelFuture channelFuture = channelFuturePool.getResource(); DefaultFullHttpRequest request = createRequest(channelFuture,url,content); Channel channel = channelFuture.channel(); channel.attr(resultKey).set(result); channel.writeAndFlush(request); String resultContent = result.get(); channelFuturePool.returnResource(channelFuture); return resultContent; } catch (Exception e) { throw new NettyHttpException(e); } } NettyHttp(ChannelFuturePool channelFuturePool); String post(String url, String content); void destory(); }
NettyHttp { public String post(String url, String content) { try { Result<String> result = new AsynResult<String>(); ChannelFuture channelFuture = channelFuturePool.getResource(); DefaultFullHttpRequest request = createRequest(channelFuture,url,content); Channel channel = channelFuture.channel(); channel.attr(resultKey).set(result); channel.writeAndFlush(request); String resultContent = result.get(); channelFuturePool.returnResource(channelFuture); return resultContent; } catch (Exception e) { throw new NettyHttpException(e); } } NettyHttp(ChannelFuturePool channelFuturePool); String post(String url, String content); void destory();  }