Skip to content

Commit d457f56

Browse files
authored
Merge pull request #1817 from steve-community/refactor-constructor-injection
Refactor constructor injection
2 parents bac12d1 + 5d7c99e commit d457f56

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+434
-386
lines changed

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
import de.rwth.idsg.steve.ocpp.soap.LoggingFeatureProxy;
2222
import de.rwth.idsg.steve.ocpp.soap.MediatorInInterceptor;
23+
import de.rwth.idsg.steve.ocpp.soap.MessageHeaderInterceptor;
2324
import de.rwth.idsg.steve.ocpp.soap.MessageIdInterceptor;
25+
import lombok.RequiredArgsConstructor;
2426
import org.apache.cxf.Bus;
2527
import org.apache.cxf.bus.spring.SpringBus;
2628
import org.apache.cxf.common.logging.LogUtils;
@@ -29,9 +31,6 @@
2931
import org.apache.cxf.interceptor.Interceptor;
3032
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
3133
import org.apache.cxf.message.Message;
32-
import org.apache.cxf.phase.PhaseInterceptor;
33-
import org.springframework.beans.factory.annotation.Autowired;
34-
import org.springframework.beans.factory.annotation.Qualifier;
3534
import org.springframework.context.annotation.Bean;
3635
import org.springframework.context.annotation.Configuration;
3736

