diff --git a/spring-jms/src/main/java/org/springframework/jms/core/JmsMessageOperations.java b/spring-jms/src/main/java/org/springframework/jms/core/JmsMessageOperations.java
index e3b1d0f35a7..d134ef9122c 100644
--- a/spring-jms/src/main/java/org/springframework/jms/core/JmsMessageOperations.java
+++ b/spring-jms/src/main/java/org/springframework/jms/core/JmsMessageOperations.java
@@ -30,8 +30,12 @@ import org.springframework.messaging.core.MessageSendingOperations;
/**
* A specialization of {@link MessageSendingOperations}, {@link MessageReceivingOperations}
- * and {@link MessageRequestReplyOperations} for JMS related operations that allow to specify
- * a destination name rather than the actual {@link jakarta.jms.Destination}.
+ * and {@link MessageRequestReplyOperations} for JMS related operations that allow to
+ * specify a destination name rather than the actual {@link jakarta.jms.Destination}.
+ *
+ *
Note: Operations in this interface throw {@link MessagingException} instead of
+ * the JMS-specific {@link org.springframework.jms.JmsException}, aligning with the
+ * {@code spring-messaging} module and its other client operation handles.
*
* @author Stephane Nicoll
* @since 4.1
@@ -68,30 +72,30 @@ public interface JmsMessageOperations extends MessageSendingOperations headers)
+ void convertAndSend(String destinationName, Object payload, @Nullable Map headers)
throws MessagingException;
/**
* Convert the given Object to serialized form, possibly using a
* {@link org.springframework.messaging.converter.MessageConverter},
- * wrap it as a message, apply the given post processor, and send
+ * wrap it as a message, apply the given post-processor, and send
* the resulting message to the given destination.
* @param destinationName the name of the target destination
* @param payload the Object to use as payload
- * @param postProcessor the post processor to apply to the message
+ * @param postProcessor the post-processor to apply to the message
*/
- void convertAndSend(String destinationName, Object payload, MessagePostProcessor postProcessor)
+ void convertAndSend(String destinationName, Object payload, @Nullable MessagePostProcessor postProcessor)
throws MessagingException;
/**
* Convert the given Object to serialized form, possibly using a
* {@link org.springframework.messaging.converter.MessageConverter},
- * wrap it as a message with the given headers, apply the given post processor,
+ * wrap it as a message with the given headers, apply the given post-processor,
* and send the resulting message to the given destination.
* @param destinationName the name of the target destination
* @param payload the Object to use as payload
* @param headers the headers for the message to send
- * @param postProcessor the post processor to apply to the message
+ * @param postProcessor the post-processor to apply to the message
*/
void convertAndSend(String destinationName, Object payload, @Nullable Map headers,
@Nullable MessagePostProcessor postProcessor) throws MessagingException;
@@ -159,13 +163,13 @@ public interface JmsMessageOperations extends MessageSendingOperations extends A
return this.destinationResolver;
}
+ protected final D resolveDestination(String destinationName) throws DestinationResolutionException {
+ Assert.state(this.destinationResolver != null,
+ "DestinationResolver is required to resolve destination names");
+ return this.destinationResolver.resolveDestination(destinationName);
+ }
+
@Override
- public void send(String destinationName, Message> message) {
+ public void send(String destinationName, Message> message) throws MessagingException {
D destination = resolveDestination(destinationName);
doSend(destination, message);
}
- protected final D resolveDestination(String destinationName) {
-
- Assert.state(this.destinationResolver != null, "DestinationResolver is required to resolve destination names");
- return this.destinationResolver.resolveDestination(destinationName);
- }
-
@Override
- public void convertAndSend(String destinationName, T payload) {
+ public void convertAndSend(String destinationName, T payload) throws MessagingException {
convertAndSend(destinationName, payload, null, null);
}
@Override
- public void convertAndSend(String destinationName, T payload, @Nullable Map headers) {
+ public void convertAndSend(String destinationName, T payload, @Nullable Map headers)
+ throws MessagingException {
+
convertAndSend(destinationName, payload, headers, null);
}
@Override
- public void convertAndSend(String destinationName, T payload, @Nullable MessagePostProcessor postProcessor) {
+ public void convertAndSend(String destinationName, T payload, @Nullable MessagePostProcessor postProcessor)
+ throws MessagingException {
+
convertAndSend(destinationName, payload, null, postProcessor);
}
@Override
- public void convertAndSend(String destinationName, T payload,
- @Nullable Map headers, @Nullable MessagePostProcessor postProcessor) {
+ public void convertAndSend(String destinationName, T payload, @Nullable Map headers,
+ @Nullable MessagePostProcessor postProcessor) throws MessagingException {
D destination = resolveDestination(destinationName);
super.convertAndSend(destination, payload, headers, postProcessor);
@@ -103,28 +108,32 @@ public abstract class AbstractDestinationResolvingMessagingTemplate extends A
@Override
@Nullable
- public Message> receive(String destinationName) {
+ public Message> receive(String destinationName) throws MessagingException {
D destination = resolveDestination(destinationName);
return super.receive(destination);
}
@Override
@Nullable
- public T receiveAndConvert(String destinationName, Class targetClass) {
+ public T receiveAndConvert(String destinationName, Class targetClass) throws MessagingException {
D destination = resolveDestination(destinationName);
return super.receiveAndConvert(destination, targetClass);
}
@Override
@Nullable
- public Message> sendAndReceive(String destinationName, Message> requestMessage) {
+ public Message> sendAndReceive(String destinationName, Message> requestMessage)
+ throws MessagingException {
+
D destination = resolveDestination(destinationName);
return super.sendAndReceive(destination, requestMessage);
}
@Override
@Nullable
- public T convertSendAndReceive(String destinationName, Object request, Class targetClass) {
+ public T convertSendAndReceive(String destinationName, Object request, Class targetClass)
+ throws MessagingException {
+
D destination = resolveDestination(destinationName);
return super.convertSendAndReceive(destination, request, targetClass);
}
@@ -132,7 +141,7 @@ public abstract class AbstractDestinationResolvingMessagingTemplate extends A
@Override
@Nullable
public T convertSendAndReceive(String destinationName, Object request,
- @Nullable Map headers, Class targetClass) {
+ @Nullable Map headers, Class targetClass) throws MessagingException {
D destination = resolveDestination(destinationName);
return super.convertSendAndReceive(destination, request, headers, targetClass);
@@ -141,7 +150,7 @@ public abstract class AbstractDestinationResolvingMessagingTemplate extends A
@Override
@Nullable
public T convertSendAndReceive(String destinationName, Object request, Class targetClass,
- @Nullable MessagePostProcessor postProcessor) {
+ @Nullable MessagePostProcessor postProcessor) throws MessagingException {
D destination = resolveDestination(destinationName);
return super.convertSendAndReceive(destination, request, targetClass, postProcessor);
@@ -151,7 +160,7 @@ public abstract class AbstractDestinationResolvingMessagingTemplate extends A
@Nullable
public T convertSendAndReceive(String destinationName, Object request,
@Nullable Map headers, Class targetClass,
- @Nullable MessagePostProcessor postProcessor) {
+ @Nullable MessagePostProcessor postProcessor) throws MessagingException {
D destination = resolveDestination(destinationName);
return super.convertSendAndReceive(destination, request, headers, targetClass, postProcessor);
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageReceivingTemplate.java b/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageReceivingTemplate.java
index e0f8974de36..2f94348d39b 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageReceivingTemplate.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageReceivingTemplate.java
@@ -18,6 +18,7 @@ package org.springframework.messaging.core;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
+import org.springframework.messaging.MessagingException;
import org.springframework.messaging.converter.MessageConversionException;
import org.springframework.messaging.converter.MessageConverter;
@@ -36,35 +37,25 @@ public abstract class AbstractMessageReceivingTemplate extends AbstractMessag
@Override
@Nullable
- public Message> receive() {
+ public Message> receive() throws MessagingException {
return doReceive(getRequiredDefaultDestination());
}
@Override
@Nullable
- public Message> receive(D destination) {
+ public Message> receive(D destination) throws MessagingException {
return doReceive(destination);
}
- /**
- * Actually receive a message from the given destination.
- * @param destination the target destination
- * @return the received message, possibly {@code null} if the message could not
- * be received, for example due to a timeout
- */
- @Nullable
- protected abstract Message> doReceive(D destination);
-
-
@Override
@Nullable
- public T receiveAndConvert(Class targetClass) {
+ public T receiveAndConvert(Class targetClass) throws MessagingException {
return receiveAndConvert(getRequiredDefaultDestination(), targetClass);
}
@Override
@Nullable
- public T receiveAndConvert(D destination, Class targetClass) {
+ public T receiveAndConvert(D destination, Class targetClass) throws MessagingException {
Message> message = doReceive(destination);
if (message != null) {
return doConvert(message, targetClass);
@@ -92,4 +83,13 @@ public abstract class AbstractMessageReceivingTemplate extends AbstractMessag
return value;
}
+ /**
+ * Actually receive a message from the given destination.
+ * @param destination the target destination
+ * @return the received message, possibly {@code null} if the
+ * message could not be received, for example due to a timeout
+ */
+ @Nullable
+ protected abstract Message> doReceive(D destination);
+
}
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageSendingTemplate.java b/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageSendingTemplate.java
index 0d5679e2f68..37baed7aa42 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageSendingTemplate.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageSendingTemplate.java
@@ -109,9 +109,6 @@ public abstract class AbstractMessageSendingTemplate implements MessageSendin
doSend(destination, message);
}
- protected abstract void doSend(D destination, Message> message);
-
-
@Override
public void convertAndSend(Object payload) throws MessagingException {
convertAndSend(payload, null);
@@ -151,13 +148,14 @@ public abstract class AbstractMessageSendingTemplate implements MessageSendin
send(destination, message);
}
+
/**
* Convert the given Object to serialized form, possibly using a
* {@link MessageConverter}, wrap it as a message with the given
- * headers and apply the given post processor.
+ * headers and apply the given post-processor.
* @param payload the Object to use as payload
* @param headers the headers for the message to send
- * @param postProcessor the post processor to apply to the message
+ * @param postProcessor the post-processor to apply to the message
* @return the converted message
*/
protected Message> doConvert(Object payload, @Nullable Map headers,
@@ -199,4 +197,11 @@ public abstract class AbstractMessageSendingTemplate implements MessageSendin
return headers;
}
+ /**
+ * Actually send the given message to the given destination.
+ * @param destination the target destination
+ * @param message the message to send
+ */
+ protected abstract void doSend(D destination, Message> message);
+
}
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessagingTemplate.java b/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessagingTemplate.java
index e9795e6a49f..5ef642a3abf 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessagingTemplate.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessagingTemplate.java
@@ -20,6 +20,7 @@ import java.util.Map;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
+import org.springframework.messaging.MessagingException;
/**
* An extension of {@link AbstractMessageReceivingTemplate} that adds support for
@@ -36,36 +37,33 @@ public abstract class AbstractMessagingTemplate extends AbstractMessageReceiv
@Override
@Nullable
- public Message> sendAndReceive(Message> requestMessage) {
+ public Message> sendAndReceive(Message> requestMessage) throws MessagingException {
return sendAndReceive(getRequiredDefaultDestination(), requestMessage);
}
@Override
@Nullable
- public Message> sendAndReceive(D destination, Message> requestMessage) {
+ public Message> sendAndReceive(D destination, Message> requestMessage) throws MessagingException {
return doSendAndReceive(destination, requestMessage);
}
- @Nullable
- protected abstract Message> doSendAndReceive(D destination, Message> requestMessage);
-
-
@Override
@Nullable
- public T convertSendAndReceive(Object request, Class targetClass) {
+ public T convertSendAndReceive(Object request, Class targetClass) throws MessagingException {
return convertSendAndReceive(getRequiredDefaultDestination(), request, targetClass);
}
@Override
@Nullable
- public T convertSendAndReceive(D destination, Object request, Class targetClass) {
+ public T convertSendAndReceive(D destination, Object request, Class targetClass) throws MessagingException {
return convertSendAndReceive(destination, request, null, targetClass);
}
@Override
@Nullable
public T convertSendAndReceive(
- D destination, Object request, @Nullable Map headers, Class targetClass) {
+ D destination, Object request, @Nullable Map headers, Class targetClass)
+ throws MessagingException {
return convertSendAndReceive(destination, request, headers, targetClass, null);
}
@@ -73,7 +71,8 @@ public abstract class AbstractMessagingTemplate extends AbstractMessageReceiv
@Override
@Nullable
public T convertSendAndReceive(
- Object request, Class targetClass, @Nullable MessagePostProcessor postProcessor) {
+ Object request, Class targetClass, @Nullable MessagePostProcessor postProcessor)
+ throws MessagingException {
return convertSendAndReceive(getRequiredDefaultDestination(), request, targetClass, postProcessor);
}
@@ -81,7 +80,7 @@ public abstract class AbstractMessagingTemplate extends AbstractMessageReceiv
@Override
@Nullable
public T convertSendAndReceive(D destination, Object request, Class targetClass,
- @Nullable MessagePostProcessor postProcessor) {
+ @Nullable MessagePostProcessor postProcessor) throws MessagingException {
return convertSendAndReceive(destination, request, null, targetClass, postProcessor);
}
@@ -90,11 +89,23 @@ public abstract class AbstractMessagingTemplate extends AbstractMessageReceiv
@Override
@Nullable
public T convertSendAndReceive(D destination, Object request, @Nullable Map headers,
- Class targetClass, @Nullable MessagePostProcessor postProcessor) {
+ Class targetClass, @Nullable MessagePostProcessor postProcessor) throws MessagingException {
Message> requestMessage = doConvert(request, headers, postProcessor);
Message> replyMessage = sendAndReceive(destination, requestMessage);
return (replyMessage != null ? (T) getMessageConverter().fromMessage(replyMessage, targetClass) : null);
}
+
+ /**
+ * Actually send the given request message to the given destination and
+ * receive a reply message for it.
+ * @param destination the target destination
+ * @param requestMessage the message to send
+ * @return the received reply, possibly {@code null} if the
+ * message could not be received, for example due to a timeout
+ */
+ @Nullable
+ protected abstract Message> doSendAndReceive(D destination, Message> requestMessage);
+
}
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolvingMessageRequestReplyOperations.java b/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolvingMessageRequestReplyOperations.java
index b06da0db343..79d17119c14 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolvingMessageRequestReplyOperations.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolvingMessageRequestReplyOperations.java
@@ -82,13 +82,13 @@ public interface DestinationResolvingMessageRequestReplyOperations extends Me
* Resolve the given destination name, convert the payload request Object
* to serialized form, possibly using a
* {@link org.springframework.messaging.converter.MessageConverter},
- * wrap it as a message, apply the given post process, and send the resulting
+ * wrap it as a message, apply the given post-process, and send the resulting
* message to the resolved destination, then receive a reply and convert its
* body to the specified target class.
* @param destinationName the name of the target destination
* @param request the payload for the request message to send
* @param targetClass the target class to convert the payload of the reply to
- * @param requestPostProcessor post process for the request message
+ * @param requestPostProcessor post-process for the request message
* @return the converted payload of the reply message, possibly {@code null} if
* the message could not be received, for example due to a timeout
*/
@@ -100,14 +100,14 @@ public interface DestinationResolvingMessageRequestReplyOperations extends Me
* Resolve the given destination name, convert the payload request Object
* to serialized form, possibly using a
* {@link org.springframework.messaging.converter.MessageConverter},
- * wrap it as a message with the given headers, apply the given post process,
+ * wrap it as a message with the given headers, apply the given post-process,
* and send the resulting message to the resolved destination, then receive
* a reply and convert its body to the specified target class.
* @param destinationName the name of the target destination
* @param request the payload for the request message to send
* @param headers the headers for the request message to send
* @param targetClass the target class to convert the payload of the reply to
- * @param requestPostProcessor post process for the request message
+ * @param requestPostProcessor post-process for the request message
* @return the converted payload of the reply message, possibly {@code null} if
* the message could not be received, for example due to a timeout
*/
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolvingMessageSendingOperations.java b/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolvingMessageSendingOperations.java
index 41f666a1414..36c6bc669f0 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolvingMessageSendingOperations.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolvingMessageSendingOperations.java
@@ -68,11 +68,11 @@ public interface DestinationResolvingMessageSendingOperations extends Message
* Resolve the given destination name to a destination, convert the payload
* Object to serialized form, possibly using a
* {@link org.springframework.messaging.converter.MessageConverter},
- * wrap it as a message, apply the given post processor, and send the resulting
+ * wrap it as a message, apply the given post-processor, and send the resulting
* message to the resolved destination.
* @param destinationName the destination name to resolve
* @param payload the Object to use as payload
- * @param postProcessor the post processor to apply to the message
+ * @param postProcessor the post-processor to apply to the message
*/
void convertAndSend(String destinationName, T payload, @Nullable MessagePostProcessor postProcessor)
throws MessagingException;
@@ -81,12 +81,12 @@ public interface DestinationResolvingMessageSendingOperations extends Message
* Resolve the given destination name to a destination, convert the payload
* Object to serialized form, possibly using a
* {@link org.springframework.messaging.converter.MessageConverter},
- * wrap it as a message with the given headers, apply the given post processor,
+ * wrap it as a message with the given headers, apply the given post-processor,
* and send the resulting message to the resolved destination.
* @param destinationName the destination name to resolve
* @param payload the Object to use as payload
* @param headers the headers for the message to send
- * @param postProcessor the post processor to apply to the message
+ * @param postProcessor the post-processor to apply to the message
*/
void convertAndSend(String destinationName, T payload, @Nullable Map headers,
@Nullable MessagePostProcessor postProcessor) throws MessagingException;
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/MessageRequestReplyOperations.java b/spring-messaging/src/main/java/org/springframework/messaging/core/MessageRequestReplyOperations.java
index eb7a13f9e97..3e0e36ce05f 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/core/MessageRequestReplyOperations.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/core/MessageRequestReplyOperations.java
@@ -99,12 +99,12 @@ public interface MessageRequestReplyOperations {
/**
* Convert the given request Object to serialized form, possibly using a
* {@link org.springframework.messaging.converter.MessageConverter},
- * apply the given post processor and send the resulting {@link Message} to a
+ * apply the given post-processor and send the resulting {@link Message} to a
* default destination, receive the reply and convert its body of the given
* target class.
* @param request payload for the request message to send
* @param targetClass the target type to convert the payload of the reply to
- * @param requestPostProcessor post process to apply to the request message
+ * @param requestPostProcessor post-process to apply to the request message
* @return the payload of the reply message, possibly {@code null} if the message
* could not be received, for example due to a timeout
*/
@@ -116,13 +116,13 @@ public interface MessageRequestReplyOperations {
/**
* Convert the given request Object to serialized form, possibly using a
* {@link org.springframework.messaging.converter.MessageConverter},
- * apply the given post processor and send the resulting {@link Message} to the
+ * apply the given post-processor and send the resulting {@link Message} to the
* given destination, receive the reply and convert its body of the given
* target class.
* @param destination the target destination
* @param request payload for the request message to send
* @param targetClass the target type to convert the payload of the reply to
- * @param requestPostProcessor post process to apply to the request message
+ * @param requestPostProcessor post-process to apply to the request message
* @return the payload of the reply message, possibly {@code null} if the message
* could not be received, for example due to a timeout
*/
@@ -133,13 +133,13 @@ public interface MessageRequestReplyOperations {
/**
* Convert the given request Object to serialized form, possibly using a
* {@link org.springframework.messaging.converter.MessageConverter},
- * wrap it as a message with the given headers, apply the given post processor
+ * wrap it as a message with the given headers, apply the given post-processor
* and send the resulting {@link Message} to the specified destination, receive
* the reply and convert its body of the given target class.
* @param destination the target destination
* @param request payload for the request message to send
* @param targetClass the target type to convert the payload of the reply to
- * @param requestPostProcessor post process to apply to the request message
+ * @param requestPostProcessor post-process to apply to the request message
* @return the payload of the reply message, possibly {@code null} if the message
* could not be received, for example due to a timeout
*/
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/MessageSendingOperations.java b/spring-messaging/src/main/java/org/springframework/messaging/core/MessageSendingOperations.java
index fb8a4861c77..8f0c64caa15 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/core/MessageSendingOperations.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/core/MessageSendingOperations.java
@@ -71,38 +71,38 @@ public interface MessageSendingOperations {
* @param payload the Object to use as payload
* @param headers the headers for the message to send
*/
- void convertAndSend(D destination, Object payload, Map headers) throws MessagingException;
+ void convertAndSend(D destination, Object payload, @Nullable Map headers) throws MessagingException;
/**
* Convert the given Object to serialized form, possibly using a
* {@link org.springframework.messaging.converter.MessageConverter},
- * wrap it as a message, apply the given post processor, and send
+ * wrap it as a message, apply the given post-processor, and send
* the resulting message to a default destination.
* @param payload the Object to use as payload
- * @param postProcessor the post processor to apply to the message
+ * @param postProcessor the post-processor to apply to the message
*/
void convertAndSend(Object payload, @Nullable MessagePostProcessor postProcessor) throws MessagingException;
/**
* Convert the given Object to serialized form, possibly using a
* {@link org.springframework.messaging.converter.MessageConverter},
- * wrap it as a message, apply the given post processor, and send
+ * wrap it as a message, apply the given post-processor, and send
* the resulting message to the given destination.
* @param destination the target destination
* @param payload the Object to use as payload
- * @param postProcessor the post processor to apply to the message
+ * @param postProcessor the post-processor to apply to the message
*/
- void convertAndSend(D destination, Object payload, MessagePostProcessor postProcessor) throws MessagingException;
+ void convertAndSend(D destination, Object payload, @Nullable MessagePostProcessor postProcessor) throws MessagingException;
/**
* Convert the given Object to serialized form, possibly using a
* {@link org.springframework.messaging.converter.MessageConverter},
- * wrap it as a message with the given headers, apply the given post processor,
+ * wrap it as a message with the given headers, apply the given post-processor,
* and send the resulting message to the given destination.
* @param destination the target destination
* @param payload the Object to use as payload
* @param headers the headers for the message to send
- * @param postProcessor the post processor to apply to the message
+ * @param postProcessor the post-processor to apply to the message
*/
void convertAndSend(D destination, Object payload, @Nullable Map headers,
@Nullable MessagePostProcessor postProcessor) throws MessagingException;