Results 1 to 3 of 3

Thread: Interceptors and Exceptions

  1. #1
    Join Date
    Aug 2005
    Posts
    19

    Default Interceptors and Exceptions

    Hello, I'm using a custom interceptor and I notice when an exception is throwed the postProcess method is not executed. Is this a bug or is the expected way to work?.

    I think that postProcess method would be executed beside exceptions. I guess its a common use case set up things in preProcess (maybe a Thread Local) and then clean that things in postProcess and this currently doesn't work when an exception is throwed.

    Thanks, Claudio.

  2. #2
    Join Date
    Aug 2005
    Posts
    19

    Default

    The class MessageInterceptionAdvice has the following code:

    Code:
            ....
            Message outputMessage = null;
            try {
                outputMessage = (Message) mi.proceed();
            } finally {
                if (outputMessage != null) {
                    Stack<MessageInterceptor> postProcessStack = new Stack<MessageInterceptor>();
                    postProcessStack.addAll(this.messageInterceptors);
                    while (!postProcessStack.empty()) {
                        MessageInterceptor interceptor = postProcessStack.pop();
                        outputMessage = interceptor.postProcess(context, inputMessage, outputMessage);
                    }
                }
            }
    when mi.proceed() throw an exception outputMessage is always null so the if sentence in the finally is false and thats the reason why the postProcess is not called.

  3. #3
    Join Date
    Apr 2005
    Location
    San Francisco, CA
    Posts
    1,224

    Default

    That's a good point, we definitely don't account for teardown of resources in the API, i.e., the equivalent of the afterCompletion callback in HandlerInterceptor. I have added a Jira to consider this for 1.5: https://jira.springsource.org/browse/FLEX-86

    In the meantime, you could handle this by having your interceptor also implement ApplicationListener, and listening for the RequestHandledEvent in order to clean up resources.
    Jeremy Grelle

    Staff Engineer, Web Products Team
    SpringSource

Posting Permissions

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