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/03/10 15:03:02 UTC
camel git commit: CAMEL-10984: Creating consumer should inject
CamelContext if consumer is aware
Repository: camel
Updated Branches:
refs/heads/master 6343f8cce -> 38b5d1df2
CAMEL-10984: Creating consumer should inject CamelContext if consumer is aware
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/38b5d1df
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/38b5d1df
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/38b5d1df
Branch: refs/heads/master
Commit: 38b5d1df236d33e3392201b1ef5a12dc8f2dc3a6
Parents: 6343f8c
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Mar 10 15:33:22 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Mar 10 16:02:54 2017 +0100
----------------------------------------------------------------------
.../org/apache/camel/impl/DefaultEndpoint.java | 5 +++
.../component/vm/ConsumerCamelContextAware.java | 36 ++++++++++++++++++++
2 files changed, 41 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/38b5d1df/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
index eb99480..3a3dc07 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
@@ -493,6 +493,11 @@ public abstract class DefaultEndpoint extends ServiceSupport implements Endpoint
}
protected void configureConsumer(Consumer consumer) throws Exception {
+ // inject CamelContext
+ if (consumer instanceof CamelContextAware) {
+ ((CamelContextAware) consumer).setCamelContext(getCamelContext());
+ }
+
if (consumerProperties != null) {
// use a defensive copy of the consumer properties as the methods below will remove the used properties
// and in case we restart routes, we need access to the original consumer properties again
http://git-wip-us.apache.org/repos/asf/camel/blob/38b5d1df/camel-core/src/test/java/org/apache/camel/component/vm/ConsumerCamelContextAware.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/vm/ConsumerCamelContextAware.java b/camel-core/src/test/java/org/apache/camel/component/vm/ConsumerCamelContextAware.java
new file mode 100644
index 0000000..464e9b2
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/vm/ConsumerCamelContextAware.java
@@ -0,0 +1,36 @@
+/**
+ * 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.vm;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.ContextTestSupport;
+
+public class ConsumerCamelContextAware extends ContextTestSupport {
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ public void testConsumerCamelContextAware() throws Exception {
+ Consumer consumer = context.getEndpoint("vm:foo").createConsumer(null);
+ assertNotNull(consumer);
+
+ VmConsumer vm = assertIsInstanceOf(VmConsumer.class, consumer);
+ assertEquals(vm.getCamelContext(), context);
+ }
+}