Browse Source

Merge branch '5.1.x'

pull/22705/head
Rossen Stoyanchev 6 years ago
parent
commit
0589989eb4
  1. 4
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java
  2. 7
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java
  3. 8
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java
  4. 6
      spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompHeaderAccessorTests.java
  5. 4
      spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java
  6. 6
      spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompSubProtocolHandlerTests.java

4
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -521,7 +521,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler @@ -521,7 +521,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
return;
}
if (StompCommand.CONNECT.equals(command)) {
if (StompCommand.CONNECT.equals(command) || StompCommand.STOMP.equals(command)) {
if (logger.isDebugEnabled()) {
logger.debug(stompAccessor.getShortLogMessage(EMPTY_PAYLOAD));
}

7
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -138,7 +138,8 @@ public class StompEncoder { @@ -138,7 +138,8 @@ public class StompEncoder {
return;
}
boolean shouldEscape = (command != StompCommand.CONNECT && command != StompCommand.CONNECTED);
boolean shouldEscape = (command != StompCommand.CONNECT && command != StompCommand.STOMP
&& command != StompCommand.CONNECTED);
for (Entry<String, List<String>> entry : nativeHeaders.entrySet()) {
if (command.requiresContentLength() && "content-length".equals(entry.getKey())) {
@ -146,7 +147,7 @@ public class StompEncoder { @@ -146,7 +147,7 @@ public class StompEncoder {
}
List<String> values = entry.getValue();
if (StompCommand.CONNECT.equals(command) &&
if ((StompCommand.CONNECT.equals(command) || StompCommand.STOMP.equals(command)) &&
StompHeaderAccessor.STOMP_PASSCODE_HEADER.equals(entry.getKey())) {
values = Collections.singletonList(StompHeaderAccessor.getPasscode(headers));
}

8
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -160,7 +160,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { @@ -160,7 +160,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
super.setSubscriptionId(value);
}
}
else if (StompCommand.CONNECT.equals(command)) {
else if (StompCommand.CONNECT.equals(command) || StompCommand.STOMP.equals(command)) {
protectPasscode();
}
}
@ -425,6 +425,10 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { @@ -425,6 +425,10 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
Principal user = getUser();
return "CONNECT" + (user != null ? " user=" + user.getName() : "") + appendSession();
}
else if (StompCommand.STOMP.equals(command)) {
Principal user = getUser();
return "STOMP" + (user != null ? " user=" + user.getName() : "") + appendSession();
}
else if (StompCommand.CONNECTED.equals(command)) {
return "CONNECTED heart-beat=" + Arrays.toString(getHeartbeat()) + appendSession();
}

6
spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompHeaderAccessorTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -102,9 +102,9 @@ public class StompHeaderAccessorTests { @@ -102,9 +102,9 @@ public class StompHeaderAccessorTests {
extHeaders.add(StompHeaderAccessor.STOMP_LOGIN_HEADER, "joe");
extHeaders.add(StompHeaderAccessor.STOMP_PASSCODE_HEADER, "joe123");
StompHeaderAccessor headerAccessor = StompHeaderAccessor.create(StompCommand.CONNECT, extHeaders);
StompHeaderAccessor headerAccessor = StompHeaderAccessor.create(StompCommand.STOMP, extHeaders);
assertEquals(StompCommand.CONNECT, headerAccessor.getCommand());
assertEquals(StompCommand.STOMP, headerAccessor.getCommand());
assertEquals(SimpMessageType.CONNECT, headerAccessor.getMessageType());
assertNotNull(headerAccessor.getHeader("stompCredentials"));
assertEquals("joe", headerAccessor.getLogin());

4
spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -271,7 +271,7 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE @@ -271,7 +271,7 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE
}
StompCommand command = headerAccessor.getCommand();
boolean isConnect = StompCommand.CONNECT.equals(command);
boolean isConnect = StompCommand.CONNECT.equals(command) || StompCommand.STOMP.equals(command);
if (isConnect) {
this.stats.incrementConnectCount();
}

6
spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompSubProtocolHandlerTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -289,7 +289,7 @@ public class StompSubProtocolHandlerTests { @@ -289,7 +289,7 @@ public class StompSubProtocolHandlerTests {
@Test
public void handleMessageFromClient() {
TextMessage textMessage = StompTextMessageBuilder.create(StompCommand.CONNECT).headers(
TextMessage textMessage = StompTextMessageBuilder.create(StompCommand.STOMP).headers(
"login:guest", "passcode:guest", "accept-version:1.1,1.0", "heart-beat:10000,10000").build();
this.protocolHandler.afterSessionStarted(this.session, this.channel);
@ -307,7 +307,7 @@ public class StompSubProtocolHandlerTests { @@ -307,7 +307,7 @@ public class StompSubProtocolHandlerTests {
assertArrayEquals(new long[] {10000, 10000}, SimpMessageHeaderAccessor.getHeartbeat(actual.getHeaders()));
StompHeaderAccessor stompAccessor = StompHeaderAccessor.wrap(actual);
assertEquals(StompCommand.CONNECT, stompAccessor.getCommand());
assertEquals(StompCommand.STOMP, stompAccessor.getCommand());
assertEquals("guest", stompAccessor.getLogin());
assertEquals("guest", stompAccessor.getPasscode());
assertArrayEquals(new long[] {10000, 10000}, stompAccessor.getHeartbeat());

Loading…
Cancel
Save