Java Code Examples for org.springframework.web.socket.CloseStatus#NORMAL

The following examples show how to use org.springframework.web.socket.CloseStatus#NORMAL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebSocketProxyServerHandlerTest.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void givenValidSession_whenTheConnectionIsClosed_thenTheSessionIsClosedAndRemovedFromRepository() throws Exception {
    CloseStatus normalClose = CloseStatus.NORMAL;
    WebSocketSession establishedSession = mock(WebSocketSession.class);
    String validSessionId = "123";
    when(establishedSession.getId()).thenReturn(validSessionId);
    routedSessions.put(validSessionId, mock(WebSocketRoutedSession.class));

    underTest.afterConnectionClosed(establishedSession, normalClose);

    verify(establishedSession).close(normalClose);
    assertThat(routedSessions.entrySet(), hasSize(0));
}
 
Example 2
Source File: MetricWsHandler.java    From artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void afterConnectionClosed(final WebSocketSession session, final CloseStatus closeStatus) throws Exception {
    remove(session);
    if (closeStatus != CloseStatus.NORMAL) {
        _logger.warn("closed:" + closeStatus);
    }
    MetricLoggerHelper.logWebSocketEvent("closed", name(), InetSocketAddressHelper.getRemoteIP(session));
}
 
Example 3
Source File: WebSocketRegistryListenerTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup() {
	MockitoAnnotations.initMocks(this);
	String sessionId = "session-id";
	MapSession session = new MapSession(sessionId);

	this.attributes = new HashMap<>();
	SessionRepositoryMessageInterceptor.setSessionId(this.attributes, sessionId);

	given(this.wsSession.getAttributes()).willReturn(this.attributes);
	given(this.wsSession.getPrincipal()).willReturn(this.principal);
	given(this.wsSession.getId()).willReturn("wsSession-id");

	given(this.wsSession2.getAttributes()).willReturn(this.attributes);
	given(this.wsSession2.getPrincipal()).willReturn(this.principal);
	given(this.wsSession2.getId()).willReturn("wsSession-id2");

	Map<String, Object> headers = new HashMap<>();
	headers.put(SimpMessageHeaderAccessor.SESSION_ATTRIBUTES, this.attributes);
	given(this.message.getHeaders()).willReturn(new MessageHeaders(headers));

	this.listener = new WebSocketRegistryListener();
	this.connect = new SessionConnectEvent(this.listener, this.wsSession);
	this.connect2 = new SessionConnectEvent(this.listener, this.wsSession2);
	this.disconnect = new SessionDisconnectEvent(this.listener, this.message, this.wsSession.getId(),
			CloseStatus.NORMAL);
	this.deleted = new SessionDeletedEvent(this.listener, session);
	this.expired = new SessionExpiredEvent(this.listener, session);
}
 
Example 4
Source File: ExceptionWebSocketHandlerDecoratorTests.java    From spring-analysis-note with MIT License 3 votes vote down vote up
@Test
public void afterConnectionClosed() throws Exception {

	CloseStatus closeStatus = CloseStatus.NORMAL;

	willThrow(new IllegalStateException("error"))
		.given(this.delegate).afterConnectionClosed(this.session, closeStatus);

	this.decorator.afterConnectionClosed(this.session, closeStatus);

	assertNull(this.session.getCloseStatus());
}
 
Example 5
Source File: ExceptionWebSocketHandlerDecoratorTests.java    From java-technology-stack with MIT License 3 votes vote down vote up
@Test
public void afterConnectionClosed() throws Exception {

	CloseStatus closeStatus = CloseStatus.NORMAL;

	willThrow(new IllegalStateException("error"))
		.given(this.delegate).afterConnectionClosed(this.session, closeStatus);

	this.decorator.afterConnectionClosed(this.session, closeStatus);

	assertNull(this.session.getCloseStatus());
}
 
Example 6
Source File: ExceptionWebSocketHandlerDecoratorTests.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
@Test
public void afterConnectionClosed() throws Exception {

	CloseStatus closeStatus = CloseStatus.NORMAL;

	willThrow(new IllegalStateException("error"))
		.given(this.delegate).afterConnectionClosed(this.session, closeStatus);

	this.decorator.afterConnectionClosed(this.session, closeStatus);

	assertNull(this.session.getCloseStatus());
}