Author: ningjiang
Date: Fri Aug 31 08:23:08 2012
New Revision: 1379352

URL: http://svn.apache.org/viewvc?rev=1379352&view=rev
Log:
CAMEL-5550 Add headerName option to xpath/xpath language with thanks to Alan

Added:
    
camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathHeaderNameResultTypeAndNamespaceTest.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathHeaderNameTest.java
    
camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XQueryHeaderNameResultTypeAndNamespaceTest.java
    
camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XQueryHeaderNameTest.java
Modified:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/XPathExpression.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/XQueryExpression.java
    
camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java?rev=1379352&r1=1379351&r2=1379352&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java
 Fri Aug 31 08:23:08 2012
@@ -580,6 +580,19 @@ public class ExpressionClause<T> extends
     public T xpath(String text) {
         return delegate.xpath(text);
     }
+    
+
+    /**
+     * Evaluates an <a href="http://camel.apache.org/xpath.html";>XPath
+     * expression</a> on the supplied header name's contents
+     * 
+     * @param text the expression to be evaluated
+     * @param headerName the name of the header to apply the expression to
+     * @return the builder to continue processing the DSL
+     */
+    public T xpath(String text, String headerName) {
+        return delegate.xpath(text, headerName);
+    }
 
     /**
      * Evaluates an <a href="http://camel.apache.org/xpath.html";>XPath
@@ -592,7 +605,21 @@ public class ExpressionClause<T> extends
     public T xpath(String text, Class<?> resultType) {
         return delegate.xpath(text, resultType);
     }
-
+    
+    /**
+     * Evaluates an <a href="http://camel.apache.org/xpath.html";>XPath
+     * expression</a> with the specified result type on the supplied
+     * header name's contents
+     * 
+     * @param text the expression to be evaluated
+     * @param resultType the return type expected by the expression
+     * @param headerName the name of the header to apply the expression to
+     * @return the builder to continue processing the DSL
+     */
+    public T xpath(String text, Class<?> resultType, String headerName) {
+        return delegate.xpath(text, resultType, headerName);
+    }
+    
     /**
      * Evaluates an <a href="http://camel.apache.org/xpath.html";>XPath
      * expression</a> with the specified result type and set of namespace
@@ -610,6 +637,22 @@ public class ExpressionClause<T> extends
     /**
      * Evaluates an <a href="http://camel.apache.org/xpath.html";>XPath
      * expression</a> with the specified result type and set of namespace
+     * prefixes and URIs on the supplied header name's contents
+     * 
+     * @param text the expression to be evaluated
+     * @param resultType the return type expected by the expression
+     * @param headerName the name of the header to apply the expression to
+     * @param namespaces the namespace prefix and URIs to use
+     * 
+     * @return the builder to continue processing the DSL
+     */
+    public T xpath(String text, Class<?> resultType, Namespaces namespaces, 
String headerName) {
+        return delegate.xpath(text, resultType, namespaces, headerName);
+    }
+    
+    /**
+     * Evaluates an <a href="http://camel.apache.org/xpath.html";>XPath
+     * expression</a> with the specified result type and set of namespace
      * prefixes and URIs
      * 
      * @param text the expression to be evaluated
@@ -655,6 +698,19 @@ public class ExpressionClause<T> extends
     public T xquery(String text) {
         return delegate.xquery(text);
     }
+    
+    /**
+     * Evaluates an <a href="http://camel.apache.org/xpath.html";>XPath
+     * expression</a> on the supplied header name's contents
+     * 
+     * @param text the expression to be evaluated
+     * @param headerName the name of the header to apply the expression to
+     * @return the builder to continue processing the DSL
+     */
+    public T xquery(String text, String headerName) {
+        return delegate.xquery(text, headerName);
+    }
+
 
     /**
      * Evaluates an <a
@@ -668,7 +724,22 @@ public class ExpressionClause<T> extends
     public T xquery(String text, Class<?> resultType) {
         return delegate.xquery(text, resultType);
     }
-
+    
+    /**
+     * Evaluates an <a
+     * href="http://camel.apache.org/xquery.html";>XQuery expression</a>
+     * with the specified result type
+     * 
+     * @param text the expression to be evaluated
+     * @param text the expression to be evaluated
+     * @param resultType the return type expected by the expression
+     * @param headerName the name of the header to apply the expression to
+     * @return the builder to continue processing the DSL
+     */
+    public T xquery(String text, Class<?> resultType, String headerName) {
+        return delegate.xquery(text, resultType, headerName);
+    }
+    
     /**
      * Evaluates an <a
      * href="http://camel.apache.org/xquery.html";>XQuery expression</a>
@@ -682,7 +753,22 @@ public class ExpressionClause<T> extends
     public T xquery(String text, Class<?> resultType, Namespaces namespaces) {
         return delegate.xquery(text, resultType, namespaces);
     }
-
+    
+    /**
+     * Evaluates an <a
+     * href="http://camel.apache.org/xquery.html";>XQuery expression</a>
+     * with the specified result type
+     * 
+     * @param text the expression to be evaluated
+     * @param resultType the return type expected by the expression
+     * @param headerName the name of the header to apply the expression to
+     * @param namespaces the namespace prefix and URIs to use
+     * 
+     * @return the builder to continue processing the DSL
+     */
+    public T xquery(String text, Class<?> resultType, Namespaces namespaces, 
String headerName) {
+        return delegate.xquery(text, resultType, namespaces, headerName);
+    }
     /**
      * Evaluates an <a
      * href="http://camel.apache.org/xquery.html";>XQuery expression</a>

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java?rev=1379352&r1=1379351&r2=1379352&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java
 Fri Aug 31 08:23:08 2012
@@ -613,7 +613,21 @@ public class ExpressionClauseSupport<T> 
     public T xpath(String text) {
         return expression(new XPathExpression(text));
     }
-
+    
+    /**
+     * Evaluates an <a href="http://camel.apache.org/xpath.html";>XPath
+     * expression</a> on the supplied header name's contents
+     * 
+     * @param text the expression to be evaluated
+     * @param headerName the name of the header to apply the expression to
+     * @return the builder to continue processing the DSL
+     */
+    public T xpath(String text, String headerName) {
+        XPathExpression expression = new XPathExpression(text);
+        expression.setHeaderName(headerName);
+        return expression(expression);
+    }
+    
     /**
      * Evaluates an <a href="http://camel.apache.org/xpath.html";>XPath
      * expression</a> with the specified result type
@@ -629,6 +643,25 @@ public class ExpressionClauseSupport<T> 
         return result;
     }
 
+    
+    /**
+     * Evaluates an <a href="http://camel.apache.org/xpath.html";>XPath
+     * expression</a> with the specified result type on the supplied
+     * header name's contents
+     *
+     * @param text the expression to be evaluated
+     * @param resultType the return type expected by the expression
+     * @param headerName the name of the header to apply the expression to
+     * @return the builder to continue processing the DSL
+     */
+    public T xpath(String text, Class<?> resultType, String headerName) {
+        XPathExpression expression = new XPathExpression(text);
+        expression.setHeaderName(headerName);
+        setExpressionType(expression);
+        return result;
+    }
+    
+
     /**
      * Evaluates an <a href="http://camel.apache.org/xpath.html";>XPath
      * expression</a> with the specified result type and set of namespace
@@ -642,6 +675,27 @@ public class ExpressionClauseSupport<T> 
     public T xpath(String text, Class<?> resultType, Namespaces namespaces) {
         return xpath(text, resultType, namespaces.getNamespaces());
     }
+    
+    /**
+     * Evaluates an <a href="http://camel.apache.org/xpath.html";>XPath
+     * expression</a> with the specified result type and set of namespace
+     * prefixes and URIs on the supplied header name's contents
+     *
+     * @param text the expression to be evaluated
+     * @param resultType the return type expected by the expression
+     * @param namespaces the namespace prefix and URIs to use
+     * @param headerName the name of the header to apply the expression to
+     * @return the builder to continue processing the DSL
+     */
+    public T xpath(String text, Class<?> resultType, Namespaces namespaces, 
String headerName) {
+        XPathExpression expression = new XPathExpression(text);
+        expression.setResultType(resultType);
+        expression.setNamespaces(namespaces.getNamespaces());
+        expression.setHeaderName(headerName);
+        setExpressionType(expression);
+        return result;
+    }
+
 
     /**
      * Evaluates an <a href="http://camel.apache.org/xpath.html";>XPath
@@ -700,6 +754,20 @@ public class ExpressionClauseSupport<T> 
     }
 
     /**
+     * Evaluates an <a href="http://camel.apache.org/xquery.html";>XQuery
+     * expression</a>
+     * 
+     * @param text the expression to be evaluated
+     * @param headerName the name of the header to apply the expression to
+     * @return the builder to continue processing the DSL
+     */
+    public T xquery(String text, String headerName) {
+        XQueryExpression expression = new XQueryExpression(text);
+        expression.setHeaderName(headerName);
+        return expression(expression);
+    }
+
+    /**
      * Evaluates an <a
      * href="http://camel.apache.org/xquery.html";>XQuery expression</a>
      * with the specified result type
@@ -714,6 +782,24 @@ public class ExpressionClauseSupport<T> 
         setExpressionType(expression);
         return result;
     }
+    
+    
+    /**
+     * Evaluates an <a
+     * href="http://camel.apache.org/xquery.html";>XQuery expression</a>
+     * with the specified result type
+     *
+     * @param text the expression to be evaluated
+     * @param resultType the return type expected by the expression
+     * @param headerName the name of the header to apply the expression to
+     * @return the builder to continue processing the DSL
+     */
+    public T xquery(String text, Class<?> resultType, String headerName) {
+        XQueryExpression expression = new XQueryExpression(text);
+        expression.setHeaderName(headerName);
+        setExpressionType(expression);
+        return result;
+    }
 
     /**
      * Evaluates an <a
@@ -728,7 +814,29 @@ public class ExpressionClauseSupport<T> 
     public T xquery(String text, Class<?> resultType, Namespaces namespaces) {
         return xquery(text, resultType, namespaces.getNamespaces());
     }
+    
+    /**
+     * Evaluates an <a
+     * href="http://camel.apache.org/xquery.html";>XQuery expression</a>
+     * with the specified result type and set of namespace prefixes and URIs
+     *
+     * @param text the expression to be evaluated
+     * @param resultType the return type expected by the expression
+     * @param namespaces the namespace prefix and URIs to use
+     * @param headerName the name of the header to apply the expression to
+     * @return the builder to continue processing the DSL
+     */
+    public T xquery(String text, Class<?> resultType, Namespaces namespaces, 
String headerName) {
+        XQueryExpression expression = new XQueryExpression(text);
+        expression.setResultType(resultType);
+        expression.setNamespaces(namespaces.getNamespaces());
+        expression.setHeaderName(headerName);
+        setExpressionType(expression);
+        return result;
+    }
+
 
