|
9 | 9 | import io.netty.handler.codec.http.FullHttpResponse; |
10 | 10 | import io.netty.handler.codec.http.HttpUtil; |
11 | 11 | import io.netty.util.ReferenceCountUtil; |
| 12 | +import org.apache.http.HttpEntity; |
| 13 | +import org.apache.http.HttpResponse; |
| 14 | +import org.apache.http.client.methods.CloseableHttpResponse; |
| 15 | +import org.apache.http.client.methods.HttpGet; |
| 16 | +import org.apache.http.concurrent.FutureCallback; |
| 17 | +import org.apache.http.impl.client.CloseableHttpClient; |
| 18 | +import org.apache.http.impl.client.HttpClients; |
| 19 | +import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; |
| 20 | +import org.apache.http.util.EntityUtils; |
12 | 21 |
|
13 | 22 | import static io.netty.handler.codec.http.HttpHeaderNames.CONNECTION; |
14 | 23 | import static io.netty.handler.codec.http.HttpHeaderValues.KEEP_ALIVE; |
|
17 | 26 | import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; |
18 | 27 |
|
19 | 28 | public class HttpHandler extends ChannelInboundHandlerAdapter { |
20 | | - |
| 29 | + |
21 | 30 | @Override |
22 | 31 | public void channelReadComplete(ChannelHandlerContext ctx) { |
23 | 32 | ctx.flush(); |
@@ -51,6 +60,13 @@ private void handlerTest(FullHttpRequest fullRequest, ChannelHandlerContext ctx, |
51 | 60 | // httpGet ... http://localhost:8801 |
52 | 61 | // 返回的响应,"hello,nio"; |
53 | 62 | // value = reponse.... |
| 63 | + String url = "http://localhost:8801"; |
| 64 | + final HttpGet httpGet = new HttpGet(url); |
| 65 | + |
| 66 | + CloseableHttpClient httpclient = HttpClients.createDefault(); |
| 67 | + CloseableHttpResponse httpResponse = httpclient.execute(httpGet); |
| 68 | + HttpEntity entity = httpResponse.getEntity(); |
| 69 | + value = EntityUtils.toString(entity, "UTF-8"); |
54 | 70 |
|
55 | 71 | response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(value.getBytes("UTF-8"))); |
56 | 72 | response.headers().set("Content-Type", "application/json"); |
|
0 commit comments