Jun 25th, 2009, 01:51 AM
What are best practices to generate a bad items file?
What are best practices to generate a bad items file? I have several Jobs, that read a file (FlatFileItemReader) then these items may be processed and finally written in other file, on a data base, etc.
Then problem is I need to generate a .bad file with all the records with problems. That problems can be originated on the read, process o write part. And this file must contain the original flat record
I successful extract the original flat record when the problem is originated in the reader, using a skipListener and the FlatFileParseException. But when the problem isn't in the reader, but in the process or in the writer i don't know how to get the original flat record. I'm only have the object.
What is the best approach to resolve this problem? maybe implementing a custom FlatFileItemReader and put the original line in the StepContext? Or there is other trick?
Thanks a lot
Jun 25th, 2009, 10:29 AM
easiest way would be to map the line to a single String Value and use a processor to map the values
with this you can access the actual line on every point in the batch
Jun 25th, 2009, 09:27 PM
I usually do something similar. I use my FieldSetMapper to generate two types of objects "records" and "errors". I let Spring Batch treat both types as "items", passing them to the processor and writer. Then i have a custom-coded composite writer that supports writing to two files. I use the composite writer to check whether the item is a "record" or an "error" and write it to the appropriate place.
Feb 27th, 2010, 12:10 PM
Can you please give more details, how to generate two types of obejects in fieldsetmapper
and also from there pass two types of objects to processor and writer
Mar 8th, 2010, 02:01 AM
Finally, i used a custom skip listener class (extending from SkipListenerSupport). This custom class use a normal FlatFileItemWriter to write the errors file.
Also, i made that all my custom VO (generated in the reader) extendes from an abstract class with some attributes to hold original readed line and error detail.
For write the processed item file, i used a composite writer.
Sorry for my bad english.