Results 1 to 8 of 8

Thread: SubclassExceptionClassifier

  1. #1
    Join Date
    Oct 2007
    Posts
    10

    Default SubclassExceptionClassifier

    I am building a prototype batch file processor using a Spring Batch M3 snapshot build. My prototype is almost done and I have only implemented 3 classes, so I think the Spring Batch developers are on the right track

    In my processing part different kinds of Exceptions can be thrown, some that should simply be logged and some that should stop the processing of the file. I want to use the LogOrRethrowExceptionHandler to provide me this behaviour and I want to inject the SubclassExceptionClassifier to classify the Exceptions that might occur.

    The SubclassExceptionClassifier has a typeMap parameter which is a Map with a java.lang.Class key and a java.lang.Object value, but I have no idea how to inject an instance of java.lang.Class for the Exception that I want to classify.

    I have tried:
    Code:
    <map>
       <entry key="java.lang.Exception" value="error" />
    </map>
    But this injects a String not an instance of java.lang.Class.

    Also:
    Code:
    <bean id="exception" class="java.lang.Exception"/>
    <map>
       <entry key-ref="exception" value="error" />
    </map>
    Did not have the desired effect. It injects an instance of java.lang.Exception which is not instance of java.lang.Class.

    Does anyone know how to inject the instance of java.lang.Class?

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Define the key type on yuor map...

    Code:
    <map key-type="java.lang.Class">
      <entry key="java.lang.Exception" value="error" />
    </map>
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Oct 2007
    Posts
    10

    Default

    Quote Originally Posted by mdeinum View Post
    Define the key type on yuor map...

    Code:
    <map key-type="java.lang.Class">
      <entry key="java.lang.Exception" value="error" />
    </map>
    Thanks a lot, that works like a charm. Now I can throw away my custom ExceptionClassifier.

  4. #4
    Join Date
    Oct 2007
    Posts
    10

    Default

    Another related question.

    The LogOrRethrowExceptionHandler doesn't do anything with an Exception that is not classified as DEBUG,WARN,ERROR or RETHROW. Is there a reason why this class doens't rethrow exceptions by default?

  5. #5

    Default

    The LogOrRethrowExceptionHandler doesn't do anything with an Exception that is not classified as DEBUG,WARN,ERROR or RETHROW. Is there a reason why this class doens't rethrow exceptions by default?
    LogOrRethrowExceptionHandler relies on ExceptionClassifier to classify the exception, so I think it is expected invariant that the exception always falls into one of the predefined categories. Adding an else clause that would throw an IllegalStateException if the exception has not been classified would make sense then.

  6. #6
    Join Date
    Oct 2007
    Posts
    10

    Default

    Quote Originally Posted by robert.kasanicky View Post
    LogOrRethrowExceptionHandler relies on ExceptionClassifier to classify the exception, so I think it is expected invariant that the exception always falls into one of the predefined categories. Adding an else clause that would throw an IllegalStateException if the exception has not been classified would make sense then.
    An IllegalStateException would indeed make sense.

    Yesterday the LogOrRethrowExceptionHandler swallowed some ClassNotFoundExceptions that were being thrown. I would expect that any unexpected exception would stop the batch processing.

    Thanks for the reply.

  7. #7

    Default

    I have created a JIRA issue with detailed description copied from this forum thread:

    http://opensource.atlassian.com/proj...owse/BATCH-188

  8. #8
    Join Date
    Oct 2007
    Posts
    10

    Default

    Excellent. Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •