CAMEL-9772: Make it easier to turn on/off logExhaustedMessageBody
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c76b432a Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c76b432a Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c76b432a Branch: refs/heads/master Commit: c76b432a991a8aef614f8d1c742d7d355cf64055 Parents: 52c5656 Author: Claus Ibsen <davscl...@apache.org> Authored: Tue Apr 12 08:21:04 2016 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Apr 12 08:21:04 2016 +0200 ---------------------------------------------------------------------- .../org/apache/camel/RuntimeConfiguration.java | 4 +-- ...CamelContextLogExhaustedMessageBodyTest.java | 5 +-- .../blueprint/CamelContextFactoryBean.java | 10 ++++++ .../xml/AbstractCamelContextFactoryBean.java | 5 +++ .../spring/boot/CamelAutoConfiguration.java | 1 + .../boot/CamelConfigurationProperties.java | 15 +++++++++ ...CamelContextLogExhaustedMessageBodyTest.java | 30 ++++++++++++++++++ ...gCamelContextLogExhaustedMessageBodyTest.xml | 33 ++++++++++++++++++++ 8 files changed, 97 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/c76b432a/camel-core/src/main/java/org/apache/camel/RuntimeConfiguration.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/RuntimeConfiguration.java b/camel-core/src/main/java/org/apache/camel/RuntimeConfiguration.java index 9ad8d69..7264ec0 100644 --- a/camel-core/src/main/java/org/apache/camel/RuntimeConfiguration.java +++ b/camel-core/src/main/java/org/apache/camel/RuntimeConfiguration.java @@ -67,14 +67,14 @@ public interface RuntimeConfiguration { Boolean isMessageHistory(); /** - * Sets whether the message body should be logged (default is disabled). + * Sets whether to log exhausted message body with message history. * * @param logExhaustedMessageBody whether message body should be logged */ void setLogExhaustedMessageBody(Boolean logExhaustedMessageBody); /** - * Returns whether the message body should be logged + * Returns whether to log exhausted message body with message history. * * @return <tt>true</tt> if logging of message body is enabled */ http://git-wip-us.apache.org/repos/asf/camel/blob/c76b432a/camel-core/src/test/java/org/apache/camel/processor/CamelContextLogExhaustedMessageBodyTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/processor/CamelContextLogExhaustedMessageBodyTest.java b/camel-core/src/test/java/org/apache/camel/processor/CamelContextLogExhaustedMessageBodyTest.java index bb294fd..f4d22b1 100644 --- a/camel-core/src/test/java/org/apache/camel/processor/CamelContextLogExhaustedMessageBodyTest.java +++ b/camel-core/src/test/java/org/apache/camel/processor/CamelContextLogExhaustedMessageBodyTest.java @@ -34,18 +34,15 @@ public class CamelContextLogExhaustedMessageBodyTest extends ContextTestSupport @Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); - context.setLogExhaustedMessageBody(Boolean.TRUE); + context.setLogExhaustedMessageBody(true); return context; } @Override protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override public void configure() throws Exception { - from("direct:start") .log("Incoming ${body}") .throwException(new IllegalArgumentException("Forced")); http://git-wip-us.apache.org/repos/asf/camel/blob/c76b432a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java ---------------------------------------------------------------------- diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java index 71dde2c..aaebc7f 100644 --- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java +++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java @@ -87,6 +87,8 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Blu @XmlAttribute(required = false) private String messageHistory; @XmlAttribute(required = false) + private String logExhaustedMessageBody; + @XmlAttribute(required = false) private String streamCache = "false"; @XmlAttribute(required = false) private String delayer; @@ -509,6 +511,14 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Blu this.messageHistory = messageHistory; } + public String getLogExhaustedMessageBody() { + return logExhaustedMessageBody; + } + + public void setLogExhaustedMessageBody(String logExhaustedMessageBody) { + this.logExhaustedMessageBody = logExhaustedMessageBody; + } + public String getStreamCache() { return streamCache; } http://git-wip-us.apache.org/repos/asf/camel/blob/c76b432a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java ---------------------------------------------------------------------- diff --git a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java index 3e9b5db..11f8151 100644 --- a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java +++ b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java @@ -695,6 +695,8 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex public abstract String getMessageHistory(); + public abstract String getLogExhaustedMessageBody(); + public abstract String getStreamCache(); public abstract String getDelayer(); @@ -772,6 +774,9 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex if (getMessageHistory() != null) { ctx.setMessageHistory(CamelContextHelper.parseBoolean(getContext(), getMessageHistory())); } + if (getLogExhaustedMessageBody() != null) { + ctx.setLogExhaustedMessageBody(CamelContextHelper.parseBoolean(getContext(), getLogExhaustedMessageBody())); + } if (getDelayer() != null) { ctx.setDelayer(CamelContextHelper.parseLong(getContext(), getDelayer())); } http://git-wip-us.apache.org/repos/asf/camel/blob/c76b432a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java index caedaf1..c0e308e 100644 --- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java +++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java @@ -65,6 +65,7 @@ public class CamelAutoConfiguration { camelContext.setStreamCaching(config.isStreamCaching()); camelContext.setTracing(config.isTracing()); camelContext.setMessageHistory(config.isMessageHistory()); + camelContext.setLogExhaustedMessageBody(config.isLogExhaustedMessageBody()); camelContext.setHandleFault(config.isHandleFault()); camelContext.setAutoStartup(config.isAutoStartup()); camelContext.setAllowUseOriginalMessage(config.isAllowUseOriginalMessage()); http://git-wip-us.apache.org/repos/asf/camel/blob/c76b432a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java index 7b2968f..8f65c9d 100644 --- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java +++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java @@ -98,6 +98,13 @@ public class CamelConfigurationProperties { private boolean messageHistory = true; /** + * Sets whether to log exhausted message body with message history. + * + * Default is false. + */ + private boolean logExhaustedMessageBody; + + /** * Sets whether fault handling is enabled or not. * * Default is false. @@ -252,6 +259,14 @@ public class CamelConfigurationProperties { this.messageHistory = messageHistory; } + public boolean isLogExhaustedMessageBody() { + return logExhaustedMessageBody; + } + + public void setLogExhaustedMessageBody(boolean logExhaustedMessageBody) { + this.logExhaustedMessageBody = logExhaustedMessageBody; + } + public boolean isHandleFault() { return handleFault; } http://git-wip-us.apache.org/repos/asf/camel/blob/c76b432a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCamelContextLogExhaustedMessageBodyTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCamelContextLogExhaustedMessageBodyTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCamelContextLogExhaustedMessageBodyTest.java new file mode 100644 index 0000000..efdd033 --- /dev/null +++ b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCamelContextLogExhaustedMessageBodyTest.java @@ -0,0 +1,30 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.spring.processor; + +import org.apache.camel.CamelContext; +import org.apache.camel.processor.CamelContextLogExhaustedMessageBodyTest; + +import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext; + +public class SpringCamelContextLogExhaustedMessageBodyTest extends CamelContextLogExhaustedMessageBodyTest { + + protected CamelContext createCamelContext() throws Exception { + return createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringCamelContextLogExhaustedMessageBodyTest.xml"); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/c76b432a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringCamelContextLogExhaustedMessageBodyTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringCamelContextLogExhaustedMessageBodyTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringCamelContextLogExhaustedMessageBodyTest.xml new file mode 100644 index 0000000..4455b84 --- /dev/null +++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringCamelContextLogExhaustedMessageBodyTest.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + <camelContext logExhaustedMessageBody="true" xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="direct:start"/> + <log message="Incoming ${body}"/> + <throwException exceptionType="java.lang.IllegalArgumentException" message="Forced"/> + </route> + </camelContext> + +</beans>