Added additional menthod to ItemSkipPolicy to determine if a step should fail. Also added a small prototype of domain-specific interceptors.
This commit is contained in:
@@ -328,12 +328,20 @@ public class ItemOrientedStep extends AbstractStep implements InitializingBean {
|
||||
fatalException.setException(e);
|
||||
stepExecution.setStatus(BatchStatus.UNKNOWN);
|
||||
}
|
||||
if (t instanceof RuntimeException) {
|
||||
throw (RuntimeException) t;
|
||||
|
||||
if(itemSkipPolicy.shouldFail(t)){
|
||||
if (t instanceof RuntimeException) {
|
||||
throw (RuntimeException) t;
|
||||
}
|
||||
else {
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RuntimeException(t);
|
||||
else{
|
||||
logger.error("Exception should not cause step to fail", t);
|
||||
}
|
||||
|
||||
result = ExitStatus.CONTINUABLE;
|
||||
}
|
||||
|
||||
// Check for interruption after transaction as well, so that
|
||||
|
||||
@@ -29,4 +29,8 @@ public class AlwaysSkipItemSkipPolicy implements ItemSkipPolicy {
|
||||
public boolean shouldSkip(Exception ex, int skipCount) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean shouldFail(Throwable t) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ public class LimitCheckingItemSkipPolicy implements ItemSkipPolicy {
|
||||
private final int skipLimit;
|
||||
|
||||
private ExceptionClassifier exceptionClassifier;
|
||||
private List failurePreventingExceptions = new ArrayList();
|
||||
|
||||
public LimitCheckingItemSkipPolicy(int skipLimit) {
|
||||
this(skipLimit, new ArrayList(0));
|
||||
@@ -95,5 +96,22 @@ public class LimitCheckingItemSkipPolicy implements ItemSkipPolicy {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean shouldFail(Throwable t) {
|
||||
if(failurePreventingExceptions.contains(t)){
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of exceptions that will prevent step execution from failing.
|
||||
*
|
||||
* @param failurePreventingExceptions
|
||||
*/
|
||||
public void setFailurePreventingExceptions(List failurePreventingExceptions) {
|
||||
this.failurePreventingExceptions = failurePreventingExceptions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,5 +29,7 @@ public class NeverSkipItemSkipPolicy implements ItemSkipPolicy{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean shouldFail(Throwable t) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user