org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession Java Examples

The following examples show how to use org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession. 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: SockJsWebSocketHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void getSubProtocolsNone() throws Exception {
	WebSocketHandler handler = new TextWebSocketHandler();
	TaskScheduler scheduler = mock(TaskScheduler.class);
	DefaultSockJsService service = new DefaultSockJsService(scheduler);
	WebSocketServerSockJsSession session = new WebSocketServerSockJsSession("1", service, handler, null);
	SockJsWebSocketHandler sockJsHandler = new SockJsWebSocketHandler(service, handler, session);

	assertNull(sockJsHandler.getSubProtocols());
}
 
Example #2
Source File: SockJsWebSocketHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void getSubProtocols() throws Exception {
	SubscribableChannel channel = mock(SubscribableChannel.class);
	SubProtocolWebSocketHandler handler = new SubProtocolWebSocketHandler(channel, channel);
	StompSubProtocolHandler stompHandler = new StompSubProtocolHandler();
	handler.addProtocolHandler(stompHandler);

	TaskScheduler scheduler = mock(TaskScheduler.class);
	DefaultSockJsService service = new DefaultSockJsService(scheduler);
	WebSocketServerSockJsSession session = new WebSocketServerSockJsSession("1", service, handler, null);
	SockJsWebSocketHandler sockJsHandler = new SockJsWebSocketHandler(service, handler, session);

	assertEquals(stompHandler.getSupportedProtocols(), sockJsHandler.getSubProtocols());
}
 
Example #3
Source File: WebSocketTransportHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void handleRequest(ServerHttpRequest request, ServerHttpResponse response,
		WebSocketHandler wsHandler, SockJsSession wsSession) throws SockJsException {

	WebSocketServerSockJsSession sockJsSession = (WebSocketServerSockJsSession) wsSession;
	try {
		wsHandler = new SockJsWebSocketHandler(getServiceConfig(), wsHandler, sockJsSession);
		this.handshakeHandler.doHandshake(request, response, wsHandler, sockJsSession.getAttributes());
	}
	catch (Throwable ex) {
		sockJsSession.tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR);
		throw new SockJsTransportFailureException("WebSocket handshake failure", wsSession.getId(), ex);
	}
}
 
Example #4
Source File: SockJsWebSocketHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void getSubProtocols() throws Exception {
	SubscribableChannel channel = mock(SubscribableChannel.class);
	SubProtocolWebSocketHandler handler = new SubProtocolWebSocketHandler(channel, channel);
	StompSubProtocolHandler stompHandler = new StompSubProtocolHandler();
	handler.addProtocolHandler(stompHandler);

	TaskScheduler scheduler = mock(TaskScheduler.class);
	DefaultSockJsService service = new DefaultSockJsService(scheduler);
	WebSocketServerSockJsSession session = new WebSocketServerSockJsSession("1", service, handler, null);
	SockJsWebSocketHandler sockJsHandler = new SockJsWebSocketHandler(service, handler, session);

	assertEquals(stompHandler.getSupportedProtocols(), sockJsHandler.getSubProtocols());
}
 
Example #5
Source File: SockJsWebSocketHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void getSubProtocolsNone() throws Exception {
	WebSocketHandler handler = new TextWebSocketHandler();
	TaskScheduler scheduler = mock(TaskScheduler.class);
	DefaultSockJsService service = new DefaultSockJsService(scheduler);
	WebSocketServerSockJsSession session = new WebSocketServerSockJsSession("1", service, handler, null);
	SockJsWebSocketHandler sockJsHandler = new SockJsWebSocketHandler(service, handler, session);

	assertEquals(Collections.emptyList(), sockJsHandler.getSubProtocols());
}
 
Example #6
Source File: SockJsWebSocketHandler.java    From java-technology-stack with MIT License 5 votes vote down vote up
public SockJsWebSocketHandler(SockJsServiceConfig serviceConfig, WebSocketHandler webSocketHandler,
		WebSocketServerSockJsSession sockJsSession) {

	Assert.notNull(serviceConfig, "serviceConfig must not be null");
	Assert.notNull(webSocketHandler, "webSocketHandler must not be null");
	Assert.notNull(sockJsSession, "session must not be null");

	this.sockJsServiceConfig = serviceConfig;
	this.sockJsSession = sockJsSession;

	webSocketHandler = WebSocketHandlerDecorator.unwrap(webSocketHandler);
	this.subProtocols = ((webSocketHandler instanceof SubProtocolCapable) ?
			new ArrayList<>(((SubProtocolCapable) webSocketHandler).getSubProtocols()) : Collections.emptyList());
}
 
Example #7
Source File: WebSocketTransportHandler.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(ServerHttpRequest request, ServerHttpResponse response,
		WebSocketHandler wsHandler, SockJsSession wsSession) throws SockJsException {

	WebSocketServerSockJsSession sockJsSession = (WebSocketServerSockJsSession) wsSession;
	try {
		wsHandler = new SockJsWebSocketHandler(getServiceConfig(), wsHandler, sockJsSession);
		this.handshakeHandler.doHandshake(request, response, wsHandler, sockJsSession.getAttributes());
	}
	catch (Throwable ex) {
		sockJsSession.tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR);
		throw new SockJsTransportFailureException("WebSocket handshake failure", wsSession.getId(), ex);
	}
}
 
