Skip to content

Commit 1fe742a

Browse files
committed
MessagingExceptionTranslator lives in support subpackage now
Issue: SPR-12038
1 parent 9be04b3 commit 1fe742a

File tree

6 files changed

+31
-24
lines changed

6 files changed

+31
-24
lines changed

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

+10-9
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@
2323

2424
import org.springframework.beans.factory.InitializingBean;
2525
import org.springframework.jms.JmsException;
26+
import org.springframework.jms.support.JmsMessagingExceptionTranslator;
2627
import org.springframework.jms.support.converter.MessageConverter;
2728
import org.springframework.jms.support.converter.MessagingMessageConverter;
2829
import org.springframework.jms.support.converter.SimpleMessageConverter;
2930
import org.springframework.messaging.Message;
3031
import org.springframework.messaging.MessagingException;
31-
import org.springframework.messaging.MessagingExceptionTranslator;
3232
import org.springframework.messaging.converter.MessageConversionException;
3333
import org.springframework.messaging.core.AbstractMessagingTemplate;
3434
import org.springframework.messaging.core.MessagePostProcessor;
35+
import org.springframework.messaging.support.MessagingExceptionTranslator;
3536
import org.springframework.util.Assert;
3637

3738
/**
@@ -230,14 +231,14 @@ public Message<?> sendAndReceive(Message<?> requestMessage) {
230231
}
231232

232233
@Override
233-
public Message<?> sendAndReceive(String destinationName, Message<?> requestMessage)
234-
throws MessagingException {
234+
public Message<?> sendAndReceive(String destinationName, Message<?> requestMessage) throws MessagingException {
235235
return doSendAndReceive(destinationName, requestMessage);
236236
}
237237

238238
@Override
239239
public <T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass)
240240
throws MessagingException {
241+
241242
return convertSendAndReceive(destinationName, request, null, targetClass);
242243
}
243244

@@ -324,8 +325,8 @@ protected Message<?> doReceive(String destinationName) {
324325
@Override
325326
protected Message<?> doSendAndReceive(Destination destination, Message<?> requestMessage) {
326327
try {
327-
javax.jms.Message jmsMessage = this.jmsTemplate
328-
.sendAndReceive(destination, createMessageCreator(requestMessage));
328+
javax.jms.Message jmsMessage = this.jmsTemplate.sendAndReceive(
329+
destination, createMessageCreator(requestMessage));
329330
return doConvert(jmsMessage);
330331
}
331332
catch (JmsException ex) {
@@ -335,8 +336,8 @@ protected Message<?> doSendAndReceive(Destination destination, Message<?> reques
335336

336337
protected Message<?> doSendAndReceive(String destinationName, Message<?> requestMessage) {
337338
try {
338-
javax.jms.Message jmsMessage = this.jmsTemplate
339-
.sendAndReceive(destinationName, createMessageCreator(requestMessage));
339+
javax.jms.Message jmsMessage = this.jmsTemplate.sendAndReceive(
340+
destinationName, createMessageCreator(requestMessage));
340341
return doConvert(jmsMessage);
341342
}
342343
catch (JmsException ex) {
@@ -396,10 +397,10 @@ public javax.jms.Message createMessage(Session session) throws JMSException {
396397
return this.messageConverter.toMessage(this.message, session);
397398
}
398399
catch (JMSException ex) {
399-
throw new MessageConversionException("Could not convert '" + message + "'", ex);
400+
throw new MessageConversionException("Could not convert '" + this.message + "'", ex);
400401
}
401402
catch (JmsException ex) {
402-
throw new MessageConversionException("Could not convert '" + message + "'", ex);
403+
throw new MessageConversionException("Could not convert '" + this.message + "'", ex);
403404
}
404405
}
405406
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
367367
* @return the reply, possibly {@code null} if the message could not be received,
368368
* for example due to a timeout
369369
* @throws JmsException checked JMSException converted to unchecked
370+
* @since 4.1
370371
*/
371372
Message sendAndReceive(MessageCreator messageCreator) throws JmsException;
372373

@@ -380,6 +381,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
380381
* @return the reply, possibly {@code null} if the message could not be received,
381382
* for example due to a timeout
382383
* @throws JmsException checked JMSException converted to unchecked
384+
* @since 4.1
383385
*/
384386
Message sendAndReceive(Destination destination, MessageCreator messageCreator) throws JmsException;
385387

