Results 1 to 6 of 6

Thread: File inbound channel adatper : copying file to folder

  1. #1

    Default File inbound channel adatper : copying file to folder

    Is there a easy way to achive the below result
    a)copy a file to folder "success" in case of a happy flow and copy file to another folder "failure" in case of an error.


    I do see samples in this forum but doesnt look like a clean one.

    Is there a definite way to achieve it.

    Looked at the reference manual and doesnt give many good idea

    thx
    m

  2. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    You should be able to add an 'error-channel' to the inbound adapter. Then you can provide a flow that does anything you want downstream from that for the "unhappy" cases. If you want to write to a dead-letter directory, then you could just add an outbound File adapter there.

    HTH,
    Mark

  3. #3

    Default key file_originalFile missing in Message header

    Thanks Mark,I followed your instruction.
    I use inbound adapter to poll a folder for file
    <file:inbound-channel-adapter id="filesIn"




    copy the file to a different folder with a unique sequence number attached to file name
    <si:channel id="archiveFile" />
    <si:service-activator input-channel="filesIn"
    ref="fileHandler" method="archiveFile" output-channel="fileToStringTransformer" />



    convert the file to string
    <si:channel id="fileToStringTransformer" />
    <file:file-to-string-transformer
    input-channel="fileToStringTransformer" output-channel="parser" delete-files="false" />




    unmarshall it to java object before passing to a business handler

    <si:channel id="xmlInputChannel" />
    <si-xml:unmarshalling-transformer id="defaultUnmarshaller"
    output-channel="docTypeChannel" input-channel="xmlInputChannel"
    unmarshaller="unmarshaller" />










    create a error channel for any error in the flow including in the business hander

    <si:channel id="errorChannel" />
    <si:service-activator input-channel="errorChannel"
    output-channel="outboundMail" ref="errorHandler" method="process" />


    If an error occurs in business handler I do get the key file_originalFile
    in message header,BUT if error occurs in unmarshalling I dont get the key in message header.This means I will not be able to complete one business process ,that is moving error file to a different error folder.

    Any solution to this

    thx
    m









    <bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="location" value="classpath:integration.properties" />
    <property name="propertiesArray">
    <list>
    <bean factory-bean="propertiesHolder" factory-method="asProperties" />
    </list>
    </property>
    </bean>

    <!--
    Spring Integration by default will looks for this channel in case of
    an error
    -->
    <si:channel id="errorChannel" />
    <si:service-activator input-channel="errorChannel"
    output-channel="outboundMail" ref="errorHandler" method="process" />


    <!-- This will be executed moment the context is loaded -->
    <file:inbound-channel-adapter id="filesIn"
    directory="file:${file.import.path}" filename-pattern="${file.name.pattern}">
    <sioller id="poller" fixed-delay="${fixed.delay}" />
    </file:inbound-channel-adapter>

    <!-- Archive the file to a different folder.Make sure you add a unique sequence number to the file -->
    <si:channel id="archiveFile" />
    <si:service-activator input-channel="filesIn"
    ref="fileHandler" method="archiveFile" output-channel="fileToStringTransformer" />

    <!-- convert the file to string -->
    <si:channel id="fileToStringTransformer" />
    <file:file-to-string-transformer
    input-channel="fileToStringTransformer" output-channel="parser" delete-files="false" />

    <!-- add/delete content from the string -->
    <si:channel id="parser" />
    <si:service-activator input-channel="parser" ref="handler"
    method="parser" output-channel="xmlInputChannel" />


    <!-- unmarshall the xml to its equivalent object -->
    <si:channel id="xmlInputChannel" />
    <si-xml:unmarshalling-transformer id="defaultUnmarshaller"
    output-channel="docTypeChannel" input-channel="xmlInputChannel"
    unmarshaller="unmarshaller" />

    <!-- The unmarshaller -->
    <bean id="unmarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshalle r">
    <property name="marshallerProperties">
    <map value-type="java.lang.Boolean" key-type="java.lang.String">
    <entry key="jaxb.formatted.output" value="true" />
    </map>
    </property>
    <!-- This is the only property setting that is mandatory -->
    <property name="classesToBeBound">
    <list>
    <value>org.vmsng.integration.schema.Deposit</value>
    <value>org.vmsng.integration.schema.Order</value>
    </list>
    </property>
    <property name="schema" value="classpath:integration.xsd" />
    </bean>

    <!-- The router to be used to decide which business handler to be used for processing -->
    <si:channel id="docTypeChannel" />
    <si:router ref="docTypeRouter" input-channel="docTypeChannel"
    method="resolveObjectTypeChannel" />
    <si:channel id="Order" />
    <si:channel id="Deposit" />


    <!-- Business handler for order -->
    <si:service-activator ref="processOrder"
    input-channel="Order" method="process" output-channel="outboundMail" />

    <!-- Business handler for deposit -->
    <si:service-activator ref="processDeposit"
    input-channel="Deposit" method="process" output-channel="outboundMail" />

    <!-- outbound email -->
    <si:channel id="outboundMail" />
    <si:service-activator ref="confEmail"
    input-channel="outboundMail" method="send" />


    <bean id="processOrder" class="org.fwk.integration.ProcessOrder" />
    <bean id="processDeposit" class="org.fwk.integration.ProcessDeposit" />
    <bean id="docTypeRouter" class="org.fwk.integration.DocumentTypeMessageRout er" />
    <bean id="handler" class="org.fwk.integration.Handler" />
    <bean id="confEmail" class="org.fwk.integration.ConfirmationEmail" />
    <bean id="errorHandler" class="org.fwk.integration.ErrorHandler" />
    <bean id="propertiesHolder" class="org.fwk.integration.PropertiesHolder" />
    <bean id="fileHandler" class="org.fwk.integration.FileHandler" />

  4. #4
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    When you have the Marshalling error, is the Exception an instance of MessagingException, and does it have the original Message in its 'failedMessage' property?

  5. #5

    Default

    Quote Originally Posted by Mark Fisher View Post
    When you have the Marshalling error, is the Exception an instance of MessagingException, and does it have the original Message in its 'failedMessage' property?



    Okay let me dig deeper
    Last edited by manoharshetty; Feb 22nd, 2011 at 02:19 PM.

  6. #6

    Default

    Quote Originally Posted by Mark Fisher View Post
    When you have the Marshalling error, is the Exception an instance of MessagingException, and does it have the original Message in its 'failedMessage' property?
    Thank you again Mark.You gave me enough direction and hint to investigate

    My new looking error handler looks good now with the changes below.

    Sorry again did not pay any attention to the original message in failedMessage property.

    I am good now
    thx again


    public class ErrorHandler {

    public Result process(Message message) {
    MessagingException me = (MessagingException) message.getPayload();
    File file = (File) me.getFailedMessage().getHeaders().get("file_origi nalFile");
    FileHandler.archiveErrorFile(file);
    Result result = new Result();
    result.setProcessingMessage(me.getMessage());
    result.setAccountNumber("009");
    System.out.println(message.toString());
    return result;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •