Thanks again for your reply, Well, ok as long as it is a simple logic when choosing a specific route, I can do that and make it work in the xml or the RouteBuilder. But what if I need to implement more complicated logic in a java bean?
Regards, Farhad Shirazi Claus Ibsen-2 wrote: > > Use the <recepientList> XML tag for that. You have mixed POJO with XML > routing. > > > > On Thu, Aug 27, 2009 at 11:41 AM, Farhad Dehghani<m...@farhad.eu> wrote: >> Hi Claus, >> It seems that the problem is the "VodIncomingProcessor" bean, which is a >> @RecipientList. Because when I remove it from the route, everything works >> fine (using exchange.getIn().setHeader() in the trailerHandler). A >> simplified version of the VodIncomingProcessor looks like: >> >> public class VodIncomingProcessor { >> private final static Log log = >> LogFactory.getLog(VodIncomingProcessor.class); >> >> �...@recipientlist >> public List<String> next(File file) throws IOException { >> List<String> recipients = new ArrayList<String>(); >> >> log.info("Invoked on file "+file.getCanonicalPath()); >> >> if(file.getName().endsWith(".mpg")){ >> recipients.add("bean:trailerHandler"); >> }else if(file.getName().endsWith(".pgp")){ >> recipients.add("bean:pgpHandler"); >> }else if(file.getName().endsWith(".ts")){ >> recipients.add("bean:movieHandler"); >> } >> return recipients; >> } >> } >> >> I guess that the VodIncomingProcessor needs to somehow forward the File's >> inputstream to the next step in the route, but i'm not sure how. >> >> Thanks, >> Farhad >> >> Begin forwarded message: >> >>> Date: August 26, 2009 7:12:26 AM GMT+02:00 >>> Subject: Re: renaming a file in a bean >>> Source: Nabble - Camel - Users >>> Author: Claus Ibsen-2 >>> >>> Hi >>> >>> You want to replace the existing header so use IN >>> exchange.getOut().setHeader(Exchange.FILE_NAME, rename(fileName)); >>> >>> Should be: >>> exchange.getIn().setHeader(Exchange.FILE_NAME, rename(fileName)); >>> >>> >>> On Wed, Aug 26, 2009 at 2:02 PM, Farhad Dehghani<m...@...> wrote: >>> >>> > Hi, >>> > Please consider the route definition below: >>> > -------- >>> > <camel:camelContext id="vod_workflow"> >>> > <camel:package>com.nordija.itv.vod.workflow</camel:package> >>> > <camel:route> >>> > <camel:from uri="file:///tmp/vodwof?recursive=true" /> >>> > <camel:to uri="file:///tmp/vodIncoming?tempPrefix=.inprogress_" >>> > /> >>> > <camel:to uri="bean:vodIncomingProcessor"/> >>> > <camel:to uri="direct:route_1"/> >>> > </camel:route> >>> > <camel:route> >>> > <camel:from uri="direct:route_1"/> >>> > <camel:to uri="bean:trailerHandler"/> >>> > <camel:to uri="file:///tmp/trailer?tempPrefix=.inprogress_"/> >>> > <camel:to uri="direct:end"/> >>> > </camel:route> >>> > .... >>> > </camel:camelContext> >>> > <bean name="trailerHandler" >>> > class="com.nordija.itv.vod.workflow.TarilerHandlerImpl" /> >>> > --------- >>> > The vodIncomingProcessor is a @RecipientList annotated bean that >>> decides >>> > if >>> > the file in question should be handled by the "trailerHandler" or >>> > something >>> > else. >>> > The trailerHandler needs among other things to rename the resulting >>> > file. >>> > The following code is a very simplified version of the bean: >>> > >>> > @Service(value="trailerHandler") >>> > public class TarilerHandlerImpl implements TrailerHandler { >>> > public void handleTrailer(Exchange exchange) { >>> > if(exchange != null){ >>> > String fileName = >>> > (String)exchange.getIn().getHeader(Exchange.FILE_NAME); >>> > if(fileName != null){ >>> > >>> > exchange.getOut().setHeader(Exchange.FILE_NAME, rename(fileName)); >>> > } >>> > } >>> > } >>> > } >>> > >>> > The "rename(String filename)" method renames the file and it's >>> > implementation is not relevant here. For test, it just prefix the >>> > filename >>> > with "trailer_". >>> > When I run the application, the following exception is thrown, and the >>> > trailerHandler gets called again and again. >>> > >>> > I appreciate any help, >>> > -Farhad Dehghani >>> > >>> > 13:02:20,913 INFO [STDOUT] 13:02:20,911 ERROR >>> [GenericFileOnCompletion] >>> > Cannot store file: /tmp/trailer/.inprogress_trailer_test.mpg >>> > org.apache.camel.component.file.GenericFileOperationFailedException: >>> > Cannot >>> > store file: /tmp/trailer/.inprogress_trailer_test.mpg >>> > at >>> > >>> > >>> org.apache.camel.component.file.FileOperations.storeFile(FileOperations.java:203) >>> > at >>> > >>> > >>> org.apache.camel.component.file.GenericFileProducer.writeFile(GenericFileProducer.java:144) >>> > at >>> > >>> > >>> org.apache.camel.component.file.GenericFileProducer.processExchange(GenericFileProducer.java:86) >>> > at >>> > >>> > >>> org.apache.camel.component.file.GenericFileProducer.process(GenericFileProducer.java:57) >>> > at >>> > >>> > >>> org.apache.camel.processor.SendProcessor$1.doInProducer(SendProcessor.java:81) >>> > at >>> > >>> > >>> org.apache.camel.processor.SendProcessor$1.doInProducer(SendProcessor.java:79) >>> > at >>> > >>> org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:141) >>> > at >>> > >>> org.apache.camel.processor.SendProcessor.process(SendProcessor.java:78) >>> > at >>> > >>> > >>> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:61) >>> > at >>> > >>> > >>> org.apache.camel.processor.RedeliveryErrorHandler.processExchange(RedeliveryErrorHandler.java:186) >>> > at >>> > >>> > >>> org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:155) >>> > at >>> > >>> > >>> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:88) >>> > at >>> > >>> > >>> org.apache.camel.processor.DefaultErrorHandler.process(DefaultErrorHandler.java:49) >>> > at >>> > >>> > >>> org.apache.camel.processor.DefaultChannel.process(DefaultChannel.java:148) >>> > at >>> org.apache.camel.processor.Pipeline.process(Pipeline.java:74) >>> > at >>> > >>> > >>> org.apache.camel.processor.UnitOfWorkProcessor.processNext(UnitOfWorkProcessor.java:70) >>> > at >>> > >>> > >>> org.apache.camel.processor.DelegateProcessor.process(DelegateProcessor.java:48) >>> > at >>> > >>> > >>> org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:45) >>> > at >>> > >>> > >>> org.apache.camel.processor.SendProcessor$1.doInProducer(SendProcessor.java:81) >>> > at >>> > >>> > >>> org.apache.camel.processor.SendProcessor$1.doInProducer(SendProcessor.java:79) >>> > at >>> > >>> org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:141) >>> > at >>> > >>> org.apache.camel.processor.SendProcessor.process(SendProcessor.java:78) >>> > at >>> > >>> > >>> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:61) >>> > at >>> > >>> > >>> org.apache.camel.processor.RedeliveryErrorHandler.processExchange(RedeliveryErrorHandler.java:186) >>> > at >>> > >>> > >>> org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:155) >>> > at >>> > >>> > >>> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:88) >>> > at >>> > >>> > >>> org.apache.camel.processor.DefaultErrorHandler.process(DefaultErrorHandler.java:49) >>> > at >>> > >>> > >>> org.apache.camel.processor.DefaultChannel.process(DefaultChannel.java:148) >>> > at >>> org.apache.camel.processor.Pipeline.process(Pipeline.java:74) >>> > at >>> > >>> > >>> org.apache.camel.processor.UnitOfWorkProcessor.processNext(UnitOfWorkProcessor.java:54) >>> > at >>> > >>> > >>> org.apache.camel.processor.DelegateProcessor.process(DelegateProcessor.java:48) >>> > at >>> > >>> > >>> org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:198) >>> > at >>> > >>> > >>> org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:120) >>> > at >>> > >>> > >>> org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:93) >>> > at >>> > >>> > >>> org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:99) >>> > at >>> > >>> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:417) >>> > at >>> > >>> > >>> java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:280) >>> > at >>> > java.util.concurrent.FutureTask.runAndReset(FutureTask.java:135) >>> > at >>> > >>> > >>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:65) >>> > at >>> > >>> > >>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:142) >>> > at >>> > >>> > >>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:166) >>> > at >>> > >>> > >>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650) >>> > at >>> > >>> > >>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675) >>> > at java.lang.Thread.run(Thread.java:613) >>> > Caused by: org.apache.camel.InvalidPayloadException: No body available >>> > of >>> > type: java.io.InputStream but has value: [bean:trailerHandler] of >>> type: >>> > java.util.ArrayList on: Message: [bean:trailerHandler]. Caused by: No >>> > type >>> > converter available to convert from type: java.util.ArrayList to the >>> > required type: java.io.InputStream with value [bean:trailerHandler] on >>> > the >>> > exchange: Exchange[Message: [bean:trailerHandler]] >>> > at >>> > >>> > >>> org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:104) >>> > at >>> > >>> > >>> org.apache.camel.util.ExchangeHelper.getMandatoryInBody(ExchangeHelper.java:136) >>> > at >>> > >>> > >>> org.apache.camel.component.file.FileOperations.storeFile(FileOperations.java:197) >>> > ... 43 more >>> > Caused by: org.apache.camel.NoTypeConversionAvailableException: No >>> type >>> > converter available to convert from type: java.util.ArrayList to the >>> > required type: java.io.InputStream with value [bean:trailerHandler] >>> > at >>> > >>> > >>> org.apache.camel.impl.converter.DefaultTypeConverter.mandatoryConvertTo(DefaultTypeConverter.java:119) >>> > at >>> > >>> > >>> org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:102) >>> > ... 45 more >>> > >>> > >>> >>> >>> >>> -- >>> Claus Ibsen >>> Apache Camel Committer >>> >>> Open Source Integration: http://fusesource.com >>> Blog: http://davsclaus.blogspot.com/ >>> Twitter: http://twitter.com/davsclaus >>> Read more… >>> >> >> > > > > -- > Claus Ibsen > Apache Camel Committer > > Open Source Integration: http://fusesource.com > Blog: http://davsclaus.blogspot.com/ > Twitter: http://twitter.com/davsclaus > > -- View this message in context: http://www.nabble.com/Fwd%3A-renaming-a-file-in-a-bean-tp25169359p25185111.html Sent from the Camel - Users mailing list archive at Nabble.com.