Example #8
Source File: SockJsWebSocketHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public SockJsWebSocketHandler(SockJsServiceConfig serviceConfig, WebSocketHandler webSocketHandler,
		WebSocketServerSockJsSession sockJsSession) {

	Assert.notNull(serviceConfig, "serviceConfig must not be null");
	Assert.notNull(webSocketHandler, "webSocketHandler must not be null");
	Assert.notNull(sockJsSession, "session must not be null");

	this.sockJsServiceConfig = serviceConfig;
	this.sockJsSession = sockJsSession;

	webSocketHandler = WebSocketHandlerDecorator.unwrap(webSocketHandler);
	this.subProtocols = ((webSocketHandler instanceof SubProtocolCapable) ?
			new ArrayList<>(((SubProtocolCapable) webSocketHandler).getSubProtocols()) : Collections.emptyList());
}
 
Example #9
Source File: WebSocketTransportHandler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void handleRequest(ServerHttpRequest request, ServerHttpResponse response,
		WebSocketHandler wsHandler, SockJsSession wsSession) throws SockJsException {

	WebSocketServerSockJsSession sockJsSession = (WebSocketServerSockJsSession) wsSession;
	try {
		wsHandler = new SockJsWebSocketHandler(getServiceConfig(), wsHandler, sockJsSession);
		this.handshakeHandler.doHandshake(request, response, wsHandler, sockJsSession.getAttributes());
	}
	catch (Throwable ex) {
		sockJsSession.tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR);
		throw new SockJsTransportFailureException("WebSocket handshake failure", wsSession.getId(), ex);
	}
}
 
Example #10
Source File: SockJsWebSocketHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void getSubProtocols() throws Exception {
	SubscribableChannel channel = mock(SubscribableChannel.class);
	SubProtocolWebSocketHandler handler = new SubProtocolWebSocketHandler(channel, channel);
	StompSubProtocolHandler stompHandler = new StompSubProtocolHandler();
	handler.addProtocolHandler(stompHandler);

	TaskScheduler scheduler = mock(TaskScheduler.class);
	DefaultSockJsService service = new DefaultSockJsService(scheduler);
	WebSocketServerSockJsSession session = new WebSocketServerSockJsSession("1", service, handler, null);
	SockJsWebSocketHandler sockJsHandler = new SockJsWebSocketHandler(service, handler, session);

	assertEquals(stompHandler.getSupportedProtocols(), sockJsHandler.getSubProtocols());
}
 
Example #11
Source File: SockJsWebSocketHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void getSubProtocolsNone() throws Exception {
	WebSocketHandler handler = new TextWebSocketHandler();
	TaskScheduler scheduler = mock(TaskScheduler.class);
	DefaultSockJsService service = new DefaultSockJsService(scheduler);
	WebSocketServerSockJsSession session = new WebSocketServerSockJsSession("1", service, handler, null);
	SockJsWebSocketHandler sockJsHandler = new SockJsWebSocketHandler(service, handler, session);

	assertEquals(Collections.emptyList(), sockJsHandler.getSubProtocols());
}
 
Example #12
Source File: SockJsWebSocketHandler.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public SockJsWebSocketHandler(SockJsServiceConfig serviceConfig, WebSocketHandler webSocketHandler,
		WebSocketServerSockJsSession sockJsSession) {

	Assert.notNull(serviceConfig, "serviceConfig must not be null");
	Assert.notNull(webSocketHandler, "webSocketHandler must not be null");
	Assert.notNull(sockJsSession, "session must not be null");

	this.sockJsServiceConfig = serviceConfig;
	this.sockJsSession = sockJsSession;

	webSocketHandler = WebSocketHandlerDecorator.unwrap(webSocketHandler);
	this.subProtocols = ((webSocketHandler instanceof SubProtocolCapable) ?
			new ArrayList<String>(((SubProtocolCapable) webSocketHandler).getSubProtocols()) : null);
}
 
Example #13
Source File: WebSocketTransportHandler.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public AbstractSockJsSession createSession(String id, WebSocketHandler handler, Map<String, Object> attrs) {
	return new WebSocketServerSockJsSession(id, getServiceConfig(), handler, attrs);
}
 
Example #14
Source File: WebSocketTransportHandler.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public AbstractSockJsSession createSession(String id, WebSocketHandler handler, Map<String, Object> attrs) {
	return new WebSocketServerSockJsSession(id, getServiceConfig(), handler, attrs);
}
 
Example #15
Source File: WebSocketTransportHandler.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public boolean checkSessionType(SockJsSession session) {
	return session instanceof WebSocketServerSockJsSession;
}
 
Example #16
Source File: WebSocketTransportHandler.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public AbstractSockJsSession createSession(String id, WebSocketHandler handler, Map<String, Object> attrs) {
	return new WebSocketServerSockJsSession(id, getServiceConfig(), handler, attrs);
}
 
Example #17
Source File: WebSocketTransportHandler.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public boolean checkSessionType(SockJsSession session) {
	return session instanceof WebSocketServerSockJsSession;
}