JmsMessagingTemplate uses local convertJmsException template method instead of generic MessagingExceptionTranslator interface

This commit also turns MessagingException into a NestedRuntimeException subclass which delivers a root message that has the cause message appended to it. That's a common expectation with the use of Spring exceptions since all of our exception hierarchies have historically been designed that way.

Issue: SPR-12064
Issue: SPR-12038
This commit is contained in:
Juergen Hoeller
2014-08-09 22:06:50 +02:00
parent 6b6ca4889b
commit c06ac06bdd
6 changed files with 45 additions and 181 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
package org.springframework.messaging;
import org.springframework.core.NestedRuntimeException;
/**
* The base exception for any failures related to messaging.
*
@@ -24,13 +26,13 @@ package org.springframework.messaging;
* @since 4.0
*/
@SuppressWarnings("serial")
public class MessagingException extends RuntimeException {
public class MessagingException extends NestedRuntimeException {
private final Message<?> failedMessage;
public MessagingException(Message<?> message) {
super();
super("");
this.failedMessage = message;
}
@@ -50,7 +52,7 @@ public class MessagingException extends RuntimeException {
}
public MessagingException(Message<?> message, Throwable cause) {
super(cause);
super("", cause);
this.failedMessage = message;
}

View File

@@ -1,47 +0,0 @@
/*
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.messaging.support;
import org.springframework.messaging.MessagingException;
/**
* Interface implemented by Spring integrations with messaging technologies
* that throw runtime exceptions, such as JMS, STOMP and AMQP.
*
* <p>This allows consistent usage of combined exception translation functionality,
* without forcing a single translator to understand every single possible type
* of exception.
*
* @author Stephane Nicoll
* @since 4.1
*/
public interface MessagingExceptionTranslator {
/**
* Translate the given runtime exception thrown by a messaging implementation
* to a corresponding exception from Spring's generic
* {@link org.springframework.messaging.MessagingException} hierarchy, if possible.
* <p>Do not translate exceptions that are not understood by this translator:
* for example, if resulting from user code or otherwise unrelated to messaging.
* @param ex a RuntimeException to translate
* @return the corresponding MessagingException (or {@code null} if the
* exception could not be translated, as in this case it may result from
* user code rather than from an actual messaging problem)
*/
MessagingException translateExceptionIfPossible(RuntimeException ex);
}