|
34 | 34 | import org.springframework.context.annotation.Bean;
|
35 | 35 | import org.springframework.context.annotation.Configuration;
|
36 | 36 |
|
37 |
| -import jakarta.annotation.PostConstruct; |
38 | 37 | import java.util.Collection;
|
39 | 38 | import java.util.Collections;
|
40 | 39 | import java.util.List;
|
@@ -62,32 +61,33 @@ public class OcppConfiguration {
|
62 | 61 | private final ocpp.cs._2015._10.CentralSystemService ocpp16Server;
|
63 | 62 | private final MessageHeaderInterceptor messageHeaderInterceptor;
|
64 | 63 |
|
65 |
| - @PostConstruct |
66 |
| - public void init() { |
| 64 | + @Bean(name = Bus.DEFAULT_BUS_ID, destroyMethod = "shutdown") |
| 65 | + public SpringBus cxf() { |
| 66 | + SpringBus bus = new SpringBus(); |
| 67 | + configure(bus); |
| 68 | + return bus; |
| 69 | + } |
| 70 | + |
| 71 | + private void configure(Bus bus) { |
67 | 72 | List<Interceptor<? extends Message>> interceptors = asList(new MessageIdInterceptor(), messageHeaderInterceptor);
|
68 | 73 | List<Feature> logging = singletonList(LoggingFeatureProxy.INSTANCE.get());
|
69 | 74 |
|
70 |
| - createOcppService(ocpp12Server, "/CentralSystemServiceOCPP12", interceptors, logging); |
71 |
| - createOcppService(ocpp15Server, "/CentralSystemServiceOCPP15", interceptors, logging); |
72 |
| - createOcppService(ocpp16Server, "/CentralSystemServiceOCPP16", interceptors, logging); |
| 75 | + createOcppService(bus, ocpp12Server, "/CentralSystemServiceOCPP12", interceptors, logging); |
| 76 | + createOcppService(bus, ocpp15Server, "/CentralSystemServiceOCPP15", interceptors, logging); |
| 77 | + createOcppService(bus, ocpp16Server, "/CentralSystemServiceOCPP16", interceptors, logging); |
73 | 78 |
|
74 | 79 | // Just a dummy service to route incoming messages to the appropriate service version. This should be the last
|
75 | 80 | // one to be created, since in MediatorInInterceptor we go over created/registered services and build a map.
|
76 | 81 | //
|
77 |
| - List<Interceptor<? extends Message>> mediator = singletonList(new MediatorInInterceptor(springBus())); |
78 |
| - createOcppService(ocpp12Server, CONFIG.getRouterEndpointPath(), mediator, Collections.emptyList()); |
79 |
| - } |
80 |
| - |
81 |
| - @Bean(name = Bus.DEFAULT_BUS_ID, destroyMethod = "shutdown") |
82 |
| - public SpringBus springBus() { |
83 |
| - return new SpringBus(); |
| 82 | + List<Interceptor<? extends Message>> mediator = singletonList(new MediatorInInterceptor(bus)); |
| 83 | + createOcppService(bus, ocpp12Server, CONFIG.getRouterEndpointPath(), mediator, Collections.emptyList()); |
84 | 84 | }
|
85 | 85 |
|
86 |
| - private void createOcppService(Object serviceBean, String address, |
| 86 | + private void createOcppService(Bus bus, Object serviceBean, String address, |
87 | 87 | List<Interceptor<? extends Message>> interceptors,
|
88 | 88 | Collection<? extends Feature> features) {
|
89 | 89 | JaxWsServerFactoryBean f = new JaxWsServerFactoryBean();
|
90 |
| - f.setBus(springBus()); |
| 90 | + f.setBus(bus); |
91 | 91 | f.setServiceBean(serviceBean);
|
92 | 92 | f.setAddress(address);
|
93 | 93 | f.getFeatures().addAll(features);
|
|
0 commit comments