Author: davsclaus
Date: Mon Aug 22 13:24:42 2011
New Revision: 1160262
URL: http://svn.apache.org/viewvc?rev=1160262&view=rev
Log:
CAMEL-4364: Simple language ognl map access now support keys with enclosing
quotes.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleOgnlMapIssueTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java?rev=1160262&r1=1160261&r2=1160262&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java
Mon Aug 22 13:24:42 2011
@@ -32,6 +32,7 @@ import org.apache.camel.component.bean.R
import org.apache.camel.util.KeyValueHolder;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.OgnlHelper;
+import org.apache.camel.util.StringHelper;
/**
* Evaluates an expression using a bean method invocation
@@ -237,9 +238,14 @@ public class BeanExpression implements E
}
private Object lookupResult(Exchange exchange, String key, Object
result, boolean nullSafe, String ognlPath, Object bean) {
+ ObjectHelper.notEmpty(key, "key", "in Simple language ognl path: "
+ ognlPath);
+
// trim key
key = key.trim();
+ // remove any enclosing quotes
+ key = StringHelper.removeLeadingAndEndingQuotes(key);
+
// try map first
Map map =
exchange.getContext().getTypeConverter().convertTo(Map.class, result);
if (map != null) {
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleOgnlMapIssueTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleOgnlMapIssueTest.java?rev=1160262&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleOgnlMapIssueTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleOgnlMapIssueTest.java
Mon Aug 22 13:24:42 2011
@@ -0,0 +1,80 @@
+/**
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Based on user forum issue
+ */
+public class SimpleOgnlMapIssueTest extends ContextTestSupport {
+
+ @SuppressWarnings("unchecked")
+ public void testSimpleOgnlIssueKing() throws Exception {
+ getMockEndpoint("mock:king").expectedMessageCount(1);
+ getMockEndpoint("mock:other").expectedMessageCount(0);
+
+ MyObjectMessage body = new MyObjectMessage();
+ body.getProperty().put("foo", "King Kong");
+ template.sendBody("direct:start", body);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testSimpleOgnlIssueOther() throws Exception {
+ getMockEndpoint("mock:king").expectedMessageCount(0);
+ getMockEndpoint("mock:other").expectedMessageCount(1);
+
+ MyObjectMessage body = new MyObjectMessage();
+ body.getProperty().put("foo", "Tiger");
+ template.sendBody("direct:start", body);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .choice()
+ .when().simple("${body.property['foo']} == 'King
Kong'")
+ .to("mock:king")
+ .otherwise()
+ .to("mock:other");
+ }
+ };
+ }
+
+ public static final class MyObjectMessage {
+ private Map property;
+
+ public MyObjectMessage() {
+ this.property = new HashMap();
+ }
+
+ public Map getProperty() {
+ return property;
+ }
+ }
+}