Mar 24th, 2011, 07:53 PM
Rejected items files & (Step/Item)Listener collaboration ?
Requirement: (Efficiently) generate a file containing all rejected (unparseable) records.
I can wire an ItemReadListener, and in the method onReadError extract the malformed line from the Exception (an FlatFileParseException actually). My question is how to do this efficiently and cleanly. I don't want to open and close the file for each malformed record, but rather open it once and close it once. You might argue that the number of rejected records should be small, but anyway I'm trying for a clean and elegant solution.
I was thinking about opening/closing the file in a StepExecutionListener. But then, how should the ItemReaderListener communicate with the StepExecutionListener? (i.e. get the File (OutputStream or whatever) from the StepExecutionListener).
Is this the right direction? Isn't there an easier way (i.e. declarative).
This seems harder than it should, so maybe there is an easier/better way that you might like to share.
Mar 25th, 2011, 02:49 AM
your ItemReadListener can also implement the ItemStream interface. It would have callbacks along the step and chunk life cycles. It should help you open, flush, and close the file stream.
Mar 29th, 2011, 01:02 PM
Thanks, I opted to create a separate ItemStream and register it with the <streams> because I'm using a built in ItemReader.
Tags for this Thread