SimpAnnotationMethodMessageHandler skips template variable check in case of no pattern
Issue: SPR-13704
This commit is contained in:
parent
9d9433a6eb
commit
e8417ea6e1
|
@ -86,8 +86,8 @@ import org.springframework.validation.Validator;
|
||||||
public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHandler<SimpMessageMappingInfo>
|
public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHandler<SimpMessageMappingInfo>
|
||||||
implements EmbeddedValueResolverAware, SmartLifecycle {
|
implements EmbeddedValueResolverAware, SmartLifecycle {
|
||||||
|
|
||||||
private static final boolean completableFuturePresent = ClassUtils.isPresent("java.util.concurrent.CompletableFuture",
|
private static final boolean completableFuturePresent = ClassUtils.isPresent(
|
||||||
SimpAnnotationMethodMessageHandler.class.getClassLoader());
|
"java.util.concurrent.CompletableFuture", SimpAnnotationMethodMessageHandler.class.getClassLoader());
|
||||||
|
|
||||||
|
|
||||||
private final SubscribableChannel clientInboundChannel;
|
private final SubscribableChannel clientInboundChannel;
|
||||||
|
@ -304,9 +304,8 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
|
||||||
|
|
||||||
|
|
||||||
protected List<HandlerMethodArgumentResolver> initArgumentResolvers() {
|
protected List<HandlerMethodArgumentResolver> initArgumentResolvers() {
|
||||||
ConfigurableBeanFactory beanFactory =
|
ConfigurableBeanFactory beanFactory = (getApplicationContext() instanceof ConfigurableApplicationContext ?
|
||||||
(ClassUtils.isAssignableValue(ConfigurableApplicationContext.class, getApplicationContext())) ?
|
((ConfigurableApplicationContext) getApplicationContext()).getBeanFactory() : null);
|
||||||
((ConfigurableApplicationContext) getApplicationContext()).getBeanFactory() : null;
|
|
||||||
|
|
||||||
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<HandlerMethodArgumentResolver>();
|
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<HandlerMethodArgumentResolver>();
|
||||||
|
|
||||||
|
@ -327,7 +326,6 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<? extends HandlerMethodReturnValueHandler> initReturnValueHandlers() {
|
protected List<? extends HandlerMethodReturnValueHandler> initReturnValueHandlers() {
|
||||||
|
|
||||||
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<HandlerMethodReturnValueHandler>();
|
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<HandlerMethodReturnValueHandler>();
|
||||||
|
|
||||||
// Single-purpose return value types
|
// Single-purpose return value types
|
||||||
|
@ -337,11 +335,13 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
|
||||||
}
|
}
|
||||||
|
|
||||||
// Annotation-based return value types
|
// Annotation-based return value types
|
||||||
SendToMethodReturnValueHandler sth = new SendToMethodReturnValueHandler(this.brokerTemplate, true);
|
SendToMethodReturnValueHandler sth =
|
||||||
|
new SendToMethodReturnValueHandler(this.brokerTemplate, true);
|
||||||
sth.setHeaderInitializer(this.headerInitializer);
|
sth.setHeaderInitializer(this.headerInitializer);
|
||||||
handlers.add(sth);
|
handlers.add(sth);
|
||||||
|
|
||||||
SubscriptionMethodReturnValueHandler sh = new SubscriptionMethodReturnValueHandler(this.clientMessagingTemplate);
|
SubscriptionMethodReturnValueHandler sh =
|
||||||
|
new SubscriptionMethodReturnValueHandler(this.clientMessagingTemplate);
|
||||||
sh.setHeaderInitializer(this.headerInitializer);
|
sh.setHeaderInitializer(this.headerInitializer);
|
||||||
handlers.add(sh);
|
handlers.add(sh);
|
||||||
|
|
||||||
|
@ -468,13 +468,15 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
|
||||||
protected void handleMatch(SimpMessageMappingInfo mapping, HandlerMethod handlerMethod,
|
protected void handleMatch(SimpMessageMappingInfo mapping, HandlerMethod handlerMethod,
|
||||||
String lookupDestination, Message<?> message) {
|
String lookupDestination, Message<?> message) {
|
||||||
|
|
||||||
String matchedPattern = mapping.getDestinationConditions().getPatterns().iterator().next();
|
Set<String> patterns = mapping.getDestinationConditions().getPatterns();
|
||||||
Map<String, String> vars = getPathMatcher().extractUriTemplateVariables(matchedPattern, lookupDestination);
|
if (!CollectionUtils.isEmpty(patterns)) {
|
||||||
|
String pattern = patterns.iterator().next();
|
||||||
if (!CollectionUtils.isEmpty(vars)) {
|
Map<String, String> vars = getPathMatcher().extractUriTemplateVariables(pattern, lookupDestination);
|
||||||
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class);
|
if (!CollectionUtils.isEmpty(vars)) {
|
||||||
Assert.state(accessor != null && accessor.isMutable());
|
MessageHeaderAccessor mha = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class);
|
||||||
accessor.setHeader(DestinationVariableMethodArgumentResolver.DESTINATION_TEMPLATE_VARIABLES_HEADER, vars);
|
Assert.state(mha != null && mha.isMutable());
|
||||||
|
mha.setHeader(DestinationVariableMethodArgumentResolver.DESTINATION_TEMPLATE_VARIABLES_HEADER, vars);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -319,7 +319,8 @@ public class MessageHeaderAccessor {
|
||||||
|
|
||||||
protected void verifyType(String headerName, Object headerValue) {
|
protected void verifyType(String headerName, Object headerValue) {
|
||||||
if (headerName != null && headerValue != null) {
|
if (headerName != null && headerValue != null) {
|
||||||
if (MessageHeaders.ERROR_CHANNEL.equals(headerName) || MessageHeaders.REPLY_CHANNEL.endsWith(headerName)) {
|
if (MessageHeaders.ERROR_CHANNEL.equals(headerName) ||
|
||||||
|
MessageHeaders.REPLY_CHANNEL.endsWith(headerName)) {
|
||||||
if (!(headerValue instanceof MessageChannel || headerValue instanceof String)) {
|
if (!(headerValue instanceof MessageChannel || headerValue instanceof String)) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"'" + headerName + "' header value must be a MessageChannel or String");
|
"'" + headerName + "' header value must be a MessageChannel or String");
|
||||||
|
@ -572,11 +573,13 @@ public class MessageHeaderAccessor {
|
||||||
* A variation of {@link #getAccessor(org.springframework.messaging.Message, Class)}
|
* A variation of {@link #getAccessor(org.springframework.messaging.Message, Class)}
|
||||||
* with a {@code MessageHeaders} instance instead of a {@code Message}.
|
* with a {@code MessageHeaders} instance instead of a {@code Message}.
|
||||||
* <p>This is for cases when a full message may not have been created yet.
|
* <p>This is for cases when a full message may not have been created yet.
|
||||||
* @return an accessor instance of the specified typem or {@code null} if none
|
* @return an accessor instance of the specified type, or {@code null} if none
|
||||||
* @since 4.1
|
* @since 4.1
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T extends MessageHeaderAccessor> T getAccessor(MessageHeaders messageHeaders, Class<T> requiredType) {
|
public static <T extends MessageHeaderAccessor> T getAccessor(
|
||||||
|
MessageHeaders messageHeaders, Class<T> requiredType) {
|
||||||
|
|
||||||
if (messageHeaders instanceof MutableMessageHeaders) {
|
if (messageHeaders instanceof MutableMessageHeaders) {
|
||||||
MutableMessageHeaders mutableHeaders = (MutableMessageHeaders) messageHeaders;
|
MutableMessageHeaders mutableHeaders = (MutableMessageHeaders) messageHeaders;
|
||||||
MessageHeaderAccessor headerAccessor = mutableHeaders.getMessageHeaderAccessor();
|
MessageHeaderAccessor headerAccessor = mutableHeaders.getMessageHeaderAccessor();
|
||||||
|
@ -593,7 +596,7 @@ public class MessageHeaderAccessor {
|
||||||
* wrapping the message with a {@code MessageHeaderAccessor} instance.
|
* wrapping the message with a {@code MessageHeaderAccessor} instance.
|
||||||
* <p>This is for cases where a header needs to be updated in generic code
|
* <p>This is for cases where a header needs to be updated in generic code
|
||||||
* while preserving the accessor type for downstream processing.
|
* while preserving the accessor type for downstream processing.
|
||||||
* @return an accessor of the required type, never {@code null}.
|
* @return an accessor of the required type (never {@code null})
|
||||||
* @since 4.1
|
* @since 4.1
|
||||||
*/
|
*/
|
||||||
public static MessageHeaderAccessor getMutableAccessor(Message<?> message) {
|
public static MessageHeaderAccessor getMutableAccessor(Message<?> message) {
|
||||||
|
@ -646,7 +649,6 @@ public class MessageHeaderAccessor {
|
||||||
if (getId() == null) {
|
if (getId() == null) {
|
||||||
IdGenerator idGenerator = (MessageHeaderAccessor.this.idGenerator != null ?
|
IdGenerator idGenerator = (MessageHeaderAccessor.this.idGenerator != null ?
|
||||||
MessageHeaderAccessor.this.idGenerator : MessageHeaders.getIdGenerator());
|
MessageHeaderAccessor.this.idGenerator : MessageHeaders.getIdGenerator());
|
||||||
|
|
||||||
UUID id = idGenerator.generateId();
|
UUID id = idGenerator.generateId();
|
||||||
if (id != null && id != MessageHeaders.ID_VALUE_NONE) {
|
if (id != null && id != MessageHeaders.ID_VALUE_NONE) {
|
||||||
getRawHeaders().put(ID, id);
|
getRawHeaders().put(ID, id);
|
||||||
|
|
Loading…
Reference in New Issue