Java Reference
In-Depth Information
" line of the file. Below was the faulty " +
"input.\n");
errorMessage.append(ffpe.getInput() + "\n");
logger.error(errorMessage.toString(), ffpe);
} else {
logger.error("An error has occured", e);
}
}
}
Configuring your listener requires you to update the step reading the file. In your case, you have
only one step in your copyJob. Listing 7-65 shows the configuration for this listener.
Listing 7-65. Configuring the CustomerItemListener
<beans:bean id="customerItemLogger"
class="com.apress.springbatch.chapter7.CustomerItemListener"/>
<job id="copyJob">
<step id="copyFileStep">
<tasklet>
<chunk reader="customerFileReader" writer="outputWriter"
commit-interval="10" skip-limit="100">
<skippable-exception-classes>
<include class="java.lang.Exception"/>
</skippable-exception-classes>
</chunk>
<listeners>
<listener ref="customerItemLogger"/>
</listeners>
</tasklet>
</step>
</job>
If you use the fixed length record job as an example and execute it with a file that contains an input
record longer than 63 characters, an exception will be thrown. However, since you have configured your
job to skip all exceptions that extend Exception, the exception will not affect your job's results, yet your
customerItemLogger will be called and log the item as required. When you execute this job, you see two
things. The first is a FlatFileParseException for each record that is invalid. The second are your log
messages. Listing 7-66 shows an example of the log messages your job generates on error.
Listing 7-66. Output of the CustomerItemLogger
2011-05-03 23:49:22,148 ERROR main [com.apress.springbatch.chapter7.CustomerItemListener] -
<An error occured while processing the 1 line of the file. Below was the faulty input.
Michael TMinella 123 4th Street Chicago IL60606ABCDE
>
 
Search WWH ::




Custom Search