Repository: camel Updated Branches: refs/heads/master bd55ef8b3 -> 58870c1bf
CAMEL-8904: Added unit test Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/58870c1b Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/58870c1b Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/58870c1b Branch: refs/heads/master Commit: 58870c1bf7ec8ba896a54e9bf51be6e6aca737ed Parents: bd55ef8 Author: Claus Ibsen <davscl...@apache.org> Authored: Wed Jul 1 09:49:43 2015 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Jul 1 09:51:15 2015 +0200 ---------------------------------------------------------------------- .../component/netty4/http/NettyHttpMessage.java | 2 +- .../netty4/http/NettyMDCLoggingTest.java | 62 ++++++++++++++++++++ .../src/test/resources/log4j.properties | 8 ++- 3 files changed, 69 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/58870c1b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpMessage.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpMessage.java b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpMessage.java index 77a7b79..2460bfa 100644 --- a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpMessage.java +++ b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpMessage.java @@ -23,7 +23,7 @@ import org.apache.camel.impl.DefaultMessage; /** * Netty HTTP based {@link org.apache.camel.Message}. * <p/> - * This implementation allows direct access to the Netty {@link HttpRequest} using + * This implementation allows direct access to the Netty {@link FullHttpRequest} using * the {@link #getHttpRequest()} method. */ public class NettyHttpMessage extends DefaultMessage { http://git-wip-us.apache.org/repos/asf/camel/blob/58870c1b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyMDCLoggingTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyMDCLoggingTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyMDCLoggingTest.java new file mode 100644 index 0000000..af1cbca --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyMDCLoggingTest.java @@ -0,0 +1,62 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.netty4.http; + +import org.apache.camel.CamelContext; +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.junit.Test; + +public class NettyMDCLoggingTest extends BaseNettyTest { + + @Test + public void testMDC() throws Exception { + getMockEndpoint("mock:input").expectedBodiesReceived("A", "B"); + getMockEndpoint("mock:result").expectedBodiesReceived("Bye A", "Bye B"); + + String out = template.requestBody("direct:start", "A", String.class); + assertEquals("Bye A", out); + out = template.requestBody("direct:start", "B", String.class); + assertEquals("Bye B", out); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + // enable MDC + context.setUseMDCLogging(true); + + from("direct:start").routeId("client") + .to("log:client-input") + .to("netty4-http:http://localhost:{{port}}/foo") + .to("log:client-output") + .to("mock:result"); + + from("netty4-http:http://0.0.0.0:{{port}}/foo").routeId("server").streamCaching() + .to("log:server-input") + .to("mock:input") + .transform().simple("Bye ${body}") + .to("log:server-output"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/58870c1b/components/camel-netty4-http/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/resources/log4j.properties b/components/camel-netty4-http/src/test/resources/log4j.properties index 602b85e..6b57733 100644 --- a/components/camel-netty4-http/src/test/resources/log4j.properties +++ b/components/camel-netty4-http/src/test/resources/log4j.properties @@ -30,10 +30,14 @@ log4j.rootLogger=INFO, file log4j.appender.out=org.apache.log4j.ConsoleAppender log4j.appender.out.layout=org.apache.log4j.PatternLayout #log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n -log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n +#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n +# MDC +log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %-10.10X{camel.breadcrumbId} - %-10.10X{camel.exchangeId} - %-10.10X{camel.correlationId} - %-10.10X{camel.routeId} - %m%n # File appender log4j.appender.file=org.apache.log4j.FileAppender log4j.appender.file.layout=org.apache.log4j.PatternLayout -log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n +#log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n log4j.appender.file.file=target/camel-netty4-http-test.log +# MDC +log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %-10.10X{camel.breadcrumbId} - %-10.10X{camel.exchangeId} - %-10.10X{camel.correlationId} - %-10.10X{camel.routeId} - %m%n