Announcement Announcement Module
Collapse
No announcement yet.
SubclassExceptionClassifier Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Define the key type on yuor map...

    Code:
    <map key-type="java.lang.Class">
      <entry key="java.lang.Exception" value="error" />
    </map>

    Comment


    • #3
      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.

      Comment


      • #4
        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?

        Comment


        • #5
          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.

          Comment


          • #6
            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.

            Comment


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

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

              Comment


              • #8
                Excellent. Thanks.

                Comment

                Working...
                X