2015-11-19 63 views
0


我已經在Jboss Fuse BluePrint中定義了一個Camel路徑。我需要在Bean的運行時設置一個變量。看到這個例子:駱駝組件:動態地從Bean中設置屬性

<camelContext xmlns="http://camel.apache.org/schema/spring"> 
    <route id="wsClient"> 
      <from uri="timer:foo?repeatCount=1" /> 
      <setBody> 
       <simple>Message</simple> 
      </setBody> 
      <transform> 
        <method bean="myBean" method="transform" /> 
      </transform> 
      <to uri="cxf:bean:MyWebService?defaultOperationName={{operation}}" /> 
      <to uri="mock:result" /> 
    </route> 
</camelContext> 

在這個例子中,我想設置名爲「操作」豆「爲myBean」中的屬性。可以做到嗎? 謝謝!

+0

看到這個常見問題:http://camel.apache.org/how-to-use-a-dynamic-uri-in -to.html –

回答

2

是的,這是可能的。 首先,從bean設置一個頭,後來使用http://camel.apache.org/recipient-list.html

我不熟悉Spring DSL,但在Java DSL它是這樣的:

.recipientList(simple("cxf:bean:MyWebService?defaultOperationName=${header.operation}")) 
1

是的,你可以做到這一點的bean中。無需傳遞任何特定參數。駱駝可以自動綁定交換,身體等等作爲方法參數。參考文獻:http://camel.apache.org/bean-binding.html

使用下面的代碼,你可以設置頁眉或財產

exchange.getIn().setHeader("HeaderName", "Value"); 

exchange.setProperty("Key", "Value"); 
+0

感謝您的回覆,這似乎很有希望。唯一的限制是我的一些Beans沒有實現Exchange模式,我的意思是他們只是接收作爲Web服務參數參數的Java POJO。換句話說,他們在輸入一個Java Object而不是Exchange。是否有可能在純Java Bean中注入Exchange對象?非常感謝 – user2824073