You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/06/24 12:13:13 UTC
[1/3] git commit: CAMEL-6480: Allow to not log message body if
CamelLogDebugBodyMaxChars is set to negative value.
Updated Branches:
refs/heads/camel-2.11.x 90a6b05f0 -> a758fd2f1
refs/heads/master ccd6447e2 -> f1879c764
CAMEL-6480: Allow to not log message body if CamelLogDebugBodyMaxChars is set to negative value.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/52e1ec7c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/52e1ec7c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/52e1ec7c
Branch: refs/heads/master
Commit: 52e1ec7ce336c3820f1abef6c24cef3231d471eb
Parents: ccd6447
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Jun 24 12:11:17 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Jun 24 12:11:17 2013 +0200
----------------------------------------------------------------------
.../org/apache/camel/util/MessageHelper.java | 18 ++++--
.../camel/impl/LogDebugBodyMaxCharsOffTest.java | 68 ++++++++++++++++++++
.../camel/impl/LogDebugBodyMaxCharsTest.java | 6 +-
3 files changed, 85 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/52e1ec7c/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java b/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
index b8a984c..d27418f 100644
--- a/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
@@ -193,10 +193,14 @@ public final class MessageHelper {
* @param prepend a message to prepend
* @param allowStreams whether or not streams is allowed
* @param allowFiles whether or not files is allowed (currently not in use)
- * @param maxChars limit to maximum number of chars. Use 0 or negative value to not limit at all.
+ * @param maxChars limit to maximum number of chars. Use 0 for not limit, and -1 for turning logging message body off.
* @return the logging message
*/
public static String extractBodyForLogging(Message message, String prepend, boolean allowStreams, boolean allowFiles, int maxChars) {
+ if (maxChars < 0) {
+ return prepend + "[Body is not logged]";
+ }
+
Object obj = message.getBody();
if (obj == null) {
return prepend + "[Body is null]";
@@ -222,6 +226,12 @@ public final class MessageHelper {
}
}
+ if (!allowFiles) {
+ if (obj instanceof WrappedFile || obj instanceof File) {
+ return prepend + "[Body is file based: " + obj + "]";
+ }
+ }
+
// is the body a stream cache
StreamCache cache;
if (obj instanceof StreamCache) {
@@ -326,9 +336,9 @@ public final class MessageHelper {
Object value = entry.getValue();
String type = ObjectHelper.classCanonicalName(value);
sb.append(prefix);
- sb.append(" <header key=\"" + entry.getKey() + "\"");
+ sb.append(" <header key=\"").append(entry.getKey()).append("\"");
if (type != null) {
- sb.append(" type=\"" + type + "\"");
+ sb.append(" type=\"").append(type).append("\"");
}
sb.append(">");
@@ -358,7 +368,7 @@ public final class MessageHelper {
sb.append(" <body");
String type = ObjectHelper.classCanonicalName(message.getBody());
if (type != null) {
- sb.append(" type=\"" + type + "\"");
+ sb.append(" type=\"").append(type).append("\"");
}
sb.append(">");
http://git-wip-us.apache.org/repos/asf/camel/blob/52e1ec7c/camel-core/src/test/java/org/apache/camel/impl/LogDebugBodyMaxCharsOffTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/LogDebugBodyMaxCharsOffTest.java b/camel-core/src/test/java/org/apache/camel/impl/LogDebugBodyMaxCharsOffTest.java
new file mode 100644
index 0000000..3be6a24
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/impl/LogDebugBodyMaxCharsOffTest.java
@@ -0,0 +1,68 @@
+/**
+ * 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.impl;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version
+ */
+public class LogDebugBodyMaxCharsOffTest extends ContextTestSupport {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ context.getProperties().put(Exchange.LOG_DEBUG_BODY_MAX_CHARS, "-1");
+ }
+
+ public void testLogBodyMaxLengthTest() throws Exception {
+ // create a big body
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < 1000; i++) {
+ int value = i % 10;
+ sb.append(value);
+ }
+ String body = sb.toString();
+
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+
+ template.sendBody("direct:start", body);
+
+ assertMockEndpointsSatisfied();
+
+ // should be empty body as toString on the message will return an empty body
+ String msg = mock.getReceivedExchanges().get(0).getIn().toString();
+ assertEquals("Message: [Body is not logged]", msg);
+
+ // but body and clipped should not be the same
+ assertNotSame("clipped log and real body should not be the same", msg, mock.getReceivedExchanges().get(0).getIn().getBody(String.class));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to("log:foo").to("mock:result");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/52e1ec7c/camel-core/src/test/java/org/apache/camel/impl/LogDebugBodyMaxCharsTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/LogDebugBodyMaxCharsTest.java b/camel-core/src/test/java/org/apache/camel/impl/LogDebugBodyMaxCharsTest.java
index efffd01..129cb6c 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/LogDebugBodyMaxCharsTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/LogDebugBodyMaxCharsTest.java
@@ -56,7 +56,7 @@ public class LogDebugBodyMaxCharsTest extends ContextTestSupport {
assertNotSame("clipped log and real body should not be the same", msg, mock.getReceivedExchanges().get(0).getIn().getBody(String.class));
}
- public void tesNotClipped() throws Exception {
+ public void testNotClipped() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
@@ -64,9 +64,9 @@ public class LogDebugBodyMaxCharsTest extends ContextTestSupport {
assertMockEndpointsSatisfied();
- // should be clipped after 20 chars
+ // should not be clipped as the message is < 20 chars
String msg = mock.getReceivedExchanges().get(0).getIn().toString();
- assertEquals("Message: 01234567890", msg);
+ assertEquals("Message: 1234567890", msg);
// but body and clipped should not be the same
assertNotSame("clipped log and real body should not be the same", msg, mock.getReceivedExchanges().get(0).getIn().getBody(String.class));
[2/3] git commit: CAMEL-6479: Fixed CS
Posted by da...@apache.org.
CAMEL-6479: Fixed CS
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f1879c76
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f1879c76
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f1879c76
Branch: refs/heads/master
Commit: f1879c764c4d53e8267063f00d853b5474a3e183
Parents: 52e1ec7
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Jun 24 12:12:35 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Jun 24 12:12:35 2013 +0200
----------------------------------------------------------------------
.../file/FileProducerFileExistTryRenameTest.java | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f1879c76/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFileExistTryRenameTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFileExistTryRenameTest.java b/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFileExistTryRenameTest.java
index dd72304..be5a9a8 100644
--- a/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFileExistTryRenameTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFileExistTryRenameTest.java
@@ -16,34 +16,30 @@
*/
package org.apache.camel.component.file;
-import java.util.Locale;
-
-import junit.framework.TestResult;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
-import org.apache.camel.TestSupport;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
/**
- * @version
+ * @version
*/
public class FileProducerFileExistTryRenameTest extends ContextTestSupport {
- @Override
+ @Override
protected void setUp() throws Exception {
deleteDirectory("target/file");
super.setUp();
template.sendBodyAndHeader("file://target/file", "Hello World", Exchange.FILE_NAME, "hello.txt");
}
-
- public void testIgnore() throws Exception {
+ public void testIgnore() throws Exception {
// Does not work on Windows
- if(TestSupport.isPlatform("windows"))
+ if (isPlatform("windows")) {
return;
-
+ }
+
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Bye World");
mock.expectedFileExists("target/file/hello.txt", "Bye World");
[3/3] git commit: CAMEL-6479: Fixed CS
Posted by da...@apache.org.
CAMEL-6479: Fixed CS
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a758fd2f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a758fd2f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a758fd2f
Branch: refs/heads/camel-2.11.x
Commit: a758fd2f1ba3b8ecdd82473ea55fcbbefb9aff9f
Parents: 90a6b05
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Jun 24 12:12:35 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Jun 24 12:12:55 2013 +0200
----------------------------------------------------------------------
.../file/FileProducerFileExistTryRenameTest.java | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/a758fd2f/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFileExistTryRenameTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFileExistTryRenameTest.java b/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFileExistTryRenameTest.java
index dd72304..be5a9a8 100644
--- a/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFileExistTryRenameTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFileExistTryRenameTest.java
@@ -16,34 +16,30 @@
*/
package org.apache.camel.component.file;
-import java.util.Locale;
-
-import junit.framework.TestResult;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
-import org.apache.camel.TestSupport;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
/**
- * @version
+ * @version
*/
public class FileProducerFileExistTryRenameTest extends ContextTestSupport {
- @Override
+ @Override
protected void setUp() throws Exception {
deleteDirectory("target/file");
super.setUp();
template.sendBodyAndHeader("file://target/file", "Hello World", Exchange.FILE_NAME, "hello.txt");
}
-
- public void testIgnore() throws Exception {
+ public void testIgnore() throws Exception {
// Does not work on Windows
- if(TestSupport.isPlatform("windows"))
+ if (isPlatform("windows")) {
return;
-
+ }
+
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Bye World");
mock.expectedFileExists("target/file/hello.txt", "Bye World");