Apache Camel: how store variable for later use

前端 未结 2 956
情话喂你
情话喂你 2021-02-07 05:27

while \'playing around\' with Camel using Spring DSL, I came across the following problem. Suppose the expected message flow looks like this:

  1. client sends HTTP POS
相关标签:
2条回答
  • 2021-02-07 05:34

    I leave you some examples:

    <setHeader headerName="token">
        <constant>someValue</constant>
    </setHeader>
    
    <setHeader headerName="userName">
        <simple>${properties:userName}</simple>  //from config
    </setHeader>
    
    <setProperty propertyName="bodyBkp">
        <simple>${in.body}</simple>
    </setProperty>
    
    <setProperty propertyName="orderNumber">
        <xpath resultType="String">//item[1]/orderNumber/text()</xpath>
    </setProperty>
    

    Getter

    ${exchangeProperty[orderNumber]}
    
    ${in.headers.token}
    

    Documentation

    Check the simple expression language: http://camel.apache.org/simple.html

    Sometimes looking at the test cases of Camel can be helpful as well, in particular for Spring DSL:

    • setProperty with Spring DSL
    • setHeader using XPATH with Spring DSL
    • simple expression language test
    0 讨论(0)
  • 2021-02-07 05:40

    you can set store data in the Exchange properties or message headers like this...

    .setHeader("ID", XPathBuilder.xpath("/order/@id", String.class))
    .setProperty("ID", XPathBuilder.xpath("/order/@id", String.class))
    

    and then retrieve them in a bean/processor from the Exchange like this...

    String propId = (String) exchange.getProperty("ID");
    String headerId = (String) exchange.getIn().getHeader("ID");                        }
    
    0 讨论(0)
提交回复
热议问题