Skip to content

Commit

Permalink
Merge pull request #22715
Browse files Browse the repository at this point in the history
Closes gh-22715
  • Loading branch information
rstoyanchev committed Nov 8, 2019
2 parents b0b6423 + 32f82c0 commit b98d8ef
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Expand Up @@ -362,9 +362,17 @@ private void unsubscribe(String id, @Nullable StompHeaders headers) {

@Override
public void disconnect() {
disconnect(null);
}

@Override
public void disconnect(@Nullable StompHeaders headers) {
this.closing = true;
try {
StompHeaderAccessor accessor = createHeaderAccessor(StompCommand.DISCONNECT);
if (headers != null) {
accessor.addNativeHeaders(headers);
}
Message<byte[]> message = createMessage(accessor, EMPTY_PAYLOAD);
execute(message);
}
Expand Down
Expand Up @@ -116,6 +116,13 @@ public interface StompSession {
*/
void disconnect();

/**
* Variant of {@link #disconnect()} with headers.
* @param headers the headers for the disconnect message frame
* @since 5.2.2
*/
void disconnect(StompHeaders headers);


/**
* A handle to use to track receipts.
Expand Down
Expand Up @@ -659,4 +659,25 @@ public void disconnect() {
verifyNoMoreInteractions(this.sessionHandler);
}

@Test
public void disconnectWithHeaders() {
this.session.afterConnected(this.connection);
assertThat(this.session.isConnected()).isTrue();

StompHeaders headers = new StompHeaders();
headers.add("foo", "bar");

this.session.disconnect(headers);

Message<byte[]> message = this.messageCaptor.getValue();
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
headers = StompHeaders.readOnlyStompHeaders(accessor.getNativeHeaders());
assertThat(headers.size()).as(headers.toString()).isEqualTo(1);
assertThat(headers.get("foo").size()).isEqualTo(1);
assertThat(headers.get("foo").get(0)).isEqualTo("bar");

assertThat(this.session.isConnected()).isFalse();
verifyNoMoreInteractions(this.sessionHandler);
}

}

0 comments on commit b98d8ef

Please sign in to comment.