org.springframework.web.socket.handler.WebSocketHandlerDecorator Java Examples
The following examples show how to use
org.springframework.web.socket.handler.WebSocketHandlerDecorator.
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: WebSocketConnectionManagerTests.java From java-technology-stack with MIT License | 7 votes |
@Test public void openConnection() throws Exception { List<String> subprotocols = Arrays.asList("abc"); TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(false); WebSocketHandler handler = new TextWebSocketHandler(); WebSocketConnectionManager manager = new WebSocketConnectionManager(client, handler , "/path/{id}", "123"); manager.setSubProtocols(subprotocols); manager.openConnection(); WebSocketHttpHeaders expectedHeaders = new WebSocketHttpHeaders(); expectedHeaders.setSecWebSocketProtocol(subprotocols); assertEquals(expectedHeaders, client.headers); assertEquals(new URI("/path/123"), client.uri); WebSocketHandlerDecorator loggingHandler = (WebSocketHandlerDecorator) client.webSocketHandler; assertEquals(LoggingWebSocketHandlerDecorator.class, loggingHandler.getClass()); assertSame(handler, loggingHandler.getDelegate()); }
Example #2
Source File: WebSocketConnectionManagerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void openConnection() throws Exception { List<String> subprotocols = Arrays.asList("abc"); TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(false); WebSocketHandler handler = new TextWebSocketHandler(); WebSocketConnectionManager manager = new WebSocketConnectionManager(client, handler , "/path/{id}", "123"); manager.setSubProtocols(subprotocols); manager.openConnection(); WebSocketHttpHeaders expectedHeaders = new WebSocketHttpHeaders(); expectedHeaders.setSecWebSocketProtocol(subprotocols); assertEquals(expectedHeaders, client.headers); assertEquals(new URI("/path/123"), client.uri); WebSocketHandlerDecorator loggingHandler = (WebSocketHandlerDecorator) client.webSocketHandler; assertEquals(LoggingWebSocketHandlerDecorator.class, loggingHandler.getClass()); assertSame(handler, loggingHandler.getDelegate()); }
Example #3
Source File: WebSocketConnectionManagerTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void openConnection() throws Exception { List<String> subprotocols = Arrays.asList("abc"); TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(false); WebSocketHandler handler = new TextWebSocketHandler(); WebSocketConnectionManager manager = new WebSocketConnectionManager(client, handler , "/path/{id}", "123"); manager.setSubProtocols(subprotocols); manager.openConnection(); WebSocketHttpHeaders expectedHeaders = new WebSocketHttpHeaders(); expectedHeaders.setSecWebSocketProtocol(subprotocols); assertEquals(expectedHeaders, client.headers); assertEquals(new URI("/path/123"), client.uri); WebSocketHandlerDecorator loggingHandler = (WebSocketHandlerDecorator) client.webSocketHandler; assertEquals(LoggingWebSocketHandlerDecorator.class, loggingHandler.getClass()); assertSame(handler, loggingHandler.getDelegate()); }
Example #4
Source File: SockJsWebSocketHandler.java From spring-analysis-note with MIT License | 5 votes |
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 #5
Source File: WebSocketMessageBrokerConfigurationSupportTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override protected void configureWebSocketTransport(WebSocketTransportRegistration registry) { registry.addDecoratorFactory(new WebSocketHandlerDecoratorFactory() { @Override public WebSocketHandlerDecorator decorate(WebSocketHandler handler) { return new WebSocketHandlerDecorator(handler) { @Override public void afterConnectionEstablished(WebSocketSession session) throws Exception { session.getAttributes().put("decorated", true); super.afterConnectionEstablished(session); } }; } }); }
Example #6
Source File: SockJsWebSocketHandler.java From spring4-understanding with Apache License 2.0 | 5 votes |
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 #7
Source File: AbstractHandshakeHandler.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Determine the sub-protocols supported by the given WebSocketHandler by * checking whether it is an instance of {@link SubProtocolCapable}. * @param handler the handler to check * @return a list of supported protocols, or an empty list if none available */ protected final List<String> determineHandlerSupportedProtocols(WebSocketHandler handler) { WebSocketHandler handlerToCheck = WebSocketHandlerDecorator.unwrap(handler); List<String> subProtocols = null; if (handlerToCheck instanceof SubProtocolCapable) { subProtocols = ((SubProtocolCapable) handlerToCheck).getSubProtocols(); } return (subProtocols != null ? subProtocols : Collections.<String>emptyList()); }
Example #8
Source File: WebSocketMessageBrokerConfigurationSupportTests.java From java-technology-stack with MIT License | 5 votes |
@Override protected void configureWebSocketTransport(WebSocketTransportRegistration registry) { registry.addDecoratorFactory(new WebSocketHandlerDecoratorFactory() { @Override public WebSocketHandlerDecorator decorate(WebSocketHandler handler) { return new WebSocketHandlerDecorator(handler) { @Override public void afterConnectionEstablished(WebSocketSession session) throws Exception { session.getAttributes().put("decorated", true); super.afterConnectionEstablished(session); } }; } }); }
Example #9
Source File: WebMvcStompEndpointRegistry.java From java-technology-stack with MIT License | 5 votes |
private static SubProtocolWebSocketHandler unwrapSubProtocolWebSocketHandler(WebSocketHandler handler) { WebSocketHandler actual = WebSocketHandlerDecorator.unwrap(handler); if (!(actual instanceof SubProtocolWebSocketHandler)) { throw new IllegalArgumentException("No SubProtocolWebSocketHandler in " + handler); } return (SubProtocolWebSocketHandler) actual; }
Example #10
Source File: SockJsWebSocketHandler.java From java-technology-stack with MIT License | 5 votes |
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 #11
Source File: AbstractHandshakeHandler.java From java-technology-stack with MIT License | 5 votes |
/** * Determine the sub-protocols supported by the given WebSocketHandler by * checking whether it is an instance of {@link SubProtocolCapable}. * @param handler the handler to check * @return a list of supported protocols, or an empty list if none available */ protected final List<String> determineHandlerSupportedProtocols(WebSocketHandler handler) { WebSocketHandler handlerToCheck = WebSocketHandlerDecorator.unwrap(handler); List<String> subProtocols = null; if (handlerToCheck instanceof SubProtocolCapable) { subProtocols = ((SubProtocolCapable) handlerToCheck).getSubProtocols(); } return (subProtocols != null ? subProtocols : Collections.emptyList()); }
Example #12
Source File: WebSocketMessageBrokerConfigurationSupportTests.java From spring-analysis-note with MIT License | 5 votes |
@Override protected void configureWebSocketTransport(WebSocketTransportRegistration registry) { registry.addDecoratorFactory(new WebSocketHandlerDecoratorFactory() { @Override public WebSocketHandlerDecorator decorate(WebSocketHandler handler) { return new WebSocketHandlerDecorator(handler) { @Override public void afterConnectionEstablished(WebSocketSession session) throws Exception { session.getAttributes().put("decorated", true); super.afterConnectionEstablished(session); } }; } }); }
Example #13
Source File: WebMvcStompEndpointRegistry.java From spring-analysis-note with MIT License | 5 votes |
private static SubProtocolWebSocketHandler unwrapSubProtocolWebSocketHandler(WebSocketHandler handler) { WebSocketHandler actual = WebSocketHandlerDecorator.unwrap(handler); if (!(actual instanceof SubProtocolWebSocketHandler)) { throw new IllegalArgumentException("No SubProtocolWebSocketHandler in " + handler); } return (SubProtocolWebSocketHandler) actual; }
Example #14
Source File: AbstractHandshakeHandler.java From spring-analysis-note with MIT License | 5 votes |
/** * Determine the sub-protocols supported by the given WebSocketHandler by * checking whether it is an instance of {@link SubProtocolCapable}. * @param handler the handler to check * @return a list of supported protocols, or an empty list if none available */ protected final List<String> determineHandlerSupportedProtocols(WebSocketHandler handler) { WebSocketHandler handlerToCheck = WebSocketHandlerDecorator.unwrap(handler); List<String> subProtocols = null; if (handlerToCheck instanceof SubProtocolCapable) { subProtocols = ((SubProtocolCapable) handlerToCheck).getSubProtocols(); } return (subProtocols != null ? subProtocols : Collections.emptyList()); }
Example #15
Source File: MessageBrokerBeanDefinitionParserTests.java From spring-analysis-note with MIT License | 4 votes |
private WebSocketHandler unwrapWebSocketHandler(WebSocketHandler handler) { return (handler instanceof WebSocketHandlerDecorator) ? ((WebSocketHandlerDecorator) handler).getLastHandler() : handler; }
Example #16
Source File: HandlersBeanDefinitionParserTests.java From java-technology-stack with MIT License | 4 votes |
private static void unwrapAndCheckDecoratedHandlerType(WebSocketHandler handler, Class<?> handlerClass) { if (handler instanceof WebSocketHandlerDecorator) { handler = ((WebSocketHandlerDecorator) handler).getLastHandler(); } assertTrue(handlerClass.isInstance(handler)); }
Example #17
Source File: MessageBrokerBeanDefinitionParserTests.java From java-technology-stack with MIT License | 4 votes |
private WebSocketHandler unwrapWebSocketHandler(WebSocketHandler handler) { return (handler instanceof WebSocketHandlerDecorator) ? ((WebSocketHandlerDecorator) handler).getLastHandler() : handler; }
Example #18
Source File: HandlersBeanDefinitionParserTests.java From spring-analysis-note with MIT License | 4 votes |
private static void unwrapAndCheckDecoratedHandlerType(WebSocketHandler handler, Class<?> handlerClass) { if (handler instanceof WebSocketHandlerDecorator) { handler = ((WebSocketHandlerDecorator) handler).getLastHandler(); } assertTrue(handlerClass.isInstance(handler)); }
Example #19
Source File: WebMvcStompEndpointRegistry.java From spring4-understanding with Apache License 2.0 | 4 votes |
private static SubProtocolWebSocketHandler unwrapSubProtocolWebSocketHandler(WebSocketHandler handler) { WebSocketHandler actual = WebSocketHandlerDecorator.unwrap(handler); Assert.isInstanceOf(SubProtocolWebSocketHandler.class, actual, "No SubProtocolWebSocketHandler in " + handler); return (SubProtocolWebSocketHandler) actual; }
Example #20
Source File: HandlersBeanDefinitionParserTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
private static void unwrapAndCheckDecoratedHandlerType(WebSocketHandler handler, Class<?> handlerClass) { if (handler instanceof WebSocketHandlerDecorator) { handler = ((WebSocketHandlerDecorator) handler).getLastHandler(); } assertTrue(handlerClass.isInstance(handler)); }
Example #21
Source File: MessageBrokerBeanDefinitionParserTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
private WebSocketHandler unwrapWebSocketHandler(WebSocketHandler handler) { return (handler instanceof WebSocketHandlerDecorator) ? ((WebSocketHandlerDecorator) handler).getLastHandler() : handler; }