Example usage for org.springframework.web.socket.sockjs.support SockJsHttpRequestHandler SockJsHttpRequestHandler

List of usage examples for org.springframework.web.socket.sockjs.support SockJsHttpRequestHandler SockJsHttpRequestHandler

Introduction

In this page you can find the example usage for org.springframework.web.socket.sockjs.support SockJsHttpRequestHandler SockJsHttpRequestHandler.

Prototype

public SockJsHttpRequestHandler(SockJsService sockJsService, WebSocketHandler webSocketHandler) 

Source Link

Document

Create a new SockJsHttpRequestHandler.

Usage

From source file:com.music.web.util.WebSocketConfigurer.java

@Bean
public SimpleUrlHandlerMapping handlerMapping() {

    SockJsService sockJsService = new DefaultSockJsService(taskScheduler());

    Map<String, Object> urlMap = new HashMap<String, Object>();
    urlMap.put("/game/websocket/**", new SockJsHttpRequestHandler(sockJsService, gameHandler));

    SimpleUrlHandlerMapping hm = new SimpleUrlHandlerMapping();
    hm.setUrlMap(urlMap);/*from w ww  . j av  a  2 s. c om*/
    return hm;
}

From source file:ch.rasc.wampspring.config.WebMvcWampWebSocketEndpointRegistration.java

public final MultiValueMap<HttpRequestHandler, String> getMappings() {
    MultiValueMap<HttpRequestHandler, String> mappings = new LinkedMultiValueMap<>();
    if (this.registration != null) {
        SockJsService sockJsService = this.registration.getSockJsService();
        for (String path : this.paths) {
            String pattern = path.endsWith("/") ? path + "**" : path + "/**";
            SockJsHttpRequestHandler handler = new SockJsHttpRequestHandler(sockJsService,
                    this.webSocketHandler);
            mappings.add(handler, pattern);
        }/*  w  w  w.  jav a  2  s  . co  m*/
    } else {
        for (String path : this.paths) {
            WebSocketHttpRequestHandler handler;
            if (this.handshakeHandler != null) {
                handler = new WebSocketHttpRequestHandler(this.webSocketHandler, this.handshakeHandler);
            } else {
                handler = new WebSocketHttpRequestHandler(this.webSocketHandler);
            }
            HandshakeInterceptor[] handshakeInterceptors = getInterceptors();
            if (handshakeInterceptors.length > 0) {
                handler.setHandshakeInterceptors(Arrays.asList(handshakeInterceptors));
            }
            mappings.add(handler, path);
        }
    }
    return mappings;
}