diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/ProtocolConverter.java b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/ProtocolConverter.java index cee4f5c5ae..ecb38c9174 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/ProtocolConverter.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/ProtocolConverter.java @@ -737,10 +737,11 @@ public class ProtocolConverter { } protected void onStompDisconnect(StompFrame command) throws ProtocolException { - checkConnected(); - sendToActiveMQ(connectionInfo.createRemoveCommand(), createResponseHandler(command)); - sendToActiveMQ(new ShutdownInfo(), createResponseHandler(command)); - connected.set(false); + if (connected.get()) { + sendToActiveMQ(connectionInfo.createRemoveCommand(), createResponseHandler(command)); + sendToActiveMQ(new ShutdownInfo(), createResponseHandler(command)); + connected.set(false); + } } protected void checkConnected() throws ProtocolException { diff --git a/activemq-optional/src/main/java/org/apache/activemq/transport/ws/StompSocket.java b/activemq-optional/src/main/java/org/apache/activemq/transport/ws/StompSocket.java index dd0744b618..5d8a3f38f3 100644 --- a/activemq-optional/src/main/java/org/apache/activemq/transport/ws/StompSocket.java +++ b/activemq-optional/src/main/java/org/apache/activemq/transport/ws/StompSocket.java @@ -21,8 +21,10 @@ import java.security.cert.X509Certificate; import java.util.concurrent.CountDownLatch; import org.apache.activemq.command.Command; +import org.apache.activemq.command.ShutdownInfo; import org.apache.activemq.transport.TransportSupport; import org.apache.activemq.transport.stomp.ProtocolConverter; +import org.apache.activemq.transport.stomp.Stomp; import org.apache.activemq.transport.stomp.StompFrame; import org.apache.activemq.transport.stomp.StompInactivityMonitor; import org.apache.activemq.transport.stomp.StompTransport; @@ -52,6 +54,11 @@ class StompSocket extends TransportSupport implements WebSocket.OnTextMessage, S @Override public void onClose(int closeCode, String message) { + try { + protocolConverter.onStompCommand(new StompFrame(Stomp.Commands.DISCONNECT)); + } catch (Exception e) { + LOG.warn("Failed to close WebSocket", e); + } } @Override