CAMEL-6395: Fixed bean language when using method name parameter and hardcoded 
parameter values with dots.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0033647c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0033647c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0033647c

Branch: refs/heads/camel-2.10.x
Commit: 0033647c9bba085b9889c8b46dd7eb57995160c0
Parents: 48aa626
Author: Claus Ibsen <davscl...@apache.org>
Authored: Fri May 24 17:26:26 2013 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Fri May 24 17:27:15 2013 +0200

----------------------------------------------------------------------
 .../apache/camel/language/bean/BeanLanguage.java   |   14 ++--
 .../BeanLanguageOGNLWithDotInParameterTest.java    |   64 +++++++++++++++
 2 files changed, 72 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0033647c/camel-core/src/main/java/org/apache/camel/language/bean/BeanLanguage.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/language/bean/BeanLanguage.java 
b/camel-core/src/main/java/org/apache/camel/language/bean/BeanLanguage.java
index 9b0215b..bad9808 100644
--- a/camel-core/src/main/java/org/apache/camel/language/bean/BeanLanguage.java
+++ b/camel-core/src/main/java/org/apache/camel/language/bean/BeanLanguage.java
@@ -87,15 +87,17 @@ public class BeanLanguage implements Language, IsSingleton {
 
         // we support both the .method name and the ?method= syntax
         // as the ?method= syntax is very common for the bean component
-        int idx = expression.lastIndexOf('.');
-        if (idx > 0) {
-            beanName = expression.substring(0, idx);
-            method = expression.substring(idx + 1);
-        } else if (expression.contains("?method=")) {
+        if (expression.contains("?method=")) {
             beanName = ObjectHelper.before(expression, "?");
             method = ObjectHelper.after(expression, "?method=");
+        } else {
+            int idx = expression.lastIndexOf('.');
+            if (idx > 0) {
+                beanName = expression.substring(0, idx);
+                method = expression.substring(idx + 1);
+            }
         }
-        
+
         return new BeanExpression(beanName, method);
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/0033647c/camel-core/src/test/java/org/apache/camel/language/BeanLanguageOGNLWithDotInParameterTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/language/BeanLanguageOGNLWithDotInParameterTest.java
 
b/camel-core/src/test/java/org/apache/camel/language/BeanLanguageOGNLWithDotInParameterTest.java
new file mode 100644
index 0000000..7cb329b
--- /dev/null
+++ 
b/camel-core/src/test/java/org/apache/camel/language/BeanLanguageOGNLWithDotInParameterTest.java
@@ -0,0 +1,64 @@
+/**
+ * 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.language;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+
+/**
+ * @version 
+ */
+public class BeanLanguageOGNLWithDotInParameterTest extends ContextTestSupport 
{
+
+    public void testDot() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+        getMockEndpoint("mock:result").expectedHeaderReceived("goto", 
"mock:MyAppV1.2.3/blah");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+
+    }
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("myBean", new MyDestinationBean());
+        return jndi;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    
.setHeader("goto").simple("${bean:myBean?method=whereToMate('MyAppV1.2.3', 
'blah')}")
+                    .to("mock:result");
+            }
+        };
+    }
+
+    public static class MyDestinationBean {
+
+        public String whereToMate(String version, String id) {
+            return "mock:" + version + "/" + id;
+        }
+
+    }
+}

Reply via email to