camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r770107 - in /camel/branches/camel-1.x/components/camel-saxon/src: main/java/org/apache/camel/component/xquery/ test/java/org/apache/camel/component/xquery/ test/resources/org/apache/camel/component/xquery/
Date Thu, 30 Apr 2009 08:09:44 GMT
Author: ningjiang
Date: Thu Apr 30 08:09:43 2009
New Revision: 770107

URL: http://svn.apache.org/viewvc?rev=770107&view=rev
Log:
CAMEL-1559 support to get the vaule of in message header in XQuery

Added:
    camel/branches/camel-1.x/components/camel-saxon/src/test/resources/org/apache/camel/component/xquery/transform_with_headers.xquery
Modified:
    camel/branches/camel-1.x/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java
    camel/branches/camel-1.x/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryPropogateHeadersTest.java

Modified: camel/branches/camel-1.x/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java?rev=770107&r1=770106&r2=770107&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java
(original)
+++ camel/branches/camel-1.x/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java
Thu Apr 30 08:09:43 2009
@@ -417,20 +417,25 @@
     protected void configureQuery(DynamicQueryContext dynamicQueryContext, Exchange exchange)
         throws Exception {
         addParameters(dynamicQueryContext, exchange.getProperties());
-        addParameters(dynamicQueryContext, exchange.getIn().getHeaders());
+        addParameters(dynamicQueryContext, exchange.getIn().getHeaders(), "in.headers.");
+        dynamicQueryContext.setParameter("in.body", exchange.getIn().getBody());
         addParameters(dynamicQueryContext, getParameters());
 
         dynamicQueryContext.setParameter("exchange", exchange);
-        Message out = exchange.getOut(false);
-        if (out != null && exchange.getPattern().isOutCapable()) {
-            dynamicQueryContext.setParameter("out", out);
+        if (exchange.getOut(false) != null && exchange.getPattern().isOutCapable())
{
+            dynamicQueryContext.setParameter("out.body", exchange.getOut().getBody());
+            addParameters(dynamicQueryContext, exchange.getOut().getHeaders(), "out.headers.");
         }
     }
-
+    
     protected void addParameters(DynamicQueryContext dynamicQueryContext, Map<String,
Object> map) {
+        addParameters(dynamicQueryContext, map, "");        
+    }
+
+    protected void addParameters(DynamicQueryContext dynamicQueryContext, Map<String,
Object> map, String parameterPrefix) {
         Set<Map.Entry<String, Object>> propertyEntries = map.entrySet();
         for (Map.Entry<String, Object> entry : propertyEntries) {
-            dynamicQueryContext.setParameter(entry.getKey(), entry.getValue());
+            dynamicQueryContext.setParameter(parameterPrefix + entry.getKey(), entry.getValue());
         }
     }
 

Modified: camel/branches/camel-1.x/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryPropogateHeadersTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryPropogateHeadersTest.java?rev=770107&r1=770106&r2=770107&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryPropogateHeadersTest.java
(original)
+++ camel/branches/camel-1.x/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryPropogateHeadersTest.java
Thu Apr 30 08:09:43 2009
@@ -28,7 +28,7 @@
     public void testPropogateHeadersTest() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
-        mock.expectedBodiesReceived("<transformed subject=\"Hey\"><mail><subject>Hey</subject>"
+        mock.expectedBodiesReceived("<transformed sender=\"bar\" subject=\"Hey\"><mail><subject>Hey</subject>"
             + "<body>Hello world!</body></mail></transformed>");
         mock.expectedHeaderReceived("foo", "bar");
 
@@ -66,7 +66,7 @@
         return new RouteBuilder() {
             public void configure() throws Exception {
                 from("direct:one")
-                    .to("xquery:org/apache/camel/component/xquery/transform.xquery")
+                    .to("xquery:org/apache/camel/component/xquery/transform_with_headers.xquery")
                     .to("mock:result");
 
                 from("direct:two")

Added: camel/branches/camel-1.x/components/camel-saxon/src/test/resources/org/apache/camel/component/xquery/transform_with_headers.xquery
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-saxon/src/test/resources/org/apache/camel/component/xquery/transform_with_headers.xquery?rev=770107&view=auto
==============================================================================
--- camel/branches/camel-1.x/components/camel-saxon/src/test/resources/org/apache/camel/component/xquery/transform_with_headers.xquery
(added)
+++ camel/branches/camel-1.x/components/camel-saxon/src/test/resources/org/apache/camel/component/xquery/transform_with_headers.xquery
Thu Apr 30 08:09:43 2009
@@ -0,0 +1,4 @@
+declare variable $in.headers.foo as xs:string external;
+<transformed sender="{$in.headers.foo}" subject="{mail/subject}">
+{.}
+</transformed>
\ No newline at end of file



Mime
View raw message