Browse Source

MessagingExceptionTranslator lives in support subpackage now

Issue: SPR-12038
pull/602/merge
Juergen Hoeller 11 years ago
parent
commit
1fe742addf
  1. 19
      spring-jms/src/main/java/org/springframework/jms/core/JmsMessagingTemplate.java
  2. 3
      spring-jms/src/main/java/org/springframework/jms/core/JmsOperations.java
  3. 3
      spring-jms/src/main/java/org/springframework/jms/core/JmsTemplate.java
  4. 10
      spring-jms/src/main/java/org/springframework/jms/support/JmsMessagingExceptionTranslator.java
  5. 3
      spring-jms/src/test/java/org/springframework/jms/support/JmsMessagingExceptionTranslatorTests.java
  6. 17
      spring-messaging/src/main/java/org/springframework/messaging/support/MessagingExceptionTranslator.java

19
spring-jms/src/main/java/org/springframework/jms/core/JmsMessagingTemplate.java

@ -23,15 +23,16 @@ import javax.jms.Session; @@ -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> @@ -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> @@ -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> @@ -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> @@ -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);
}
}
}

3
spring-jms/src/main/java/org/springframework/jms/core/JmsOperations.java

@ -367,6 +367,7 @@ public interface JmsOperations { @@ -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 { @@ -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 { @@ -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;

3
spring-jms/src/main/java/org/springframework/jms/core/JmsTemplate.java

@ -936,6 +936,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations @@ -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 @@ -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 {

10
spring-jms/src/main/java/org/springframework/jms/core/JmsMessagingExceptionTranslator.java → spring-jms/src/main/java/org/springframework/jms/support/JmsMessagingExceptionTranslator.java

@ -14,14 +14,14 @@ @@ -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 @@ -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);
}
}

3
spring-jms/src/test/java/org/springframework/jms/core/JmsMessagingExceptionTranslatorTests.java → spring-jms/src/test/java/org/springframework/jms/support/JmsMessagingExceptionTranslatorTests.java

@ -14,7 +14,7 @@ @@ -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 { @@ -31,4 +31,5 @@ public class JmsMessagingExceptionTranslatorTests {
public void translateNonJmsException() {
assertNull(translator.translateExceptionIfPossible(new NullPointerException()));
}
}

17
spring-messaging/src/main/java/org/springframework/messaging/MessagingExceptionTranslator.java → spring-messaging/src/main/java/org/springframework/messaging/support/MessagingExceptionTranslator.java

@ -14,7 +14,9 @@ @@ -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 { @@ -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);
}
Loading…
Cancel
Save