Skip to content

Commit c975c63

Browse files
committed
fix: Create ocpp services at startup
1 parent 1769bcf commit c975c63

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/main/java/de/rwth/idsg/steve/config/OcppConfiguration.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
import org.springframework.beans.factory.annotation.Qualifier;
3535
import org.springframework.context.annotation.Bean;
3636
import org.springframework.context.annotation.Configuration;
37+
import org.springframework.context.event.ContextRefreshedEvent;
38+
import org.springframework.context.event.ContextStartedEvent;
39+
import org.springframework.context.event.EventListener;
40+
import org.springframework.stereotype.Component;
3741

3842
import java.util.Collection;
3943
import java.util.Collections;
@@ -56,10 +60,24 @@ public class OcppConfiguration {
5660
LogUtils.setLoggerClass(Slf4jLogger.class);
5761
}
5862

63+
private final CentralSystemService ocpp12Server;
64+
private final ocpp.cs._2012._06.CentralSystemService ocpp15Server;
65+
private final ocpp.cs._2015._10.CentralSystemService ocpp16Server;
66+
private final List<Interceptor<? extends Message>> interceptors;
67+
private final List<Feature> logging;
68+
private final String routerEndpointPath;
69+
5970
public OcppConfiguration(CentralSystemService ocpp12Server, ocpp.cs._2012._06.CentralSystemService ocpp15Server, ocpp.cs._2015._10.CentralSystemService ocpp16Server, @Qualifier("MessageHeaderInterceptor") PhaseInterceptor<Message> messageHeaderInterceptor) {
60-
List<Interceptor<? extends Message>> interceptors = asList(new MessageIdInterceptor(), messageHeaderInterceptor);
61-
List<Feature> logging = singletonList(LoggingFeatureProxy.INSTANCE.get());
71+
this.ocpp12Server = ocpp12Server;
72+
this.ocpp15Server = ocpp15Server;
73+
this.ocpp16Server = ocpp16Server;
74+
this.interceptors = asList(new MessageIdInterceptor(), messageHeaderInterceptor);
75+
this.logging = singletonList(LoggingFeatureProxy.INSTANCE.get());
76+
this.routerEndpointPath = CONFIG.getRouterEndpointPath();
77+
}
6278

79+
@EventListener
80+
public void afterStart(ContextRefreshedEvent event) {
6381
createOcppService(ocpp12Server, "/CentralSystemServiceOCPP12", interceptors, logging);
6482
createOcppService(ocpp15Server, "/CentralSystemServiceOCPP15", interceptors, logging);
6583
createOcppService(ocpp16Server, "/CentralSystemServiceOCPP16", interceptors, logging);
@@ -68,7 +86,7 @@ public OcppConfiguration(CentralSystemService ocpp12Server, ocpp.cs._2012._06.Ce
6886
// one to be created, since in MediatorInInterceptor we go over created/registered services and build a map.
6987
//
7088
List<Interceptor<? extends Message>> mediator = singletonList(new MediatorInInterceptor(springBus()));
71-
createOcppService(ocpp12Server, CONFIG.getRouterEndpointPath(), mediator, Collections.emptyList());
89+
createOcppService(ocpp12Server, routerEndpointPath, mediator, Collections.emptyList());
7290
}
7391

7492
@Bean(name = Bus.DEFAULT_BUS_ID, destroyMethod = "shutdown")

0 commit comments

Comments
 (0)