2013-05-15 221 views
1

我們對於駝峯路由的DSL有一些問題。這似乎是不可能翻譯下面的XML配置成Groovy的(或Java)DSLApache Camel:DSL(Groovy或Java)中的嵌套過濾器(過濾器...過濾器...結束...過濾器...結束..end)

<route id="myroute" > 
     <from uri="fromURI" /> 
     <filter> 
      <xpath>//entity[contains(@destinations, 'databasedestination')]</xpath> 
      <filter> 
       <xpath>//entity[@objectType = 'objectType']</xpath> 
       <camel:setHeader headerName="bodyTemp"> 
        <simple>${body}</simple> 
       </camel:setHeader> 
       <filter> 
        <xpath>//entity[@command = 'add']</xpath> 
        <convertBodyTo type="com.foo.bar.Entity" /> 
        <bean ref="handler" method="add" /> 
       </filter> 
       <filter> 
        <xpath>//entity[@command = 'foo']</xpath> 
        <convertBodyTo type="com.foo.bar.Entity" /> 
        <bean ref="handler" method="foo" /> 
       </filter> 
       <filter> 
        <xpath>//entity[@command = 'bar']</xpath> 
        <convertBodyTo type="com.foo.bar.Entity" /> 
        <bean ref="handler" method="bar" /> 
       </filter> 
       <to uri="toURI" />  
      </filter> 
     </filter> 
    </route> 

魏某想它基於Groovy RouteBuilder內翻譯如下:

from("fromURI") 
     .filter().xpath('//entity[contains(@destinations, \'databasedestination\')]') 
      .setHeader("bodyTemp", simple('${body}')) 
      .filter().xpath('//entity[@objectType = \'objectType\']') 

       .filter().xpath('//entity[@command = \'add\']') 
        .convertBodyTo(com.foo.bar.Entity) 
        .bean(handler, "add") 
       .end() 
       .filter().xpath('//entity[@command = \'foo\']') 
        .convertBodyTo(com.foo.bar.Entity) 
        .bean(handler, "foo") 
       .end() 
       .filter().xpath('//entity[@command = \'bar\']') 
        .convertBodyTo(com.foo.bar.Entity) 
        .bean(handler, "bar") 
       .end() 

       .to("toURI") 
      .end() 
     .end() 

但是,顯然不起作用。我們得到一個javax.xml.xpath.XPathExpressionException與消息:Invalid xpath: //entity[@command = 'foo']

