@Test public void init() throws UnknownHostException, InterruptedException { HttpConnection connection = new HttpConnection(); connection.setAddress("localhost"); connection.setPort(PORT); connection.setPath(ExportServer.HEALTH); NettyHttpClient nettyClient = new NettyHttpClient(connection, new HttpClientInitializer()); nettyClient.write(HttpMethod.GET, ExportServer.HEALTH, ""); System.out.println(); }
public static void init(String[] args) throws Exception { Map<String, BiConsumer<ChannelHandlerContext, HttpRequest>> mapping = new HashMap<>(); mapping.put(HEALTH, (channelHandlerContext, request) -> { ExportResult result = SyncerHealth.export(); String json = result.getJson(); Health.HealthStatus overall = result.getOverall(); FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, overall == Health.HealthStatus.GREEN ? HttpResponseStatus.OK : HttpResponseStatus.INTERNAL_SERVER_ERROR, Unpooled.wrappedBuffer(json.getBytes())); response.headers().set(CONTENT_TYPE, TEXT_PLAIN); response.headers().set(CONTENT_LENGTH, response.content().readableBytes()); channelHandlerContext.write(response); }); ChannelInitializer<SocketChannel> initializer = new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline(); p.addLast(new LoggingHandler(LogLevel.INFO)); p.addLast(new HttpServerCodec()); p.addLast(new DispatchHandler(mapping)); } }; int port = PORT; HashMap<String, String> kvMap = ArgUtil.toMap(args); String cmdPort = kvMap.get("port"); if (cmdPort != null) { port = Integer.parseUnsignedInt(cmdPort); } NettyServer.startAndSync(initializer, port); }
ExportServer { public static void init(String[] args) throws Exception { Map<String, BiConsumer<ChannelHandlerContext, HttpRequest>> mapping = new HashMap<>(); mapping.put(HEALTH, (channelHandlerContext, request) -> { ExportResult result = SyncerHealth.export(); String json = result.getJson(); Health.HealthStatus overall = result.getOverall(); FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, overall == Health.HealthStatus.GREEN ? HttpResponseStatus.OK : HttpResponseStatus.INTERNAL_SERVER_ERROR, Unpooled.wrappedBuffer(json.getBytes())); response.headers().set(CONTENT_TYPE, TEXT_PLAIN); response.headers().set(CONTENT_LENGTH, response.content().readableBytes()); channelHandlerContext.write(response); }); ChannelInitializer<SocketChannel> initializer = new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline(); p.addLast(new LoggingHandler(LogLevel.INFO)); p.addLast(new HttpServerCodec()); p.addLast(new DispatchHandler(mapping)); } }; int port = PORT; HashMap<String, String> kvMap = ArgUtil.toMap(args); String cmdPort = kvMap.get("port"); if (cmdPort != null) { port = Integer.parseUnsignedInt(cmdPort); } NettyServer.startAndSync(initializer, port); } }
ExportServer { public static void init(String[] args) throws Exception { Map<String, BiConsumer<ChannelHandlerContext, HttpRequest>> mapping = new HashMap<>(); mapping.put(HEALTH, (channelHandlerContext, request) -> { ExportResult result = SyncerHealth.export(); String json = result.getJson(); Health.HealthStatus overall = result.getOverall(); FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, overall == Health.HealthStatus.GREEN ? HttpResponseStatus.OK : HttpResponseStatus.INTERNAL_SERVER_ERROR, Unpooled.wrappedBuffer(json.getBytes())); response.headers().set(CONTENT_TYPE, TEXT_PLAIN); response.headers().set(CONTENT_LENGTH, response.content().readableBytes()); channelHandlerContext.write(response); }); ChannelInitializer<SocketChannel> initializer = new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline(); p.addLast(new LoggingHandler(LogLevel.INFO)); p.addLast(new HttpServerCodec()); p.addLast(new DispatchHandler(mapping)); } }; int port = PORT; HashMap<String, String> kvMap = ArgUtil.toMap(args); String cmdPort = kvMap.get("port"); if (cmdPort != null) { port = Integer.parseUnsignedInt(cmdPort); } NettyServer.startAndSync(initializer, port); }  }
ExportServer { public static void init(String[] args) throws Exception { Map<String, BiConsumer<ChannelHandlerContext, HttpRequest>> mapping = new HashMap<>(); mapping.put(HEALTH, (channelHandlerContext, request) -> { ExportResult result = SyncerHealth.export(); String json = result.getJson(); Health.HealthStatus overall = result.getOverall(); FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, overall == Health.HealthStatus.GREEN ? HttpResponseStatus.OK : HttpResponseStatus.INTERNAL_SERVER_ERROR, Unpooled.wrappedBuffer(json.getBytes())); response.headers().set(CONTENT_TYPE, TEXT_PLAIN); response.headers().set(CONTENT_LENGTH, response.content().readableBytes()); channelHandlerContext.write(response); }); ChannelInitializer<SocketChannel> initializer = new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline(); p.addLast(new LoggingHandler(LogLevel.INFO)); p.addLast(new HttpServerCodec()); p.addLast(new DispatchHandler(mapping)); } }; int port = PORT; HashMap<String, String> kvMap = ArgUtil.toMap(args); String cmdPort = kvMap.get("port"); if (cmdPort != null) { port = Integer.parseUnsignedInt(cmdPort); } NettyServer.startAndSync(initializer, port); }  static void init(String[] args); }
ExportServer { public static void init(String[] args) throws Exception { Map<String, BiConsumer<ChannelHandlerContext, HttpRequest>> mapping = new HashMap<>(); mapping.put(HEALTH, (channelHandlerContext, request) -> { ExportResult result = SyncerHealth.export(); String json = result.getJson(); Health.HealthStatus overall = result.getOverall(); FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, overall == Health.HealthStatus.GREEN ? HttpResponseStatus.OK : HttpResponseStatus.INTERNAL_SERVER_ERROR, Unpooled.wrappedBuffer(json.getBytes())); response.headers().set(CONTENT_TYPE, TEXT_PLAIN); response.headers().set(CONTENT_LENGTH, response.content().readableBytes()); channelHandlerContext.write(response); }); ChannelInitializer<SocketChannel> initializer = new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline(); p.addLast(new LoggingHandler(LogLevel.INFO)); p.addLast(new HttpServerCodec()); p.addLast(new DispatchHandler(mapping)); } }; int port = PORT; HashMap<String, String> kvMap = ArgUtil.toMap(args); String cmdPort = kvMap.get("port"); if (cmdPort != null) { port = Integer.parseUnsignedInt(cmdPort); } NettyServer.startAndSync(initializer, port); }  static void init(String[] args);  }