Author: davsclaus
Date: Fri Nov 6 11:47:01 2009
New Revision: 833360
URL:
http://svn.apache.org/viewvc?rev=833360&view=revLog:
CAMEL-2141: Added showFuture option to log component to prevent it from logging Future bodies.
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/log/LogFormatter.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/log/LogFormatterTest.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/log/LogFormatter.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/log/LogFormatter.java?rev=833360&r1=833359&r2=833360&view=diff==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/log/LogFormatter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/log/LogFormatter.java Fri Nov 6 11:47:01 2009
@@ -18,6 +18,7 @@
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.util.concurrent.Future;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
@@ -41,6 +42,7 @@
private boolean showStackTrace;
private boolean showAll;
private boolean multiline;
+ private boolean showFuture;
private int maxChars;
public Object format(Exchange exchange) {
@@ -260,9 +262,30 @@
this.multiline = multiline;
}
+ public boolean isShowFuture() {
+ return showFuture;
+ }
+
+ /**
+ * If enabled Camel will on Future objects wait for it to complete to obtain the payload to be logged.
+ * <p/>
+ * Is default disabled.
+ */
+ public void setShowFuture(boolean showFuture) {
+ this.showFuture = showFuture;
+ }
+
+
// Implementation methods
//-------------------------------------------------------------------------
protected Object getBodyAsString(Message message) {
+ if (message.getBody() instanceof Future) {
+ if (!isShowFuture()) {
+ // just use a to string of the future object
+ return message.getBody().toString();
+ }
+ }
+
StreamCache newBody = message.getBody(StreamCache.class);
if (newBody != null) {
message.setBody(newBody);
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/log/LogFormatterTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/log/LogFormatterTest.java?rev=833360&r1=833359&r2=833360&view=diff==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/log/LogFormatterTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/log/LogFormatterTest.java Fri Nov 6 11:47:01 2009
@@ -16,6 +16,10 @@
*/
package org.apache.camel.component.log;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
@@ -30,6 +34,7 @@
template.sendBody("log:org.apache.camel.TEST", "Hello World");
}
+ @SuppressWarnings("unchecked")
public void testSendMessageToLogSingleOptions() throws Exception {
template.sendBody("log:org.apache.camel.TEST?showExchangeId=true", "Hello World");
template.sendBody("log:org.apache.camel.TEST?showProperties=true", "Hello World");
@@ -41,6 +46,17 @@
template.sendBody("log:org.apache.camel.TEST?showOut=true&showBodyType=true", "Hello World");
template.sendBody("log:org.apache.camel.TEST?showOut=true&showBody=true", "Hello World");
template.sendBody("log:org.apache.camel.TEST?showAll=true", "Hello World");
+
+ template.sendBody("log:org.apache.camel.TEST?showFuture=true", new MyFuture(new Callable() {
+ public Object call() throws Exception {
+ return "foo";
+ }
+ }));
+ template.sendBody("log:org.apache.camel.TEST?showFuture=false", new MyFuture(new Callable() {
+ public Object call() throws Exception {
+ return "bar";
+ }
+ }));
}
public void testSendMessageToLogMultiOptions() throws Exception {
@@ -160,4 +176,30 @@
assertEquals(0, formatter.getMaxChars());
}
+ private class MyFuture extends FutureTask {
+
+ public MyFuture(Callable callable) {
+ super(callable);
+ }
+
+ public MyFuture(Runnable runnable, Object o) {
+ super(runnable, o);
+ }
+
+ @Override
+ public boolean isDone() {
+ return true;
+ }
+
+ @Override
+ public Object get() throws InterruptedException, ExecutionException {
+ return "foo";
+ }
+
+ @Override
+ public String toString() {
+ return "ThisIsMyFuture";
+ }
+ }
+
}