提交 1fe742ad 编写于 作者: J Juergen Hoeller

MessagingExceptionTranslator lives in support subpackage now

Issue: SPR-12038
上级 9be04b38
......@@ -23,15 +23,16 @@ import javax.jms.Session;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jms.JmsException;
import org.springframework.jms.support.JmsMessagingExceptionTranslator;
import org.springframework.jms.support.converter.MessageConverter;
import org.springframework.jms.support.converter.MessagingMessageConverter;
import org.springframework.jms.support.converter.SimpleMessageConverter;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;
import org.springframework.messaging.MessagingExceptionTranslator;
import org.springframework.messaging.converter.MessageConversionException;
import org.springframework.messaging.core.AbstractMessagingTemplate;
import org.springframework.messaging.core.MessagePostProcessor;
import org.springframework.messaging.support.MessagingExceptionTranslator;
import org.springframework.util.Assert;
/**
......@@ -230,14 +231,14 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate<Destination>
}
@Override
public Message<?> sendAndReceive(String destinationName, Message<?> requestMessage)
throws MessagingException {
public Message<?> sendAndReceive(String destinationName, Message<?> requestMessage) throws MessagingException {
return doSendAndReceive(destinationName, requestMessage);
}
@Override
public <T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass)
throws MessagingException {
return convertSendAndReceive(destinationName, request, null, targetClass);
}
......@@ -324,8 +325,8 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate<Destination>
@Override
protected Message<?> doSendAndReceive(Destination destination, Message<?> requestMessage) {
try {
javax.jms.Message jmsMessage = this.jmsTemplate
.sendAndReceive(destination, createMessageCreator(requestMessage));
javax.jms.Message jmsMessage = this.jmsTemplate.sendAndReceive(
destination, createMessageCreator(requestMessage));
return doConvert(jmsMessage);
}
catch (JmsException ex) {
......@@ -335,8 +336,8 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate<Destination>
protected Message<?> doSendAndReceive(String destinationName, Message<?> requestMessage) {
try {
javax.jms.Message jmsMessage = this.jmsTemplate
.sendAndReceive(destinationName, createMessageCreator(requestMessage));
javax.jms.Message jmsMessage = this.jmsTemplate.sendAndReceive(
destinationName, createMessageCreator(requestMessage));
return doConvert(jmsMessage);
}
catch (JmsException ex) {
......@@ -396,10 +397,10 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate<Destination>
return this.messageConverter.toMessage(this.message, session);
}
catch (JMSException ex) {
throw new MessageConversionException("Could not convert '" + message + "'", ex);
throw new MessageConversionException("Could not convert '" + this.message + "'", ex);
}
catch (JmsException ex) {
throw new MessageConversionException("Could not convert '" + message + "'", ex);
throw new MessageConversionException("Could not convert '" + this.message + "'", ex);
}
}
}
......
......@@ -367,6 +367,7 @@ public interface JmsOperations {
* @return the reply, possibly {@code null} if the message could not be received,
* for example due to a timeout
* @throws JmsException checked JMSException converted to unchecked
* @since 4.1
*/
Message sendAndReceive(MessageCreator messageCreator) throws JmsException;
......@@ -380,6 +381,7 @@ public interface JmsOperations {
* @return the reply, possibly {@code null} if the message could not be received,
* for example due to a timeout
* @throws JmsException checked JMSException converted to unchecked
* @since 4.1
*/
Message sendAndReceive(Destination destination, MessageCreator messageCreator) throws JmsException;
......@@ -394,6 +396,7 @@ public interface JmsOperations {
* @return the reply, possibly {@code null} if the message could not be received,
* for example due to a timeout
* @throws JmsException checked JMSException converted to unchecked
* @since 4.1
*/
Message sendAndReceive(String destinationName, MessageCreator messageCreator) throws JmsException;
......
......@@ -936,6 +936,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
*/
protected Message doSendAndReceive(Session session, Destination destination, MessageCreator messageCreator)
throws JMSException {
Assert.notNull(messageCreator, "MessageCreator must not be null");
TemporaryQueue responseQueue = null;
MessageProducer producer = null;
......@@ -963,7 +964,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
/**
* A variant of {@link #execute(SessionCallback, boolean)} that explicitly
* creates a non transactional session. The given {@link SessionCallback}
* creates a non-transactional {@link Session}. The given {@link SessionCallback}
* does not participate in an existing transaction.
*/
private <T> T executeLocal(SessionCallback<T> action, boolean startConnection) throws JmsException {
......
......@@ -14,14 +14,14 @@
* limitations under the License.
*/
package org.springframework.jms.core;
package org.springframework.jms.support;
import org.springframework.jms.InvalidDestinationException;
import org.springframework.jms.JmsException;
import org.springframework.jms.support.converter.MessageConversionException;
import org.springframework.jms.support.destination.DestinationResolutionException;
import org.springframework.messaging.MessagingException;
import org.springframework.messaging.MessagingExceptionTranslator;
import org.springframework.messaging.support.MessagingExceptionTranslator;
/**
* {@link MessagingExceptionTranslator} capable of translating {@link JmsException}
......@@ -41,16 +41,14 @@ public class JmsMessagingExceptionTranslator implements MessagingExceptionTransl
}
private MessagingException convertJmsException(JmsException ex) {
if (ex instanceof DestinationResolutionException ||
ex instanceof InvalidDestinationException) {
if (ex instanceof DestinationResolutionException || ex instanceof InvalidDestinationException) {
return new org.springframework.messaging.core.DestinationResolutionException(ex.getMessage(), ex);
}
if (ex instanceof MessageConversionException) {
return new org.springframework.messaging.converter.MessageConversionException(ex.getMessage(), ex);
}
// Fallback
return new MessagingException(ex.getMessage(), ex);
}
}
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.jms.core;
package org.springframework.jms.support;
import org.junit.Test;
......@@ -31,4 +31,5 @@ public class JmsMessagingExceptionTranslatorTests {
public void translateNonJmsException() {
assertNull(translator.translateExceptionIfPossible(new NullPointerException()));
}
}
......@@ -14,7 +14,9 @@
* limitations under the License.
*/
package org.springframework.messaging;
package org.springframework.messaging.support;
import org.springframework.messaging.MessagingException;
/**
* Interface implemented by Spring integrations with messaging technologies
......@@ -31,14 +33,15 @@ public interface MessagingExceptionTranslator {
/**
* Translate the given runtime exception thrown by a messaging implementation
* to a corresponding exception from Spring's generic {@link MessagingException}
* hierarchy, if possible.
* <p>Do not translate exceptions that are not understand by this translator:
* for example, if resulting from user code and unrelated to messaging.
* @param ex a RuntimeException thrown
* 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 an actual messaging problem)
* user code rather than from an actual messaging problem)
*/
MessagingException translateExceptionIfPossible(RuntimeException ex);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册