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 2015/12/05 11:09:43 UTC
[2/2] camel git commit: CAMEL-9380: Using method call expression
should be nice and take care if the user specify the bean name with ref or
bean as prefix.
CAMEL-9380: Using method call expression should be nice and take care if the user specify the bean name with ref or bean as prefix.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0af39922
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0af39922
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0af39922
Branch: refs/heads/master
Commit: 0af399221e1236d5e1cb0367213896f4a3522e0b
Parents: 24dd79f
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Dec 5 11:08:03 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Dec 5 11:09:35 2015 +0100
----------------------------------------------------------------------
.../camel/component/bean/RegistryBean.java | 17 ++++--
.../bean/MethodCallRefOrBeanPrefixTest.java | 58 ++++++++++++++++++++
2 files changed, 71 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/0af39922/camel-core/src/main/java/org/apache/camel/component/bean/RegistryBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/bean/RegistryBean.java b/camel-core/src/main/java/org/apache/camel/component/bean/RegistryBean.java
index 5f645f9..742aaa4 100644
--- a/camel-core/src/main/java/org/apache/camel/component/bean/RegistryBean.java
+++ b/camel-core/src/main/java/org/apache/camel/component/bean/RegistryBean.java
@@ -35,15 +35,24 @@ public class RegistryBean implements BeanHolder {
private ParameterMappingStrategy parameterMappingStrategy;
public RegistryBean(CamelContext context, String name) {
- this.context = context;
- this.name = name;
- this.registry = context.getRegistry();
+ this(context.getRegistry(), context, name);
}
public RegistryBean(Registry registry, CamelContext context, String name) {
this.registry = registry;
this.context = context;
- this.name = name;
+ if (name != null) {
+ // for ref it may have "ref:" or "bean:" as prefix by mistake
+ if (name.startsWith("ref:")) {
+ this.name = name.substring(4);
+ } else if (name.startsWith("bean:")) {
+ this.name = name.substring(5);
+ } else {
+ this.name = name;
+ }
+ } else {
+ this.name = null;
+ }
}
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/0af39922/camel-core/src/test/java/org/apache/camel/component/bean/MethodCallRefOrBeanPrefixTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/bean/MethodCallRefOrBeanPrefixTest.java b/camel-core/src/test/java/org/apache/camel/component/bean/MethodCallRefOrBeanPrefixTest.java
new file mode 100644
index 0000000..94081c2
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/bean/MethodCallRefOrBeanPrefixTest.java
@@ -0,0 +1,58 @@
+/**
+ * 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.bean;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+
+/**
+ * @version
+ */
+public class MethodCallRefOrBeanPrefixTest extends ContextTestSupport {
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ jndi.bind("foo", new MyFooBean());
+ return jndi;
+ }
+
+ public void testRefOrBeanPrefix() throws Exception {
+ getMockEndpoint("mock:a").expectedBodiesReceived("Hello A");
+ getMockEndpoint("mock:b").expectedBodiesReceived("Hello B");
+
+ template.sendBody("direct:a", "A");
+ template.sendBody("direct:b", "B");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:a")
+ .transform().method("ref:foo").to("mock:a");
+
+ from("direct:b")
+ .transform().method("bean:foo").to("mock:b");
+ }
+ };
+ }
+}
\ No newline at end of file