forked from steve-community/steve
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOcppWebSocketConfiguration.java
More file actions
77 lines (68 loc) · 3.29 KB
/
OcppWebSocketConfiguration.java
File metadata and controls
77 lines (68 loc) · 3.29 KB
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
72
73
74
75
76
77
/*
* SteVe - SteckdosenVerwaltung - https://github.com/steve-community/steve
* Copyright (C) 2013-2025 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.SteveConfiguration;
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.ChargePointRegistrationService;
import de.rwth.idsg.steve.web.validation.ChargeBoxIdValidator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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;
/**
* @author Sevket Goekay <sevketgokay@gmail.com>
* @since 11.03.2015
*/
@EnableWebSocket
@Configuration
@Slf4j
@RequiredArgsConstructor
public class OcppWebSocketConfiguration implements WebSocketConfigurer {
public static final Duration WS_PING_INTERVAL = Duration.ofMinutes(15);
public static final Duration WS_IDLE_TIMEOUT = Duration.ofHours(2);
public static final int WS_MAX_MSG_SIZE = 8_388_608; // 8 MB for max message size
private final ChargePointRegistrationService chargePointRegistrationService;
private final ChargeBoxIdValidator chargeBoxIdValidator;
private final SteveConfiguration config;
private final Ocpp12WebSocketEndpoint ocpp12WebSocketEndpoint;
private final Ocpp15WebSocketEndpoint ocpp15WebSocketEndpoint;
private final Ocpp16WebSocketEndpoint ocpp16WebSocketEndpoint;
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
var handshakeHandler = new OcppWebSocketHandshakeHandler(
chargeBoxIdValidator,
new DefaultHandshakeHandler(),
Lists.newArrayList(ocpp16WebSocketEndpoint, ocpp15WebSocketEndpoint, ocpp12WebSocketEndpoint),
chargePointRegistrationService,
config.getPaths().getWsPathInfix() + "/");
registry.addHandler(
handshakeHandler.getDummyWebSocketHandler(),
config.getPaths().getWsPathInfix() + "/*")
.setHandshakeHandler(handshakeHandler)
.setAllowedOrigins("*");
}
}