Hi You may have a corner case when you decide the return Message instances in the split bean. Could you ensure all headers is propagated from the Exchange IN message in all the returned Message's in that list?
On Wed, Jul 20, 2011 at 6:17 PM, cwhistler <chadd.whist...@sungard.com> wrote: > I am using camel version 2.7.2 > > I am watching an inbound folder for files. when I pick up a file I need to > determine if I should do anything with it or just ignore it. If it's a file > I want then I need to split the data in the file into multiple output files. > After a file is processed I want to move the original file to a bkup folder > and append a timestamp to the file name. > > So my java route is basically: > from(file://inbound?move=//bkup/${file:name}-${date:now:yyyyMMddHHmmssSSSS}) > .choice() > .when(some criteria).to("direct:processFile") > .otherwise().to("direct:donotprocessFile"); > > from("direct:processFile") > .split().method("javasplitclass", "splitmethod") > .to(file://outbound) > > from("direct:donotprocessFile") > .process(javanoprocessclass); > > in the javanoprocessclass I am simply printing out the file name: > public void process(Exchange exchange) > { > String fileName = (String) > exchange.getIn().getHeader(Exchange.FILE_NAME_ONLY); > log.info("Skipping unknown file - " + fileName); > > } > > > The files that go to the donotprocessFile route are correctly moved to the > bkup folder and renamed. > > The files that go through the split are split correctly, but the original > file remains in the input folder where it is processed repeatedly. > > In the javasplitclass, I need to split the file into multiple output files. > so my split method returns a List of Message objects. Each Message > represents the records for a separate file which I name in the message > Header. > > public List<Message> splitBody(Exchange exchange) > { > String fileName = (String) > exchange.getIn().getHeader(Exchange.FILE_NAME_ONLY); > log.info("Processing file - " + fileName); > BufferedReader inputReader = > exchange.getIn().getBody(BufferedReader.class); > StringBuffer sb = new StringBuffer(); > List<Message> messages = new ArrayList<Message>(); > String line = null; > String participant = null; > SsbXref ssbXref = null; > try > { > while (null != (line = inputReader.readLine())) > { > if (isFileHeader(line)) > { > // we just skip this > log.debug("File header " + line); > } > else if (isParticipantHeader(line)) > { > // we are on a new participant so write out the > previous records first > if (sb.length() > 0) > { > messages.add(createOutput(fileName, > participant, sb)); > sb = new StringBuffer(); > } > sb.append(line); > sb.append("\n"); > } > else > { > // need to append the line > sb.append(line); > sb.append("\n"); > } > } > if (sb.length() > 0) > { > messages.add(createOutput(fileName, participant, sb)); > } > } > catch (Exception e) > { > > e.printStackTrace(); > } > > log.info("Completed processing file - " + fileName); > return messages; > > } > > private Message createOutput(String fileName, String participant, > StringBuffer sb) > { > Message message = new DefaultMessage(); > message.setBody(sb.toString()); > message.setHeader(Exchange.FILE_NAME, fileName + "." + participant); > return message; > } > > so have I done something that is preventing the original file from moving to > the bkup folder after splitting the records out of it?? What can I do to > fix this? > > thanks > > -- > View this message in context: > http://camel.465427.n5.nabble.com/file-move-option-not-working-when-using-split-tp4616425p4616425.html > Sent from the Camel - Users mailing list archive at Nabble.com. > -- Claus Ibsen ----------------- FuseSource Email: cib...@fusesource.com Web: http://fusesource.com Twitter: davsclaus, fusenews Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/