Support STOMP in addition to CONNECT frame
One is literally an alias for the other with "the advantage that a protocol sniffer/discriminator will be able to differentiate the STOMP connection from an HTTP connection". Closes gh-22652
This commit is contained in:
parent
50acbae4cf
commit
1aaadb39c0
|
@ -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");
|
* 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.
|
||||||
|
@ -521,7 +521,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StompCommand.CONNECT.equals(command)) {
|
if (StompCommand.CONNECT.equals(command) || StompCommand.STOMP.equals(command)) {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(stompAccessor.getShortLogMessage(EMPTY_PAYLOAD));
|
logger.debug(stompAccessor.getShortLogMessage(EMPTY_PAYLOAD));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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");
|
* 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.
|
||||||
|
@ -138,7 +138,8 @@ public class StompEncoder {
|
||||||
return;
|
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()) {
|
for (Entry<String, List<String>> entry : nativeHeaders.entrySet()) {
|
||||||
if (command.requiresContentLength() && "content-length".equals(entry.getKey())) {
|
if (command.requiresContentLength() && "content-length".equals(entry.getKey())) {
|
||||||
|
@ -146,7 +147,7 @@ public class StompEncoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> values = entry.getValue();
|
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())) {
|
StompHeaderAccessor.STOMP_PASSCODE_HEADER.equals(entry.getKey())) {
|
||||||
values = Collections.singletonList(StompHeaderAccessor.getPasscode(headers));
|
values = Collections.singletonList(StompHeaderAccessor.getPasscode(headers));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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");
|
* 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.
|
||||||
|
@ -160,7 +160,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
|
||||||
super.setSubscriptionId(value);
|
super.setSubscriptionId(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (StompCommand.CONNECT.equals(command)) {
|
else if (StompCommand.CONNECT.equals(command) || StompCommand.STOMP.equals(command)) {
|
||||||
protectPasscode();
|
protectPasscode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -425,6 +425,10 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
|
||||||
Principal user = getUser();
|
Principal user = getUser();
|
||||||
return "CONNECT" + (user != null ? " user=" + user.getName() : "") + appendSession();
|
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)) {
|
else if (StompCommand.CONNECTED.equals(command)) {
|
||||||
return "CONNECTED heart-beat=" + Arrays.toString(getHeartbeat()) + appendSession();
|
return "CONNECTED heart-beat=" + Arrays.toString(getHeartbeat()) + appendSession();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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");
|
* 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.
|
||||||
|
@ -102,9 +102,9 @@ public class StompHeaderAccessorTests {
|
||||||
extHeaders.add(StompHeaderAccessor.STOMP_LOGIN_HEADER, "joe");
|
extHeaders.add(StompHeaderAccessor.STOMP_LOGIN_HEADER, "joe");
|
||||||
extHeaders.add(StompHeaderAccessor.STOMP_PASSCODE_HEADER, "joe123");
|
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());
|
assertEquals(SimpMessageType.CONNECT, headerAccessor.getMessageType());
|
||||||
assertNotNull(headerAccessor.getHeader("stompCredentials"));
|
assertNotNull(headerAccessor.getHeader("stompCredentials"));
|
||||||
assertEquals("joe", headerAccessor.getLogin());
|
assertEquals("joe", headerAccessor.getLogin());
|
||||||
|
|
|
@ -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");
|
* 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.
|
||||||
|
@ -271,7 +271,7 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE
|
||||||
}
|
}
|
||||||
|
|
||||||
StompCommand command = headerAccessor.getCommand();
|
StompCommand command = headerAccessor.getCommand();
|
||||||
boolean isConnect = StompCommand.CONNECT.equals(command);
|
boolean isConnect = StompCommand.CONNECT.equals(command) || StompCommand.STOMP.equals(command);
|
||||||
if (isConnect) {
|
if (isConnect) {
|
||||||
this.stats.incrementConnectCount();
|
this.stats.incrementConnectCount();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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");
|
* 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.
|
||||||
|
@ -289,7 +289,7 @@ public class StompSubProtocolHandlerTests {
|
||||||
@Test
|
@Test
|
||||||
public void handleMessageFromClient() {
|
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();
|
"login:guest", "passcode:guest", "accept-version:1.1,1.0", "heart-beat:10000,10000").build();
|
||||||
|
|
||||||
this.protocolHandler.afterSessionStarted(this.session, this.channel);
|
this.protocolHandler.afterSessionStarted(this.session, this.channel);
|
||||||
|
@ -307,7 +307,7 @@ public class StompSubProtocolHandlerTests {
|
||||||
assertArrayEquals(new long[] {10000, 10000}, SimpMessageHeaderAccessor.getHeartbeat(actual.getHeaders()));
|
assertArrayEquals(new long[] {10000, 10000}, SimpMessageHeaderAccessor.getHeartbeat(actual.getHeaders()));
|
||||||
|
|
||||||
StompHeaderAccessor stompAccessor = StompHeaderAccessor.wrap(actual);
|
StompHeaderAccessor stompAccessor = StompHeaderAccessor.wrap(actual);
|
||||||
assertEquals(StompCommand.CONNECT, stompAccessor.getCommand());
|
assertEquals(StompCommand.STOMP, stompAccessor.getCommand());
|
||||||
assertEquals("guest", stompAccessor.getLogin());
|
assertEquals("guest", stompAccessor.getLogin());
|
||||||
assertEquals("guest", stompAccessor.getPasscode());
|
assertEquals("guest", stompAccessor.getPasscode());
|
||||||
assertArrayEquals(new long[] {10000, 10000}, stompAccessor.getHeartbeat());
|
assertArrayEquals(new long[] {10000, 10000}, stompAccessor.getHeartbeat());
|
||||||
|
|
Loading…
Reference in New Issue