Java Code Examples for org.springframework.web.socket.config.annotation.ServletWebSocketHandlerRegistry

Following code examples demonstrate how to use org.springframework.web.socket.config.annotation.ServletWebSocketHandlerRegistryfrom spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.web.socket.config.annotation.ServletWebSocketHandlerRegistryand various code implementation of this class.

    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
        ServletWebSocketHandlerRegistry servletWebSocketHandlerRegistry = (ServletWebSocketHandlerRegistry) webSocketHandlerRegistry;
        servletWebSocketHandlerRegistry.setOrder(2);
        servletWebSocketHandlerRegistry.setUrlPathHelper(new UrlPathHelper());
        webSocketHandlerRegistry.addHandler(testHandler(), TEST_PATH)
                .setAllowedOrigins("*")
                .withSockJS();
    } 


	private ServletWebSocketHandlerRegistry initHandlerRegistry() {
		if (this.handlerRegistry == null) {
			this.handlerRegistry = new ServletWebSocketHandlerRegistry();
			registerWebSocketHandlers(this.handlerRegistry);
		}
		return this.handlerRegistry;
	} 

	public HandlerMapping webSocketHandlerMapping() {
		ServletWebSocketHandlerRegistry registry = initHandlerRegistry();
		return registry.getHandlerMapping();
	} 

Advertisement
Javadoc
WebSocketHandlerRegistry with Spring MVC handler mappings for the handshake requests. @author Rossen

Stoyanchev @since 4.0

Read More
Advertisement