-
-
Notifications
You must be signed in to change notification settings - Fork 362
/
WebSocketConfiguration.java
71 lines (62 loc) · 3.03 KB
/
WebSocketConfiguration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* SteVe - SteckdosenVerwaltung - https://github.com/steve-community/steve
* Copyright (C) 2013-2024 SteVe Community Team
* All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.rwth.idsg.steve.config;
import com.google.common.collect.Lists;
import de.rwth.idsg.steve.ocpp.ws.OcppWebSocketHandshakeHandler;
import de.rwth.idsg.steve.ocpp.ws.ocpp12.Ocpp12WebSocketEndpoint;
import de.rwth.idsg.steve.ocpp.ws.ocpp15.Ocpp15WebSocketEndpoint;
import de.rwth.idsg.steve.ocpp.ws.ocpp16.Ocpp16WebSocketEndpoint;
import de.rwth.idsg.steve.service.ChargePointHelperService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
/**
* @author Sevket Goekay <sevketgokay@gmail.com>
* @since 11.03.2015
*/
@EnableWebSocket
@Configuration
@Slf4j
public class WebSocketConfiguration implements WebSocketConfigurer {
@Autowired private ChargePointHelperService chargePointHelperService;
@Autowired private Ocpp12WebSocketEndpoint ocpp12WebSocketEndpoint;
@Autowired private Ocpp15WebSocketEndpoint ocpp15WebSocketEndpoint;
@Autowired private Ocpp16WebSocketEndpoint ocpp16WebSocketEndpoint;
public static final String PATH_INFIX = "/websocket/CentralSystemService/";
public static final long PING_INTERVAL = TimeUnit.MINUTES.toMinutes(15);
public static final Duration IDLE_TIMEOUT = Duration.ofHours(2);
public static final int MAX_MSG_SIZE = 8_388_608; // 8 MB for max message size
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
OcppWebSocketHandshakeHandler handshakeHandler = new OcppWebSocketHandshakeHandler(
new DefaultHandshakeHandler(),
Lists.newArrayList(ocpp16WebSocketEndpoint, ocpp15WebSocketEndpoint, ocpp12WebSocketEndpoint),
chargePointHelperService
);
registry.addHandler(handshakeHandler.getDummyWebSocketHandler(), PATH_INFIX + "*")
.setHandshakeHandler(handshakeHandler)
.setAllowedOrigins("*");
}
}