+    
     /**
      * Evaluates an <a
      * href="http://camel.apache.org/xquery.html";>XQuery expression</a>

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/XPathExpression.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/XPathExpression.java?rev=1379352&r1=1379351&r2=1379352&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/XPathExpression.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/XPathExpression.java
 Fri Aug 31 08:23:08 2012
@@ -45,11 +45,14 @@ public class XPathExpression extends Nam
     private String objectModel;
     @XmlAttribute(name = "logNamespaces")
     private Boolean logNamespaces;
-
+    @XmlAttribute(name = "headerName")
+    private String headerName;
+    
     @XmlTransient
     private Class<?> resultType;
     @XmlTransient
     private XPathFactory xpathFactory;
+    
 
     public XPathExpression() {
     }
@@ -121,6 +124,14 @@ public class XPathExpression extends Nam
     public boolean isLogNamespaces() {
         return logNamespaces != null && logNamespaces;
     }
+    
+    public String getHeaderName() {
+        return headerName;
+    }
+
+    public void setHeaderName(String headerName) {
+        this.headerName = headerName;
+    }
 
     @Override
     public Expression createExpression(CamelContext camelContext) {
@@ -158,6 +169,9 @@ public class XPathExpression extends Nam
         if (isLogNamespaces()) {
             ObjectHelper.cast(XPathBuilder.class, 
expression).setLogNamespaces(true);
         }
+        if (ObjectHelper.isNotEmpty(getHeaderName())) {
+            ObjectHelper.cast(XPathBuilder.class, 
expression).setHeaderName(getHeaderName());
+        }
         // moved the super configuration to the bottom so that the namespace 
init picks up the newly set XPath Factory
         super.configureExpression(camelContext, expression);
 
@@ -180,6 +194,9 @@ public class XPathExpression extends Nam
         if (isLogNamespaces()) {
             ObjectHelper.cast(XPathBuilder.class, 
predicate).setLogNamespaces(true);
         }
+        if (ObjectHelper.isNotEmpty(getHeaderName())) {
+            ObjectHelper.cast(XPathBuilder.class, 
predicate).setHeaderName(getHeaderName());
+        }
         // moved the super configuration to the bottom so that the namespace 
init picks up the newly set XPath Factory
         super.configurePredicate(camelContext, predicate);
     }

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/XQueryExpression.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/XQueryExpression.java?rev=1379352&r1=1379351&r2=1379352&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/XQueryExpression.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/XQueryExpression.java
 Fri Aug 31 08:23:08 2012
@@ -39,6 +39,8 @@ public class XQueryExpression extends Na
     private String type;
     @XmlTransient
     private Class<?> resultType;
+    @XmlAttribute
+    private String headerName;
 
     public XQueryExpression() {
     }
@@ -67,6 +69,14 @@ public class XQueryExpression extends Na
         this.resultType = resultType;
     }
 
+    public String getHeaderName() {
+        return headerName;
+    }
+
+    public void setHeaderName(String headerName) {
+        this.headerName = headerName;
+    }
+    
     @Override
     public Expression createExpression(CamelContext camelContext) {
         if (resultType == null && type != null) {
@@ -86,6 +96,9 @@ public class XQueryExpression extends Na
         if (resultType != null) {
             setProperty(expression, "resultType", resultType);
         }
+        if (ObjectHelper.isNotEmpty(getHeaderName())) {
+            setProperty(expression, "headerName", getHeaderName());
+        }
     }
 
     @Override
@@ -94,6 +107,9 @@ public class XQueryExpression extends Na
         if (resultType != null) {
             setProperty(predicate, "resultType", resultType);
         }
+        if (ObjectHelper.isNotEmpty(getHeaderName())) {
+            setProperty(predicate, "headerName", getHeaderName());
+        }
     }
 
 }

Added: 
camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathHeaderNameResultTypeAndNamespaceTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathHeaderNameResultTypeAndNamespaceTest.java?rev=1379352&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathHeaderNameResultTypeAndNamespaceTest.java
 (added)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathHeaderNameResultTypeAndNamespaceTest.java
 Fri Aug 31 08:23:08 2012
@@ -0,0 +1,51 @@
+/**
+ * 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.builder.xml;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * Test XPath DSL with the ability to apply XPath on a header
+ */
+public class XPathHeaderNameResultTypeAndNamespaceTest extends 
ContextTestSupport {
+    public void testXPathWithNamespace() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:55");
+        mock.expectedBodiesReceived("body");
+        mock.expectedHeaderReceived("cheeseDetails", "<number 
xmlns=\"http://acme.com/cheese\";>55</number>");
+
+        template.sendBodyAndHeader("direct:in", "body", "cheeseDetails", 
"<number xmlns=\"http://acme.com/cheese\";>55</number>");
+
+        mock.assertIsSatisfied();
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                Namespaces ns = new Namespaces("c", "http://acme.com/cheese";);
+
+                from("direct:in").choice()
+                    .when().xpath("/c:number = 55", Integer.class, ns, 
"cheeseDetails")
+                        .to("mock:55")
+                    .otherwise()
+                        .to("mock:other")
+                    .end();
+            }
+        };
+    }
+}

