Search in sources :

Example 1 with WebSocketHandlerRegistration

use of org.springframework.web.socket.config.annotation.WebSocketHandlerRegistration in project spring-integration by spring-projects.

the class ServerWebSocketContainer method registerWebSocketHandlers.

@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
    WebSocketHandler webSocketHandler = this.webSocketHandler;
    if (this.decoratorFactories != null) {
        for (WebSocketHandlerDecoratorFactory factory : this.decoratorFactories) {
            webSocketHandler = factory.decorate(webSocketHandler);
        }
    }
    WebSocketHandlerRegistration registration = registry.addHandler(webSocketHandler, this.paths).setHandshakeHandler(this.handshakeHandler).addInterceptors(this.interceptors).setAllowedOrigins(this.origins);
    if (this.sockJsServiceOptions != null) {
        SockJsServiceRegistration sockJsServiceRegistration = registration.withSockJS();
        if (this.sockJsServiceOptions.webSocketEnabled != null) {
            sockJsServiceRegistration.setWebSocketEnabled(this.sockJsServiceOptions.webSocketEnabled);
        }
        if (this.sockJsServiceOptions.clientLibraryUrl != null) {
            sockJsServiceRegistration.setClientLibraryUrl(this.sockJsServiceOptions.clientLibraryUrl);
        }
        if (this.sockJsServiceOptions.disconnectDelay != null) {
            sockJsServiceRegistration.setDisconnectDelay(this.sockJsServiceOptions.disconnectDelay);
        }
        if (this.sockJsServiceOptions.heartbeatTime != null) {
            sockJsServiceRegistration.setHeartbeatTime(this.sockJsServiceOptions.heartbeatTime);
        }
        if (this.sockJsServiceOptions.httpMessageCacheSize != null) {
            sockJsServiceRegistration.setHttpMessageCacheSize(this.sockJsServiceOptions.httpMessageCacheSize);
        }
        if (this.sockJsServiceOptions.heartbeatTime != null) {
            sockJsServiceRegistration.setHeartbeatTime(this.sockJsServiceOptions.heartbeatTime);
        }
        if (this.sockJsServiceOptions.sessionCookieNeeded != null) {
            sockJsServiceRegistration.setSessionCookieNeeded(this.sockJsServiceOptions.sessionCookieNeeded);
        }
        if (this.sockJsServiceOptions.streamBytesLimit != null) {
            sockJsServiceRegistration.setStreamBytesLimit(this.sockJsServiceOptions.streamBytesLimit);
        }
        if (this.sockJsServiceOptions.transportHandlers != null) {
            sockJsServiceRegistration.setTransportHandlers(this.sockJsServiceOptions.transportHandlers);
        }
        if (this.sockJsServiceOptions.taskScheduler != null) {
            sockJsServiceRegistration.setTaskScheduler(this.sockJsServiceOptions.taskScheduler);
        }
        if (this.sockJsServiceOptions.messageCodec != null) {
            sockJsServiceRegistration.setMessageCodec(this.sockJsServiceOptions.messageCodec);
        }
        if (this.sockJsServiceOptions.suppressCors != null) {
            sockJsServiceRegistration.setSupressCors(this.sockJsServiceOptions.suppressCors);
        }
    }
}
Also used : SockJsServiceRegistration(org.springframework.web.socket.config.annotation.SockJsServiceRegistration) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) WebSocketHandlerDecoratorFactory(org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory) WebSocketHandlerRegistration(org.springframework.web.socket.config.annotation.WebSocketHandlerRegistration)

Example 2 with WebSocketHandlerRegistration

use of org.springframework.web.socket.config.annotation.WebSocketHandlerRegistration in project ma-core-public by infiniteautomation.

the class MangoWebSocketConfiguration method registerWebSocketHandlers.

@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
    // Setup Allowed Origins for CORS requests
    boolean hasOrigins = false;
    String[] origins = null;
    if (Common.envProps.getBoolean("rest.cors.enabled", false)) {
        hasOrigins = true;
        origins = Common.envProps.getStringArray("rest.cors.allowedOrigins", ",", new String[0]);
    }
    for (WebSocketDefinition def : websocketDefinitions()) {
        WebSocketHandler handler = def.getHandlerInstance();
        if (def.perConnection()) {
            PerConnectionWebSocketHandler perConnection = new PerConnectionWebSocketHandler(handler.getClass());
            beanFactory.initializeBean(perConnection, PerConnectionWebSocketHandler.class.getName());
            handler = perConnection;
        } else {
            beanFactory.autowireBean(handler);
            handler = (WebSocketHandler) beanFactory.initializeBean(handler, handler.getClass().getName());
        }
        WebSocketHandlerRegistration registration = registry.addHandler(handler, def.getUrl()).setHandshakeHandler(handshakeHandler()).addInterceptors(handshakeIterceptor());
        if (hasOrigins)
            registration.setAllowedOrigins(origins);
    }
}
Also used : WebSocketHandler(org.springframework.web.socket.WebSocketHandler) PerConnectionWebSocketHandler(org.springframework.web.socket.handler.PerConnectionWebSocketHandler) WebSocketHandlerRegistration(org.springframework.web.socket.config.annotation.WebSocketHandlerRegistration) WebSocketDefinition(com.serotonin.m2m2.module.WebSocketDefinition) PerConnectionWebSocketHandler(org.springframework.web.socket.handler.PerConnectionWebSocketHandler)

Example 3 with WebSocketHandlerRegistration

use of org.springframework.web.socket.config.annotation.WebSocketHandlerRegistration in project pinpoint by naver.

the class WebSocketConfig method registerWebSocketHandlers.

@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
    final String[] allowedOriginArray = getAllowedOriginArray(configProperties.getWebSocketAllowedOrigins());
    for (PinpointWebSocketHandler handler : handlerRepository.getWebSocketHandlerRepository()) {
        String path = handler.getRequestMapping() + WEBSOCKET_SUFFIX;
        WebSocketHandler webSocketHandler = webSocketHandlerDecoratorFactory.decorate(handler);
        final WebSocketHandlerRegistration webSocketHandlerRegistration = registry.addHandler(webSocketHandler, path);
        webSocketHandlerRegistration.addInterceptors(new HttpSessionHandshakeInterceptor());
        webSocketHandlerRegistration.addInterceptors(new WebSocketSessionContextPrepareHandshakeInterceptor());
        if (Objects.nonNull(customHandshakeInterceptor)) {
            webSocketHandlerRegistration.addInterceptors(customHandshakeInterceptor);
        }
        webSocketHandlerRegistration.setAllowedOrigins(allowedOriginArray);
    }
}
Also used : HttpSessionHandshakeInterceptor(org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) WebSocketHandlerRegistration(org.springframework.web.socket.config.annotation.WebSocketHandlerRegistration)

Aggregations

WebSocketHandler (org.springframework.web.socket.WebSocketHandler)3 WebSocketHandlerRegistration (org.springframework.web.socket.config.annotation.WebSocketHandlerRegistration)3 WebSocketDefinition (com.serotonin.m2m2.module.WebSocketDefinition)1 SockJsServiceRegistration (org.springframework.web.socket.config.annotation.SockJsServiceRegistration)1 PerConnectionWebSocketHandler (org.springframework.web.socket.handler.PerConnectionWebSocketHandler)1 WebSocketHandlerDecoratorFactory (org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory)1 HttpSessionHandshakeInterceptor (org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor)1