Do match message type
SimpMessageTypeMessageCondition was lenient in matching the message type, essentially matching on any non-null message type with an exact match given a preference only in comparing mulitple matches. This commit modifies matching logic to look for an exact match. Issue: SPR-16109
This commit is contained in:
parent
a58002a5de
commit
64bc9b4311
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -74,11 +74,8 @@ public class SimpMessageTypeMessageCondition extends AbstractMessageCondition<Si
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public SimpMessageTypeMessageCondition getMatchingCondition(Message<?> message) {
|
public SimpMessageTypeMessageCondition getMatchingCondition(Message<?> message) {
|
||||||
Object actualMessageType = SimpMessageHeaderAccessor.getMessageType(message.getHeaders());
|
SimpMessageType actual = SimpMessageHeaderAccessor.getMessageType(message.getHeaders());
|
||||||
if (actualMessageType == null) {
|
return (actual != null && actual.equals(this.messageType) ? this : null);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -51,6 +51,7 @@ import org.springframework.messaging.simp.SimpAttributes;
|
||||||
import org.springframework.messaging.simp.SimpAttributesContextHolder;
|
import org.springframework.messaging.simp.SimpAttributesContextHolder;
|
||||||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
||||||
import org.springframework.messaging.simp.SimpMessageSendingOperations;
|
import org.springframework.messaging.simp.SimpMessageSendingOperations;
|
||||||
|
import org.springframework.messaging.simp.SimpMessageType;
|
||||||
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||||
import org.springframework.messaging.simp.annotation.SubscribeMapping;
|
import org.springframework.messaging.simp.annotation.SubscribeMapping;
|
||||||
import org.springframework.messaging.support.MessageBuilder;
|
import org.springframework.messaging.support.MessageBuilder;
|
||||||
|
@ -159,7 +160,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void subscribeEventDestinationVariableResolution() {
|
public void subscribeEventDestinationVariableResolution() {
|
||||||
Message<?> message = createMessage("/pre/sub/bar/value");
|
Message<?> message = createMessage(SimpMessageType.SUBSCRIBE, "/pre/sub/bar/value", null);
|
||||||
this.messageHandler.registerHandler(this.testController);
|
this.messageHandler.registerHandler(this.testController);
|
||||||
this.messageHandler.handleMessage(message);
|
this.messageHandler.handleMessage(message);
|
||||||
|
|
||||||
|
@ -328,7 +329,11 @@ public class SimpAnnotationMethodMessageHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Message<?> createMessage(String destination, Map<String, Object> headers) {
|
private Message<?> createMessage(String destination, Map<String, Object> headers) {
|
||||||
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
|
return createMessage(SimpMessageType.MESSAGE, destination, headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Message<?> createMessage(SimpMessageType messageType, String destination, Map<String, Object> headers) {
|
||||||
|
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(messageType);
|
||||||
accessor.setSessionId("session1");
|
accessor.setSessionId("session1");
|
||||||
accessor.setSessionAttributes(new HashMap<>());
|
accessor.setSessionAttributes(new HashMap<>());
|
||||||
accessor.setDestination(destination);
|
accessor.setDestination(destination);
|
||||||
|
|
Loading…
Reference in New Issue