Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6958589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:09:34+00:00 2026-05-27T15:09:34+00:00

I am new in Spring Integeration.I have one requirement Using spring integeration read a

  • 0

I am new in Spring Integeration.I have one requirement Using spring integeration

  1. read a txt file (from Source folder)
  2. do some validation
  3. if validation is success -write into sucess file (in sucess folder)
  4. If the validation is fail -write into failure file (in error folder)
  5. if the file format is incorrect means I have to move that file into error folder(Ex excepted columns is 2 but in my file contain columns is 1)

My config file is like this

     <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:si="http://www.springframework.org/schema/integration"
        xmlns:file="http://www.springframework.org/schema/integration/file"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                http://www.springframework.org/schema/integration
                http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
                http://www.springframework.org/schema/integration/file
                http://www.springframework.org/schema/integration/file/spring-integration-file-1.0.xsd">

        <bean id="checkCSVReader"
            class="com.check.wrapper">
            <property name="pzMapXML" value="classpath:sampleFileFormat.xml" />
        </bean>

        <bean id="checkTrasnFomer"
            class="com.check.checkTransfomer">
            <property name="wrapper" ref="checkCSVReader" />
        </bean>

        <bean id="fileErrorProcessor"
            class="com.check.ErrorChannelWriter">
        </bean>
        <bean id="listToStringTrans"
            class="com.check.ListToStringTransfomer"></bean>


    <bean id="validation"
            class="com.check.Validation"/>

        <file:inbound-channel-adapter directory="file://D:\check\soruce"   prevent-duplicates="false" 
            auto-create-directory="true" channel="readChannel" >
            <si:poller id="Poller">
                <si:interval-trigger interval="10000" />
            </si:poller>
        </file:inbound-channel-adapter>

        <si:channel id="readChannel" />

        <si:chain input-channel="readChannel" output-channel="processChannel">
            <si:header-enricher error-channel="errorFile" />
            <file:file-to-string-transformer />
            <si:transformer ref="checkTrasnFomer" method="transform" />
            <si:service-activator ref="validation"
                method="validate" />
        </si:chain>

        <si:channel id="processChannel" />

        <si:transformer ref="listToStringTrans" method="transformList"
            input-channel="processChannel" output-channel="finalOut" />

        <si:channel id="finalOut" />

        <file:outbound-channel-adapter id="checkSuccFileOutBound"
            auto-create-directory="true" delete-source-files="true"
            directory="file://D:\check\success" channel="finalOut">
        </file:outbound-channel-adapter>

        <si:channel id="errorFile" />

        <si:transformer ref="fileErrorProcessor"
            input-channel="errorFile" output-channel="errorChannel" method="transformError" />

        <file:outbound-channel-adapter id="errorChannel"
            directory="file://D:\check\error" delete-source-files="true"
             />

        <si:channel id="checkFileErr" />
    </beans>

my checkFlatPackCVSParserWrapper class is

    public class checkFlatPackCVSParserWrapper {
        private static final Log LOG = LogFactory.getLog("checkFlatPackCVSParserWrapper");
        private Resource pzMapXML;
        private char delimiter = ',';
        private char qualifier = '"';
        private boolean ignoreFirstRecord = false;

        public Resource getPzMapXML() {
            return pzMapXML;
        }
        public void setPzMapXML(Resource pzMapXML) {
            this.pzMapXML = pzMapXML;
        }
        public char getDelimiter() {
            return delimiter;
        }
        public void setDelimiter(char delimiter) {
            this.delimiter = delimiter;
        }
        public char getQualifier() {
            return qualifier;
        }
        public void setQualifier(char qualifier) {
            this.qualifier = qualifier;
        }
        public boolean isIgnoreFirstRecord() {
            return ignoreFirstRecord;
        }
        public void setIgnoreFirstRecord(boolean ignoreFirstRecord) {
            this.ignoreFirstRecord = ignoreFirstRecord;
        }

        public Parser getParser(String csv) {
            if(LOG.isDebugEnabled())
                LOG.debug("getParser: " + csv);

            Parser result = null;
            try {
                result = DefaultParserFactory.getInstance().newDelimitedParser(
                        pzMapXML.getInputStream(), //xml column mapping
                        new ByteArrayInputStream(csv.getBytes()),  //txt file to parse
                        delimiter, //delimiter
                        qualifier, //text qualfier
                        ignoreFirstRecord);

            }catch (Exception e) {
                if(LOG.isDebugEnabled())
                   LOG.debug("Unable to read file:  " + e );
                throw new RuntimeException("File Parse exception");
            }   
            return result;
        }
    }

