Announcement Announcement Module
Collapse
No announcement yet.
ItemListenerSupport not being called Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ItemListenerSupport not being called

    I want to send an email on a file read error. I created a stub (just prints and logs) ItemListenerSupport and registered it as a listener on the SimpleStep but it appears it is not being called. I feel like I'm just missing a small detail here. Any ideas?

    Using Spring Batch version 1.1.2

    Related Code:
    Code:
     <bean id="inventoryDailyJob" class="org.springframework.batch.core.job.SimpleJob">
            <property name="jobRepository" ref="jobRepository" />
            <property name="steps">
                <list>
                    <bean id="process" class="org.springframework.batch.core.step.item.SimpleStepFactoryBean">
                        <property name="allowStartIfComplete" value="true" />
                        <property name="commitInterval" value="10" />
                        <property name="startLimit" value="100" />
                        <property name="itemReader" ref="inventoryFileItemReader" />
                        <property name="itemWriter" ref="hibernateItemWriter" />
                        <property name="listeners">
                            <list>
                                <ref bean="inputFile" />
                                <bean class="batch.ItemErrorListener" />
                            </list>
                        </property>
                    </bean>
                    <bean id="deleteFilesInDir" parent="taskletStep">
                        <property name="tasklet">
                            <bean class="batch.FileBackupTask">
                                <property name="fileResource" ref="inputFile" />
                            </bean>
                        </property>
                    </bean>
                </list>
            </property>
            <property name="restartable" value="true" />
        </bean>
    Code:
    <bean id="inventoryFileItemReader"
              class="org.springframework.batch.item.file.FlatFileItemReader">
            <property name="resource" ref="inputFile" />
            <property name="lineTokenizer">
                <bean class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
                    <property name="names" value="scaleId,ticket,isVoid,creationTimeStamp,stockpile,customerId,originId,seamId,seamDescr,productId,leaseId,haulerId,barcode,timeIn,timeOut,tare,gross,quantity,modified,haulType" />
                    <property name="columns" value="1-3,4-10,11-11,12-23,24-29,30-35,36-41,42-47,48-72,73-78,79-84,85-87,88-93,94-105,106-117,118-123,124-129,130-135,136-136,137-137" />
                </bean>
            </property>
            <property name="fieldSetMapper">
                <bean class="batch.InventoryFieldSetMapper" />
            </property>
        </bean>
    Code:
    <bean id="hibernateItemWriter"                      class="org.springframework.batch.item.database.HibernateAwareItemWriter">
            <property name="sessionFactory" ref="sessionFactory" />
            <property name="delegate" ref="inventoryItemWriter" />
        </bean>
    <bean name="inventoryItemWriter" class="batch.InventoryItemWriter">
            <property name="inventoryManager" ref="inventoryManager"/>
        </bean>
    Code:
    public class ItemErrorListener extends ItemListenerSupport {
    
        private static Log logger = LogFactory.getLog(ItemErrorListener.class);    
        public void onReadError(Exception ex) {
            logger.error("Encountered error on read", ex);
            System.out.println("Encountered error on read");
        }
        
        public void onWriteError(Exception ex) {
            logger.error("Encountered error on write", ex);
            System.out.println("Encountered error on write");
        }
        
        public void onErrorInStep(Exception ex) {
            logger.error("Encountered error in step", ex);
            System.out.println("Encountered error in step");
        }
    }
    server log file
    Code:
    Encountered an error executing the step: class org.springframework.batch.item.file.FlatFileParseException: Parsing error at line: 1008 in resource=URL [file:c:/extract/qbits-bil09052008.txt], input=[BIL 557989N20070801112129    25    23    62    62 BOT 5                 8     996   06 569   569   200708010729200708011121  5.00 20.40- 15.4NI]
    Closing org.springframework.context.support.ClassPathXmlApplicationContext@6f8b01: display name [Job ApplicationContext inventoryDailyJob]; startup date [Thu Oct 02 21:35:00 EDT 2008]; parent: [email protected]19e102c
    Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@13af73f: defining beans [simpleStep,taskletStep,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,txAdvice,customEditorConfigurer,inventoryDailyJob,jobRunner,inventoryItemWriter,hibernateItemWriter,inputFile,inventoryFileItemReader]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@843d2
    Job: [org.springframework.batch.core.configuration.support.ClassPathXmlApplicationContextJobFactory$ContextClosingJob@281d5b] failed with the following parameters: [{filename=qbits-bil09052008.txt, path=c:\extract}{}{}{}]
    org.springframework.batch.item.file.FlatFileParseException: Parsing error at line: 1008 in resource=URL [file:c:/extract/qbits-bil09052008.txt], input=[BIL 557989N20070801112129    25    23    62    62 BOT 5                 8     996   06 569   569   200708010729200708011121  5.00 20.40- 15.4NI]
            at org.springframework.batch.item.file.FlatFileItemReader.doRead(FlatFileItemReader.java:276)
            at org.springframework.batch.item.support.AbstractBufferedItemReaderItemStream.read(AbstractBufferedItemReaderItemStream.java:92)
    .....
    I have searched all through the log file and never see the ItemErrorListener log or println() statements.
    Thank you,
    Todd
    Last edited by tbone21w; Oct 2nd, 2008, 08:47 PM. Reason: Adding Spring Batch version

  • #2
    I apologize to everyone, I knew that I was missing something and it turned out that I am not calling this file. I made some changes to the app and I had so much going on I forgot ithat I needed to delete this file. Everything worked perfect once I added it to the correct config.

    Comment

    Working...
    X