You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/08/03 21:53:35 UTC
svn commit: r562566 - in /activemq/camel/trunk/components/camel-ognl: ./
src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/camel/ src/main/java/org/apache/camel/language/
src/main/java/org/apache/camel/...
Author: jstrachan
Date: Fri Aug 3 12:53:33 2007
New Revision: 562566
URL: http://svn.apache.org/viewvc?view=rev&rev=562566
Log:
added support for OGNL expressiona and predicates for CAMEL-87
Added:
activemq/camel/trunk/components/camel-ognl/
activemq/camel/trunk/components/camel-ognl/pom.xml
activemq/camel/trunk/components/camel-ognl/src/
activemq/camel/trunk/components/camel-ognl/src/main/
activemq/camel/trunk/components/camel-ognl/src/main/java/
activemq/camel/trunk/components/camel-ognl/src/main/java/org/
activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/
activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/
activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/
activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/
activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlExpression.java
activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlLanguage.java
activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/RootObject.java
activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/package.html
activemq/camel/trunk/components/camel-ognl/src/main/resources/
activemq/camel/trunk/components/camel-ognl/src/main/resources/META-INF/
activemq/camel/trunk/components/camel-ognl/src/main/resources/META-INF/services/
activemq/camel/trunk/components/camel-ognl/src/main/resources/META-INF/services/org/
activemq/camel/trunk/components/camel-ognl/src/main/resources/META-INF/services/org/apache/
activemq/camel/trunk/components/camel-ognl/src/main/resources/META-INF/services/org/apache/camel/
activemq/camel/trunk/components/camel-ognl/src/main/resources/META-INF/services/org/apache/camel/language/
activemq/camel/trunk/components/camel-ognl/src/main/resources/META-INF/services/org/apache/camel/language/ognl
activemq/camel/trunk/components/camel-ognl/src/test/
activemq/camel/trunk/components/camel-ognl/src/test/java/
activemq/camel/trunk/components/camel-ognl/src/test/java/org/
activemq/camel/trunk/components/camel-ognl/src/test/java/org/apache/
activemq/camel/trunk/components/camel-ognl/src/test/java/org/apache/camel/
activemq/camel/trunk/components/camel-ognl/src/test/java/org/apache/camel/language/
activemq/camel/trunk/components/camel-ognl/src/test/java/org/apache/camel/language/ognl/
activemq/camel/trunk/components/camel-ognl/src/test/java/org/apache/camel/language/ognl/OgnlTest.java
activemq/camel/trunk/components/camel-ognl/src/test/resources/
Added: activemq/camel/trunk/components/camel-ognl/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ognl/pom.xml?view=auto&rev=562566
==============================================================================
--- activemq/camel/trunk/components/camel-ognl/pom.xml (added)
+++ activemq/camel/trunk/components/camel-ognl/pom.xml Fri Aug 3 12:53:33 2007
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-parent</artifactId>
+ <version>1.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-ognl</artifactId>
+ <name>Camel :: OGNL</name>
+ <description>Camel OGNL support</description>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>ognl</groupId>
+ <artifactId>ognl</artifactId>
+ <version>2.6.9</version>
+ </dependency>
+
+ <!-- testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Added: activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlExpression.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlExpression.java?view=auto&rev=562566
==============================================================================
--- activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlExpression.java (added)
+++ activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlExpression.java Fri Aug 3 12:53:33 2007
@@ -0,0 +1,78 @@
+/*
+ * 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.ognl;
+
+import ognl.Ognl;
+import ognl.OgnlContext;
+import ognl.OgnlException;
+import org.apache.camel.Exchange;
+import org.apache.camel.language.IllegalSyntaxException;
+import org.apache.camel.language.ExpressionEvaluationException;
+import org.apache.camel.impl.ExpressionSupport;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @version $Revision: $
+ */
+public class OgnlExpression extends ExpressionSupport<Exchange> {
+
+ private final String expressionString;
+ private final Class<?> type;
+ private Object expression;
+
+ public static OgnlExpression ognl(String expression) {
+ return new OgnlExpression(new OgnlLanguage(), expression, Object.class);
+ }
+
+ public OgnlExpression(OgnlLanguage language, String expressionString, Class<?> type) {
+ this.expressionString = expressionString;
+ this.type = type;
+ try {
+ this.expression = Ognl.parseExpression(expressionString);
+ }
+ catch (OgnlException e) {
+ throw new IllegalSyntaxException(language, expressionString);
+ }
+ }
+
+ public Object evaluate(Exchange exchange) {
+ // TODO we could use caching here but then we'd have possible concurrency issues
+ // so lets assume that the provider caches
+ Map values = new HashMap();
+ populateContext(values, exchange);
+ OgnlContext oglContext = new OgnlContext();
+ try {
+ return Ognl.getValue(expression, oglContext, new RootObject(exchange));
+ }
+ catch (OgnlException e) {
+ throw new ExpressionEvaluationException(this, exchange, e);
+ }
+ }
+
+
+ protected void populateContext(Map map, Exchange exchange) {
+ map.put("exchange", exchange);
+ map.put("in", exchange.getIn());
+ map.put("out", exchange.getOut());
+ }
+
+ protected String assertionFailureMessage(Exchange exchange) {
+ return expressionString;
+ }
+}
Added: activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlLanguage.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlLanguage.java?view=auto&rev=562566
==============================================================================
--- activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlLanguage.java (added)
+++ activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlLanguage.java Fri Aug 3 12:53:33 2007
@@ -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.language.ognl;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
+import org.apache.camel.Predicate;
+import org.apache.camel.spi.Language;
+
+/**
+ * @version $Revision: $
+ */
+public class OgnlLanguage implements Language {
+
+ public Predicate<Exchange> createPredicate(String expression) {
+ return new OgnlExpression(this, expression, Boolean.class);
+ }
+
+ public Expression<Exchange> createExpression(String expression) {
+ return new OgnlExpression(this, expression, Object.class);
+ }
+}
Added: activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/RootObject.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/RootObject.java?view=auto&rev=562566
==============================================================================
--- activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/RootObject.java (added)
+++ activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/RootObject.java Fri Aug 3 12:53:33 2007
@@ -0,0 +1,81 @@
+/*
+ * 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.ognl;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+
+import java.util.Map;
+
+/**
+ * @version $Revision: $
+ */
+public class RootObject {
+ private final Exchange exchange;
+
+ public RootObject(Exchange exchange) {
+ this.exchange = exchange;
+ }
+
+ public Exchange getExchange() {
+ return exchange;
+ }
+
+ public CamelContext getContext() {
+ return exchange.getContext();
+ }
+
+ public Throwable getException() {
+ return exchange.getException();
+ }
+
+ public String getExchangeId() {
+ return exchange.getExchangeId();
+ }
+
+ public Message getFault() {
+ return exchange.getFault();
+ }
+
+ public Message getRequest() {
+ return exchange.getIn();
+ }
+ public Message getIn() {
+ return exchange.getIn();
+ }
+
+ public Message getOut() {
+ return exchange.getOut();
+ }
+
+ public Message getResponse() {
+ return exchange.getOut();
+ }
+
+ public Map<String, Object> getProperties() {
+ return exchange.getProperties();
+ }
+
+ public Object getProperty(String name) {
+ return exchange.getProperty(name);
+ }
+
+ public <T> T getProperty(String name, Class<T> type) {
+ return exchange.getProperty(name, type);
+ }
+}
Added: activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/package.html
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/package.html?view=auto&rev=562566
==============================================================================
--- activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/package.html (added)
+++ activemq/camel/trunk/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/package.html Fri Aug 3 12:53:33 2007
@@ -0,0 +1,26 @@
+<!--
+ 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.
+-->
+<html>
+<head>
+</head>
+<body>
+
+A <a href="http://activemq.apache.org/camel/language.html">Language Plugin</a> for the
+<a href="http://activemq.apache.org/camel/ognl.html">OGNL Language</a>
+
+</body>
+</html>
Added: activemq/camel/trunk/components/camel-ognl/src/main/resources/META-INF/services/org/apache/camel/language/ognl
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ognl/src/main/resources/META-INF/services/org/apache/camel/language/ognl?view=auto&rev=562566
==============================================================================
--- activemq/camel/trunk/components/camel-ognl/src/main/resources/META-INF/services/org/apache/camel/language/ognl (added)
+++ activemq/camel/trunk/components/camel-ognl/src/main/resources/META-INF/services/org/apache/camel/language/ognl Fri Aug 3 12:53:33 2007
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.language.ognl.OgnlLanguage
\ No newline at end of file
Added: activemq/camel/trunk/components/camel-ognl/src/test/java/org/apache/camel/language/ognl/OgnlTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ognl/src/test/java/org/apache/camel/language/ognl/OgnlTest.java?view=auto&rev=562566
==============================================================================
--- activemq/camel/trunk/components/camel-ognl/src/test/java/org/apache/camel/language/ognl/OgnlTest.java (added)
+++ activemq/camel/trunk/components/camel-ognl/src/test/java/org/apache/camel/language/ognl/OgnlTest.java Fri Aug 3 12:53:33 2007
@@ -0,0 +1,38 @@
+/*
+ * 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.ognl;
+
+import org.apache.camel.LanguageTestSupport;
+
+
+/**
+ * @version $Revision: $
+ */
+public class OgnlTest extends LanguageTestSupport {
+ public void testElExpressions() throws Exception {
+ assertExpression("exchange", exchange);
+ assertExpression("exchange.getIn().body", "<hello id='m123'>world!</hello>");
+ assertExpression("getIn().body", "<hello id='m123'>world!</hello>");
+ assertExpression("getIn().headers['foo']", "abc");
+ assertExpression("getIn().headers.foo", "abc");
+ assertExpression("request.headers.foo", "abc");
+ }
+
+ protected String getLanguageName() {
+ return "ognl";
+ }
+}