From 9596b70b2ae00a6c5ba5494f78413d161dccec95 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 4 Jul 2025 18:20:19 +0200 Subject: [PATCH 1/2] Consistent nullability and exception declarations Closes gh-35159 --- .../jms/core/JmsMessageOperations.java | 28 ++++++----- ...DestinationResolvingMessagingTemplate.java | 47 +++++++++++-------- .../AbstractMessageReceivingTemplate.java | 28 +++++------ .../core/AbstractMessageSendingTemplate.java | 15 ++++-- .../core/AbstractMessagingTemplate.java | 35 +++++++++----- ...esolvingMessageRequestReplyOperations.java | 8 ++-- ...tionResolvingMessageSendingOperations.java | 8 ++-- .../core/MessageRequestReplyOperations.java | 12 ++--- .../core/MessageSendingOperations.java | 16 +++---- 9 files changed, 113 insertions(+), 84 deletions(-) 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; From 65e5c1424529d17441adadcbf03f1200ccdb2839 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 4 Jul 2025 18:20:27 +0200 Subject: [PATCH 2/2] Polishing --- .../jdbc/core/JdbcTemplate.java | 42 ++++++++--------- .../springframework/jms/core/JmsTemplate.java | 27 ++++------- .../destination/JmsDestinationAccessor.java | 2 +- .../support/MessageHeaderAccessor.java | 46 +++++++++---------- 4 files changed, 53 insertions(+), 64 deletions(-) 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 9293b39aff1..a35eb90b55d 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 @@ -263,7 +263,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } /** - * Set the query timeout for statements that this JdbcTemplate executes. + * Set the query timeout (seconds) for statements that this JdbcTemplate executes. *

Default is -1, indicating to use the JDBC driver's default * (i.e. to not pass a specific query timeout setting on the driver). *

Note: Any timeout specified here will be overridden by the remaining @@ -276,7 +276,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } /** - * Return the query timeout for statements that this JdbcTemplate executes. + * Return the query timeout (seconds) for statements that this JdbcTemplate executes. */ public int getQueryTimeout() { return this.queryTimeout; @@ -422,7 +422,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - public void execute(final String sql) throws DataAccessException { + public void execute(String sql) throws DataAccessException { if (logger.isDebugEnabled()) { logger.debug("Executing SQL statement [" + sql + "]"); } @@ -446,7 +446,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { @Override @Nullable - public T query(final String sql, final ResultSetExtractor rse) throws DataAccessException { + public T query(String sql, ResultSetExtractor rse) throws DataAccessException { Assert.notNull(sql, "SQL must not be null"); Assert.notNull(rse, "ResultSetExtractor must not be null"); if (logger.isDebugEnabled()) { @@ -542,7 +542,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - public int update(final String sql) throws DataAccessException { + public int update(String sql) throws DataAccessException { Assert.notNull(sql, "SQL must not be null"); if (logger.isDebugEnabled()) { logger.debug("Executing SQL update [" + sql + "]"); @@ -568,7 +568,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - public int[] batchUpdate(final String... sql) throws DataAccessException { + public int[] batchUpdate(String... sql) throws DataAccessException { Assert.notEmpty(sql, "SQL array must not be empty"); if (logger.isDebugEnabled()) { logger.debug("Executing SQL batch update of " + sql.length + " statements"); @@ -714,7 +714,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { */ @Nullable public T query( - PreparedStatementCreator psc, @Nullable final PreparedStatementSetter pss, final ResultSetExtractor rse) + PreparedStatementCreator psc, @Nullable PreparedStatementSetter pss, ResultSetExtractor rse) throws DataAccessException { Assert.notNull(rse, "ResultSetExtractor must not be null"); @@ -964,7 +964,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { return result(query(sql, args, new SqlRowSetResultSetExtractor())); } - protected int update(final PreparedStatementCreator psc, @Nullable final PreparedStatementSetter pss) + protected int update(PreparedStatementCreator psc, @Nullable PreparedStatementSetter pss) throws DataAccessException { logger.debug("Executing prepared SQL update"); @@ -994,7 +994,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - public int update(final PreparedStatementCreator psc, final KeyHolder generatedKeyHolder) + public int update(PreparedStatementCreator psc, KeyHolder generatedKeyHolder) throws DataAccessException { Assert.notNull(generatedKeyHolder, "KeyHolder must not be null"); @@ -1027,8 +1027,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - public int[] batchUpdate(final PreparedStatementCreator psc, final BatchPreparedStatementSetter pss, - final KeyHolder generatedKeyHolder) throws DataAccessException { + public int[] batchUpdate(PreparedStatementCreator psc, BatchPreparedStatementSetter pss, + KeyHolder generatedKeyHolder) throws DataAccessException { int[] result = execute(psc, getPreparedStatementCallback(pss, generatedKeyHolder)); @@ -1037,7 +1037,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - public int[] batchUpdate(String sql, final BatchPreparedStatementSetter pss) throws DataAccessException { + public int[] batchUpdate(String sql, BatchPreparedStatementSetter pss) throws DataAccessException { if (logger.isDebugEnabled()) { logger.debug("Executing SQL batch update [" + sql + "]"); } @@ -1057,7 +1057,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - public int[] batchUpdate(String sql, List batchArgs, final int[] argTypes) throws DataAccessException { + public int[] batchUpdate(String sql, List batchArgs, int[] argTypes) throws DataAccessException { if (batchArgs.isEmpty()) { return new int[0]; } @@ -1094,8 +1094,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - public int[][] batchUpdate(String sql, final Collection batchArgs, final int batchSize, - final ParameterizedPreparedStatementSetter pss) throws DataAccessException { + public int[][] batchUpdate(String sql, Collection batchArgs, int batchSize, + ParameterizedPreparedStatementSetter pss) throws DataAccessException { if (logger.isDebugEnabled()) { logger.debug("Executing SQL batch update [" + sql + "] with a batch size of " + batchSize); @@ -1209,9 +1209,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()) { @@ -1261,7 +1261,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { int rsIndex = 0; int updateIndex = 0; boolean moreResults; - if (!this.skipResultsProcessing) { + if (!isSkipResultsProcessing()) { do { if (updateCount == -1) { if (resultSetParameters != null && resultSetParameters.size() > rsIndex) { @@ -1270,7 +1270,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { rsIndex++; } else { - if (!this.skipUndeclaredResults) { + if (!isSkipUndeclaredResults()) { String rsName = RETURN_RESULT_SET_PREFIX + (rsIndex + 1); SqlReturnResultSet undeclaredRsParam = new SqlReturnResultSet(rsName, getColumnMapRowMapper()); if (logger.isTraceEnabled()) { @@ -1289,7 +1289,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { updateIndex++; } else { - if (!this.skipUndeclaredResults) { + if (!isSkipUndeclaredResults()) { String undeclaredName = RETURN_UPDATE_COUNT_PREFIX + (updateIndex + 1); if (logger.isTraceEnabled()) { logger.trace("Added default SqlReturnUpdateCount parameter named '" + undeclaredName + "'"); diff --git a/spring-jms/src/main/java/org/springframework/jms/core/JmsTemplate.java b/spring-jms/src/main/java/org/springframework/jms/core/JmsTemplate.java index 9b86454281e..6198d50be06 100644 --- a/spring-jms/src/main/java/org/springframework/jms/core/JmsTemplate.java +++ b/spring-jms/src/main/java/org/springframework/jms/core/JmsTemplate.java @@ -47,10 +47,9 @@ import org.springframework.util.ClassUtils; /** * Helper class that simplifies synchronous JMS access code. * - *

If you want to use dynamic destination creation, you must specify - * the type of JMS destination to create, using the "pubSubDomain" property. - * For other operations, this is not necessary. Point-to-Point (Queues) is the default - * domain. + *

If you want to use dynamic destination creation, you must specify the type of + * JMS destination to create, using the "pubSubDomain" property. For other operations, + * this is not necessary. Point-to-Point (Queues) is the default domain. * *

Default settings for JMS Sessions are "not transacted" and "auto-acknowledge". * As defined by the Jakarta EE specification, the transaction and acknowledgement @@ -105,7 +104,6 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations @Nullable private MessageConverter messageConverter; - private boolean messageIdEnabled = true; private boolean messageTimestampEnabled = true; @@ -116,7 +114,6 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations private long deliveryDelay = -1; - private boolean explicitQosEnabled = false; private int deliveryMode = Message.DEFAULT_DELIVERY_MODE; @@ -151,11 +148,8 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations } /** - * Initialize the default implementations for the template's strategies: - * DynamicDestinationResolver and SimpleMessageConverter. - * @see #setDestinationResolver + * Initialize the default implementations for the template's strategies. * @see #setMessageConverter - * @see org.springframework.jms.support.destination.DynamicDestinationResolver * @see org.springframework.jms.support.converter.SimpleMessageConverter */ protected void initDefaultStrategies() { @@ -262,7 +256,6 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations return converter; } - /** * Set whether message IDs are enabled. Default is "true". *

This is only a hint to the JMS producer. @@ -352,7 +345,6 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations return this.deliveryDelay; } - /** * Set if the QOS values (deliveryMode, priority, timeToLive) * should be used for sending a message. @@ -454,7 +446,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations * Set the time-to-live of the message when sending. *

Since a default value may be defined administratively, * this is only used when "isExplicitQosEnabled" equals "true". - * @param timeToLive the message's lifetime (in milliseconds) + * @param timeToLive the message lifetime (in milliseconds) * @see #isExplicitQosEnabled * @see jakarta.jms.Message#DEFAULT_TIME_TO_LIVE * @see jakarta.jms.MessageProducer#send(jakarta.jms.Message, int, int, long) @@ -472,7 +464,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations /** * Configure the {@link ObservationRegistry} to use for recording JMS observations. - * @param observationRegistry the observation registry to use. + * @param observationRegistry the observation registry to use * @since 6.1 * @see io.micrometer.jakarta9.instrument.jms.JmsInstrumentation */ @@ -480,6 +472,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations this.observationRegistry = observationRegistry; } + //--------------------------------------------------------------------------------------- // JmsOperations execute methods //--------------------------------------------------------------------------------------- @@ -699,8 +692,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations } @Override - public void convertAndSend( - Destination destination, Object message, MessagePostProcessor postProcessor) + public void convertAndSend(Destination destination, Object message, MessagePostProcessor postProcessor) throws JmsException { send(destination, session -> { @@ -710,8 +702,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations } @Override - public void convertAndSend( - String destinationName, Object message, MessagePostProcessor postProcessor) + public void convertAndSend(String destinationName, Object message, MessagePostProcessor postProcessor) throws JmsException { send(destinationName, session -> { diff --git a/spring-jms/src/main/java/org/springframework/jms/support/destination/JmsDestinationAccessor.java b/spring-jms/src/main/java/org/springframework/jms/support/destination/JmsDestinationAccessor.java index 56ffc9bf994..ff9690274fd 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/destination/JmsDestinationAccessor.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/destination/JmsDestinationAccessor.java @@ -69,7 +69,7 @@ public abstract class JmsDestinationAccessor extends JmsAccessor { * @see org.springframework.jms.support.destination.JndiDestinationResolver */ public void setDestinationResolver(DestinationResolver destinationResolver) { - Assert.notNull(destinationResolver, "'destinationResolver' must not be null"); + Assert.notNull(destinationResolver, "DestinationResolver must not be null"); this.destinationResolver = destinationResolver; } 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 65def7d4c6f..49e178d43e6 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 { @Nullable private 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) { @@ -576,10 +557,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