You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "ben.oday" <be...@initekconsulting.com> on 2011/04/21 08:08:43 UTC

Re: how can i modify variable bases xpath in configure() method

use http://camel.apache.org/recipient-list.html

something like this should allow you to dynamically determine the next
endpoint based on the map and xpath result...

replace you inline Processor and to(rcvQSRmttr) with this

recipientList().method(MessageRouter.class, "routeTo")
...

public class MessageRouter {
    public String routeTo(@XPath("/order/city") String key) {
        return apc3AddrMap.get(key);
    }
}


aronftd wrote:
> 
> how can i modify rcvQSRmttr  bases xpath("/order/city") and a map , 
> xpath("/order/city").toString() as the key of the map;
> appricate for you advice!
> 
> rcvQSRmttr = apc3AddrMap.get(xpath("/order/city").toString());    
> public class FileToJMSRouter extends RouteBuilder {
> 	private Map&lt;String,String&gt; apc3AddrMap;
> 	public String rcvQ;
> 	public String sendQ;
>     @Override
>     public void configure() throws Exception {
>         // load file orders from src/data into the JMS queue
> //    	DataFormat jaxb = new
> JaxbDataFormat("com.sinosky.cdip.route.xsd.rply");
>     	String sendQStr = "jms:" + sendQ;
>     	String rcvQStr = "jms:" + rcvQ;
>     	String rcvQSRmttr = "jmsRmt:" + rcvQ;
>     	
>         errorHandler(defaultErrorHandler()
>                 .maximumRedeliveries(2)
>                 .redeliveryDelay(1000)
>                 .retryAttemptedLogLevel(LoggingLevel.WARN));            
>     	from("file:src/data?delay=1000")
>     	.to(sendQStr)
>     
> .to("file:logs/send?fileName=${date:now:yyyy-MM-dd}/${exchangeId}.xml")
>     	.process(new Processor() {    		
>     		public void process(Exchange exchange) throws Exception {
>     			rcvQSRmttr = apc3AddrMap.get(xpath("/order/city").toString());    			
>     			}
>     		})
>     	.to(rcvQSRmttr)
>     	.setBody(constant("success"))
>     	.to(rcvQStr)
>     
> .to("file:logs/receive?fileName=${date:now:yyyy-MM-dd}/${exchangeId}.xml");
>     }
> 


-----
Ben O'Day
IT Consultant -http://benoday.blogspot.com

--
View this message in context: http://camel.465427.n5.nabble.com/how-can-i-modify-variable-bases-xpath-in-configure-method-tp4330030p4330067.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: how can i modify variable bases xpath in configure() method

Posted by "ben.oday" <be...@initekconsulting.com>.
see this example...http://camel.apache.org/recipientlist-annotation.html


aronftd wrote:
> 
> i define MessageRouter in spring xml ,when i be in debug mode ,i find the
> apc3AddrMap property is null; 
> but i test  MessageRouter  not in camel ,it can get  the map property , 
> how can i do ,thanks!     
> 
> 
> 
> public class FileToJMSRouter extends RouteBuilder { 
>         
>         public String rcvQ; 
>         public String sendQ; 
>     @Override 
>     public void configure() throws Exception { 
>         // load file orders from src/data into the JMS queue 
> //     DataFormat jaxb = new
> JaxbDataFormat("com.sinosky.cdip.route.xsd.rply"); 
>     String sendQStr = "jms:" + sendQ; 
>     String rcvQStr = "jms:" + rcvQ;     
>         errorHandler(defaultErrorHandler() 
>                 .maximumRedeliveries(2) 
>                 .redeliveryDelay(1000) 
>                 .retryAttemptedLogLevel(LoggingLevel.WARN));             
>     from("file:src/data?delay=1000") 
>     .to(sendQStr) 
>    
> .to("file:logs/send?fileName=${date:now:yyyy-MM-dd}/${exchangeId}.xml")     
>     .recipientList().method(MessageRouter.class, "routeTo") 
>     .setBody(constant("success")) 
>     .to(rcvQStr) 
>    
> .to("file:logs/receive?fileName=${date:now:yyyy-MM-dd}/${exchangeId}.xml"); 
>     ; 
>     } 
>         public String getRcvQ() { 
>                 return rcvQ; 
>         } 
>         public void setRcvQ(String rcvQ) { 
>                 this.rcvQ = rcvQ; 
>         } 
>         public String getSendQ() { 
>                 return sendQ; 
>         } 
>         public void setSendQ(String sendQ) { 
>                 this.sendQ = sendQ; 
>         } 
> } 
> 
> 
> public class MessageRouter { 
>         private Map&lt;String,String&gt; apc3AddrMap; 
> 
>         public Map&lt;String, String&gt; getApc3AddrMap() { 
>                 return apc3AddrMap; 
>         } 
> 
>         public void setApc3AddrMap(Map&lt;String, String&gt; apc3AddrMap)
> { 
>                 this.apc3AddrMap = apc3AddrMap; 
>         } 
>         public String routeTo(@XPath("/R/RCV/APC3/text()") String key) { 
>             String str = apc3AddrMap.get(key); 
>         return str; 
>     } 
> 
> }
> 

-----
Ben O'Day
IT Consultant -http://benoday.blogspot.com

--
View this message in context: http://camel.465427.n5.nabble.com/how-can-i-modify-variable-bases-xpath-in-configure-method-tp4330030p4334748.html
Sent from the Camel - Users mailing list archive at Nabble.com.