Search in sources :

Example 1 with WebSocketHandlerRegistry

use of org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry in project steve by RWTH-i5-IDSG.

the class WebSocketConfiguration method registerWebSocketHandlers.

@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
    WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
    policy.setMaxTextMessageBufferSize(MAX_MSG_SIZE);
    policy.setMaxTextMessageSize(MAX_MSG_SIZE);
    policy.setIdleTimeout(IDLE_TIMEOUT);
    List<AbstractWebSocketEndpoint> endpoints = getEndpoints();
    String[] protocols = endpoints.stream().map(e -> e.getVersion().getValue()).toArray(String[]::new);
    OcppWebSocketUpgrader upgradeStrategy = new OcppWebSocketUpgrader(policy, endpoints, chargePointRepository, notificationService, chargePointHelperService);
    DefaultHandshakeHandler handler = new DefaultHandshakeHandler(upgradeStrategy);
    handler.setSupportedProtocols(protocols);
    for (AbstractWebSocketEndpoint endpoint : endpoints) {
        registry.addHandler(endpoint, "/websocket/CentralSystemService/*").setHandshakeHandler(handler).setAllowedOrigins("*");
    }
}
Also used : WebSocketPolicy(org.eclipse.jetty.websocket.api.WebSocketPolicy) Ocpp15WebSocketEndpoint(de.rwth.idsg.steve.ocpp.ws.ocpp15.Ocpp15WebSocketEndpoint) NotificationService(de.rwth.idsg.steve.service.NotificationService) Ocpp16WebSocketEndpoint(de.rwth.idsg.steve.ocpp.ws.ocpp16.Ocpp16WebSocketEndpoint) WebSocketConfigurer(org.springframework.web.socket.config.annotation.WebSocketConfigurer) WebSocketHandlerRegistry(org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry) OcppWebSocketUpgrader(de.rwth.idsg.steve.ocpp.ws.OcppWebSocketUpgrader) EnableWebSocket(org.springframework.web.socket.config.annotation.EnableWebSocket) Ocpp12WebSocketEndpoint(de.rwth.idsg.steve.ocpp.ws.ocpp12.Ocpp12WebSocketEndpoint) Autowired(org.springframework.beans.factory.annotation.Autowired) Configuration(org.springframework.context.annotation.Configuration) TimeUnit(java.util.concurrent.TimeUnit) ChargePointHelperService(de.rwth.idsg.steve.service.ChargePointHelperService) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Lists(com.google.common.collect.Lists) AbstractWebSocketEndpoint(de.rwth.idsg.steve.ocpp.ws.AbstractWebSocketEndpoint) WebSocketPolicy(org.eclipse.jetty.websocket.api.WebSocketPolicy) DefaultHandshakeHandler(org.springframework.web.socket.server.support.DefaultHandshakeHandler) WebSocketBehavior(org.eclipse.jetty.websocket.api.WebSocketBehavior) ChargePointRepository(de.rwth.idsg.steve.repository.ChargePointRepository) AbstractWebSocketEndpoint(de.rwth.idsg.steve.ocpp.ws.AbstractWebSocketEndpoint) OcppWebSocketUpgrader(de.rwth.idsg.steve.ocpp.ws.OcppWebSocketUpgrader) DefaultHandshakeHandler(org.springframework.web.socket.server.support.DefaultHandshakeHandler)

Aggregations

Lists (com.google.common.collect.Lists)1 AbstractWebSocketEndpoint (de.rwth.idsg.steve.ocpp.ws.AbstractWebSocketEndpoint)1 OcppWebSocketUpgrader (de.rwth.idsg.steve.ocpp.ws.OcppWebSocketUpgrader)1 Ocpp12WebSocketEndpoint (de.rwth.idsg.steve.ocpp.ws.ocpp12.Ocpp12WebSocketEndpoint)1 Ocpp15WebSocketEndpoint (de.rwth.idsg.steve.ocpp.ws.ocpp15.Ocpp15WebSocketEndpoint)1 Ocpp16WebSocketEndpoint (de.rwth.idsg.steve.ocpp.ws.ocpp16.Ocpp16WebSocketEndpoint)1 ChargePointRepository (de.rwth.idsg.steve.repository.ChargePointRepository)1 ChargePointHelperService (de.rwth.idsg.steve.service.ChargePointHelperService)1 NotificationService (de.rwth.idsg.steve.service.NotificationService)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 Slf4j (lombok.extern.slf4j.Slf4j)1 WebSocketBehavior (org.eclipse.jetty.websocket.api.WebSocketBehavior)1 WebSocketPolicy (org.eclipse.jetty.websocket.api.WebSocketPolicy)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Configuration (org.springframework.context.annotation.Configuration)1 EnableWebSocket (org.springframework.web.socket.config.annotation.EnableWebSocket)1 WebSocketConfigurer (org.springframework.web.socket.config.annotation.WebSocketConfigurer)1 WebSocketHandlerRegistry (org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry)1 DefaultHandshakeHandler (org.springframework.web.socket.server.support.DefaultHandshakeHandler)1