Added: 
camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathHeaderNameTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathHeaderNameTest.java?rev=1379352&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathHeaderNameTest.java
 (added)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathHeaderNameTest.java
 Fri Aug 31 08:23:08 2012
@@ -0,0 +1,70 @@
+/**
+ * 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.builder.xml;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * Test XPath DSL with the ability to apply XPath on a header
+ */
+public class XPathHeaderNameTest extends ContextTestSupport {
+    public void testChoiceWithHeaderNamePremium() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:premium");
+        mock.expectedBodiesReceived("<response>OK</response>");
+        mock.expectedHeaderReceived("invoiceDetails", "<invoice 
orderType='premium'><person><name>Alan</name></person></invoice>");
+ 
+        template.sendBodyAndHeader("direct:in", "<response>OK</response>",
+                                   "invoiceDetails", "<invoice 
orderType='premium'><person><name>Alan</name></person></invoice>");
+
+        mock.assertIsSatisfied();
+    }
+
+    public void testChoiceWithHeaderNameStandard() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:standard");
+        mock.expectedBodiesReceived("<response>OK</response>");
+        mock.expectedHeaderReceived("invoiceDetails", "<invoice 
orderType='standard'><person><name>Alan</name></person></invoice>");
+ 
+        template.sendBodyAndHeader("direct:in", "<response>OK</response>",
+                                   "invoiceDetails", "<invoice 
orderType='standard'><person><name>Alan</name></person></invoice>");
+
+        mock.assertIsSatisfied();
+    }
+    
+    public void testChoiceWithHeaderNameUnknown() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:unknown");
+        mock.expectedBodiesReceived("<response>OK</response>");
+        mock.expectedHeaderReceived("invoiceDetails", "<invoice />");
+ 
+        template.sendBodyAndHeader("direct:in", "<response>OK</response>",
+                                   "invoiceDetails", "<invoice />");
+
+        mock.assertIsSatisfied();
+    }
+    
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("direct:in")
+                    .choice().when().xpath("/invoice/@orderType = 'premium'", 
"invoiceDetails")
+                    .to("mock:premium").when().xpath("/invoice/@orderType = 
'standard'", "invoiceDetails")
+                    .to("mock:standard").otherwise().to("mock:unknown").end();
+            }
+        };
+    }
+}

