You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Kondalarv <ko...@gmail.com> on 2015/05/25 09:33:28 UTC

Content Based Router : Java DSL is not working

I have choice with many options, and using java operation for conditions. 
The route is going to otherwise() option always and checckFilePattern()
method is not executing.


from(FILE_WATCHER_DSL)
		 .log(LoggingLevel.INFO, FileWatchDSLUtil.getFileLogPattern())			 
		 .choice()
		 
.when(checckFilePattern(header("CamelFileAbsolutePath").toString())).process(new
FileConsumerProcesser()).endChoice()	 	
		 	.otherwise().log("File Patten is not Matched. ${file:absolute.path}")
		 	  .to("file:/app/work01/FileWatcherAgent/quarantine").process(new
FileConsumerErrorProcesser()).stop().endChoice()
		 .end()
		 .log("End Processing Route");
		;


private static Predicate checckFilePattern(String fileName){	
	logger.info("checckFilePattern==> File Name : {}", fileName);
	boolean flag = false;
	if(fileName.endsWith("txt")) flag= true;
	Predicate predicate =  PredicateBuilder.constant(flag);
	logger.info("checckFilePattern==> predicate: {}", predicate);
	return predicate;
	}



--
View this message in context: http://camel.465427.n5.nabble.com/Content-Based-Router-Java-DSL-is-not-working-tp5767440.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Content Based Router : Java DSL is not working

Posted by Kondalarv <ko...@gmail.com>.
How to get EndPoint File Directory using camel annotation, I am getting
"preMove" directory from Headers, not EndPoint Dir. 
Looks like I need  @Exchange annotation but it is not available.
((FileEndpoint)exchange.getFromEndpoint()).getConfiguration().getDirectory();

Please help me on this.



--
View this message in context: http://camel.465427.n5.nabble.com/Content-Based-Router-Java-DSL-is-not-working-tp5767440p5767576.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Content Based Router : Java DSL is not working

Posted by Willem Jiang <wi...@gmail.com>.
It looks like your Predicate is a static now, which cannot take the message header as parameter. Please take a look at the Bean Language[1], it shows you how to write a right one.

[1]http://camel.apache.org/bean-language.html

--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On May 25, 2015 at 3:33:38 PM, Kondalarv (kondala.source@gmail.com) wrote:
> I have choice with many options, and using java operation for conditions.
> The route is going to otherwise() option always and checckFilePattern()
> method is not executing.
>  
>  
> from(FILE_WATCHER_DSL)
> .log(LoggingLevel.INFO, FileWatchDSLUtil.getFileLogPattern())
> .choice()
>  
> .when(checckFilePattern(header("CamelFileAbsolutePath").toString())).process(new  
> FileConsumerProcesser()).endChoice()
> .otherwise().log("File Patten is not Matched. ${file:absolute.path}")
> .to("file:/app/work01/FileWatcherAgent/quarantine").process(new
> FileConsumerErrorProcesser()).stop().endChoice()
> .end()
> .log("End Processing Route");
> ;
>  
>  
> private static Predicate checckFilePattern(String fileName){
> logger.info("checckFilePattern==> File Name : {}", fileName);
> boolean flag = false;
> if(fileName.endsWith("txt")) flag= true;
> Predicate predicate = PredicateBuilder.constant(flag);
> logger.info("checckFilePattern==> predicate: {}", predicate);
> return predicate;
> }
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Content-Based-Router-Java-DSL-is-not-working-tp5767440.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.
>  


Re: Content Based Router : Java DSL is not working

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

> .when(checckFilePattern(header("CamelFileAbsolutePath").toString())).

This is wrong. This code is only invoked once to setup the routes.

Use a bean as predicate instead of header for dynamic, and just write
it as plain java code

public static boolean checkPattern(@Header("CamelFileAbsolutePath") path) {
 ...
}

And use a bean as the predicate.



On Mon, May 25, 2015 at 9:33 AM, Kondalarv <ko...@gmail.com> wrote:
> I have choice with many options, and using java operation for conditions.
> The route is going to otherwise() option always and checckFilePattern()
> method is not executing.
>
>
> from(FILE_WATCHER_DSL)
>                  .log(LoggingLevel.INFO, FileWatchDSLUtil.getFileLogPattern())
>                  .choice()
>
> .when(checckFilePattern(header("CamelFileAbsolutePath").toString())).process(new
> FileConsumerProcesser()).endChoice()
>                         .otherwise().log("File Patten is not Matched. ${file:absolute.path}")
>                           .to("file:/app/work01/FileWatcherAgent/quarantine").process(new
> FileConsumerErrorProcesser()).stop().endChoice()
>                  .end()
>                  .log("End Processing Route");
>                 ;
>
>
> private static Predicate checckFilePattern(String fileName){
>         logger.info("checckFilePattern==> File Name : {}", fileName);
>         boolean flag = false;
>         if(fileName.endsWith("txt")) flag= true;
>         Predicate predicate =  PredicateBuilder.constant(flag);
>         logger.info("checckFilePattern==> predicate: {}", predicate);
>         return predicate;
>         }
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Content-Based-Router-Java-DSL-is-not-working-tp5767440.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: Content Based Router : Java DSL is not working

Posted by yogu13 <yo...@gmail.com>.
Hi,

I would suggest to split the route in smaller route using direct and then
check

from(FILE_WATCHER_DSL) 
                 .log(LoggingLevel.INFO,
FileWatchDSLUtil.getFileLogPattern())	
                 .choice() 
                     
.when(checckFilePattern(header("CamelFileAbsolutePath").toString()))
                      .to(direct:process)
                  .otherwise()
                      .to(direct:processOtherwise)  

place the logic in respective direct endpoints.





--
View this message in context: http://camel.465427.n5.nabble.com/Content-Based-Router-Java-DSL-is-not-working-tp5767440p5767443.html
Sent from the Camel - Users mailing list archive at Nabble.com.