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 2017/01/27 13:27:25 UTC
[3/3] camel git commit: CAMEL-10741: Fixed NPE in log component if
created the endpoint from properties component. Thanks to David Martin for
test case and reporting.
CAMEL-10741: Fixed NPE in log component if created the endpoint from properties component. Thanks to David Martin for test case and reporting.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/00be849d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/00be849d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/00be849d
Branch: refs/heads/camel-2.17.x
Commit: 00be849dcc499b2cd7459cabdf10ad9fd4487786
Parents: 4a83c2a
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Jan 27 14:26:28 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Jan 27 14:27:14 2017 +0100
----------------------------------------------------------------------
.../apache/camel/component/log/LogEndpoint.java | 60 ++++++++++++--------
.../camel/processor/LogPropertiesTest.java | 47 +++++++++++++++
.../org/apache/camel/processor/foo.properties | 18 ++++++
3 files changed, 102 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/00be849d/camel-core/src/main/java/org/apache/camel/component/log/LogEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/log/LogEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/log/LogEndpoint.java
index 69cc6fb..f6bdad4 100644
--- a/camel-core/src/main/java/org/apache/camel/component/log/LogEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/log/LogEndpoint.java
@@ -78,28 +78,7 @@ public class LogEndpoint extends ProcessorEndpoint {
@Override
protected void doStart() throws Exception {
if (logger == null) {
- // setup a new logger here
- CamelLogger camelLogger;
- LoggingLevel loggingLevel = LoggingLevel.INFO;
- if (level != null) {
- loggingLevel = LoggingLevel.valueOf(level);
- }
- if (providedLogger == null) {
- camelLogger = new CamelLogger(loggerName, loggingLevel, getMarker());
- } else {
- camelLogger = new CamelLogger(providedLogger, loggingLevel, getMarker());
- }
- if (getGroupSize() != null) {
- logger = new ThroughputLogger(camelLogger, getGroupSize());
- } else if (getGroupInterval() != null) {
- Boolean groupActiveOnly = getGroupActiveOnly() != null ? getGroupActiveOnly() : Boolean.TRUE;
- Long groupDelay = getGroupDelay();
- logger = new ThroughputLogger(camelLogger, this.getCamelContext(), getGroupInterval(), groupDelay, groupActiveOnly);
- } else {
- logger = new CamelLogProcessor(camelLogger, localFormatter);
- }
- // the logger is the processor
- setProcessor(this.logger);
+ logger = createLogger();
}
ServiceHelper.startService(logger);
}
@@ -121,7 +100,12 @@ public class LogEndpoint extends ProcessorEndpoint {
@Override
public Producer createProducer() throws Exception {
- return new LogProducer(this, this.logger);
+ // ensure logger is created and started first
+ if (logger == null) {
+ logger = createLogger();
+ }
+ ServiceHelper.startService(logger);
+ return new LogProducer(this, logger);
}
@Override
@@ -130,6 +114,36 @@ public class LogEndpoint extends ProcessorEndpoint {
}
/**
+ * Creates the logger {@link Processor} to be used.
+ */
+ protected Processor createLogger() throws Exception {
+ Processor answer;
+ // setup a new logger here
+ CamelLogger camelLogger;
+ LoggingLevel loggingLevel = LoggingLevel.INFO;
+ if (level != null) {
+ loggingLevel = LoggingLevel.valueOf(level);
+ }
+ if (providedLogger == null) {
+ camelLogger = new CamelLogger(loggerName, loggingLevel, getMarker());
+ } else {
+ camelLogger = new CamelLogger(providedLogger, loggingLevel, getMarker());
+ }
+ if (getGroupSize() != null) {
+ answer = new ThroughputLogger(camelLogger, getGroupSize());
+ } else if (getGroupInterval() != null) {
+ Boolean groupActiveOnly = getGroupActiveOnly() != null ? getGroupActiveOnly() : Boolean.TRUE;
+ Long groupDelay = getGroupDelay();
+ answer = new ThroughputLogger(camelLogger, this.getCamelContext(), getGroupInterval(), groupDelay, groupActiveOnly);
+ } else {
+ answer = new CamelLogProcessor(camelLogger, localFormatter);
+ }
+ // the logger is the processor
+ setProcessor(answer);
+ return answer;
+ }
+
+ /**
* Logging level to use.
* <p/>
* The default value is INFO.
http://git-wip-us.apache.org/repos/asf/camel/blob/00be849d/camel-core/src/test/java/org/apache/camel/processor/LogPropertiesTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/LogPropertiesTest.java b/camel-core/src/test/java/org/apache/camel/processor/LogPropertiesTest.java
new file mode 100644
index 0000000..7bd02f2
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/LogPropertiesTest.java
@@ -0,0 +1,47 @@
+/**
+ * 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 org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version
+ */
+public class LogPropertiesTest extends ContextTestSupport {
+
+ public void testLogProperties() throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .to("properties:dude?locations=org/apache/camel/processor/foo.properties")
+ .to("mock:result");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/00be849d/camel-core/src/test/resources/org/apache/camel/processor/foo.properties
----------------------------------------------------------------------
diff --git a/camel-core/src/test/resources/org/apache/camel/processor/foo.properties b/camel-core/src/test/resources/org/apache/camel/processor/foo.properties
new file mode 100644
index 0000000..3e85c8f
--- /dev/null
+++ b/camel-core/src/test/resources/org/apache/camel/processor/foo.properties
@@ -0,0 +1,18 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+dude=log:dude
\ No newline at end of file