|
24 | 24 | import de.rwth.idsg.steve.ocpp.soap.MessageIdInterceptor; |
25 | 25 | import lombok.RequiredArgsConstructor; |
26 | 26 | import org.apache.cxf.Bus; |
27 | | -import org.apache.cxf.bus.spring.SpringBus; |
28 | | -import org.apache.cxf.common.logging.LogUtils; |
29 | | -import org.apache.cxf.common.logging.Slf4jLogger; |
30 | 27 | import org.apache.cxf.feature.Feature; |
31 | 28 | import org.apache.cxf.interceptor.Interceptor; |
32 | | -import org.apache.cxf.jaxws.JaxWsServerFactoryBean; |
| 29 | +import org.apache.cxf.jaxws.EndpointImpl; |
33 | 30 | import org.apache.cxf.message.Message; |
34 | | -import org.apache.cxf.transport.servlet.CXFServlet; |
35 | | -import org.springframework.boot.web.servlet.ServletRegistrationBean; |
36 | 31 | import org.springframework.context.annotation.Bean; |
37 | 32 | import org.springframework.context.annotation.Configuration; |
38 | 33 |
|
39 | | -import java.util.Collection; |
40 | 34 | import java.util.Collections; |
41 | 35 | import java.util.List; |
42 | 36 |
|
43 | | -import static java.util.Arrays.asList; |
44 | | -import static java.util.Collections.singletonList; |
45 | | - |
46 | 37 | /** |
47 | 38 | * Configuration and beans related to OCPP. |
48 | 39 | * |
|
53 | 44 | @Configuration |
54 | 45 | public class OcppConfiguration { |
55 | 46 |
|
56 | | - static { |
57 | | - LogUtils.setLoggerClass(Slf4jLogger.class); |
58 | | - } |
59 | | - |
| 47 | + private final Bus bus; |
60 | 48 | private final ocpp.cs._2010._08.CentralSystemService ocpp12Server; |
61 | 49 | private final ocpp.cs._2012._06.CentralSystemService ocpp15Server; |
62 | 50 | private final ocpp.cs._2015._10.CentralSystemService ocpp16Server; |
63 | 51 | private final MessageHeaderInterceptor messageHeaderInterceptor; |
64 | 52 |
|
| 53 | + private final MessageIdInterceptor messageIdInterceptor = new MessageIdInterceptor(); |
| 54 | + |
65 | 55 | @Bean |
66 | | - public ServletRegistrationBean<CXFServlet> cxfServletServletRegistrationBean() { |
67 | | - var bean = new ServletRegistrationBean<>(new CXFServlet(), SteveProperties.CXF_MAPPING + "/*"); |
68 | | - bean.setLoadOnStartup(1); |
69 | | - return bean; |
| 56 | + public EndpointImpl ocpp12Endpoint() { |
| 57 | + return createDefaultEndpoint(ocpp12Server, "/CentralSystemServiceOCPP12"); |
70 | 58 | } |
71 | 59 |
|
72 | | - @Bean(name = Bus.DEFAULT_BUS_ID, destroyMethod = "shutdown") |
73 | | - public SpringBus cxf() { |
74 | | - SpringBus bus = new SpringBus(); |
75 | | - configure(bus); |
76 | | - return bus; |
| 60 | + @Bean |
| 61 | + public EndpointImpl ocpp15Endpoint() { |
| 62 | + return createDefaultEndpoint(ocpp15Server, "/CentralSystemServiceOCPP15"); |
77 | 63 | } |
78 | 64 |
|
79 | | - private void configure(Bus bus) { |
80 | | - List<Interceptor<? extends Message>> interceptors = asList(new MessageIdInterceptor(), messageHeaderInterceptor); |
81 | | - List<Feature> logging = singletonList(LoggingFeatureProxy.INSTANCE.get()); |
| 65 | + @Bean |
| 66 | + public EndpointImpl ocpp16Endpoint() { |
| 67 | + return createDefaultEndpoint(ocpp16Server, "/CentralSystemServiceOCPP16"); |
| 68 | + } |
82 | 69 |
|
83 | | - createOcppService(bus, ocpp12Server, "/CentralSystemServiceOCPP12", interceptors, logging); |
84 | | - createOcppService(bus, ocpp15Server, "/CentralSystemServiceOCPP15", interceptors, logging); |
85 | | - createOcppService(bus, ocpp16Server, "/CentralSystemServiceOCPP16", interceptors, logging); |
| 70 | + /** |
| 71 | + * Just a dummy service to route incoming messages to the appropriate service version. |
| 72 | + */ |
| 73 | + @Bean |
| 74 | + public EndpointImpl routerEndpoint(EndpointImpl ocpp12Endpoint, |
| 75 | + EndpointImpl ocpp15Endpoint, |
| 76 | + EndpointImpl ocpp16Endpoint) { |
| 77 | + var mediator = new MediatorInInterceptor(List.of(ocpp12Endpoint, ocpp15Endpoint, ocpp16Endpoint)); |
| 78 | + return createEndpoint( |
| 79 | + ocpp12Server, SteveProperties.ROUTER_ENDPOINT_PATH, List.of(mediator), Collections.emptyList() |
| 80 | + ); |
| 81 | + } |
86 | 82 |
|
87 | | - // Just a dummy service to route incoming messages to the appropriate service version. This should be the last |
88 | | - // one to be created, since in MediatorInInterceptor we go over created/registered services and build a map. |
89 | | - // |
90 | | - List<Interceptor<? extends Message>> mediator = singletonList(new MediatorInInterceptor(bus)); |
91 | | - createOcppService(bus, ocpp12Server, SteveProperties.ROUTER_ENDPOINT_PATH, mediator, Collections.emptyList()); |
| 83 | + private EndpointImpl createDefaultEndpoint(Object serviceBean, String address) { |
| 84 | + return createEndpoint( |
| 85 | + serviceBean, address, List.of(messageIdInterceptor, messageHeaderInterceptor), List.of(LoggingFeatureProxy.INSTANCE.get()) |
| 86 | + ); |
92 | 87 | } |
93 | 88 |
|
94 | | - private void createOcppService(Bus bus, Object serviceBean, String address, |
95 | | - List<Interceptor<? extends Message>> interceptors, |
96 | | - Collection<? extends Feature> features) { |
97 | | - JaxWsServerFactoryBean f = new JaxWsServerFactoryBean(); |
98 | | - f.setBus(bus); |
99 | | - f.setServiceBean(serviceBean); |
100 | | - f.setAddress(address); |
101 | | - f.getFeatures().addAll(features); |
102 | | - f.getInInterceptors().addAll(interceptors); |
103 | | - f.create(); |
| 89 | + private EndpointImpl createEndpoint(Object serviceBean, String address, |
| 90 | + List<Interceptor<? extends Message>> interceptors, |
| 91 | + List<? extends Feature> features) { |
| 92 | + EndpointImpl endpoint = new EndpointImpl(bus, serviceBean); |
| 93 | + endpoint.getInInterceptors().addAll(interceptors); |
| 94 | + endpoint.getFeatures().addAll(features); |
| 95 | + endpoint.publish(address); |
| 96 | + return endpoint; |
104 | 97 | } |
105 | 98 | } |
0 commit comments