@@ -394,6 +396,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
394396
* @return the reply, possibly {@code null} if the message could not be received,
395397
* for example due to a timeout
396398
* @throws JmsException checked JMSException converted to unchecked
399+
* @since 4.1
397400
*/
398401
Message sendAndReceive(String destinationName, MessageCreator messageCreator) throws JmsException;
399402

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,7 @@ public Message doInJms(Session session) throws JMSException {
936936
*/
937937
protected Message doSendAndReceive(Session session, Destination destination, MessageCreator messageCreator)
938938
throws JMSException {
939+
939940
Assert.notNull(messageCreator, "MessageCreator must not be null");
940941
TemporaryQueue responseQueue = null;
941942
MessageProducer producer = null;
@@ -963,7 +964,7 @@ protected Message doSendAndReceive(Session session, Destination destination, Mes
963964

964965
/**
965966
* A variant of {@link #execute(SessionCallback, boolean)} that explicitly
966-
* creates a non transactional session. The given {@link SessionCallback}
967+
* creates a non-transactional {@link Session}. The given {@link SessionCallback}
967968
* does not participate in an existing transaction.
968969
*/
969970
private <T> T executeLocal(SessionCallback<T> action, boolean startConnection) throws JmsException {

spring-jms/src/main/java/org/springframework/jms/core/JmsMessagingExceptionTranslator.java renamed to spring-jms/src/main/java/org/springframework/jms/support/JmsMessagingExceptionTranslator.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.jms.core;
17+
package org.springframework.jms.support;
1818

1919
import org.springframework.jms.InvalidDestinationException;
2020
import org.springframework.jms.JmsException;
2121
import org.springframework.jms.support.converter.MessageConversionException;
2222
import org.springframework.jms.support.destination.DestinationResolutionException;
2323
import org.springframework.messaging.MessagingException;
24-
import org.springframework.messaging.MessagingExceptionTranslator;
24+
import org.springframework.messaging.support.MessagingExceptionTranslator;
2525

2626
/**
2727
* {@link MessagingExceptionTranslator} capable of translating {@link JmsException}
@@ -41,16 +41,14 @@ public MessagingException translateExceptionIfPossible(RuntimeException ex) {
4141
}
4242

4343
private MessagingException convertJmsException(JmsException ex) {
44-
if (ex instanceof DestinationResolutionException ||
45-
ex instanceof InvalidDestinationException) {
44+
if (ex instanceof DestinationResolutionException || ex instanceof InvalidDestinationException) {
4645
return new org.springframework.messaging.core.DestinationResolutionException(ex.getMessage(), ex);
4746
}
4847
if (ex instanceof MessageConversionException) {
4948
return new org.springframework.messaging.converter.MessageConversionException(ex.getMessage(), ex);
5049
}
51-
52-
5350
// Fallback
5451
return new MessagingException(ex.getMessage(), ex);
5552
}
53+
5654
}

spring-jms/src/test/java/org/springframework/jms/core/JmsMessagingExceptionTranslatorTests.java renamed to spring-jms/src/test/java/org/springframework/jms/support/JmsMessagingExceptionTranslatorTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.jms.core;
17+
package org.springframework.jms.support;
1818

1919
import org.junit.Test;
2020

@@ -31,4 +31,5 @@ public class JmsMessagingExceptionTranslatorTests {
3131
public void translateNonJmsException() {
3232
assertNull(translator.translateExceptionIfPossible(new NullPointerException()));
3333
}
34+
3435
}

spring-messaging/src/main/java/org/springframework/messaging/MessagingExceptionTranslator.java renamed to spring-messaging/src/main/java/org/springframework/messaging/support/MessagingExceptionTranslator.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.messaging;
17+
package org.springframework.messaging.support;
18+
19+
import org.springframework.messaging.MessagingException;
1820

1921
/**
2022
* Interface implemented by Spring integrations with messaging technologies
@@ -31,14 +33,15 @@ public interface MessagingExceptionTranslator {
3133

3234
/**
3335
* Translate the given runtime exception thrown by a messaging implementation
34-
* to a corresponding exception from Spring's generic {@link MessagingException}
35-
* hierarchy, if possible.
36-
* <p>Do not translate exceptions that are not understand by this translator:
37-
* for example, if resulting from user code and unrelated to messaging.
38-
* @param ex a RuntimeException thrown
36+
* to a corresponding exception from Spring's generic
37+
* {@link org.springframework.messaging.MessagingException} hierarchy, if possible.
38+
* <p>Do not translate exceptions that are not understood by this translator:
39+
* for example, if resulting from user code or otherwise unrelated to messaging.
40+
* @param ex a RuntimeException to translate
3941
* @return the corresponding MessagingException (or {@code null} if the
4042
* exception could not be translated, as in this case it may result from
41-
* user code rather than an actual messaging problem)
43+
* user code rather than from an actual messaging problem)
4244
*/
4345
MessagingException translateExceptionIfPossible(RuntimeException ex);
46+
4447
}

0 commit comments

Comments
 (0)