sampleFileFormat.xml is

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE PZMAP SYSTEM  "flatpack.dtd" >
    <PZMAP>
        <COLUMN name="FIRSTNAME" />
        <COLUMN name="LASTNAME" />
    </PZMAP> 


 and checkTransfomer is 


    public class checkTransfomer {
        private static final Log LOG = LogFactory.getLog(checkTransfomer.class);
        private CheckFlatPackCVSParserWrapper wrapper;

        public String transform(String csv) {
            Parser parser = wrapper.getParser(csv);
            if(LOG.isDebugEnabled()) {
                LOG.debug("Parser is: " + parser);
            }        
            DataSet ds = parser.parse();
            ArrayList<Check> list = new ArrayList<Check>();
            while(ds.next()) {
                Check check= new Check();
                check.setFirstName(ds.getString("FIRSTNAME"));
                check.setLastName(ds.getString("LASTNAME"));
                if(LOG.isDebugEnabled()) {
                    LOG.debug("Bean value is: " + bean);
                }        
                list.add(bean);            
            }
            if(LOG.isDebugEnabled()) {
                LOG.debug("Records fetched is: " + list.size());
            }        
            return list.toString();
        }

        public CheckFlatPackCVSParserWrapper getWrapper() {
            return wrapper;
        }

        public void setWrapper(CheckFlatPackCVSParserWrapper wrapper) {
            this.wrapper = wrapper;
        }

And my ErrorChannelWriter is

    public class ErrorChannelWriter {

        public static final Log LOG = LogFactory.getLog(ErrorChannelWriter.class);

        public Message<?> transformError(ErrorMessage errorMessage) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Transforming errorMessage is: " + errorMessage);
            }
            return ((MessagingException) errorMessage.getPayload())
                    .getFailedMessage();
        }
        }

and my validagtion class is

  com.check.Validation

  public class Validation 
  {

   void validation(CheckCheck)
   {
  if(Check.getFirstName().equals("maya"))
  {
  throw new RuntimeException("Name Already exist");
  }



  }

  }

and my ListToStringTransfomer is

      public class ListToStringTransfomer {
        private static final Log LOG=LogFactory.getLog(ListToStringTransfomer.class);


        public String transformList(List<IssueAppBean> list) {
            return list.toString();
        }

    }

and my file containing one fields instead of two fields

> maya 

here my file format is wrong, so record is moving to error folder.but there is no error message. how can i add error message(TOO FEW COLUMNS WANTED: 2 GOT: 1) when my file format is incorrect.
my requirement is in my error file should contaion

maya -TOO FEW COLUMNS WANTED: 2 GOT: 1 or(Any error message )

please give me any solution

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:09:37+00:00Added an answer on May 27, 2026 at 3:09 pm

    I don’t think that you should go through the error channel to solve this requirement. The main reason for this is that invalid input in this case is an expected scenario. The errorChannel is the channel that Spring Integration sends messages to if an unexpected exception happens in an endpoint.

    If you add some header to the message if a validation failed, you can route based on that header and also record the failure message there. You can then send your error message to a log file or whatever on your own.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to spring controllers using annotated controllers. Here is my configuration Bean definition
I am new to spring and I am currently using ClassPathXmlApplicationContext to getBean inside
I'm brand spanking new at Spring and have gotten a majority of the knowledge
I am relatively new to the Spring Framework and Spring security. I have used
Almost every new Java-web-project is using a modern MVC-framework such as Struts or Spring
I am new to Spring Integration. I've configured a Spring file inbound-channel-adapter, e.g. <file:inbound-channel-adapter
I have a Spring/Hibernate webapp that has some integration tests that run on an
currently I am working on a spring based application. I do have some unit
I'm writing some integration tests using a robot. I have the robot opening a
Hi we are using IBM Commerce Sever Moving from one view to another using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.