mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-25 16:29:28 +00:00
Merge branch '6.2.x'
# Conflicts: # spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java # spring-jms/src/main/java/org/springframework/jms/core/JmsTemplate.java # spring-messaging/src/main/java/org/springframework/messaging/core/AbstractDestinationResolvingMessagingTemplate.java # spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageReceivingTemplate.java # spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessagingTemplate.java # spring-messaging/src/main/java/org/springframework/messaging/core/MessageRequestReplyOperations.java # spring-messaging/src/main/java/org/springframework/messaging/core/MessageSendingOperations.java
This commit is contained in:
@@ -1199,9 +1199,9 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
public Map<String, Object> call(CallableStatementCreator csc, List<SqlParameter> declaredParameters)
|
||||
throws DataAccessException {
|
||||
|
||||
final List<SqlParameter> updateCountParameters = new ArrayList<>();
|
||||
final List<SqlParameter> resultSetParameters = new ArrayList<>();
|
||||
final List<SqlParameter> callParameters = new ArrayList<>();
|
||||
List<SqlParameter> updateCountParameters = new ArrayList<>();
|
||||
List<SqlParameter> resultSetParameters = new ArrayList<>();
|
||||
List<SqlParameter> callParameters = new ArrayList<>();
|
||||
|
||||
for (SqlParameter parameter : declaredParameters) {
|
||||
if (parameter.isResultsParameter()) {
|
||||
|
||||
@@ -242,7 +242,7 @@ public interface JmsMessageOperations extends MessageSendingOperations<Destinati
|
||||
* @param destinationName the name of 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
|
||||
*/
|
||||
@@ -258,7 +258,7 @@ public interface JmsMessageOperations extends MessageSendingOperations<Destinati
|
||||
* @param destinationName the name of 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
|
||||
*/
|
||||
|
||||
+1
-1
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+28
-19
@@ -21,6 +21,7 @@ import java.util.Map;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -64,69 +65,77 @@ public abstract class AbstractDestinationResolvingMessagingTemplate<D> 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 <T> void convertAndSend(String destinationName, T payload) {
|
||||
public <T> void convertAndSend(String destinationName, T payload) throws MessagingException {
|
||||
convertAndSend(destinationName, payload, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void convertAndSend(String destinationName, T payload, @Nullable Map<String, Object> headers) {
|
||||
public <T> void convertAndSend(String destinationName, T payload, @Nullable Map<String, Object> headers)
|
||||
throws MessagingException {
|
||||
|
||||
convertAndSend(destinationName, payload, headers, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void convertAndSend(String destinationName, T payload, @Nullable MessagePostProcessor postProcessor) {
|
||||
public <T> void convertAndSend(String destinationName, T payload, @Nullable MessagePostProcessor postProcessor)
|
||||
throws MessagingException {
|
||||
|
||||
convertAndSend(destinationName, payload, null, postProcessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void convertAndSend(String destinationName, T payload,
|
||||
@Nullable Map<String, Object> headers, @Nullable MessagePostProcessor postProcessor) {
|
||||
public <T> void convertAndSend(String destinationName, T payload, @Nullable Map<String, Object> 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 <T> @Nullable T receiveAndConvert(String destinationName, Class<T> targetClass) {
|
||||
public <T> @Nullable T receiveAndConvert(String destinationName, Class<T> 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 <T> @Nullable T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass) {
|
||||
public <T> @Nullable T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass)
|
||||
throws MessagingException {
|
||||
|
||||
D destination = resolveDestination(destinationName);
|
||||
return super.convertSendAndReceive(destination, request, targetClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T convertSendAndReceive(String destinationName, Object request,
|
||||
@Nullable Map<String, Object> headers, Class<T> targetClass) {
|
||||
@Nullable Map<String, Object> headers, Class<T> targetClass) throws MessagingException {
|
||||
|
||||
D destination = resolveDestination(destinationName);
|
||||
return super.convertSendAndReceive(destination, request, headers, targetClass);
|
||||
@@ -134,7 +143,7 @@ public abstract class AbstractDestinationResolvingMessagingTemplate<D> extends A
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T convertSendAndReceive(String destinationName, Object request, Class<T> 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<D> extends A
|
||||
@Override
|
||||
public <T> @Nullable T convertSendAndReceive(String destinationName, Object request,
|
||||
@Nullable Map<String, Object> headers, Class<T> targetClass,
|
||||
@Nullable MessagePostProcessor postProcessor) {
|
||||
@Nullable MessagePostProcessor postProcessor) throws MessagingException {
|
||||
|
||||
D destination = resolveDestination(destinationName);
|
||||
return super.convertSendAndReceive(destination, request, headers, targetClass, postProcessor);
|
||||
|
||||
+13
-13
@@ -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<D> extends AbstractMessag
|
||||
implements MessageReceivingOperations<D> {
|
||||
|
||||
@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 <T> @Nullable T receiveAndConvert(Class<T> targetClass) {
|
||||
public <T> @Nullable T receiveAndConvert(Class<T> targetClass) throws MessagingException {
|
||||
return receiveAndConvert(getRequiredDefaultDestination(), targetClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T receiveAndConvert(D destination, Class<T> targetClass) {
|
||||
public <T> @Nullable T receiveAndConvert(D destination, Class<T> targetClass) throws MessagingException {
|
||||
Message<?> message = doReceive(destination);
|
||||
if (message != null) {
|
||||
return doConvert(message, targetClass);
|
||||
@@ -87,4 +79,12 @@ public abstract class AbstractMessageReceivingTemplate<D> 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);
|
||||
|
||||
}
|
||||
|
||||
+8
-3
@@ -108,9 +108,6 @@ public abstract class AbstractMessageSendingTemplate<D> 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<D> 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<D> 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);
|
||||
|
||||
}
|
||||
|
||||
+8
@@ -104,6 +104,14 @@ public abstract class AbstractMessagingTemplate<D> 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);
|
||||
|
||||
}
|
||||
|
||||
+4
-4
@@ -80,13 +80,13 @@ public interface DestinationResolvingMessageRequestReplyOperations<D> 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<D> 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
|
||||
*/
|
||||
|
||||
+4
-4
@@ -69,11 +69,11 @@ public interface DestinationResolvingMessageSendingOperations<D> 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
|
||||
*/
|
||||
<T> void convertAndSend(String destinationName, T payload, @Nullable MessagePostProcessor postProcessor)
|
||||
throws MessagingException;
|
||||
@@ -82,12 +82,12 @@ public interface DestinationResolvingMessageSendingOperations<D> 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
|
||||
*/
|
||||
<T> void convertAndSend(String destinationName, T payload, @Nullable Map<String, Object> headers,
|
||||
@Nullable MessagePostProcessor postProcessor) throws MessagingException;
|
||||
|
||||
+4
-4
@@ -116,7 +116,7 @@ public interface MessageRequestReplyOperations<D> {
|
||||
* 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<D> {
|
||||
* @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<D> {
|
||||
* 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<D> {
|
||||
* @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
|
||||
*/
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ public interface MessageSendingOperations<D> {
|
||||
* @param payload the Object to use as payload
|
||||
* @param headers the headers for the message to send
|
||||
*/
|
||||
void convertAndSend(D destination, Object payload, Map<String, Object> headers) throws MessagingException;
|
||||
void convertAndSend(D destination, Object payload, @Nullable Map<String, Object> headers) throws MessagingException;
|
||||
|
||||
/**
|
||||
* Convert the given Object to serialized form, possibly using a
|
||||
|
||||
+22
-24
@@ -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<String, Object> 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 {
|
||||
* <p>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.
|
||||
* <p>By default this is set to {@code false}.
|
||||
* <p>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<String, Object> 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.
|
||||
* <p>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
|
||||
|
||||
Reference in New Issue
Block a user