Author: ningjiang
Date: Sun Mar 24 06:54:08 2013
New Revision: 1460266
URL: http://svn.apache.org/r1460266
Log:
CAMEL-6179 Fixed the issue that Simple expression in spring XML doesn't work if
it comes in multiple xml lines with thanks to Othman
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleWhiteSpaceTest.java
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/language/spel/SpringSimpleMultiLineExpressionTest.java
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/language/SpringSimpleMultiLineExpressionTest.xml
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java?rev=1460266&r1=1460265&r2=1460266&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java
Sun Mar 24 06:54:08 2013
@@ -34,6 +34,9 @@ public final class SimpleTokenizer {
static {
// add known tokens
KNOWN_TOKENS.add(new SimpleTokenType(TokenType.whiteSpace, " "));
+ KNOWN_TOKENS.add(new SimpleTokenType(TokenType.whiteSpace, "\t"));
+ KNOWN_TOKENS.add(new SimpleTokenType(TokenType.whiteSpace, "\n"));
+ KNOWN_TOKENS.add(new SimpleTokenType(TokenType.whiteSpace, "\r"));
KNOWN_TOKENS.add(new SimpleTokenType(TokenType.singleQuote, "'"));
KNOWN_TOKENS.add(new SimpleTokenType(TokenType.doubleQuote, "\""));
KNOWN_TOKENS.add(new SimpleTokenType(TokenType.functionStart, "${"));
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleWhiteSpaceTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleWhiteSpaceTest.java?rev=1460266&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleWhiteSpaceTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleWhiteSpaceTest.java
Sun Mar 24 06:54:08 2013
@@ -0,0 +1,57 @@
+/**
+ * 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.simple;
+
+import org.apache.camel.LanguageTestSupport;
+
+public class SimpleWhiteSpaceTest extends LanguageTestSupport {
+
+ @Override
+ protected String getLanguageName() {
+ return "simple";
+ }
+
+ public void testExpressionWithSpace() {
+ exchange.getIn().setBody("some text");
+ assertPredicate("${in.body} contains 'some' and ${in.body} contains
'text'", true);
+ }
+
+ public void testExpressionWithTabs() {
+ exchange.getIn().setBody("some text");
+ assertPredicate("${in.body} contains 'some' and\t${in.body} contains
'text'", true);
+ }
+
+ public void testUnixMultiLineExpression() {
+ exchange.getIn().setBody("some text");
+ assertPredicate("${in.body} contains 'some' and\n${in.body} contains
'text'", true);
+ }
+
+ public void testWindowsMultiLineExpression() {
+ exchange.getIn().setBody("some text");
+ assertPredicate("${in.body} contains 'some' and\r\n${in.body} contains
'text'", true);
+ }
+
+ public void testMacMultiLineExpression() {
+ exchange.getIn().setBody("some text");
+ assertPredicate("${in.body} contains 'some' and\r${in.body} contains
'text'", true);
+ }
+
+ public void testExpressionWithMultiLineString() {
+ exchange.getIn().setBody("\tsome\nmulti\rline\r\ntext");
+ assertPredicate("${in.body} == '\tsome\nmulti\rline\r\ntext'", true);
+ }
+}
Added:
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/language/spel/SpringSimpleMultiLineExpressionTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/language/spel/SpringSimpleMultiLineExpressionTest.java?rev=1460266&view=auto
==============================================================================
---
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/language/spel/SpringSimpleMultiLineExpressionTest.java
(added)
+++
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/language/spel/SpringSimpleMultiLineExpressionTest.java
Sun Mar 24 06:54:08 2013
@@ -0,0 +1,37 @@
+/**
+ * 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.spel;
+
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class SpringSimpleMultiLineExpressionTest extends SpringTestSupport {
+
+ @Override
+ protected AbstractXmlApplicationContext createApplicationContext() {
+ return new
ClassPathXmlApplicationContext("org/apache/camel/language/SpringSimpleMultiLineExpressionTest.xml");
+ }
+
+ public void testSimpleMultiLineExpression() {
+ String result = template.requestBodyAndHeader("direct:start", "Camel",
"h", "some text", String.class);
+ assertThat(result, is("correct"));
+ }
+}
Added:
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/language/SpringSimpleMultiLineExpressionTest.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/language/SpringSimpleMultiLineExpressionTest.xml?rev=1460266&view=auto
==============================================================================
---
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/language/SpringSimpleMultiLineExpressionTest.xml
(added)
+++
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/language/SpringSimpleMultiLineExpressionTest.xml
Sun Mar 24 06:54:08 2013
@@ -0,0 +1,47 @@
+<?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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <choice>
+ <when>
+ <simple>
+ ${header.h} contains 'some' and
+ ${header.h} contains 'text'
+ </simple>
+ <transform>
+ <constant>correct</constant>
+ </transform>
+ </when>
+ <otherwise>
+ <transform>
+ <constant>incorrect</constant>
+ </transform>
+ </otherwise>
+ </choice>
+ </route>
+ </camelContext>
+
+</beans>