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/13 14:04:50 UTC
[1/4] git commit: Seda consumer should validate that thet are all
have same multiple consumers option as they cannot have different values.
This is per queue.
Updated Branches:
refs/heads/master 011002fd6 -> 0cad912e0
Seda consumer should validate that thet are all have same multiple consumers option as they cannot have different values. This is per queue.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ad43a48a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ad43a48a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ad43a48a
Branch: refs/heads/master
Commit: ad43a48a65a42847dc76b6f3a8e78f9387ed6b72
Parents: de9de10
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jun 12 16:00:29 2013 -0400
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jun 12 16:00:29 2013 -0400
----------------------------------------------------------------------
.../camel/component/seda/SedaComponent.java | 22 +++++-
.../camel/component/seda/SedaEndpoint.java | 13 +++-
...edaQueueMultipleConsumersDifferenceTest.java | 70 ++++++++++++++++++++
3 files changed, 102 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ad43a48a/camel-core/src/main/java/org/apache/camel/component/seda/SedaComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/seda/SedaComponent.java b/camel-core/src/main/java/org/apache/camel/component/seda/SedaComponent.java
index 2578da9..77a8177 100644
--- a/camel-core/src/main/java/org/apache/camel/component/seda/SedaComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/seda/SedaComponent.java
@@ -61,7 +61,15 @@ public class SedaComponent extends UriEndpointComponent {
return defaultConcurrentConsumers;
}
+ /**
+ * @deprecated use {@link #getOrCreateQueue(String, Integer, Boolean)}
+ */
+ @Deprecated
public synchronized QueueReference getOrCreateQueue(String uri, Integer size) {
+ return getOrCreateQueue(uri, size, null);
+ }
+
+ public synchronized QueueReference getOrCreateQueue(String uri, Integer size, Boolean multipleConsumers) {
String key = getQueueKey(uri);
QueueReference ref = getQueues().get(key);
@@ -97,7 +105,7 @@ public class SedaComponent extends UriEndpointComponent {
log.debug("Created queue {} with size {}", key, size);
// create and add a new reference queue
- ref = new QueueReference(queue, size);
+ ref = new QueueReference(queue, size, multipleConsumers);
ref.addReference();
getQueues().put(key, ref);
@@ -108,6 +116,10 @@ public class SedaComponent extends UriEndpointComponent {
return queues;
}
+ public QueueReference getQueueReference(String key) {
+ return queues.get(key);
+ }
+
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
int consumers = getAndRemoveParameter(parameters, "concurrentConsumers", Integer.class, defaultConcurrentConsumers);
@@ -165,10 +177,12 @@ public class SedaComponent extends UriEndpointComponent {
private final BlockingQueue<Exchange> queue;
private volatile int count;
private Integer size;
+ private Boolean multipleConsumers;
- private QueueReference(BlockingQueue<Exchange> queue, Integer size) {
+ private QueueReference(BlockingQueue<Exchange> queue, Integer size, Boolean multipleConsumers) {
this.queue = queue;
this.size = size;
+ this.multipleConsumers = multipleConsumers;
}
void addReference() {
@@ -195,6 +209,10 @@ public class SedaComponent extends UriEndpointComponent {
return size;
}
+ public Boolean getMultipleConsumers() {
+ return multipleConsumers;
+ }
+
/**
* Gets the queue
*/
http://git-wip-us.apache.org/repos/asf/camel/blob/ad43a48a/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
index 56a5d4e..656736c 100644
--- a/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
@@ -106,6 +106,17 @@ public class SedaEndpoint extends DefaultEndpoint implements BrowsableEndpoint,
}
public Consumer createConsumer(Processor processor) throws Exception {
+ if (getComponent() != null) {
+ // all consumers must match having the same multipleConsumers options
+ String key = getComponent().getQueueKey(getEndpointUri());
+ SedaComponent.QueueReference ref = getComponent().getQueueReference(key);
+ if (ref != null && ref.getMultipleConsumers() != isMultipleConsumers()) {
+ // there is already a multiple consumers, so make sure they matches
+ throw new IllegalArgumentException("Cannot use existing queue " + key + " as the existing queue multiple consumers "
+ + ref.getMultipleConsumers() + " does not match given multiple consumers " + multipleConsumers);
+ }
+ }
+
Consumer answer = new SedaConsumer(this, processor);
configureConsumer(answer);
return answer;
@@ -119,7 +130,7 @@ public class SedaEndpoint extends DefaultEndpoint implements BrowsableEndpoint,
if (getComponent() != null) {
// use null to indicate default size (= use what the existing queue has been configured with)
Integer size = getSize() == Integer.MAX_VALUE ? null : getSize();
- SedaComponent.QueueReference ref = getComponent().getOrCreateQueue(getEndpointUri(), size);
+ SedaComponent.QueueReference ref = getComponent().getOrCreateQueue(getEndpointUri(), size, isMultipleConsumers());
queue = ref.getQueue();
String key = getComponent().getQueueKey(getEndpointUri());
LOG.info("Endpoint {} is using shared queue: {} with size: {}", new Object[]{this, key, ref.getSize() != null ? ref.getSize() : Integer.MAX_VALUE});
http://git-wip-us.apache.org/repos/asf/camel/blob/ad43a48a/camel-core/src/test/java/org/apache/camel/component/seda/SameSedaQueueMultipleConsumersDifferenceTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/seda/SameSedaQueueMultipleConsumersDifferenceTest.java b/camel-core/src/test/java/org/apache/camel/component/seda/SameSedaQueueMultipleConsumersDifferenceTest.java
new file mode 100644
index 0000000..98856df
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/seda/SameSedaQueueMultipleConsumersDifferenceTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.seda;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ *
+ */
+public class SameSedaQueueMultipleConsumersDifferenceTest extends ContextTestSupport {
+
+ public void testSameOptions() throws Exception {
+ getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:bar").expectedBodiesReceived("Hello World");
+
+ template.sendBody("seda:foo?multipleConsumers=true", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testSameOptionsProducerStillOkay() throws Exception {
+ getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:bar").expectedBodiesReceived("Hello World");
+
+ template.sendBody("seda:foo", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testAddConsumer() throws Exception {
+ try {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("seda:foo").routeId("fail").to("mock:fail");
+ }
+ });
+ fail("Should have thrown exception");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Cannot use existing queue seda://foo as the existing queue multiple consumers true does not match given multiple consumers false", e.getMessage());
+ }
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("seda:foo?multipleConsumers=true").routeId("foo").to("mock:foo");
+ from("seda:foo?multipleConsumers=true").routeId("bar").to("mock:bar");
+ }
+ };
+ }
+}
[2/4] git commit: Fixed CS
Posted by da...@apache.org.
Fixed CS
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5660eb22
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5660eb22
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5660eb22
Branch: refs/heads/master
Commit: 5660eb22e17ca6dddf0be8ac3b294746034537ab
Parents: ad43a48
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jun 12 16:02:52 2013 -0400
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jun 12 16:04:16 2013 -0400
----------------------------------------------------------------------
camel-core/src/main/java/org/apache/camel/CamelContext.java | 5 +++--
.../main/java/org/apache/camel/util/CamelContextHelper.java | 6 +++---
.../org/apache/camel/core/osgi/utils/BundleContextUtils.java | 5 +++--
3 files changed, 9 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/5660eb22/camel-core/src/main/java/org/apache/camel/CamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java b/camel-core/src/main/java/org/apache/camel/CamelContext.java
index 7f467f1..9e747c5 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -1202,9 +1202,10 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration {
* Find information about all the Camel components available in the classpath and {@link org.apache.camel.spi.Registry}.
*
* @return a map with the component name, and value with component details.
- * @throws Exception is thrown if error occurred
+ * @throws LoadPropertiesException is thrown if error during classpath discovery of the components
+ * @throws IOException is thrown if error during classpath discovery of the components
*/
- Map<String,Properties> findComponents() throws LoadPropertiesException, IOException;
+ Map<String, Properties> findComponents() throws LoadPropertiesException, IOException;
/**
http://git-wip-us.apache.org/repos/asf/camel/blob/5660eb22/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java b/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
index fc81164..35095a6 100644
--- a/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
@@ -359,9 +359,9 @@ public final class CamelContextHelper {
return findComponents(camelContext, iter);
}
- public static SortedMap<String, Properties> findComponents(CamelContext camelContext,
- Enumeration<URL> componentDescriptionIter)
- throws LoadPropertiesException {
+ public static SortedMap<String, Properties> findComponents(CamelContext camelContext, Enumeration<URL> componentDescriptionIter)
+ throws LoadPropertiesException {
+
SortedMap<String, Properties> map = new TreeMap<String, Properties>();
while (componentDescriptionIter != null && componentDescriptionIter.hasMoreElements()) {
URL url = componentDescriptionIter.nextElement();
http://git-wip-us.apache.org/repos/asf/camel/blob/5660eb22/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/utils/BundleContextUtils.java
----------------------------------------------------------------------
diff --git a/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/utils/BundleContextUtils.java b/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/utils/BundleContextUtils.java
index 015f8a6..bc0652e 100644
--- a/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/utils/BundleContextUtils.java
+++ b/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/utils/BundleContextUtils.java
@@ -84,12 +84,13 @@ public final class BundleContextUtils {
* Finds the components available on the bundle context and camel context
*/
public static Map<String, Properties> findComponents(BundleContext bundleContext, CamelContext camelContext)
- throws IOException, LoadPropertiesException {
+ throws IOException, LoadPropertiesException {
+
SortedMap<String, Properties> answer = new TreeMap<String, Properties>();
Bundle[] bundles = bundleContext.getBundles();
for (Bundle bundle : bundles) {
Enumeration<URL> iter = bundle.getResources(CamelContextHelper.COMPONENT_DESCRIPTOR);
- SortedMap<String,Properties> map = CamelContextHelper.findComponents(camelContext, iter);
+ SortedMap<String, Properties> map = CamelContextHelper.findComponents(camelContext, iter);
answer.putAll(map);
}
return answer;
[3/4] git commit: CAMEL-6407: Include message history in stacktraces
from error handler,
making it easier to know where the problem was. Work in progress.
Posted by da...@apache.org.
CAMEL-6407: Include message history in stacktraces from error handler, making it easier to know where the problem was. Work in progress.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/55901baa
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/55901baa
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/55901baa
Branch: refs/heads/master
Commit: 55901baa31b099f4afcf182ab3b7d3df0b08f5e5
Parents: 5660eb2
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jun 12 20:48:45 2013 -0400
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jun 13 14:03:27 2013 +0200
----------------------------------------------------------------------
.../camel/component/log/LogComponent.java | 5 +-
.../camel/component/log/LogFormatter.java | 357 ------------------
.../camel/processor/CamelLogProcessor.java | 7 +-
.../org/apache/camel/processor/CamelLogger.java | 2 +-
.../processor/DefaultExchangeFormatter.java | 366 +++++++++++++++++++
.../camel/processor/RedeliveryErrorHandler.java | 13 +-
.../org/apache/camel/util/MessageHelper.java | 40 +-
.../java/org/apache/camel/util/StopWatch.java | 9 +
.../log/DefaultExchangeFormatterTest.java | 210 +++++++++++
.../camel/component/log/LogFormatterTest.java | 209 -----------
10 files changed, 637 insertions(+), 581 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/55901baa/camel-core/src/main/java/org/apache/camel/component/log/LogComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/log/LogComponent.java b/camel-core/src/main/java/org/apache/camel/component/log/LogComponent.java
index eb14626..4325114 100644
--- a/camel-core/src/main/java/org/apache/camel/component/log/LogComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/log/LogComponent.java
@@ -25,6 +25,7 @@ import org.apache.camel.LoggingLevel;
import org.apache.camel.Processor;
import org.apache.camel.impl.DefaultComponent;
import org.apache.camel.processor.CamelLogProcessor;
+import org.apache.camel.processor.DefaultExchangeFormatter;
import org.apache.camel.processor.ThroughputLogger;
import org.apache.camel.spi.ExchangeFormatter;
import org.apache.camel.util.CamelLogger;
@@ -65,7 +66,7 @@ public class LogComponent extends DefaultComponent {
}
// if no formatter is available in the Registry, create a local one of the default type, for a single use
if (localFormatter == null) {
- localFormatter = new LogFormatter();
+ localFormatter = new DefaultExchangeFormatter();
setProperties(localFormatter, parameters);
}
logger = new CamelLogProcessor(camelLogger, localFormatter);
@@ -92,7 +93,7 @@ public class LogComponent extends DefaultComponent {
/**
* Sets a custom {@link ExchangeFormatter} to convert the Exchange to a String suitable for logging.
* <p />
- * If not specified, we default to {@link LogFormatter}.
+ * If not specified, we default to {@link DefaultExchangeFormatter}.
* @param exchangeFormatter
*/
public void setExchangeFormatter(ExchangeFormatter exchangeFormatter) {
http://git-wip-us.apache.org/repos/asf/camel/blob/55901baa/camel-core/src/main/java/org/apache/camel/component/log/LogFormatter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/log/LogFormatter.java b/camel-core/src/main/java/org/apache/camel/component/log/LogFormatter.java
deleted file mode 100644
index c190974..0000000
--- a/camel-core/src/main/java/org/apache/camel/component/log/LogFormatter.java
+++ /dev/null
@@ -1,357 +0,0 @@
-/**
- * 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.log;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.concurrent.Future;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.spi.ExchangeFormatter;
-import org.apache.camel.util.MessageHelper;
-import org.apache.camel.util.ObjectHelper;
-
-/**
- * Logger formatter to format the logging output.
- */
-public class LogFormatter implements ExchangeFormatter {
-
- protected static final String LS = System.getProperty("line.separator");
-
- private boolean showExchangeId;
- private boolean showExchangePattern = true;
- private boolean showProperties;
- private boolean showHeaders;
- private boolean showBodyType = true;
- private boolean showBody = true;
- private boolean showOut;
- private boolean showException;
- private boolean showCaughtException;
- private boolean showStackTrace;
- private boolean showAll;
- private boolean multiline;
- private boolean showFuture;
- private boolean showStreams;
- private boolean showFiles;
- private int maxChars = 10000;
-
- public String format(Exchange exchange) {
- Message in = exchange.getIn();
-
- StringBuilder sb = new StringBuilder();
- if (showAll || showExchangeId) {
- if (multiline) {
- sb.append(LS);
- }
- sb.append(", Id:").append(exchange.getExchangeId());
- }
- if (showAll || showExchangePattern) {
- if (multiline) {
- sb.append(LS);
- }
- sb.append(", ExchangePattern:").append(exchange.getPattern());
- }
-
- if (showAll || showProperties) {
- if (multiline) {
- sb.append(LS);
- }
- sb.append(", Properties:").append(exchange.getProperties());
- }
- if (showAll || showHeaders) {
- if (multiline) {
- sb.append(LS);
- }
- sb.append(", Headers:").append(in.getHeaders());
- }
- if (showAll || showBodyType) {
- if (multiline) {
- sb.append(LS);
- }
- sb.append(", BodyType:").append(getBodyTypeAsString(in));
- }
- if (showAll || showBody) {
- if (multiline) {
- sb.append(LS);
- }
- sb.append(", Body:").append(getBodyAsString(in));
- }
-
- if (showAll || showException || showCaughtException) {
-
- // try exception on exchange first
- Exception exception = exchange.getException();
- boolean caught = false;
- if ((showAll || showCaughtException) && exception == null) {
- // fallback to caught exception
- exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
- caught = true;
- }
-
- if (exception != null) {
- if (multiline) {
- sb.append(LS);
- }
- if (caught) {
- sb.append(", CaughtExceptionType:").append(exception.getClass().getCanonicalName());
- sb.append(", CaughtExceptionMessage:").append(exception.getMessage());
- } else {
- sb.append(", ExceptionType:").append(exception.getClass().getCanonicalName());
- sb.append(", ExceptionMessage:").append(exception.getMessage());
- }
- if (showAll || showStackTrace) {
- StringWriter sw = new StringWriter();
- exception.printStackTrace(new PrintWriter(sw));
- sb.append(", StackTrace:").append(sw.toString());
- }
- }
- }
-
- if (showAll || showOut) {
- if (exchange.hasOut()) {
- Message out = exchange.getOut();
- if (showAll || showHeaders) {
- if (multiline) {
- sb.append(LS);
- }
- sb.append(", OutHeaders:").append(out.getHeaders());
- }
- if (showAll || showBodyType) {
- if (multiline) {
- sb.append(LS);
- }
- sb.append(", OutBodyType:").append(getBodyTypeAsString(out));
- }
- if (showAll || showBody) {
- if (multiline) {
- sb.append(LS);
- }
- sb.append(", OutBody:").append(getBodyAsString(out));
- }
- } else {
- if (multiline) {
- sb.append(LS);
- }
- sb.append(", Out: null");
- }
- }
-
- if (maxChars > 0) {
- StringBuilder answer = new StringBuilder();
- for (String s : sb.toString().split(LS)) {
- if (s != null) {
- if (s.length() > maxChars) {
- s = s.substring(0, maxChars);
- answer.append(s).append("...");
- } else {
- answer.append(s);
- }
- if (multiline) {
- answer.append(LS);
- }
- }
- }
-
- // switch string buffer
- sb = answer;
- }
-
- if (multiline) {
- sb.insert(0, "Exchange[");
- sb.append("]");
- return sb.toString();
- } else {
- // get rid of the leading space comma if needed
- if (sb.length() > 0 && sb.charAt(0) == ',' && sb.charAt(1) == ' ') {
- sb.replace(0, 2, "");
- }
- sb.insert(0, "Exchange[");
- sb.append("]");
-
- return sb.toString();
- }
- }
-
- public boolean isShowExchangeId() {
- return showExchangeId;
- }
-
- public void setShowExchangeId(boolean showExchangeId) {
- this.showExchangeId = showExchangeId;
- }
-
- public boolean isShowProperties() {
- return showProperties;
- }
-
- public void setShowProperties(boolean showProperties) {
- this.showProperties = showProperties;
- }
-
- public boolean isShowHeaders() {
- return showHeaders;
- }
-
- public void setShowHeaders(boolean showHeaders) {
- this.showHeaders = showHeaders;
- }
-
- public boolean isShowBodyType() {
- return showBodyType;
- }
-
- public void setShowBodyType(boolean showBodyType) {
- this.showBodyType = showBodyType;
- }
-
- public boolean isShowBody() {
- return showBody;
- }
-
- public void setShowBody(boolean showBody) {
- this.showBody = showBody;
- }
-
- public boolean isShowOut() {
- return showOut;
- }
-
- public void setShowOut(boolean showOut) {
- this.showOut = showOut;
- }
-
- public boolean isShowAll() {
- return showAll;
- }
-
- public void setShowAll(boolean showAll) {
- this.showAll = showAll;
- }
-
- public boolean isShowException() {
- return showException;
- }
-
- public void setShowException(boolean showException) {
- this.showException = showException;
- }
-
- public boolean isShowStackTrace() {
- return showStackTrace;
- }
-
- public void setShowStackTrace(boolean showStackTrace) {
- this.showStackTrace = showStackTrace;
- }
-
- public boolean isShowCaughtException() {
- return showCaughtException;
- }
-
- public void setShowCaughtException(boolean showCaughtException) {
- this.showCaughtException = showCaughtException;
- }
-
- public boolean isMultiline() {
- return multiline;
- }
-
- public int getMaxChars() {
- return maxChars;
- }
-
- public void setMaxChars(int maxChars) {
- this.maxChars = maxChars;
- }
-
- /**
- * If enabled then each information is outputted on a newline.
- */
- public void setMultiline(boolean multiline) {
- 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;
- }
-
- public boolean isShowExchangePattern() {
- return showExchangePattern;
- }
-
- public void setShowExchangePattern(boolean showExchangePattern) {
- this.showExchangePattern = showExchangePattern;
- }
-
- public boolean isShowStreams() {
- return showStreams;
- }
-
- /**
- * If enabled Camel will output stream objects
- * <p/>
- * Is default disabled.
- */
- public void setShowStreams(boolean showStreams) {
- this.showStreams = showStreams;
- }
-
- public boolean isShowFiles() {
- return showFiles;
- }
-
- /**
- * If enabled Camel will output files
- * <p/>
- * Is default disabled.
- */
- public void setShowFiles(boolean showFiles) {
- this.showFiles = showFiles;
- }
-
- // Implementation methods
- //-------------------------------------------------------------------------
- protected String getBodyAsString(Message message) {
- if (message.getBody() instanceof Future) {
- if (!isShowFuture()) {
- // just use a to string of the future object
- return message.getBody().toString();
- }
- }
-
- return MessageHelper.extractBodyForLogging(message, "", isShowStreams(), isShowFiles(), -1);
- }
-
- protected String getBodyTypeAsString(Message message) {
- String answer = ObjectHelper.classCanonicalName(message.getBody());
- if (answer != null && answer.startsWith("java.lang.")) {
- return answer.substring(10);
- }
- return answer;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/55901baa/camel-core/src/main/java/org/apache/camel/processor/CamelLogProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/CamelLogProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/CamelLogProcessor.java
index 9ca228d..052d1e7 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/CamelLogProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/CamelLogProcessor.java
@@ -43,7 +43,7 @@ public class CamelLogProcessor implements AsyncProcessor {
}
public CamelLogProcessor(CamelLogger log) {
- this.formatter = new DefaultExchangeFormatter();
+ this.formatter = new ToStringExchangeFormatter();
this.log = log;
}
@@ -97,7 +97,10 @@ public class CamelLogProcessor implements AsyncProcessor {
log.setMarker(marker);
}
- static class DefaultExchangeFormatter implements ExchangeFormatter {
+ /**
+ * {@link ExchangeFormatter} that calls <tt>toString</tt> on the {@link Exchange}.
+ */
+ static class ToStringExchangeFormatter implements ExchangeFormatter {
public String format(Exchange exchange) {
return exchange.toString();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/55901baa/camel-core/src/main/java/org/apache/camel/processor/CamelLogger.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/CamelLogger.java b/camel-core/src/main/java/org/apache/camel/processor/CamelLogger.java
index 6fc1b69..7ac0843 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/CamelLogger.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/CamelLogger.java
@@ -51,7 +51,7 @@ public class CamelLogger extends ServiceSupport implements AsyncProcessor {
}
public CamelLogger(Logger log, LoggingLevel level) {
- this.formatter = new CamelLogProcessor.DefaultExchangeFormatter();
+ this.formatter = new CamelLogProcessor.ToStringExchangeFormatter();
this.log = log;
this.level = level;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/55901baa/camel-core/src/main/java/org/apache/camel/processor/DefaultExchangeFormatter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/DefaultExchangeFormatter.java b/camel-core/src/main/java/org/apache/camel/processor/DefaultExchangeFormatter.java
new file mode 100644
index 0000000..8f474a3
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/processor/DefaultExchangeFormatter.java
@@ -0,0 +1,366 @@
+/**
+ * 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.processor;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.Future;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.spi.ExchangeFormatter;
+import org.apache.camel.util.MessageHelper;
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * Default {@link ExchangeFormatter} that have fine grained options to configure what to include in the output.
+ */
+public class DefaultExchangeFormatter implements ExchangeFormatter {
+
+ protected static final String LS = System.getProperty("line.separator");
+
+ private boolean showExchangeId;
+ private boolean showExchangePattern = true;
+ private boolean showProperties;
+ private boolean showHeaders;
+ private boolean showBodyType = true;
+ private boolean showBody = true;
+ private boolean showOut;
+ private boolean showException;
+ private boolean showCaughtException;
+ private boolean showStackTrace;
+ private boolean showAll;
+ private boolean multiline;
+ private boolean showFuture;
+ private boolean showStreams;
+ private boolean showFiles;
+ private int maxChars = 10000;
+
+ public String format(Exchange exchange) {
+ Message in = exchange.getIn();
+
+ StringBuilder sb = new StringBuilder();
+ if (showAll || showExchangeId) {
+ if (multiline) {
+ sb.append(LS);
+ }
+ sb.append(", Id:").append(exchange.getExchangeId());
+ }
+ if (showAll || showExchangePattern) {
+ if (multiline) {
+ sb.append(LS);
+ }
+ sb.append(", ExchangePattern:").append(exchange.getPattern());
+ }
+
+ if (showAll || showProperties) {
+ if (multiline) {
+ sb.append(LS);
+ }
+ sb.append(", Properties:").append(sortMap(exchange.getProperties()));
+ }
+ if (showAll || showHeaders) {
+ if (multiline) {
+ sb.append(LS);
+ }
+ sb.append(", Headers:").append(sortMap(in.getHeaders()));
+ }
+ if (showAll || showBodyType) {
+ if (multiline) {
+ sb.append(LS);
+ }
+ sb.append(", BodyType:").append(getBodyTypeAsString(in));
+ }
+ if (showAll || showBody) {
+ if (multiline) {
+ sb.append(LS);
+ }
+ sb.append(", Body:").append(getBodyAsString(in));
+ }
+
+ if (showAll || showException || showCaughtException) {
+
+ // try exception on exchange first
+ Exception exception = exchange.getException();
+ boolean caught = false;
+ if ((showAll || showCaughtException) && exception == null) {
+ // fallback to caught exception
+ exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
+ caught = true;
+ }
+
+ if (exception != null) {
+ if (multiline) {
+ sb.append(LS);
+ }
+ if (caught) {
+ sb.append(", CaughtExceptionType:").append(exception.getClass().getCanonicalName());
+ sb.append(", CaughtExceptionMessage:").append(exception.getMessage());
+ } else {
+ sb.append(", ExceptionType:").append(exception.getClass().getCanonicalName());
+ sb.append(", ExceptionMessage:").append(exception.getMessage());
+ }
+ if (showAll || showStackTrace) {
+ StringWriter sw = new StringWriter();
+ exception.printStackTrace(new PrintWriter(sw));
+ sb.append(", StackTrace:").append(sw.toString());
+ }
+ }
+ }
+
+ if (showAll || showOut) {
+ if (exchange.hasOut()) {
+ Message out = exchange.getOut();
+ if (showAll || showHeaders) {
+ if (multiline) {
+ sb.append(LS);
+ }
+ sb.append(", OutHeaders:").append(sortMap(out.getHeaders()));
+ }
+ if (showAll || showBodyType) {
+ if (multiline) {
+ sb.append(LS);
+ }
+ sb.append(", OutBodyType:").append(getBodyTypeAsString(out));
+ }
+ if (showAll || showBody) {
+ if (multiline) {
+ sb.append(LS);
+ }
+ sb.append(", OutBody:").append(getBodyAsString(out));
+ }
+ } else {
+ if (multiline) {
+ sb.append(LS);
+ }
+ sb.append(", Out: null");
+ }
+ }
+
+ if (maxChars > 0) {
+ StringBuilder answer = new StringBuilder();
+ for (String s : sb.toString().split(LS)) {
+ if (s != null) {
+ if (s.length() > maxChars) {
+ s = s.substring(0, maxChars);
+ answer.append(s).append("...");
+ } else {
+ answer.append(s);
+ }
+ if (multiline) {
+ answer.append(LS);
+ }
+ }
+ }
+
+ // switch string buffer
+ sb = answer;
+ }
+
+ if (multiline) {
+ sb.insert(0, "Exchange[");
+ sb.append("]");
+ return sb.toString();
+ } else {
+ // get rid of the leading space comma if needed
+ if (sb.length() > 0 && sb.charAt(0) == ',' && sb.charAt(1) == ' ') {
+ sb.replace(0, 2, "");
+ }
+ sb.insert(0, "Exchange[");
+ sb.append("]");
+
+ return sb.toString();
+ }
+ }
+
+ public boolean isShowExchangeId() {
+ return showExchangeId;
+ }
+
+ public void setShowExchangeId(boolean showExchangeId) {
+ this.showExchangeId = showExchangeId;
+ }
+
+ public boolean isShowProperties() {
+ return showProperties;
+ }
+
+ public void setShowProperties(boolean showProperties) {
+ this.showProperties = showProperties;
+ }
+
+ public boolean isShowHeaders() {
+ return showHeaders;
+ }
+
+ public void setShowHeaders(boolean showHeaders) {
+ this.showHeaders = showHeaders;
+ }
+
+ public boolean isShowBodyType() {
+ return showBodyType;
+ }
+
+ public void setShowBodyType(boolean showBodyType) {
+ this.showBodyType = showBodyType;
+ }
+
+ public boolean isShowBody() {
+ return showBody;
+ }
+
+ public void setShowBody(boolean showBody) {
+ this.showBody = showBody;
+ }
+
+ public boolean isShowOut() {
+ return showOut;
+ }
+
+ public void setShowOut(boolean showOut) {
+ this.showOut = showOut;
+ }
+
+ public boolean isShowAll() {
+ return showAll;
+ }
+
+ public void setShowAll(boolean showAll) {
+ this.showAll = showAll;
+ }
+
+ public boolean isShowException() {
+ return showException;
+ }
+
+ public void setShowException(boolean showException) {
+ this.showException = showException;
+ }
+
+ public boolean isShowStackTrace() {
+ return showStackTrace;
+ }
+
+ public void setShowStackTrace(boolean showStackTrace) {
+ this.showStackTrace = showStackTrace;
+ }
+
+ public boolean isShowCaughtException() {
+ return showCaughtException;
+ }
+
+ public void setShowCaughtException(boolean showCaughtException) {
+ this.showCaughtException = showCaughtException;
+ }
+
+ public boolean isMultiline() {
+ return multiline;
+ }
+
+ public int getMaxChars() {
+ return maxChars;
+ }
+
+ public void setMaxChars(int maxChars) {
+ this.maxChars = maxChars;
+ }
+
+ /**
+ * If enabled then each information is outputted on a newline.
+ */
+ public void setMultiline(boolean multiline) {
+ 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;
+ }
+
+ public boolean isShowExchangePattern() {
+ return showExchangePattern;
+ }
+
+ public void setShowExchangePattern(boolean showExchangePattern) {
+ this.showExchangePattern = showExchangePattern;
+ }
+
+ public boolean isShowStreams() {
+ return showStreams;
+ }
+
+ /**
+ * If enabled Camel will output stream objects
+ * <p/>
+ * Is default disabled.
+ */
+ public void setShowStreams(boolean showStreams) {
+ this.showStreams = showStreams;
+ }
+
+ public boolean isShowFiles() {
+ return showFiles;
+ }
+
+ /**
+ * If enabled Camel will output files
+ * <p/>
+ * Is default disabled.
+ */
+ public void setShowFiles(boolean showFiles) {
+ this.showFiles = showFiles;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected String getBodyAsString(Message message) {
+ if (message.getBody() instanceof Future) {
+ if (!isShowFuture()) {
+ // just use a to string of the future object
+ return message.getBody().toString();
+ }
+ }
+
+ return MessageHelper.extractBodyForLogging(message, "", isShowStreams(), isShowFiles(), -1);
+ }
+
+ protected String getBodyTypeAsString(Message message) {
+ String answer = ObjectHelper.classCanonicalName(message.getBody());
+ if (answer != null && answer.startsWith("java.lang.")) {
+ return answer.substring(10);
+ }
+ return answer;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static Map sortMap(Map<String, Object> map) {
+ TreeMap answer = new TreeMap(String.CASE_INSENSITIVE_ORDER);
+ answer.putAll(map);
+ return answer;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/55901baa/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java b/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
index 4f0f0f8..d76fd7c 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
@@ -30,6 +30,7 @@ import org.apache.camel.Message;
import org.apache.camel.Predicate;
import org.apache.camel.Processor;
import org.apache.camel.model.OnExceptionDefinition;
+import org.apache.camel.spi.ExchangeFormatter;
import org.apache.camel.spi.ShutdownPrepared;
import org.apache.camel.spi.SubUnitOfWorkCallback;
import org.apache.camel.spi.UnitOfWork;
@@ -67,6 +68,7 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
protected final boolean useOriginalMessagePolicy;
protected boolean redeliveryEnabled;
protected volatile boolean preparingShutdown;
+ protected final ExchangeFormatter exchangeFormatter;
/**
* Contains the current redelivery data
@@ -193,6 +195,13 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
this.useOriginalMessagePolicy = useOriginalMessagePolicy;
this.retryWhilePolicy = retryWhile;
this.executorService = executorService;
+
+ // setup exchange formatter to be used for message history dump
+ DefaultExchangeFormatter formatter = new DefaultExchangeFormatter();
+ formatter.setShowExchangeId(true);
+ formatter.setMultiline(true);
+ formatter.setShowHeaders(true);
+ this.exchangeFormatter = formatter;
}
public boolean supportTransacted() {
@@ -958,7 +967,7 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
// should we include message history
if (!shouldRedeliver && data.currentRedeliveryPolicy.isLogExhaustedMessageHistory()) {
- String routeStackTrace = MessageHelper.dumpMessageHistoryStacktrace(exchange, false);
+ String routeStackTrace = MessageHelper.dumpMessageHistoryStacktrace(exchange, exchangeFormatter, false);
if (routeStackTrace != null) {
msg = msg + "\n" + routeStackTrace;
}
@@ -975,7 +984,7 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
String msg = message;
// should we include message history
if (!shouldRedeliver && data.currentRedeliveryPolicy.isLogExhaustedMessageHistory()) {
- String routeStackTrace = MessageHelper.dumpMessageHistoryStacktrace(exchange, e != null && logStackTrace);
+ String routeStackTrace = MessageHelper.dumpMessageHistoryStacktrace(exchange, exchangeFormatter, e != null && logStackTrace);
if (routeStackTrace != null) {
msg = msg + "\n" + routeStackTrace;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/55901baa/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 26f84b3..f732645 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
@@ -21,6 +21,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
+import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@@ -33,6 +34,7 @@ import org.apache.camel.MessageHistory;
import org.apache.camel.StreamCache;
import org.apache.camel.StringSource;
import org.apache.camel.WrappedFile;
+import org.apache.camel.spi.ExchangeFormatter;
/**
* Some helper methods when working with {@link org.apache.camel.Message}.
@@ -399,11 +401,13 @@ public final class MessageHelper {
/**
* Dumps the {@link MessageHistory} from the {@link Exchange} in a human readable format.
*
- * @param exchange the exchange
- * @param logStackTrace whether to include a header for the stacktrace, to be added (not included in this dump).
+ * @param exchange the exchange
+ * @param exchangeFormatter if provided then information about the exchange is included in the dump
+ * @param logStackTrace whether to include a header for the stacktrace, to be added (not included in this dump).
* @return a human readable message history as a table
*/
- public static String dumpMessageHistoryStacktrace(Exchange exchange, boolean logStackTrace) {
+ @SuppressWarnings("unchecked")
+ public static String dumpMessageHistoryStacktrace(Exchange exchange, ExchangeFormatter exchangeFormatter, boolean logStackTrace) {
List<MessageHistory> list = exchange.getProperty(Exchange.MESSAGE_HISTORY, List.class);
if (list == null || list.isEmpty()) {
return null;
@@ -416,17 +420,37 @@ public final class MessageHelper {
sb.append(String.format(MESSAGE_HISTORY_HEADER, "RouteId", "ProcessorId", "Processor", "Elapsed (ms)"));
sb.append("\n");
- for (MessageHistory history : list) {
+ // add incoming origin of message on the top
+ String routeId = exchange.getFromRouteId();
+ String id = routeId;
+ String label = URISupport.sanitizeUri(exchange.getFromEndpoint().getEndpointUri());
+ long elapsed = 0;
+ Date created = exchange.getProperty(Exchange.CREATED_TIMESTAMP, Date.class);
+ if (created != null) {
+ elapsed = new StopWatch(created).stop();
+ }
+
+ sb.append(String.format(MESSAGE_HISTORY_OUTPUT, routeId, id, label, elapsed));
+ sb.append("\n");
- String routeId = history.getRouteId();
- String id = history.getNode().getId();
- String label = history.getNode().getLabel();
- long elapsed = history.getElapsed();
+ // and then each history
+ for (MessageHistory history : list) {
+ routeId = history.getRouteId();
+ id = history.getNode().getId();
+ label = history.getNode().getLabel();
+ elapsed = history.getElapsed();
sb.append(String.format(MESSAGE_HISTORY_OUTPUT, routeId, id, label, elapsed));
sb.append("\n");
}
+ if (exchangeFormatter != null) {
+ sb.append("\nExchange\n");
+ sb.append("---------------------------------------------------------------------------------------------------------------------------------------\n");
+ sb.append(exchangeFormatter.format(exchange));
+ sb.append("\n");
+ }
+
if (logStackTrace) {
sb.append("\nStacktrace\n");
sb.append("---------------------------------------------------------------------------------------------------------------------------------------");
http://git-wip-us.apache.org/repos/asf/camel/blob/55901baa/camel-core/src/main/java/org/apache/camel/util/StopWatch.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/StopWatch.java b/camel-core/src/main/java/org/apache/camel/util/StopWatch.java
index b5db7ac..d1d67f3 100644
--- a/camel-core/src/main/java/org/apache/camel/util/StopWatch.java
+++ b/camel-core/src/main/java/org/apache/camel/util/StopWatch.java
@@ -16,6 +16,8 @@
*/
package org.apache.camel.util;
+import java.util.Date;
+
/**
* A very simple stop watch.
* <p/>
@@ -36,6 +38,13 @@ public final class StopWatch {
}
/**
+ * Starts the stop watch from the given timestamp
+ */
+ public StopWatch(Date startTimestamp) {
+ start = startTimestamp.getTime();
+ }
+
+ /**
* Creates the stop watch
*
* @param started whether it should start immediately
http://git-wip-us.apache.org/repos/asf/camel/blob/55901baa/camel-core/src/test/java/org/apache/camel/component/log/DefaultExchangeFormatterTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/log/DefaultExchangeFormatterTest.java b/camel-core/src/test/java/org/apache/camel/component/log/DefaultExchangeFormatterTest.java
new file mode 100644
index 0000000..e906623
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/log/DefaultExchangeFormatterTest.java
@@ -0,0 +1,210 @@
+/**
+ * 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.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;
+import org.apache.camel.Producer;
+import org.apache.camel.processor.DefaultExchangeFormatter;
+
+/**
+ * Logger formatter test.
+ */
+public class DefaultExchangeFormatterTest extends ContextTestSupport {
+
+ public void testSendMessageToLogDefault() throws Exception {
+ template.sendBody("log:org.apache.camel.TEST", "Hello World");
+ }
+
+ public void testSendMessageToLogAllOff() throws Exception {
+ template.sendBody("log:org.apache.camel.TEST?showBody=false&showBodyType=false&showExchangePattern=false", "Hello World");
+ }
+
+ public void testSendMessageToLogSingleOptions() throws Exception {
+ template.sendBody("log:org.apache.camel.TEST?showExchangeId=true", "Hello World");
+ template.sendBody("log:org.apache.camel.TEST?showExchangePattern=true", "Hello World");
+ template.sendBody("log:org.apache.camel.TEST?showExchangePattern=false", "Hello World");
+ template.sendBody("log:org.apache.camel.TEST?showProperties=true", "Hello World");
+ template.sendBody("log:org.apache.camel.TEST?showHeaders=true", "Hello World");
+ template.sendBody("log:org.apache.camel.TEST?showBodyType=true", "Hello World");
+ template.sendBody("log:org.apache.camel.TEST?showBody=true", "Hello World");
+ template.sendBody("log:org.apache.camel.TEST?showOut=true", "Hello World");
+ template.sendBody("log:org.apache.camel.TEST?showOut=true&showHeaders=true", "Hello World");
+ 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<String>() {
+ public String call() throws Exception {
+ return "foo";
+ }
+ }));
+ template.sendBody("log:org.apache.camel.TEST?showFuture=false", new MyFuture(new Callable<String>() {
+ public String call() throws Exception {
+ return "bar";
+ }
+ }));
+ }
+
+ public void testSendMessageToLogMultiOptions() throws Exception {
+ template.sendBody("log:org.apache.camel.TEST?showHeaders=true&showOut=true", "Hello World");
+ template.sendBody("log:org.apache.camel.TEST?showProperties=true&showHeaders=true&showOut=true", "Hello World");
+ }
+
+ public void testSendMessageToLogShowFalse() throws Exception {
+ template.sendBody("log:org.apache.camel.TEST?showBodyType=false", "Hello World");
+ }
+
+ public void testSendMessageToLogMultiLine() throws Exception {
+ template.sendBody("log:org.apache.camel.TEST?multiline=true", "Hello World");
+ }
+
+ public void testSendByteArrayMessageToLogDefault() throws Exception {
+ template.sendBody("log:org.apache.camel.TEST", "Hello World".getBytes());
+ }
+
+ public void testSendMessageToLogMaxChars() throws Exception {
+ template.sendBody("log:org.apache.camel.TEST",
+ "Hello World this is a very long string that is NOT going to be chopped by maxchars");
+
+ template.sendBody("log:org.apache.camel.TEST?maxChars=50",
+ "Hello World this is a very long string that is going to be chopped by maxchars");
+
+ template.sendBody("log:org.apache.camel.TEST?maxChars=50&showAll=true&multiline=true",
+ "Hello World this is a very long string that is going to be chopped by maxchars");
+ }
+
+ public void testSendExchangeWithOut() throws Exception {
+ Endpoint endpoint = resolveMandatoryEndpoint("log:org.apache.camel.TEST?showAll=true&multiline=true");
+ Exchange exchange = endpoint.createExchange();
+ exchange.getIn().setBody("Hello World");
+ exchange.getOut().setBody(22);
+
+ Producer producer = endpoint.createProducer();
+ producer.start();
+ producer.process(exchange);
+ producer.stop();
+ }
+
+ public void testSendExchangeWithException() throws Exception {
+ Endpoint endpoint = resolveMandatoryEndpoint("log:org.apache.camel.TEST?showException=true");
+ Exchange exchange = endpoint.createExchange();
+ exchange.getIn().setBody("Hello World");
+ exchange.setException(new IllegalArgumentException("Damn"));
+
+ Producer producer = endpoint.createProducer();
+ producer.start();
+ producer.process(exchange);
+ producer.stop();
+ }
+
+ public void testSendCaughtExchangeWithException() throws Exception {
+ Endpoint endpoint = resolveMandatoryEndpoint("log:org.apache.camel.TEST?showCaughtException=true");
+ Exchange exchange = endpoint.createExchange();
+ exchange.getIn().setBody("Hello World");
+ exchange.setProperty(Exchange.EXCEPTION_CAUGHT, new IllegalArgumentException("I am caught"));
+
+ Producer producer = endpoint.createProducer();
+ producer.start();
+ producer.process(exchange);
+ producer.stop();
+ }
+
+ public void testSendCaughtExchangeWithExceptionAndMultiline() throws Exception {
+ Endpoint endpoint = resolveMandatoryEndpoint("log:org.apache.camel.TEST?showCaughtException=true&multiline=true");
+ Exchange exchange = endpoint.createExchange();
+ exchange.getIn().setBody("Hello World");
+ exchange.setProperty(Exchange.EXCEPTION_CAUGHT, new IllegalArgumentException("I am caught"));
+
+ Producer producer = endpoint.createProducer();
+ producer.start();
+ producer.process(exchange);
+ producer.stop();
+ }
+
+ public void testSendExchangeWithExceptionAndStackTrace() throws Exception {
+ Endpoint endpoint = resolveMandatoryEndpoint("log:org.apache.camel.TEST?showException=true&showStackTrace=true");
+ Exchange exchange = endpoint.createExchange();
+ exchange.getIn().setBody("Hello World");
+ exchange.setException(new IllegalArgumentException("Damn"));
+
+ Producer producer = endpoint.createProducer();
+ producer.start();
+ producer.process(exchange);
+ producer.stop();
+ }
+
+ public void testSendCaughtExchangeWithExceptionAndStackTrace() throws Exception {
+ Endpoint endpoint = resolveMandatoryEndpoint("log:org.apache.camel.TEST?showCaughtException=true&showStackTrace=true");
+ Exchange exchange = endpoint.createExchange();
+ exchange.getIn().setBody("Hello World");
+ exchange.setProperty(Exchange.EXCEPTION_CAUGHT, new IllegalArgumentException("I am caught"));
+
+ Producer producer = endpoint.createProducer();
+ producer.start();
+ producer.process(exchange);
+ producer.stop();
+ }
+
+ public void testConfiguration() {
+ DefaultExchangeFormatter formatter = new DefaultExchangeFormatter();
+
+ assertFalse(formatter.isShowExchangeId());
+ assertFalse(formatter.isShowProperties());
+ assertFalse(formatter.isShowHeaders());
+ assertTrue(formatter.isShowBodyType());
+ assertTrue(formatter.isShowBody());
+ assertFalse(formatter.isShowOut());
+ assertFalse(formatter.isShowException());
+ assertFalse(formatter.isShowCaughtException());
+ assertFalse(formatter.isShowStackTrace());
+ assertFalse(formatter.isShowAll());
+ assertFalse(formatter.isMultiline());
+ assertEquals(10000, formatter.getMaxChars());
+ }
+
+ private static class MyFuture extends FutureTask<String> {
+
+ public MyFuture(Callable<String> callable) {
+ super(callable);
+ }
+
+ public MyFuture(Runnable runnable, String o) {
+ super(runnable, o);
+ }
+
+ @Override
+ public boolean isDone() {
+ return true;
+ }
+
+ @Override
+ public String get() throws InterruptedException, ExecutionException {
+ return "foo";
+ }
+
+ @Override
+ public String toString() {
+ return "ThisIsMyFuture";
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/55901baa/camel-core/src/test/java/org/apache/camel/component/log/LogFormatterTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/log/LogFormatterTest.java b/camel-core/src/test/java/org/apache/camel/component/log/LogFormatterTest.java
deleted file mode 100644
index 5267c2f..0000000
--- a/camel-core/src/test/java/org/apache/camel/component/log/LogFormatterTest.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/**
- * 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.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;
-import org.apache.camel.Producer;
-
-/**
- * Logger formatter test.
- */
-public class LogFormatterTest extends ContextTestSupport {
-
- public void testSendMessageToLogDefault() throws Exception {
- template.sendBody("log:org.apache.camel.TEST", "Hello World");
- }
-
- public void testSendMessageToLogAllOff() throws Exception {
- template.sendBody("log:org.apache.camel.TEST?showBody=false&showBodyType=false&showExchangePattern=false", "Hello World");
- }
-
- public void testSendMessageToLogSingleOptions() throws Exception {
- template.sendBody("log:org.apache.camel.TEST?showExchangeId=true", "Hello World");
- template.sendBody("log:org.apache.camel.TEST?showExchangePattern=true", "Hello World");
- template.sendBody("log:org.apache.camel.TEST?showExchangePattern=false", "Hello World");
- template.sendBody("log:org.apache.camel.TEST?showProperties=true", "Hello World");
- template.sendBody("log:org.apache.camel.TEST?showHeaders=true", "Hello World");
- template.sendBody("log:org.apache.camel.TEST?showBodyType=true", "Hello World");
- template.sendBody("log:org.apache.camel.TEST?showBody=true", "Hello World");
- template.sendBody("log:org.apache.camel.TEST?showOut=true", "Hello World");
- template.sendBody("log:org.apache.camel.TEST?showOut=true&showHeaders=true", "Hello World");
- 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<String>() {
- public String call() throws Exception {
- return "foo";
- }
- }));
- template.sendBody("log:org.apache.camel.TEST?showFuture=false", new MyFuture(new Callable<String>() {
- public String call() throws Exception {
- return "bar";
- }
- }));
- }
-
- public void testSendMessageToLogMultiOptions() throws Exception {
- template.sendBody("log:org.apache.camel.TEST?showHeaders=true&showOut=true", "Hello World");
- template.sendBody("log:org.apache.camel.TEST?showProperties=true&showHeaders=true&showOut=true", "Hello World");
- }
-
- public void testSendMessageToLogShowFalse() throws Exception {
- template.sendBody("log:org.apache.camel.TEST?showBodyType=false", "Hello World");
- }
-
- public void testSendMessageToLogMultiLine() throws Exception {
- template.sendBody("log:org.apache.camel.TEST?multiline=true", "Hello World");
- }
-
- public void testSendByteArrayMessageToLogDefault() throws Exception {
- template.sendBody("log:org.apache.camel.TEST", "Hello World".getBytes());
- }
-
- public void testSendMessageToLogMaxChars() throws Exception {
- template.sendBody("log:org.apache.camel.TEST",
- "Hello World this is a very long string that is NOT going to be chopped by maxchars");
-
- template.sendBody("log:org.apache.camel.TEST?maxChars=50",
- "Hello World this is a very long string that is going to be chopped by maxchars");
-
- template.sendBody("log:org.apache.camel.TEST?maxChars=50&showAll=true&multiline=true",
- "Hello World this is a very long string that is going to be chopped by maxchars");
- }
-
- public void testSendExchangeWithOut() throws Exception {
- Endpoint endpoint = resolveMandatoryEndpoint("log:org.apache.camel.TEST?showAll=true&multiline=true");
- Exchange exchange = endpoint.createExchange();
- exchange.getIn().setBody("Hello World");
- exchange.getOut().setBody(22);
-
- Producer producer = endpoint.createProducer();
- producer.start();
- producer.process(exchange);
- producer.stop();
- }
-
- public void testSendExchangeWithException() throws Exception {
- Endpoint endpoint = resolveMandatoryEndpoint("log:org.apache.camel.TEST?showException=true");
- Exchange exchange = endpoint.createExchange();
- exchange.getIn().setBody("Hello World");
- exchange.setException(new IllegalArgumentException("Damn"));
-
- Producer producer = endpoint.createProducer();
- producer.start();
- producer.process(exchange);
- producer.stop();
- }
-
- public void testSendCaughtExchangeWithException() throws Exception {
- Endpoint endpoint = resolveMandatoryEndpoint("log:org.apache.camel.TEST?showCaughtException=true");
- Exchange exchange = endpoint.createExchange();
- exchange.getIn().setBody("Hello World");
- exchange.setProperty(Exchange.EXCEPTION_CAUGHT, new IllegalArgumentException("I am caught"));
-
- Producer producer = endpoint.createProducer();
- producer.start();
- producer.process(exchange);
- producer.stop();
- }
-
- public void testSendCaughtExchangeWithExceptionAndMultiline() throws Exception {
- Endpoint endpoint = resolveMandatoryEndpoint("log:org.apache.camel.TEST?showCaughtException=true&multiline=true");
- Exchange exchange = endpoint.createExchange();
- exchange.getIn().setBody("Hello World");
- exchange.setProperty(Exchange.EXCEPTION_CAUGHT, new IllegalArgumentException("I am caught"));
-
- Producer producer = endpoint.createProducer();
- producer.start();
- producer.process(exchange);
- producer.stop();
- }
-
- public void testSendExchangeWithExceptionAndStackTrace() throws Exception {
- Endpoint endpoint = resolveMandatoryEndpoint("log:org.apache.camel.TEST?showException=true&showStackTrace=true");
- Exchange exchange = endpoint.createExchange();
- exchange.getIn().setBody("Hello World");
- exchange.setException(new IllegalArgumentException("Damn"));
-
- Producer producer = endpoint.createProducer();
- producer.start();
- producer.process(exchange);
- producer.stop();
- }
-
- public void testSendCaughtExchangeWithExceptionAndStackTrace() throws Exception {
- Endpoint endpoint = resolveMandatoryEndpoint("log:org.apache.camel.TEST?showCaughtException=true&showStackTrace=true");
- Exchange exchange = endpoint.createExchange();
- exchange.getIn().setBody("Hello World");
- exchange.setProperty(Exchange.EXCEPTION_CAUGHT, new IllegalArgumentException("I am caught"));
-
- Producer producer = endpoint.createProducer();
- producer.start();
- producer.process(exchange);
- producer.stop();
- }
-
- public void testConfiguration() {
- LogFormatter formatter = new LogFormatter();
-
- assertFalse(formatter.isShowExchangeId());
- assertFalse(formatter.isShowProperties());
- assertFalse(formatter.isShowHeaders());
- assertTrue(formatter.isShowBodyType());
- assertTrue(formatter.isShowBody());
- assertFalse(formatter.isShowOut());
- assertFalse(formatter.isShowException());
- assertFalse(formatter.isShowCaughtException());
- assertFalse(formatter.isShowStackTrace());
- assertFalse(formatter.isShowAll());
- assertFalse(formatter.isMultiline());
- assertEquals(10000, formatter.getMaxChars());
- }
-
- private static class MyFuture extends FutureTask<String> {
-
- public MyFuture(Callable<String> callable) {
- super(callable);
- }
-
- public MyFuture(Runnable runnable, String o) {
- super(runnable, o);
- }
-
- @Override
- public boolean isDone() {
- return true;
- }
-
- @Override
- public String get() throws InterruptedException, ExecutionException {
- return "foo";
- }
-
- @Override
- public String toString() {
- return "ThisIsMyFuture";
- }
- }
-}
[4/4] git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/camel
Posted by da...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/camel
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0cad912e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0cad912e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0cad912e
Branch: refs/heads/master
Commit: 0cad912e0bd04ece2f97184ae6236303adade1e1
Parents: 55901ba 011002f
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jun 13 14:04:27 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jun 13 14:04:27 2013 +0200
----------------------------------------------------------------------
.../component/netty/http/NettyHttpEndpoint.java | 9 +++----
.../component/netty/http/NettyHttpSSLTest.java | 16 +++++++++++-
.../camel/component/netty/NettyConstants.java | 1 +
.../camel/component/netty/NettyEndpoint.java | 27 +++++++++++++++++---
.../camel/component/netty/NettySSLTest.java | 9 ++++++-
5 files changed, 50 insertions(+), 12 deletions(-)
----------------------------------------------------------------------