4 Replies Latest reply on Feb 10, 2009 2:47 AM by davsclaus

    File consumer.regexPattern not recognising the Pattern.

    mrichards_mrichards

      Hi Guys,

      Is any body able to help me with what should be a really simple operation.

      I have the following route defined

       

      private void configureMoveConfirmProductionPOFilesRoute(){

       

      StringBuffer sourceFileUrl = new

      StringBuffer("file://C:/temp/EXPORT_ERP?consumer.regexPattern=RCA_mo_*&moveNamePrefix=&noop=true");

                 

      StringBuffer targetFileUrl = new

      StringBuffer("file://C:/temp/EXPORT_ERP/confirmProductionPO?autoCreate=false");

                 

              from(sourceFileUrl.toString()).to(targetFileUrl.toString());

       

      }

       

      When I run my app, copies ALL files from the source directory to the target directory

       

      Am I using the consumer.regexPattern option correctly?

       

      This should be simple I know, but I seem to be missing the obvious....

       

      Could this be related to this

      http://issues.apache.org/activemq/browse/CAMEL-920

       

      Cheers

      Mark

        • 1. Re: File consumer.regexPattern not recognising the Pattern.
          davsclaus

          Hi

           

          CAMEL-920 is a bug where the regexp would also match directories. So for instance if you have some sub folders then the folder name was also matched.

          We only want it to match on filenames.

           

          Reg exp is always a problem to get correct.

           

          I would recommend to write a little unit test / java main where you try out until you get the reg exp correct

           

          The pattern "RCA_mo_*" looks a bit odd?

           

          Remember to use .* if you want it to match (0..chars).

           

          What are you files names that you tested with?

          • 2. Re: File consumer.regexPattern not recognising the Pattern.
            davsclaus

            BTW I created a new ticket for Camel

            https://issues.apache.org/activemq/browse/CAMEL-1319

             

            To add includeNameXXX options so you dont have to mess with reg exp, for simple file name matching cases.

            • 3. Re: File consumer.regexPattern not recognising the Pattern.
              mrichards_mrichards

              Hi Claus,

               

              Thank you very much for your amazingly quick response, sorry. 

               

              I've revisited what I was trying to achieve, and have gone with using the Router Pattern, which works perfectly.

               

              I am routing files from an external application based on their file names.

               

              Please see the code below. 

               

              My next issue is how to implement this using xml configuration e.g. from spring.xml.

               

              Is there an example xml config that uses  and has choices based on the file name?

               

              I'll post a new thread.

               

              Cheers

              Guys!

               

              private void configureExportPOToMeCRoute()

                   {

                        //Source (from) and Target (to) uri

                        String belharraExportPOFTPUri =

                             "ftp://user@machinename/EXPORT_ERP?password=aPassword&binary=false" +

                                  "&consumer.delay=10000&directory=true&consumer.setNames=true" +

                                  "&consumer.excludedNamePrefix=RCE_&consumer.moveNamePrefix=RCA_MOVED/&consumer.recursive=false";

                         

                        String mecBMIConfirmProductionPOFileUri =

                             "file://C:/temp/Belharra/home/ftp_rce/EXPORT_ERP/MBI.ConfirmProductionPO?autoCreate=false";

                         

                        String mecBMIUpdateProductionPOFileUri =

                             "file://C:/temp/Belharra/home/ftp_rce/EXPORT_ERP/MBI.ConfirmProductionPO?autoCreate=false";

                         

                        String mecBMIAdviseShipmentOnPOFileUri =

                             "file://C:/temp/Belharra/home/ftp_rce/EXPORT_ERP/BMI.AdviseShipmentOnPO?autoCreate=false";

                         

                        String mecBMICreatePackagesFileUri =

                             "file://C:/temp/Belharra/home/ftp_rce/EXPORT_ERP/BMI.CreatePackages?autoCreate=false";

                         

                        String mecBMIUpdateShipmentTransportNotifyFileUri =

                             "file://C:/temp/Belharra/home/ftp_rce/EXPORT_ERP/BMI.UpdateShipmentTransportNotify?autoCreate=false";

                         

                        String mecDeadLetterFileUri =

                             "file://C:/temp/Belharra/home/ftp_rce/EXPORT_ERP/deadLetter?autoCreate=false";

                         

                        //File name patterns - identifies the message we are dealing

                        String confirmPOFileNamePattern                = "RCA_po_ERP_";

                        String updatePOFileNamePattern                               = "RCA_mo_ERP_";

                        String adviseShipmentOnPOFileNamePattern                = "RCA_createShipment_";

                        String createPackagesFileNamePattern                     = "RCA_packingList_";

                        String updateShipmentTransportNotifyFileNamePattern = "RCA_update_";

                         

                      from(belharraExportPOFTPUri).choice()

                           .when(header(FileComponent.HEADER_FILE_NAME).contains(confirmPOFileNamePattern)).to(mecBMIConfirmProductionPOFileUri)

                           .when(header(FileComponent.HEADER_FILE_NAME).contains(updatePOFileNamePattern)).to(mecBMIUpdateProductionPOFileUri)

                           .when(header(FileComponent.HEADER_FILE_NAME).contains(adviseShipmentOnPOFileNamePattern)).to(mecBMIAdviseShipmentOnPOFileUri)

                           .when(header(FileComponent.HEADER_FILE_NAME).contains(createPackagesFileNamePattern)).to(mecBMICreatePackagesFileUri)

                          .when(header(FileComponent.HEADER_FILE_NAME).contains(updateShipmentTransportNotifyFileNamePattern)).to(mecBMIUpdateShipmentTransportNotifyFileUri)

                          .otherwise().to(mecDeadLetterFileUri);

                                  

                   }

              • 4. Re: File consumer.regexPattern not recognising the Pattern.
                davsclaus

                Hi

                 

                The content based router EIP pattern has a sample for when in spring XML

                http://camel.apache.org/content-based-router.html

                 

                But the Java DSL is more powerful, where you use the contains. In Spring XML you need to use some sort of language to configure this in the XML directly.

                http://camel.apache.org/languages.html

                 

                The first link demonstrates using the xpath language where you can compare using = operator. Maybe that cover you needs.

                 

                xpath is provided in the camel core so no need for other jars.