3 Replies Latest reply on Feb 26, 2013 12:16 PM by Keith Babo

    File Consumer - Don't delete if exception

    Kevin Stone Newbie

      I have a simple file consumer that consumes files dropped into a folder.  Here is the relevent part of the switchyard.xml:

       

              <service name="AccountingFileConsumer" promote="AccountingFileConsumer">

                  <file:binding.file>

                      <file:contextMapper/>

                      <!-- Monitor this directory -->

                      <file:directory>/forAccounting</file:directory>

                      <file:consume>

                          <!-- delete file when accounting is done -->

                          <file:delete>true</file:delete>

                          <!-- Dont process files until you see a .DONE file with the same name -->

                          <file:doneFileName>${file:name}.DONE</file:doneFileName>

                      </file:consume>

                  </file:binding.file>

              </service>

       

      If AccountingFileConsumerBean (the class that is called) has an unhandled exception, is it possible to get switchyard to not delete the file (as specified in switchyard.xml)?  I thought throwing a HandlerException would work but it didn't.  If I can't stop the delete, I'll have to do it in the java class and get rid of it in the switchyard xml.

        • 1. Re: File Consumer - Don't delete if exception
          Łukasz Dywicki Novice

          You can use moveFailed option to avoid loss of file.

          • 2. Re: File Consumer - Don't delete if exception
            Kevin Stone Newbie

            I tried this:

             

              <service name="AccountingFileConsumer" promote="AccountingFileConsumer">

                        <file:binding.file>

                            <file:contextMapper/>

                            <!-- Monitor this directory -->

                            <file:directory>/forAccounting</file:directory>

                            <file:consume>

                                   <file:move>Ready/${file:name}</file:move>

                                   <file:moveFailed>Error/${file:name}</file:moveFailed>

                                  <!-- Dont process files until you see a .DONE file with the same name -->

                                <file:doneFileName>${file:name}.DONE</file:doneFileName>

                            </file:consume>

                        </file:binding.file>

                    </service>

             

            In the bean that is called to consume the file, I put in code generate an Exception which I catch and then throw a HandlerException.  It still moved the file to the Ready directory not the Error directory.  What am I doing wrong?

            • 3. Re: File Consumer - Don't delete if exception
              Keith Babo Master

              There is a limitation right now where the error is not propagated back to the gateway for in-only message exchange patterns.  The error is not dropped - it's logged, but that's not enough for the case you are describing.  We are actually meeting this week to discuss some core changes and this will be included.  I will post back to the forum with a potential solution.  If the core changes go as planned, the answer will simply be "it just works now".