也請參閱相應的堆棧跟蹤。

 
    ->> 814 | doInEvaluateAs  in org.apache.camel.builder.xml.XPathBuilder 
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    | 697 | evaluateAs   in  '' 
    | 139 | matches . . . . . . in  '' 
    |  47 | process    in org.apache.camel.processor.FilterProcessor 
    |  73 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper 
    |  99 | processNext   in org.apache.camel.processor.DelegateAsyncProcessor 
    |  90 | process . . . . . . in  '' 
    |  73 | process    in org.apache.camel.management.InstrumentationProcessor 
    |  99 | processNext . . . . in org.apache.camel.processor.DelegateAsyncProcessor 
    |  90 | process    in  '' 
    |  91 | process . . . . . . in    org.apache.camel.processor.interceptor.TraceInterceptor 
    |  73 | process    in org.apache.camel.util.AsyncProcessorHelper 
    | 330 | processErrorHandler in org.apache.camel.processor.RedeliveryErrorHandler 
    | 220 | process    in  '' 
    |  45 | processNext . . . . in org.apache.camel.processor.RouteContextProcessor 
    |  90 | process    in org.apache.camel.processor.DelegateAsyncProcessor 
    | 303 | process . . . . . . in org.apache.camel.processor.interceptor.DefaultChannel 
    |  73 | process    in org.apache.camel.util.AsyncProcessorHelper 
    | 117 | process . . . . . . in org.apache.camel.processor.Pipeline 
    |  80 | process    in  '' 
    |  45 | processNext . . . . in org.apache.camel.processor.RouteContextProcessor 
    |  90 | process    in org.apache.camel.processor.DelegateAsyncProcessor 
    | 150 | processAsync . . . in org.apache.camel.processor.UnitOfWorkProcessor 
    | 117 | process    in  '' 
    |  48 | processNext . . . . in  org.apache.camel.processor.RouteInflightRepositoryProcessor 
    |  90 | process    in org.apache.camel.processor.DelegateAsyncProcessor 
    |  73 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper 
    |  99 | processNext   in org.apache.camel.processor.DelegateAsyncProcessor 
    |  90 | process . . . . . . in  '' 
    |  73 | process    in org.apache.camel.management.InstrumentationProcessor 
    |  99 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper 
    |  86 | process    in org.apache.camel.processor.DelegateAsyncProcessor 
    | 105 | onMessage . . . . . in org.apache.camel.component.jms.EndpointMessageListener 
    | 1110 | runWorker   in java.util.concurrent.ThreadPoolExecutor 
    | 603 | run . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker 
    ^ 722 | run     in java.lang.Thread 
    Caused by XPathExpressionException: null 
    ->> 200 | evaluate   in  com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl 
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    | 800 | doInEvaluateAs  in org.apache.camel.builder.xml.XPathBuilder 
    | 697 | evaluateAs . . . . in  '' 
    | 139 | matches    in  '' 
    |  47 | process . . . . . . in org.apache.camel.processor.FilterProcessor 
    |  73 | process    in org.apache.camel.util.AsyncProcessorHelper 
    |  99 | processNext . . . . in org.apache.camel.processor.DelegateAsyncProcessor 
    |  90 | process    in  '' 
    |  73 | process . . . . . . in org.apache.camel.management.InstrumentationProcessor 
    |  99 | processNext   in org.apache.camel.processor.DelegateAsyncProcessor 
    |  90 | process . . . . . . in  '' 
    |  91 | process    in org.apache.camel.processor.interceptor.TraceInterceptor 
    |  73 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper 
    | 330 | processErrorHandler in org.apache.camel.processor.RedeliveryErrorHandler 
    | 220 | process . . . . . . in  '' 
    |  45 | processNext   in org.apache.camel.processor.RouteContextProcessor 
    |  90 | process . . . . . . in org.apache.camel.processor.DelegateAsyncProcessor 
    | 303 | process    in org.apache.camel.processor.interceptor.DefaultChannel 
    |  73 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper 
    | 117 | process    in org.apache.camel.processor.Pipeline 
    |  80 | process . . . . . . in  '' 
    |  45 | processNext   in org.apache.camel.processor.RouteContextProcessor 
    |  90 | process . . . . . . in org.apache.camel.processor.DelegateAsyncProcessor 
    | 150 | processAsync  in org.apache.camel.processor.UnitOfWorkProcessor 
    | 117 | process . . . . . . in  '' 
    |  48 | processNext   in  org.apache.camel.processor.RouteInflightRepositoryProcessor 
    |  90 | process . . . . . . in org.apache.camel.processor.DelegateAsyncProcessor 
    |  73 | process    in org.apache.camel.util.AsyncProcessorHelper 
    |  99 | processNext . . . . in org.apache.camel.processor.DelegateAsyncProcessor 
    |  90 | process    in  '' 
    |  73 | process . . . . . . in org.apache.camel.management.InstrumentationProcessor 
    |  99 | process    in org.apache.camel.util.AsyncProcessorHelper 
    |  86 | process . . . . . . in org.apache.camel.processor.DelegateAsyncProcessor 
    | 105 | onMessage   in  org.apache.camel.component.jms.EndpointMessageListener 
    | 1110 | runWorker . . . . . in java.util.concurrent.ThreadPoolExecutor 
    | 603 | run     in java.util.concurrent.ThreadPoolExecutor$Worker 
    ^ 722 | run . . . . . . . . in java.lang.Thread 
    Caused by TransformerException: Unable to evaluate expression using this context 
    ->> 367 | execute    in com.sun.org.apache.xpath.internal.XPath 
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    | 129 | eval    in  com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl 
    | 105 | eval . . . . . . . in  '' 
    | 187 | evaluate   in  '' 
    | 800 | doInEvaluateAs . . in org.apache.camel.builder.xml.XPathBuilder 
    | 697 | evaluateAs   in  '' 
    | 139 | matches . . . . . . in  '' 
    |  47 | process    in org.apache.camel.processor.FilterProcessor 
    |  73 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper 
    |  99 | processNext   in org.apache.camel.processor.DelegateAsyncProcessor 
    |  90 | process . . . . . . in  '' 
    |  73 | process    in org.apache.camel.management.InstrumentationProcessor 
    |  99 | processNext . . . . in org.apache.camel.processor.DelegateAsyncProcessor 
    |  90 | process    in  '' 
    |  91 | process . . . . . . in  org.apache.camel.processor.interceptor.TraceInterceptor 
    |  73 | process    in org.apache.camel.util.AsyncProcessorHelper 
    | 330 | processErrorHandler in org.apache.camel.processor.RedeliveryErrorHandler 
    | 220 | process    `enter code here`in  '' 
    |  45 | processNext . . . . in org.apache.camel.processor.RouteContextProcessor 
    |  90 | process    in org.apache.camel.processor.DelegateAsyncProcessor 
    | 303 | process . . . . . . in org.apache.camel.processor.interceptor.DefaultChannel 
    |  73 | process    in org.apache.camel.util.AsyncProcessorHelper 
    | 117 | process . . . . . . in org.apache.camel.processor.Pipeline 
    |  80 | process    in  '' 
    |  45 | processNext . . . . in org.apache.camel.processor.RouteContextProcessor 
    |  90 | process    in org.apache.camel.processor.DelegateAsyncProcessor 
    | 150 | processAsync . . . in org.apache.camel.processor.UnitOfWorkProcessor 
    | 117 | process    in  '' 
    |  48 | processNext . . . . in  org.apache.camel.processor.RouteInflightRepositoryProcessor 
    |  90 | process    in org.apache.camel.processor.DelegateAsyncProcessor 
    |  73 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper 
    |  99 | processNext   in org.apache.camel.processor.DelegateAsyncProcessor 
    |  90 | process . . . . . . in  '' 
    |  73 | process    in org.apache.camel.management.InstrumentationProcessor 
    |  99 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper 
    |  86 | process    in org.apache.camel.processor.DelegateAsyncProcessor 
    | 105 | onMessage . . . . . in  org.apache.camel.component.jms.EndpointMessageListener 
    | 1110 | runWorker   in java.util.concurrent.ThreadPoolExecutor 
    | 603 | run . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker 
    ^ 722 | run     in java.lang.Thread 
    Caused by RuntimeException: Unable to evaluate expression using this context 
    ->> 266 | setRoot    in com.sun.org.apache.xpath.internal.axes.NodeSequence 
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    | 214 | execute    in  com.sun.org.apache.xpath.internal.axes.LocPathIterator 
    | 339 | execute . . . . . . in com.sun.org.apache.xpath.internal.XPath 
    | 129 | eval    in  com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl 
    | 105 | eval . . . . . . . in  '' 
    | 187 | evaluate   in  '' 
    | 800 | doInEvaluateAs . . in org.apache.camel.builder.xml.XPathBuilder 
    | 697 | evaluateAs   in  '' 
    | 139 | matches . . . . . . in  '' 
    |  47 | process    in org.apache.camel.processor.FilterProcessor 
    |  73 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper 
    |  99 | processNext   in org.apache.camel.processor.DelegateAsyncProcessor 
    |  90 | process . . . . . . in  '' 
    |  73 | process    in org.apache.camel.management.InstrumentationProcessor 
    |  99 | processNext . . . . in org.apache.camel.processor.DelegateAsyncProcessor 
    |  90 | process    in  '' 
    |  91 | process . . . . . . in  org.apache.camel.processor.interceptor.TraceInterceptor 
    |  73 | process    in org.apache.camel.util.AsyncProcessorHelper 
    | 330 | processErrorHandler in org.apache.camel.processor.RedeliveryErrorHandler 
    | 220 | process    in  '' 
    |  45 | processNext . . . . in org.apache.camel.processor.RouteContextProcessor 
    |  90 | process    in org.apache.camel.processor.DelegateAsyncProcessor 
    | 303 | process . . . . . . in org.apache.camel.processor.interceptor.DefaultChannel 
    |  73 | process    in org.apache.camel.util.AsyncProcessorHelper 
    | 117 | process . . . . . . in org.apache.camel.processor.Pipeline 
    |  80 | process    in  '' 
    |  45 | processNext . . . . in org.apache.camel.processor.RouteContextProcessor 
    |  90 | process    in org.apache.camel.processor.DelegateAsyncProcessor 
    | 150 | processAsync . . . in org.apache.camel.processor.UnitOfWorkProcessor 
    | 117 | process    in  '' 
    |  48 | processNext . . . . in  org.apache.camel.processor.RouteInflightRepositoryProcessor 
    |  90 | process    in org.apache.camel.processor.DelegateAsyncProcessor 
    |  73 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper 
    |  99 | processNext   in org.apache.camel.processor.DelegateAsyncProcessor 
    |  90 | process . . . . . . in  '' 
    |  73 | process    in org.apache.camel.management.InstrumentationProcessor 
    |  99 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper 
    |  86 | process    in org.apache.camel.processor.DelegateAsyncProcessor 
    | 105 | onMessage . . . . . in  org.apache.camel.component.jms.EndpointMessageListener 
    | 1110 | runWorker   in java.util.concurrent.ThreadPoolExecutor 
    | 603 | run . . `enter code here`. . . . . . in  java.util.concurrent.ThreadPoolExecutor$Worker 
    ^ 722 | run     in java.lang.Thread 

感謝您的幫助

馬庫斯

回答

0

您的代碼似乎是更合適的基於內容的路由,利用選擇EIP的。

您是否能夠使用選擇語句? http://camel.apache.org/content-based-router.html

+0

我不認爲這將適用於所示場景。我寧願通過過濾器解決它,我想我也需要。請解釋一下我的例子究竟有什麼問題? –