Modified: 
camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java?rev=1379352&r1=1379351&r2=1379352&view=diff
==============================================================================
--- 
camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java
 (original)
+++ 
camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java
 Fri Aug 31 08:23:08 2012
@@ -194,8 +194,8 @@ public abstract class XQueryBuilder impl
         initialize(exchange);
 
         StringWriter buffer = new StringWriter();
-        SequenceIterator<?> iter = 
getExpression().iterator(createDynamicContext(exchange));
-        for (Item<?> item = iter.next(); item != null; item = iter.next()) {
+        SequenceIterator iter = 
getExpression().iterator(createDynamicContext(exchange));
+        for (Item item = iter.next(); item != null; item = iter.next()) {
             buffer.append(item.getStringValueCS());
         }
 
@@ -463,7 +463,7 @@ public abstract class XQueryBuilder impl
         DynamicQueryContext dynamicQueryContext = new 
DynamicQueryContext(config);
 
         Message in = exchange.getIn();
-        Item<?> item = null;
+        Item item = null;
         if (ObjectHelper.isNotEmpty(getHeaderName())) {
             item = in.getHeader(getHeaderName(), Item.class);
         } else {

Added: 
camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XQueryHeaderNameResultTypeAndNamespaceTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XQueryHeaderNameResultTypeAndNamespaceTest.java?rev=1379352&view=auto
==============================================================================
--- 
camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XQueryHeaderNameResultTypeAndNamespaceTest.java
 (added)
+++ 
camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XQueryHeaderNameResultTypeAndNamespaceTest.java
 Fri Aug 31 08:23:08 2012
@@ -0,0 +1,54 @@
+/**
+ * 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.builder.saxon;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.builder.xml.Namespaces;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * Test XPath DSL with the ability to apply XPath on a header
+ */
+public class XQueryHeaderNameResultTypeAndNamespaceTest extends 
CamelTestSupport {
+    @Test
+    public void testXPathWithNamespace() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:55");
+        mock.expectedBodiesReceived("body");
+        mock.expectedHeaderReceived("cheeseDetails", "<number 
xmlns=\"http://acme.com/cheese\";>55</number>");
+
+        template.sendBodyAndHeader("direct:in", "body", "cheeseDetails", 
"<number xmlns=\"http://acme.com/cheese\";>55</number>");
+
+        mock.assertIsSatisfied();
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                Namespaces ns = new Namespaces("c", "http://acme.com/cheese";);
+
+                from("direct:in").choice()
+                    .when().xquery("/c:number = 55", Integer.class, ns, 
"cheeseDetails")
+                        .to("mock:55")
+                    .otherwise()
+                        .to("mock:other")
+                    .end();
+            }
+        };
+    }
+}

