Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E51D6814B for ; Mon, 22 Aug 2011 13:25:07 +0000 (UTC) Received: (qmail 16465 invoked by uid 500); 22 Aug 2011 13:25:07 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 16429 invoked by uid 500); 22 Aug 2011 13:25:07 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 16422 invoked by uid 99); 22 Aug 2011 13:25:07 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Aug 2011 13:25:07 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Aug 2011 13:25:03 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id A96832388A02 for ; Mon, 22 Aug 2011 13:24:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1160262 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/language/bean/BeanExpression.java test/java/org/apache/camel/language/SimpleOgnlMapIssueTest.java Date: Mon, 22 Aug 2011 13:24:42 -0000 To: commits@camel.apache.org From: davsclaus@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110822132442.A96832388A02@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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; + } + } +}