BATCH-1127:Added logging statement to FFIR for parsing exceptions, and wrap all exceptions within DefaultLineMapper with a FlatFileParseException.

This commit is contained in:
lucasward
2009-03-09 13:06:02 +00:00
parent c3d14a4a8a
commit 4785cef982
3 changed files with 72 additions and 3 deletions

View File

@@ -176,7 +176,14 @@ public class FlatFileItemReader<T> extends AbstractItemCountingItemStreamItemRea
return null;
}
else {
return lineMapper.mapLine(logicalLine, lineCount);
try{
return lineMapper.mapLine(logicalLine, lineCount);
}
catch(Exception ex){
logger.error("Parsing error at line: " + lineCount + " in resource=" +
resource.getDescription() + ", input=[" + line + "]", ex);
throw ex;
}
}
}

View File

@@ -16,6 +16,7 @@
package org.springframework.batch.item.file.mapping;
import org.springframework.batch.item.file.FlatFileParseException;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.batch.item.file.transform.LineTokenizer;
import org.springframework.beans.factory.InitializingBean;
@@ -23,9 +24,13 @@ import org.springframework.util.Assert;
/**
* Two-phase {@link LineMapper} implementation consisting of tokenization of the
* line into {@link FieldSet} followed by mapping to item.
* line into {@link FieldSet} followed by mapping to item. By default, any exceptions
* thrown by either delegates will be wrapped in a {@link FlatFileParseException} before
* being rethrown. If finer grained control of exceptions is needed, the {@link LineMapper}
* interface should be implemented directly.
*
* @author Robert Kasanicky
* @author Lucas Ward
*
* @param <T> type of the item
*/
@@ -36,7 +41,13 @@ public class DefaultLineMapper<T> implements LineMapper<T>, InitializingBean {
private FieldSetMapper<T> fieldSetMapper;
public T mapLine(String line, int lineNumber) throws Exception {
return fieldSetMapper.mapFieldSet(tokenizer.tokenize(line));
try{
return fieldSetMapper.mapFieldSet(tokenizer.tokenize(line));
}
catch(Exception ex){
throw new FlatFileParseException("Parsing error at line: " + lineNumber +
", input=[" + line + "]", ex, line, lineNumber);
}
}
public void setLineTokenizer(LineTokenizer tokenizer) {