diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java index a111549fbed..1b3e14d3686 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java @@ -1199,9 +1199,9 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { public Map call(CallableStatementCreator csc, List declaredParameters) throws DataAccessException { - final List updateCountParameters = new ArrayList<>(); - final List resultSetParameters = new ArrayList<>(); - final List callParameters = new ArrayList<>(); + List updateCountParameters = new ArrayList<>(); + List resultSetParameters = new ArrayList<>(); + List callParameters = new ArrayList<>(); for (SqlParameter parameter : declaredParameters) { if (parameter.isResultsParameter()) { 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 44b8ae2fc76..560e9c7cc0f 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 @@ -242,7 +242,7 @@ 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); } @Override - public @Nullable Message receive(String destinationName) { + public @Nullable Message receive(String destinationName) throws MessagingException { D destination = resolveDestination(destinationName); return super.receive(destination); } @Override - public @Nullable T receiveAndConvert(String destinationName, Class targetClass) { + public @Nullable T receiveAndConvert(String destinationName, Class targetClass) throws MessagingException { D destination = resolveDestination(destinationName); return super.receiveAndConvert(destination, targetClass); } @Override - public @Nullable Message sendAndReceive(String destinationName, Message requestMessage) { + public @Nullable Message sendAndReceive(String destinationName, Message requestMessage) + throws MessagingException { + D destination = resolveDestination(destinationName); return super.sendAndReceive(destination, requestMessage); } @Override - public @Nullable T convertSendAndReceive(String destinationName, Object request, Class targetClass) { + public @Nullable T convertSendAndReceive(String destinationName, Object request, Class targetClass) + throws MessagingException { + D destination = resolveDestination(destinationName); return super.convertSendAndReceive(destination, request, targetClass); } @Override public @Nullable 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); @@ -134,7 +143,7 @@ public abstract class AbstractDestinationResolvingMessagingTemplate extends A @Override public @Nullable 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); @@ -143,7 +152,7 @@ public abstract class AbstractDestinationResolvingMessagingTemplate extends A @Override public @Nullable 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 1167094a4b1..c4f002435ef 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 @@ -19,6 +19,7 @@ package org.springframework.messaging.core; import org.jspecify.annotations.Nullable; import org.springframework.messaging.Message; +import org.springframework.messaging.MessagingException; import org.springframework.messaging.converter.MessageConversionException; import org.springframework.messaging.converter.MessageConverter; @@ -36,31 +37,22 @@ public abstract class AbstractMessageReceivingTemplate extends AbstractMessag implements MessageReceivingOperations { @Override - public @Nullable Message receive() { + public @Nullable Message receive() throws MessagingException { return doReceive(getRequiredDefaultDestination()); } @Override - public @Nullable Message receive(D destination) { + public @Nullable 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 - */ - protected abstract @Nullable Message doReceive(D destination); - - @Override - public @Nullable T receiveAndConvert(Class targetClass) { + public @Nullable T receiveAndConvert(Class targetClass) throws MessagingException { return receiveAndConvert(getRequiredDefaultDestination(), targetClass); } @Override - public @Nullable T receiveAndConvert(D destination, Class targetClass) { + public @Nullable T receiveAndConvert(D destination, Class targetClass) throws MessagingException { Message message = doReceive(destination); if (message != null) { return doConvert(message, targetClass); @@ -87,4 +79,12 @@ 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 + */ + protected abstract @Nullable 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 544157bb8d6..4ebf412e695 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 @@ -108,9 +108,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, null); @@ -162,6 +159,7 @@ 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 @@ -209,4 +207,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 1eec77c623f..1f8b1a69520 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 @@ -104,6 +104,14 @@ public abstract class AbstractMessagingTemplate extends AbstractMessageReceiv } + /** + * 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 + */ protected abstract @Nullable 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 adf81d50476..0fcb2772d20 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 @@ -80,13 +80,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 */ @@ -97,14 +97,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 296d35e3f6b..0627dc78945 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 @@ -69,11 +69,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; @@ -82,12 +82,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 3fec2cce1a3..975fbca0546 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 @@ -116,7 +116,7 @@ public interface MessageRequestReplyOperations { * 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 */ @@ -133,7 +133,7 @@ public interface MessageRequestReplyOperations { * @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 */ @@ -148,7 +148,7 @@ public interface MessageRequestReplyOperations { * 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 * @since 7.0 @@ -166,7 +166,7 @@ public interface MessageRequestReplyOperations { * @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 65ce8e47ab9..59364f92d1d 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 @@ -83,7 +83,7 @@ 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 diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java b/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java index 9eed3cc28af..049dd16b0c5 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java @@ -123,10 +123,6 @@ public class MessageHeaderAccessor { private @Nullable IdGenerator idGenerator; - private MessageHeaderAccessor(@Nullable MessageHeaders headers) { - this.headers = new MutableMessageHeaders(headers); - } - /** * A constructor to create new headers. @@ -143,23 +139,8 @@ public class MessageHeaderAccessor { this(message != null ? message.getHeaders() : null); } - - /** - * Create an instance from a plain {@link Map}. - * @param map the raw headers - * @since 6.2 - */ - public static MessageHeaderAccessor fromMap(@Nullable Map map) { - return fromMessageHeaders(new MessageHeaders(map)); - } - - /** - * Create an instance from an existing {@link MessageHeaders} instance. - * @param headers the headers - * @since 6.2 - */ - public static MessageHeaderAccessor fromMessageHeaders(@Nullable MessageHeaders headers) { - return new MessageHeaderAccessor(headers); + private MessageHeaderAccessor(@Nullable MessageHeaders headers) { + this.headers = new MutableMessageHeaders(headers); } @@ -187,7 +168,7 @@ public class MessageHeaderAccessor { *

When modifications are complete use {@link #setImmutable()} to prevent * further changes. The intended use case for this mechanism is initialization * of a Message within a single thread. - *

By default this is set to {@code false}. + *

By default, this is set to {@code false}. * @since 4.1 */ public void setLeaveMutable(boolean leaveMutable) { @@ -570,10 +551,27 @@ public class MessageHeaderAccessor { // Static factory methods + /** + * Create an instance from a plain {@link Map}. + * @param map the raw headers + * @since 6.2 + */ + public static MessageHeaderAccessor fromMap(@Nullable Map map) { + return fromMessageHeaders(new MessageHeaders(map)); + } + + /** + * Create an instance from an existing {@link MessageHeaders} instance. + * @param headers the headers + * @since 6.2 + */ + public static MessageHeaderAccessor fromMessageHeaders(@Nullable MessageHeaders headers) { + return new MessageHeaderAccessor(headers); + } + /** * Return the original {@code MessageHeaderAccessor} used to create the headers - * of the given {@code Message}, or {@code null} if that's not available or if - * its type does not match the required type. + * of the given {@code Message}, or {@code null} if that's not available. *

This is for cases where the existence of an accessor is strongly expected * (followed up with an assertion) or where an accessor will be created otherwise. * @param message the message to get an accessor for