codehaus


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XML file contains filename to be moved (with itself).. what packages should I use?


Hi

Just use Java - You can use Java File API to check for the existence
of a file ;)

You can also use a file filter to only pickup the file where you check
for the existence of that other file.
You can then write a bit of Java code as the filter and configure it
on the file endpoint. In the filter you grab the file context, do the
xpath to extract the name, and check for the file exists.

Also mind that noop=true will leave the file as-is after processing
it, but will not pickup it again, unless you configure the idempotent
to false also. Which you would need in cases while you may
wait for that other file.

So the better alternative is the file filter, and then move the files
after it has been processed, so you wont process the file again in the
future.
On Thu, Dec 13, 2018 at 1:58 AM John F. Berry
<bohnjerry@xxxxxxxxx.invalid> wrote:
>
> OK.. not hearing any pre-build advise.. I started building.
> I can successfully extract the XML field value that is the name of the work file out of the consumed file of the route.
> What I need to do is only move both (the file I'm consuming and it's work file).. if the work file shows up..
>
> Here's what I got so far....
>
>
> package org.mainegeneral.camel;
> import org.apache.camel.Processor;
> import org.apache.camel.Exchange;
> import org.apache.camel.builder.RouteBuilder;
> public class MyRouteBuilder extends RouteBuilder {
>     public void configure() {
>         from("file:src/data?noop=true&include=.*\\.xml")
>         .setProperty("SourceFN").xpath("/SYSTEMJOB/WORKDETAIL/SOURCE_FILENAME", String.class)
>         .process(new Processor() {
>                      public void process(Exchange exchange) throws Exception {
>              }
>           } )
>         .log("Reading XML file: ${header.CamelFileName}")
>         .log("XML Source Filename = ${property.SourceFN}")
>         .to("file:target/messages/others");
>     }
> }
>
>
> Now I will need to not move the XML I'm consuming if the file named in SOURCE_FILENAME doesn't yet exist, and go on to the other XML files in the directory and come back to check this one.
> I was going to use a choice to perform both those moves in.. but struggling to check for the named SOURCE_FILENAME's existance.
>
> Suggestions?
>
> Thanks!
>
>
>
>
>
> On Monday, December 10, 2018, 3:10:09 PM EST, John F. Berry <bohnjerry@xxxxxxxxx.INVALID> wrote:
>
>
>
>
>
> Figured I'd try something new and ask for advice here first before hitting a brick wall and asking after I hit that dead end...I need to poll for XML files dumping into a specific NFS directory, read in the XML, find the "work" file generated by the task that generated the XML, and move both files together.  The XML file is a custom small app specific job detail sort of file, with the exported work contained in a file named between the <SOURCE_FILENAME> tag.I could just regex the file, instead of parsing XML "officially", then use a choice and when satisfied, move both the file I'm reading, and the result from the regex.  I don't really need the 50 or so other job statistic tags contained in the XML.  I plan to use Java DSL with a blueprint or some Karaf supported type to run as a bundle.
> Since these xml files are generated at invocation, the "work" file might not show up for a few minutes.  In that time, I'm hoping to round-robin any other XML files to find completed "pairs" in this landing directory. Sound simple enough?  Any gotchas that people can think of?
> Thanks!



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2