Java Code Examples for org.springframework.web.socket.WebSocketHandler#afterConnectionEstablished()

The following examples show how to use org.springframework.web.socket.WebSocketHandler#afterConnectionEstablished() . 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: WebSocketMessageBrokerConfigurationSupportTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void webSocketHandlerDecorator() throws Exception {
	ApplicationContext config = createConfig(WebSocketHandlerDecoratorConfig.class);
	WebSocketHandler handler = config.getBean(SubProtocolWebSocketHandler.class);
	assertNotNull(handler);

	SimpleUrlHandlerMapping mapping = (SimpleUrlHandlerMapping) config.getBean("stompWebSocketHandlerMapping");
	WebSocketHttpRequestHandler httpHandler = (WebSocketHttpRequestHandler) mapping.getHandlerMap().get("/test");
	handler = httpHandler.getWebSocketHandler();

	WebSocketSession session = new TestWebSocketSession("id");
	handler.afterConnectionEstablished(session);
	assertEquals(true, session.getAttributes().get("decorated"));
}
 
Example 2
Source File: WebSocketMessageBrokerConfigurationSupportTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void webSocketHandlerDecorator() throws Exception {
	ApplicationContext config = createConfig(WebSocketHandlerDecoratorConfig.class);
	WebSocketHandler handler = config.getBean(SubProtocolWebSocketHandler.class);
	assertNotNull(handler);

	SimpleUrlHandlerMapping mapping = (SimpleUrlHandlerMapping) config.getBean("stompWebSocketHandlerMapping");
	WebSocketHttpRequestHandler httpHandler = (WebSocketHttpRequestHandler) mapping.getHandlerMap().get("/test");
	handler = httpHandler.getWebSocketHandler();

	WebSocketSession session = new TestWebSocketSession("id");
	handler.afterConnectionEstablished(session);
	assertEquals(true, session.getAttributes().get("decorated"));
}
 
Example 3
Source File: WebSocketMessageBrokerConfigurationSupportTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void webSocketHandlerDecorator() throws Exception {
	ApplicationContext config = createConfig(WebSocketHandlerDecoratorConfig.class);
	WebSocketHandler handler = config.getBean(SubProtocolWebSocketHandler.class);
	assertNotNull(handler);

	SimpleUrlHandlerMapping mapping = (SimpleUrlHandlerMapping) config.getBean("stompWebSocketHandlerMapping");
	WebSocketHttpRequestHandler httpHandler = (WebSocketHttpRequestHandler) mapping.getHandlerMap().get("/test");
	handler = httpHandler.getWebSocketHandler();

	WebSocketSession session = new TestWebSocketSession("id");
	handler.afterConnectionEstablished(session);
	assertEquals(true, session.getAttributes().get("decorated"));
}
 
Example 4
Source File: WebSocketConnectHandlerDecoratorFactoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void decorateAfterConnectionEstablished() throws Exception {
	WebSocketHandler decorated = this.factory.decorate(this.delegate);

	decorated.afterConnectionEstablished(this.session);

	verify(this.eventPublisher).publishEvent(this.event.capture());
	assertThat(this.event.getValue().getWebSocketSession()).isSameAs(this.session);
}
 
Example 5
Source File: WebSocketConnectHandlerDecoratorFactoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void decorateAfterConnectionEstablishedEventError() throws Exception {
	WebSocketHandler decorated = this.factory.decorate(this.delegate);
	willThrow(new IllegalStateException("Test throw on publishEvent")).given(this.eventPublisher)
			.publishEvent(any(ApplicationEvent.class));

	decorated.afterConnectionEstablished(this.session);

	verify(this.eventPublisher).publishEvent(any(SessionConnectEvent.class));
}
 
Example 6
Source File: PerConnectionWebSocketHandler.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
	WebSocketHandler handler = this.provider.getHandler();
	this.handlers.put(session, handler);
	handler.afterConnectionEstablished(session);
}
 
Example 7
Source File: WebSocketStompClientTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private TcpConnection<byte[]> getTcpConnection() throws Exception {
	WebSocketHandler webSocketHandler = connect();
	webSocketHandler.afterConnectionEstablished(this.webSocketSession);
	return (TcpConnection<byte[]>) webSocketHandler;
}
 
Example 8
Source File: PerConnectionWebSocketHandler.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
	WebSocketHandler handler = this.provider.getHandler();
	this.handlers.put(session, handler);
	handler.afterConnectionEstablished(session);
}
 
Example 9
Source File: WebSocketStompClientTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private TcpConnection<byte[]> getTcpConnection() throws Exception {
	WebSocketHandler webSocketHandler = connect();
	webSocketHandler.afterConnectionEstablished(this.webSocketSession);
	return (TcpConnection<byte[]>) webSocketHandler;
}
 
Example 10
Source File: PerConnectionWebSocketHandler.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
	WebSocketHandler handler = this.provider.getHandler();
	this.handlers.put(session, handler);
	handler.afterConnectionEstablished(session);
}
 
Example 11
Source File: WebSocketStompClientTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private TcpConnection<byte[]> getTcpConnection() throws Exception {
	WebSocketHandler webSocketHandler = connect();
	webSocketHandler.afterConnectionEstablished(this.webSocketSession);
	return (TcpConnection<byte[]>) webSocketHandler;
}