Announcement Announcement Module
Collapse
No announcement yet.
integration file outbound error handler Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • integration file outbound error handler

    The case i have is am reading a file from inputdirectory and move it across to ouputfolder.

    But when my file:outbound-channel-adapter tries to write the file/message to a directory, which has no write permission (this is a case i need to test) the spring integration messagehandlingexception is thrown.

    I know its a runtime but is there any way i could handle it - like move the message to a different location i.e an error location ?.

    Any help ?

  • #2
    Can you post your config file so we can see some context?

    Comment


    • #3
      ok

      <integration:channel id="INBOUND_CHANNEL"/>
      <integration:channel id="OUTBOUND_CHANNEL"/>

      <int-file:inbound-channel-adapter id="K00ABATLANTIC001-CRB02-INBOUND"
      auto-startup="${k00abatlantic001-crb02-autostart}"
      prevent-duplicates="true"
      channel="INBOUND_CHANNEL"
      scanner="flagFileNameFilter"
      auto-create-directory="false"
      directory="${k00abatlantic001-crb02-in-location}">
      <integrationoller id="poller">
      <integration:interval-trigger interval="${k00abatlantic001-crb02-in-poller-interval}" time-unit="SECONDS"/>
      </integrationoller>
      </int-file:inbound-channel-adapter>

      <integration:bridge id="K00ABATLANTIC001-CRB02-SA"
      input-channel="INBOUND_CHANNEL"
      output-channel="OUTBOUND_CHANNEL"/>

      <int-file:outbound-channel-adapter id="out"
      channel="OUTBOUND_CHANNEL"
      delete-source-files="true"
      auto-create-directory="false"
      directory="${k00abatlantic001-crb02-out-location}"/>

      Comment


      • #4
        retry

        That works fine for simple file move. But what i wanted to do is to bring a replay rule and if there is a failure more than 3 times move the file(s) to error folder. thats what i wanted to get out of this.

        Thanks

        Comment


        • #5
          Yes, you can write a custom error handler; for example...

          Code:
          public class ErrorHandler {
          
          	public void myHandler(Exception e) {
                          //handle
          		e.printStackTrace();
          	}
          }
          In your config...

          Code:
          <integration:service-activator ref="eh" input-channel="errorChannel"/>
          
          <bean id="eh" class="gpr.ErrorHandler"/>
          Result:

          Code:
          org.springframework.integration.MessageHandlingException: failed to write Message payload to file
          	at 
          ...
          	at java.lang.Thread.run(Thread.java:662)
          Caused by: java.io.FileNotFoundException: /tmp/out/zzzx.writing (Permission denied)
          ...
          	... 40 more
          Error messages, by default, are sent to a well-known channel called 'errorChannel' which you can consume messages from.

          Comment


          • #6
            Note that the MessageHandlingException has the original message in a property called 'failedMessage'.

            Your error handler can then send this to a <delayer/>, perhaps adding/incrementing a retry count header. The delayer would send it again after some delay and your errorhandler could eventually fail it after so many tries.

            Change the signature to something like

            Code:
            public Message<File> myHandler(Exception e)
            and put an output-channel on the service activator, sending it to a <delayer>

            Comment


            • #7
              i was about to ask that :-)

              Thanks for the help.

              Comment


              • #8
                got it almost working

                Gary

                Thanks once again for the help.

                I have got it working almost. There is a small problem

                My inbound filter picks up 2 messages based on a file name filter - like an txt and a corresponding flag file. but while exception case the original message in the exception object is just the flag file. so, when i move the originally filtered files after my retries i could get only one file, which is the flag file.

                is there anything i need to look into. i have just kind of followed what you have suggested. in my error handler header field is incremented and once it reaches 3 count i put the message into a errorouput channel which is consumed by an outbound adapter.

                Comment


                • #9
                  update to the above the files are moved into the error folder but the originals are still remains in the inbound folder even with delete from source enabled
                  ???

                  Comment

                  Working...
                  X