parent
e4ec376075
commit
dc2947c52d
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
|
|
@ -306,6 +306,12 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler {
|
|||
else if (SimpMessageType.CONNECT.equals(messageType)) {
|
||||
logMessage(message);
|
||||
if (sessionId != null) {
|
||||
if (this.sessions.get(sessionId) != null) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Ignoring CONNECT in session " + sessionId + ". Already connected.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
long[] heartbeatIn = SimpMessageHeaderAccessor.getHeartbeat(headers);
|
||||
long[] heartbeatOut = getHeartbeatValue();
|
||||
Principal user = SimpMessageHeaderAccessor.getUser(headers);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
|
|
@ -552,6 +552,12 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
|||
}
|
||||
|
||||
if (StompCommand.CONNECT.equals(command) || StompCommand.STOMP.equals(command)) {
|
||||
if (this.connectionHandlers.get(sessionId) != null) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Ignoring CONNECT in session " + sessionId + ". Already connected.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(stompAccessor.getShortLogMessage(EMPTY_PAYLOAD));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
|
|
@ -260,6 +260,30 @@ class StompBrokerRelayMessageHandlerTests {
|
|||
assertThat(captor.getValue()).isSameAs(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
void alreadyConnected() {
|
||||
|
||||
this.brokerRelay.start();
|
||||
|
||||
Message<byte[]> connect = connectMessage("sess1", "joe");
|
||||
this.brokerRelay.handleMessage(connect);
|
||||
|
||||
assertThat(this.tcpClient.getSentMessages().size()).isEqualTo(2);
|
||||
|
||||
StompHeaderAccessor headers1 = this.tcpClient.getSentHeaders(0);
|
||||
assertThat(headers1.getCommand()).isEqualTo(StompCommand.CONNECT);
|
||||
assertThat(headers1.getSessionId()).isEqualTo(StompBrokerRelayMessageHandler.SYSTEM_SESSION_ID);
|
||||
|
||||
StompHeaderAccessor headers2 = this.tcpClient.getSentHeaders(1);
|
||||
assertThat(headers2.getCommand()).isEqualTo(StompCommand.CONNECT);
|
||||
assertThat(headers2.getSessionId()).isEqualTo("sess1");
|
||||
|
||||
this.brokerRelay.handleMessage(connect);
|
||||
|
||||
assertThat(this.tcpClient.getSentMessages().size()).isEqualTo(2);
|
||||
assertThat(this.outboundChannel.getMessages()).isEmpty();
|
||||
}
|
||||
|
||||
private Message<byte[]> connectMessage(String sessionId, String user) {
|
||||
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.CONNECT);
|
||||
headers.setSessionId(sessionId);
|
||||
|
|
|
|||
Loading…
Reference in New Issue