Added: 
camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XQueryHeaderNameTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XQueryHeaderNameTest.java?rev=1379352&view=auto
==============================================================================
--- 
camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XQueryHeaderNameTest.java
 (added)
+++ 
camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XQueryHeaderNameTest.java
 Fri Aug 31 08:23:08 2012
@@ -0,0 +1,79 @@
+/**
+ * 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.builder.saxon;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * Test XQuery DSL with the ability to apply XPath on a header
+ */
+public class XQueryHeaderNameTest extends CamelTestSupport {
+    @Test
+    public void testChoiceWithHeaderNamePremium() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:premium");
+        mock.expectedBodiesReceived("<response>OK</response>");
+        mock.expectedHeaderReceived("invoiceDetails", "<invoice 
orderType='premium'><person><name>Alan</name></person></invoice>");
+ 
+        template.sendBodyAndHeader("direct:in", "<response>OK</response>",
+                                   "invoiceDetails", "<invoice 
orderType='premium'><person><name>Alan</name></person></invoice>");
+
+        mock.assertIsSatisfied();
+    }
+
+    @Test
+    public void testChoiceWithHeaderNameStandard() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:standard");
+        mock.expectedBodiesReceived("<response>OK</response>");
+        mock.expectedHeaderReceived("invoiceDetails", "<invoice 
orderType='standard'><person><name>Alan</name></person></invoice>");
+ 
+        template.sendBodyAndHeader("direct:in", "<response>OK</response>",
+                                   "invoiceDetails", "<invoice 
orderType='standard'><person><name>Alan</name></person></invoice>");
+
+        mock.assertIsSatisfied();
+    }
+    
+    @Test
+    public void testChoiceWithHeaderNameUnknown() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:unknown");
+        mock.expectedBodiesReceived("<response>OK</response>");
+        mock.expectedHeaderReceived("invoiceDetails", "<invoice />");
+ 
+        template.sendBodyAndHeader("direct:in", "<response>OK</response>",
+                                   "invoiceDetails", "<invoice />");
+
+        mock.assertIsSatisfied();
+    }
+    
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("direct:in")
+                    .choice()
+                        .when().xquery("/invoice/@orderType = 'premium'", 
"invoiceDetails")
+                            .to("mock:premium")
+                        .when().xquery("/invoice/@orderType = 'standard'", 
"invoiceDetails")
+                            .to("mock:standard")
+                        .otherwise()
+                            .to("mock:unknown")
+                        .end();
+            }
+        };
+    }
+}


Reply via email to