@@ -50,20 +49,18 @@
5049
* @author Sevket Goekay <[email protected]>
5150
* @since 18.11.2014
5251
*/
52+
@RequiredArgsConstructor
5353
@Configuration
5454
public class OcppConfiguration {
5555

5656
static {
5757
LogUtils.setLoggerClass(Slf4jLogger.class);
5858
}
5959

60-
@Autowired private ocpp.cs._2010._08.CentralSystemService ocpp12Server;
61-
@Autowired private ocpp.cs._2012._06.CentralSystemService ocpp15Server;
62-
@Autowired private ocpp.cs._2015._10.CentralSystemService ocpp16Server;
63-
64-
@Autowired
65-
@Qualifier("MessageHeaderInterceptor")
66-
private PhaseInterceptor<Message> messageHeaderInterceptor;
60+
private final ocpp.cs._2010._08.CentralSystemService ocpp12Server;
61+
private final ocpp.cs._2012._06.CentralSystemService ocpp15Server;
62+
private final ocpp.cs._2015._10.CentralSystemService ocpp16Server;
63+
private final MessageHeaderInterceptor messageHeaderInterceptor;
6764

6865
@PostConstruct
6966
public void init() {

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,31 @@
2323
import de.rwth.idsg.steve.ocpp.ws.ocpp12.Ocpp12WebSocketEndpoint;
2424
import de.rwth.idsg.steve.ocpp.ws.ocpp15.Ocpp15WebSocketEndpoint;
2525
import de.rwth.idsg.steve.ocpp.ws.ocpp16.Ocpp16WebSocketEndpoint;
26-
import de.rwth.idsg.steve.service.ChargePointHelperService;
26+
import de.rwth.idsg.steve.service.ChargePointRegistrationService;
27+
import lombok.RequiredArgsConstructor;
2728
import lombok.extern.slf4j.Slf4j;
28-
import org.springframework.beans.factory.annotation.Autowired;
2929
import org.springframework.context.annotation.Configuration;
3030
import org.springframework.web.socket.config.annotation.EnableWebSocket;
3131
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
3232
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
3333
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
3434

3535
import java.time.Duration;
36-
import java.util.concurrent.TimeUnit;
3736

3837
/**
3938
* @author Sevket Goekay <[email protected]>
4039
* @since 11.03.2015
4140
*/
41+
@RequiredArgsConstructor
4242
@EnableWebSocket
4343
@Configuration
4444
@Slf4j
4545
public class WebSocketConfiguration implements WebSocketConfigurer {
4646

47-
@Autowired private ChargePointHelperService chargePointHelperService;
48-
49-
@Autowired private Ocpp12WebSocketEndpoint ocpp12WebSocketEndpoint;
50-
@Autowired private Ocpp15WebSocketEndpoint ocpp15WebSocketEndpoint;
51-
@Autowired private Ocpp16WebSocketEndpoint ocpp16WebSocketEndpoint;
47+
private final ChargePointRegistrationService chargePointRegistrationService;
48+
private final Ocpp12WebSocketEndpoint ocpp12WebSocketEndpoint;
49+
private final Ocpp15WebSocketEndpoint ocpp15WebSocketEndpoint;
50+
private final Ocpp16WebSocketEndpoint ocpp16WebSocketEndpoint;
5251

5352
public static final String PATH_INFIX = "/websocket/CentralSystemService/";
5453
public static final Duration PING_INTERVAL = Duration.ofMinutes(15);
@@ -57,11 +56,10 @@ public class WebSocketConfiguration implements WebSocketConfigurer {
5756

5857
@Override
5958
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
60-
6159
OcppWebSocketHandshakeHandler handshakeHandler = new OcppWebSocketHandshakeHandler(
6260
new DefaultHandshakeHandler(),
6361
Lists.newArrayList(ocpp16WebSocketEndpoint, ocpp15WebSocketEndpoint, ocpp12WebSocketEndpoint),
64-
chargePointHelperService
62+
chargePointRegistrationService
6563
);
6664

6765
registry.addHandler(handshakeHandler.getDummyWebSocketHandler(), PATH_INFIX + "*")

src/main/java/de/rwth/idsg/steve/ocpp/soap/CentralSystemService12_SoapServer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import de.rwth.idsg.steve.ocpp.converter.Server12to15Impl;
2525
import de.rwth.idsg.steve.ocpp.converter.Server15to16Impl;
2626
import de.rwth.idsg.steve.service.CentralSystemService16_Service;
27+
import lombok.RequiredArgsConstructor;
2728
import lombok.extern.slf4j.Slf4j;
2829
import ocpp.cs._2010._08.AuthorizeRequest;
2930
import ocpp.cs._2010._08.AuthorizeResponse;
@@ -44,7 +45,6 @@
4445
import ocpp.cs._2010._08.StatusNotificationResponse;
4546
import ocpp.cs._2010._08.StopTransactionRequest;
4647
import ocpp.cs._2010._08.StopTransactionResponse;
47-
import org.springframework.beans.factory.annotation.Autowired;
4848
import org.springframework.stereotype.Service;
4949

5050
import jakarta.jws.WebService;
@@ -53,6 +53,7 @@
5353
import jakarta.xml.ws.Response;
5454
import jakarta.xml.ws.soap.Addressing;
5555
import jakarta.xml.ws.soap.SOAPBinding;
56+
5657
import java.util.concurrent.Future;
5758

5859
/**
@@ -61,6 +62,7 @@
6162
* @author Sevket Goekay <[email protected]>
6263
*/
6364
@Slf4j
65+
@RequiredArgsConstructor
6466
@Service
6567
@Addressing(enabled = true, required = false)
6668
@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)
@@ -71,7 +73,7 @@
7173
endpointInterface = "ocpp.cs._2010._08.CentralSystemService")
7274
public class CentralSystemService12_SoapServer implements CentralSystemService {
7375

74-
@Autowired private CentralSystemService16_Service service;
76+
private final CentralSystemService16_Service service;
7577

7678
public BootNotificationResponse bootNotificationWithTransport(BootNotificationRequest parameters,
7779
String chargeBoxIdentity, OcppProtocol protocol) {

src/main/java/de/rwth/idsg/steve/ocpp/soap/CentralSystemService15_SoapServer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import de.rwth.idsg.steve.ocpp.converter.Convert;
2424
import de.rwth.idsg.steve.ocpp.converter.Server15to16Impl;
2525
import de.rwth.idsg.steve.service.CentralSystemService16_Service;
26+
import lombok.RequiredArgsConstructor;
2627
import lombok.extern.slf4j.Slf4j;
2728
import ocpp.cs._2012._06.AuthorizeRequest;
2829
import ocpp.cs._2012._06.AuthorizeResponse;
@@ -45,7 +46,6 @@
4546
import ocpp.cs._2012._06.StatusNotificationResponse;
4647
import ocpp.cs._2012._06.StopTransactionRequest;
4748
import ocpp.cs._2012._06.StopTransactionResponse;
48-
import org.springframework.beans.factory.annotation.Autowired;
4949
import org.springframework.stereotype.Service;
5050

5151
import jakarta.jws.WebService;
@@ -54,6 +54,7 @@
5454
import jakarta.xml.ws.Response;
5555
import jakarta.xml.ws.soap.Addressing;
5656
import jakarta.xml.ws.soap.SOAPBinding;
57+
5758
import java.util.concurrent.Future;
5859

5960
/**
@@ -62,6 +63,7 @@
6263
* @author Sevket Goekay <[email protected]>
6364
*/
6465
@Slf4j
66+
@RequiredArgsConstructor
6567
@Service
6668
@Addressing(enabled = true, required = false)
6769
@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)
@@ -72,7 +74,7 @@
7274
endpointInterface = "ocpp.cs._2012._06.CentralSystemService")
7375
public class CentralSystemService15_SoapServer implements CentralSystemService {
7476

75-
@Autowired private CentralSystemService16_Service service;
77+
private final CentralSystemService16_Service service;
7678

7779
public BootNotificationResponse bootNotificationWithTransport(BootNotificationRequest parameters,
7880
String chargeBoxIdentity, OcppProtocol protocol) {

src/main/java/de/rwth/idsg/steve/ocpp/soap/CentralSystemService16_SoapServer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import de.rwth.idsg.steve.ocpp.OcppProtocol;
2222
import de.rwth.idsg.steve.ocpp.OcppVersion;
2323
import de.rwth.idsg.steve.service.CentralSystemService16_Service;
24+
import lombok.RequiredArgsConstructor;
2425
import lombok.extern.slf4j.Slf4j;
2526
import ocpp.cs._2015._10.AuthorizeRequest;
2627
import ocpp.cs._2015._10.AuthorizeResponse;
@@ -43,7 +44,6 @@
4344
import ocpp.cs._2015._10.StatusNotificationResponse;
4445
import ocpp.cs._2015._10.StopTransactionRequest;
4546
import ocpp.cs._2015._10.StopTransactionResponse;
46-
import org.springframework.beans.factory.annotation.Autowired;
4747
import org.springframework.stereotype.Service;
4848

4949
import jakarta.jws.WebService;
@@ -52,13 +52,15 @@
5252
import jakarta.xml.ws.Response;
5353
import jakarta.xml.ws.soap.Addressing;
5454
import jakarta.xml.ws.soap.SOAPBinding;
55+
5556
import java.util.concurrent.Future;
5657

5758
/**
5859
* @author Sevket Goekay <[email protected]>
5960
* @since 13.03.2018
6061
*/
6162
@Slf4j
63+
@RequiredArgsConstructor
6264
@Service
6365
@Addressing(enabled = true, required = false)
6466
@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)
@@ -69,7 +71,7 @@
6971
endpointInterface = "ocpp.cs._2015._10.CentralSystemService")
7072
public class CentralSystemService16_SoapServer implements CentralSystemService {
7173

72-
@Autowired private CentralSystemService16_Service service;
74+
private final CentralSystemService16_Service service;
7375

7476
public BootNotificationResponse bootNotificationWithTransport(BootNotificationRequest parameters,
7577
String chargeBoxIdentity, OcppProtocol protocol) {

src/main/java/de/rwth/idsg/steve/ocpp/soap/ClientProvider.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
import org.jetbrains.annotations.Nullable;
2929
import org.springframework.stereotype.Component;
3030

31-
import jakarta.annotation.PostConstruct;
31+
import jakarta.xml.ws.soap.SOAPBinding;
32+
3233
import javax.net.ssl.SSLContext;
3334
import javax.net.ssl.SSLSocketFactory;
34-
import jakarta.xml.ws.soap.SOAPBinding;
3535

3636
import static de.rwth.idsg.steve.SteveConfiguration.CONFIG;
3737

@@ -42,10 +42,9 @@
4242
@Component
4343
public class ClientProvider {
4444

45-
@Nullable private TLSClientParameters tlsClientParams;
45+
@Nullable private final TLSClientParameters tlsClientParams;
4646

47-
@PostConstruct
48-
private void init() {
47+
public ClientProvider() {
4948
if (shouldInitSSL()) {
5049
tlsClientParams = new TLSClientParameters();
5150
tlsClientParams.setSSLSocketFactory(setupSSL());

src/main/java/de/rwth/idsg/steve/ocpp/soap/MessageHeaderInterceptor.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import de.rwth.idsg.steve.ocpp.OcppProtocol;
2323
import de.rwth.idsg.steve.repository.OcppServerRepository;
2424
import de.rwth.idsg.steve.repository.impl.ChargePointRepositoryImpl;
25-
import de.rwth.idsg.steve.service.ChargePointHelperService;
25+
import de.rwth.idsg.steve.service.ChargePointRegistrationService;
2626
import lombok.extern.slf4j.Slf4j;
2727
import ocpp.cs._2015._10.RegistrationStatus;
2828
import org.apache.cxf.binding.soap.Soap12;
@@ -37,7 +37,6 @@
3737
import org.apache.cxf.ws.addressing.AddressingProperties;
3838
import org.apache.cxf.ws.addressing.ContextUtils;
3939
import org.apache.cxf.ws.addressing.EndpointReferenceType;
40-
import org.springframework.beans.factory.annotation.Autowired;
4140
import org.springframework.stereotype.Component;
4241

4342
import javax.xml.namespace.QName;
@@ -60,15 +59,20 @@
6059
@Component("MessageHeaderInterceptor")
6160
public class MessageHeaderInterceptor extends AbstractPhaseInterceptor<Message> {
6261

63-
@Autowired private OcppServerRepository ocppServerRepository;
64-
@Autowired private ChargePointHelperService chargePointHelperService;
65-
@Autowired private DelegatingTaskExecutor asyncTaskExecutor;
62+
private final OcppServerRepository ocppServerRepository;
63+
private final ChargePointRegistrationService chargePointRegistrationService;
64+
private final DelegatingTaskExecutor asyncTaskExecutor;
6665

6766
private static final String BOOT_OPERATION_NAME = "BootNotification";
6867
private static final String CHARGEBOX_ID_HEADER = "ChargeBoxIdentity";
6968

70-
public MessageHeaderInterceptor() {
69+
public MessageHeaderInterceptor(OcppServerRepository ocppServerRepository,
70+
ChargePointRegistrationService chargePointRegistrationService,
71+
DelegatingTaskExecutor asyncTaskExecutor) {
7172
super(Phase.PRE_INVOKE);
73+
this.ocppServerRepository = ocppServerRepository;
74+
this.chargePointRegistrationService = chargePointRegistrationService;
75+
this.asyncTaskExecutor = asyncTaskExecutor;
7276
}
7377

7478
@Override
@@ -82,7 +86,7 @@ public void handleMessage(Message message) throws Fault {
8286
QName opName = message.getExchange().getBindingOperationInfo().getOperationInfo().getName();
8387

8488
if (!BOOT_OPERATION_NAME.equals(opName.getLocalPart())) {
85-
Optional<RegistrationStatus> status = chargePointHelperService.getRegistrationStatus(chargeBoxId);
89+
Optional<RegistrationStatus> status = chargePointRegistrationService.getRegistrationStatus(chargeBoxId);
8690
boolean allow = status.isPresent() && status.get() != RegistrationStatus.REJECTED;
8791
if (!allow) {
8892
throw createAuthFault(opName);

src/main/java/de/rwth/idsg/steve/ocpp/ws/AbstractWebSocketEndpoint.java

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,21 @@
1919
package de.rwth.idsg.steve.ocpp.ws;
2020

2121
import com.google.common.base.Strings;
22-
import de.rwth.idsg.steve.config.WebSocketConfiguration;
2322
import de.rwth.idsg.steve.config.DelegatingTaskScheduler;
23+
import de.rwth.idsg.steve.config.WebSocketConfiguration;
2424
import de.rwth.idsg.steve.ocpp.OcppTransport;
2525
import de.rwth.idsg.steve.ocpp.OcppVersion;
2626
import de.rwth.idsg.steve.ocpp.ws.data.CommunicationContext;
2727
import de.rwth.idsg.steve.ocpp.ws.data.SessionContext;
28+
import de.rwth.idsg.steve.ocpp.ws.pipeline.OcppCallHandler;
29+
import de.rwth.idsg.steve.ocpp.ws.pipeline.Deserializer;
2830
import de.rwth.idsg.steve.ocpp.ws.pipeline.IncomingPipeline;
2931
import de.rwth.idsg.steve.repository.OcppServerRepository;
3032
import de.rwth.idsg.steve.service.notification.OcppStationWebSocketConnected;
3133
import de.rwth.idsg.steve.service.notification.OcppStationWebSocketDisconnected;
3234
import org.joda.time.DateTime;
33-
import org.springframework.beans.factory.annotation.Autowired;
35+
import org.slf4j.Logger;
36+
import org.slf4j.LoggerFactory;
3437
import org.springframework.context.ApplicationEventPublisher;
3538
import org.springframework.web.socket.BinaryMessage;
3639
import org.springframework.web.socket.CloseStatus;
@@ -53,31 +56,42 @@
5356
* @author Sevket Goekay <[email protected]>
5457
* @since 17.03.2015
5558
*/
56-
public abstract class AbstractWebSocketEndpoint extends ConcurrentWebSocketHandler implements SubProtocolCapable {
57-
58-
@Autowired private DelegatingTaskScheduler asyncTaskScheduler;
59-
@Autowired private OcppServerRepository ocppServerRepository;
60-
@Autowired private FutureResponseContextStore futureResponseContextStore;
61-
@Autowired private ApplicationEventPublisher applicationEventPublisher;
59+
public abstract class AbstractWebSocketEndpoint extends ConcurrentWebSocketHandler implements SubProtocolCapable, OcppCallHandler {
6260

6361
public static final String CHARGEBOX_ID_KEY = "CHARGEBOX_ID_KEY";
6462

63+
private final DelegatingTaskScheduler asyncTaskScheduler;
64+
private final OcppServerRepository ocppServerRepository;
65+
private final FutureResponseContextStore futureResponseContextStore;
66+
private final IncomingPipeline pipeline;
67+
68+
private final Logger log = LoggerFactory.getLogger(getClass());
6569
private final SessionContextStore sessionContextStore = new SessionContextStoreImpl();
6670
private final List<Consumer<String>> connectedCallbackList = new ArrayList<>();
6771
private final List<Consumer<String>> disconnectedCallbackList = new ArrayList<>();
6872
private final Object sessionContextLock = new Object();
6973

70-
private IncomingPipeline pipeline;
71-
72-
public abstract OcppVersion getVersion();
73-
74-
public void init(IncomingPipeline pipeline) {
75-
this.pipeline = pipeline;
74+
public AbstractWebSocketEndpoint(DelegatingTaskScheduler asyncTaskScheduler,
75+
OcppServerRepository ocppServerRepository,
76+
FutureResponseContextStore futureResponseContextStore,
77+
ApplicationEventPublisher applicationEventPublisher,
78+
AbstractTypeStore typeStore) {
79+
this.asyncTaskScheduler = asyncTaskScheduler;
80+
this.ocppServerRepository = ocppServerRepository;
81+
this.futureResponseContextStore = futureResponseContextStore;
82+
this.pipeline = new IncomingPipeline(new Deserializer(futureResponseContextStore, typeStore), this);
7683

7784
connectedCallbackList.add((chargeBoxId) -> applicationEventPublisher.publishEvent(new OcppStationWebSocketConnected(chargeBoxId)));
7885
disconnectedCallbackList.add((chargeBoxId) -> applicationEventPublisher.publishEvent(new OcppStationWebSocketDisconnected(chargeBoxId)));
7986
}
8087

88+
public abstract OcppVersion getVersion();
89+
90+
@Override
91+
public Logger getLogger() {
92+
return log;
93+
}
94+
8195
@Override
8296
public List<String> getSubProtocols() {
8397
return Collections.singletonList(getVersion().getValue());

0 commit comments

Comments
 (0)