This is an automated email from the ASF dual-hosted git repository. lburgazzoli pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git
The following commit(s) were added to refs/heads/master by this push: new 315fe8b chore(netty): improve health service 315fe8b is described below commit 315fe8b4de4d22ee52adf6a184851a58cf419760 Author: lburgazzoli <lburgazz...@gmail.com> AuthorDate: Fri Mar 1 13:52:41 2019 +0100 chore(netty): improve health service --- .../org/apache/camel/k/health/HealthEndpoint.java | 45 ++++++++++++---------- .../src/test/resources/log4j2-test.xml | 5 ++- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/camel-k-runtime-health/src/main/java/org/apache/camel/k/health/HealthEndpoint.java b/camel-k-runtime-health/src/main/java/org/apache/camel/k/health/HealthEndpoint.java index 0599063..4f0516e 100644 --- a/camel-k-runtime-health/src/main/java/org/apache/camel/k/health/HealthEndpoint.java +++ b/camel-k-runtime-health/src/main/java/org/apache/camel/k/health/HealthEndpoint.java @@ -32,10 +32,10 @@ import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.codec.http.DefaultFullHttpResponse; import io.netty.handler.codec.http.FullHttpResponse; +import io.netty.handler.codec.http.HttpObject; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpServerCodec; -import io.netty.handler.codec.http.HttpServerExpectContinueHandler; import io.netty.handler.codec.http.HttpVersion; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; @@ -80,7 +80,6 @@ public class HealthEndpoint extends ServiceSupport { protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline() .addLast(new HttpServerCodec()) - .addLast(new HttpServerExpectContinueHandler()) .addLast(new Handler()); } }); @@ -98,33 +97,37 @@ public class HealthEndpoint extends ServiceSupport { } } - private class Handler extends SimpleChannelInboundHandler<HttpRequest> { + private class Handler extends SimpleChannelInboundHandler<HttpObject> { @Override public void channelReadComplete(ChannelHandlerContext ctx) { ctx.flush(); } @Override - protected void channelRead0(ChannelHandlerContext ctx, HttpRequest msg) throws Exception { - HttpResponseStatus status; - ByteBuf content; - - if (!Objects.equals(path, msg.uri())) { - status = HttpResponseStatus.NOT_FOUND; - content = Unpooled.wrappedBuffer(KO); - } else if (context.getStatus() == ServiceStatus.Started) { - status = HttpResponseStatus.OK; - content = Unpooled.wrappedBuffer(OK); - } else { - status = HttpResponseStatus.SERVICE_UNAVAILABLE; - content = Unpooled.wrappedBuffer(KO); - } + protected void channelRead0(ChannelHandlerContext ctx, HttpObject object) throws Exception { + if (object instanceof HttpRequest) { + final HttpRequest msg = (HttpRequest)object; + + HttpResponseStatus status; + ByteBuf content; - FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, content); - response.headers().set(CONTENT_TYPE, "text/plain"); - response.headers().setInt(CONTENT_LENGTH, response.content().readableBytes()); + if (!Objects.equals(path, msg.uri())) { + status = HttpResponseStatus.NOT_FOUND; + content = Unpooled.wrappedBuffer(KO); + } else if (context.getStatus() == ServiceStatus.Started) { + status = HttpResponseStatus.OK; + content = Unpooled.wrappedBuffer(OK); + } else { + status = HttpResponseStatus.SERVICE_UNAVAILABLE; + content = Unpooled.wrappedBuffer(KO); + } - ctx.write(response).addListener(ChannelFutureListener.CLOSE); + FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, content); + response.headers().set(CONTENT_TYPE, "text/plain"); + response.headers().setInt(CONTENT_LENGTH, response.content().readableBytes()); + + ctx.write(response).addListener(ChannelFutureListener.CLOSE); + } } } } diff --git a/camel-k-runtime-health/src/test/resources/log4j2-test.xml b/camel-k-runtime-health/src/test/resources/log4j2-test.xml index fb3238e..7c6c8d3 100644 --- a/camel-k-runtime-health/src/test/resources/log4j2-test.xml +++ b/camel-k-runtime-health/src/test/resources/log4j2-test.xml @@ -2,13 +2,14 @@ <Configuration status="INFO"> <Appenders> <Console name="STDOUT" target="SYSTEM_OUT"> - <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}|%-5level|%t|%c{1} - %msg%n"/> + <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}|%-5level|%t|%c - %msg%n"/> </Console> <Null name="NONE"/> </Appenders> <Loggers> - <Logger name="io.netty" level="DEBUG"/> + <Logger name="io.netty" level="INFO"/> + <Logger name="io.netty.handler.logging" level="DEBUG"/> <Root level="INFO"> <!--<AppenderRef ref="STDOUT"/>--> <AppenderRef ref="NONE"/>