Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer constructor injection #1226

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions src/main/java/de/rwth/idsg/steve/config/OcppConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import de.rwth.idsg.steve.ocpp.soap.LoggingFeatureProxy;
import de.rwth.idsg.steve.ocpp.soap.MediatorInInterceptor;
import de.rwth.idsg.steve.ocpp.soap.MessageIdInterceptor;
import ocpp.cs._2010._08.CentralSystemService;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.common.logging.LogUtils;
Expand All @@ -30,12 +31,12 @@
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.PhaseInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;

import javax.annotation.PostConstruct;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand All @@ -57,19 +58,29 @@ public class OcppConfiguration {
LogUtils.setLoggerClass(Slf4jLogger.class);
}

@Autowired private ocpp.cs._2010._08.CentralSystemService ocpp12Server;
@Autowired private ocpp.cs._2012._06.CentralSystemService ocpp15Server;
@Autowired private ocpp.cs._2015._10.CentralSystemService ocpp16Server;
private final CentralSystemService ocpp12Server;
private final ocpp.cs._2012._06.CentralSystemService ocpp15Server;
private final ocpp.cs._2015._10.CentralSystemService ocpp16Server;
private final List<Interceptor<? extends Message>> interceptors;
private final List<Feature> logging;
private final String routerEndpointPath;

@Autowired
@Qualifier("MessageHeaderInterceptor")
private PhaseInterceptor<Message> messageHeaderInterceptor;

@PostConstruct
public void init() {
List<Interceptor<? extends Message>> interceptors = asList(new MessageIdInterceptor(), messageHeaderInterceptor);
List<Feature> logging = singletonList(LoggingFeatureProxy.INSTANCE.get());
public OcppConfiguration(
CentralSystemService ocpp12Server,
ocpp.cs._2012._06.CentralSystemService ocpp15Server,
ocpp.cs._2015._10.CentralSystemService ocpp16Server,
@Qualifier("MessageHeaderInterceptor") PhaseInterceptor<Message> messageHeaderInterceptor
) {
this.ocpp12Server = ocpp12Server;
this.ocpp15Server = ocpp15Server;
this.ocpp16Server = ocpp16Server;
this.interceptors = asList(new MessageIdInterceptor(), messageHeaderInterceptor);
this.logging = singletonList(LoggingFeatureProxy.INSTANCE.get());
this.routerEndpointPath = CONFIG.getRouterEndpointPath();
}

@EventListener
public void afterStart(ContextRefreshedEvent event) {
createOcppService(ocpp12Server, "/CentralSystemServiceOCPP12", interceptors, logging);
createOcppService(ocpp15Server, "/CentralSystemServiceOCPP15", interceptors, logging);
createOcppService(ocpp16Server, "/CentralSystemServiceOCPP16", interceptors, logging);
Expand All @@ -78,7 +89,7 @@ public void init() {
// one to be created, since in MediatorInInterceptor we go over created/registered services and build a map.
//
List<Interceptor<? extends Message>> mediator = singletonList(new MediatorInInterceptor(springBus()));
createOcppService(ocpp12Server, CONFIG.getRouterEndpointPath(), mediator, Collections.emptyList());
createOcppService(ocpp12Server, routerEndpointPath, mediator, Collections.emptyList());
}

@Bean(name = Bus.DEFAULT_BUS_ID, destroyMethod = "shutdown")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import de.rwth.idsg.steve.ocpp.ws.ocpp15.Ocpp15WebSocketEndpoint;
import de.rwth.idsg.steve.ocpp.ws.ocpp16.Ocpp16WebSocketEndpoint;
import de.rwth.idsg.steve.service.ChargePointHelperService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
Expand All @@ -42,13 +42,13 @@
@EnableWebSocket
@Configuration
@Slf4j
@RequiredArgsConstructor
public class WebSocketConfiguration implements WebSocketConfigurer {

@Autowired private ChargePointHelperService chargePointHelperService;

@Autowired private Ocpp12WebSocketEndpoint ocpp12WebSocketEndpoint;
@Autowired private Ocpp15WebSocketEndpoint ocpp15WebSocketEndpoint;
@Autowired private Ocpp16WebSocketEndpoint ocpp16WebSocketEndpoint;
private final ChargePointHelperService chargePointHelperService;
private final Ocpp12WebSocketEndpoint ocpp12WebSocketEndpoint;
private final Ocpp15WebSocketEndpoint ocpp15WebSocketEndpoint;
private final Ocpp16WebSocketEndpoint ocpp16WebSocketEndpoint;

public static final String PATH_INFIX = "/websocket/CentralSystemService/";
public static final long PING_INTERVAL = TimeUnit.MINUTES.toMinutes(15);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,40 @@
import de.rwth.idsg.steve.ocpp.task.UnlockConnectorTask;
import de.rwth.idsg.steve.ocpp.task.UpdateFirmwareTask;
import de.rwth.idsg.steve.ocpp.ws.ChargePointServiceInvoker;
import de.rwth.idsg.steve.ocpp.ws.SessionContextStore;
import de.rwth.idsg.steve.ocpp.ws.ocpp12.Ocpp12TypeStore;
import de.rwth.idsg.steve.ocpp.ws.ocpp12.Ocpp12WebSocketEndpoint;
import de.rwth.idsg.steve.ocpp.ws.pipeline.OutgoingCallPipeline;
import de.rwth.idsg.steve.repository.dto.ChargePointSelect;
import ocpp.cp._2010._08.ChargePointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
* @author Sevket Goekay <[email protected]>
* @since 10.03.2018
*/
@Service
@Qualifier("ChargePointService12_Invoker")
public class ChargePointService12_InvokerImpl implements ChargePointService12_Invoker {

private final ChargePointServiceInvoker wsHelper;
private final ClientProviderWithCache<ChargePointService> soapHelper;

@Autowired
public ChargePointService12_InvokerImpl(OutgoingCallPipeline pipeline, Ocpp12WebSocketEndpoint endpoint, ClientProvider clientProvider) {
this.wsHelper = new ChargePointServiceInvoker(pipeline, endpoint, Ocpp12TypeStore.INSTANCE);
public ChargePointService12_InvokerImpl(
OutgoingCallPipeline pipeline,
@Qualifier("sessionContextStore12") SessionContextStore sessionContextStore,
ClientProvider clientProvider
) {
this.wsHelper = new ChargePointServiceInvoker(pipeline, sessionContextStore, Ocpp12TypeStore.INSTANCE);
this.soapHelper = new ClientProviderWithCache<>(clientProvider);
}

@Override
public void reset(ChargePointSelect cp, ResetTask task) {
if (cp.isSoap()) {
create(cp).resetAsync(task.getOcpp12Request(), cp.getChargeBoxId(), task.getOcpp12Handler(cp.getChargeBoxId()));
create(cp).resetAsync(
task.getOcpp12Request(), cp.getChargeBoxId(), task.getOcpp12Handler(cp.getChargeBoxId())
);
} else {
runPipeline(cp, task);
}
Expand All @@ -66,7 +72,9 @@ public void reset(ChargePointSelect cp, ResetTask task) {
@Override
public void clearCache(ChargePointSelect cp, ClearCacheTask task) {
if (cp.isSoap()) {
create(cp).clearCacheAsync(task.getOcpp12Request(), cp.getChargeBoxId(), task.getOcpp12Handler(cp.getChargeBoxId()));
create(cp).clearCacheAsync(
task.getOcpp12Request(), cp.getChargeBoxId(), task.getOcpp12Handler(cp.getChargeBoxId())
);
} else {
runPipeline(cp, task);
}
Expand All @@ -75,7 +83,9 @@ public void clearCache(ChargePointSelect cp, ClearCacheTask task) {
@Override
public void getDiagnostics(ChargePointSelect cp, GetDiagnosticsTask task) {
if (cp.isSoap()) {
create(cp).getDiagnosticsAsync(task.getOcpp12Request(), cp.getChargeBoxId(), task.getOcpp12Handler(cp.getChargeBoxId()));
create(cp).getDiagnosticsAsync(
task.getOcpp12Request(), cp.getChargeBoxId(), task.getOcpp12Handler(cp.getChargeBoxId())
);
} else {
runPipeline(cp, task);
}
Expand All @@ -84,7 +94,9 @@ public void getDiagnostics(ChargePointSelect cp, GetDiagnosticsTask task) {
@Override
public void updateFirmware(ChargePointSelect cp, UpdateFirmwareTask task) {
if (cp.isSoap()) {
create(cp).updateFirmwareAsync(task.getOcpp12Request(), cp.getChargeBoxId(), task.getOcpp12Handler(cp.getChargeBoxId()));
create(cp).updateFirmwareAsync(
task.getOcpp12Request(), cp.getChargeBoxId(), task.getOcpp12Handler(cp.getChargeBoxId())
);
} else {
runPipeline(cp, task);
}
Expand All @@ -93,7 +105,9 @@ public void updateFirmware(ChargePointSelect cp, UpdateFirmwareTask task) {
@Override
public void unlockConnector(ChargePointSelect cp, UnlockConnectorTask task) {
if (cp.isSoap()) {
create(cp).unlockConnectorAsync(task.getOcpp12Request(), cp.getChargeBoxId(), task.getOcpp12Handler(cp.getChargeBoxId()));
create(cp).unlockConnectorAsync(
task.getOcpp12Request(), cp.getChargeBoxId(), task.getOcpp12Handler(cp.getChargeBoxId())
);
} else {
runPipeline(cp, task);
}
Expand All @@ -102,7 +116,9 @@ public void unlockConnector(ChargePointSelect cp, UnlockConnectorTask task) {
@Override
public void changeAvailability(ChargePointSelect cp, ChangeAvailabilityTask task) {
if (cp.isSoap()) {
create(cp).changeAvailabilityAsync(task.getOcpp12Request(), cp.getChargeBoxId(), task.getOcpp12Handler(cp.getChargeBoxId()));
create(cp).changeAvailabilityAsync(
task.getOcpp12Request(), cp.getChargeBoxId(), task.getOcpp12Handler(cp.getChargeBoxId())
);
} else {
runPipeline(cp, task);
}
Expand All @@ -111,7 +127,9 @@ public void changeAvailability(ChargePointSelect cp, ChangeAvailabilityTask task
@Override
public void changeConfiguration(ChargePointSelect cp, ChangeConfigurationTask task) {
if (cp.isSoap()) {
create(cp).changeConfigurationAsync(task.getOcpp12Request(), cp.getChargeBoxId(), task.getOcpp12Handler(cp.getChargeBoxId()));
create(cp).changeConfigurationAsync(
task.getOcpp12Request(), cp.getChargeBoxId(), task.getOcpp12Handler(cp.getChargeBoxId())
);
} else {
runPipeline(cp, task);
}
Expand All @@ -120,7 +138,9 @@ public void changeConfiguration(ChargePointSelect cp, ChangeConfigurationTask ta
@Override
public void remoteStartTransaction(ChargePointSelect cp, RemoteStartTransactionTask task) {
if (cp.isSoap()) {
create(cp).remoteStartTransactionAsync(task.getOcpp12Request(), cp.getChargeBoxId(), task.getOcpp12Handler(cp.getChargeBoxId()));
create(cp).remoteStartTransactionAsync(
task.getOcpp12Request(), cp.getChargeBoxId(), task.getOcpp12Handler(cp.getChargeBoxId())
);
} else {
runPipeline(cp, task);
}
Expand All @@ -129,7 +149,9 @@ public void remoteStartTransaction(ChargePointSelect cp, RemoteStartTransactionT
@Override
public void remoteStopTransaction(ChargePointSelect cp, RemoteStopTransactionTask task) {
if (cp.isSoap()) {
create(cp).remoteStopTransactionAsync(task.getOcpp12Request(), cp.getChargeBoxId(), task.getOcpp12Handler(cp.getChargeBoxId()));
create(cp).remoteStopTransactionAsync(
task.getOcpp12Request(), cp.getChargeBoxId(), task.getOcpp12Handler(cp.getChargeBoxId())
);
} else {
runPipeline(cp, task);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,31 @@
import de.rwth.idsg.steve.ocpp.task.UnlockConnectorTask;
import de.rwth.idsg.steve.ocpp.task.UpdateFirmwareTask;
import de.rwth.idsg.steve.ocpp.ws.ChargePointServiceInvoker;
import de.rwth.idsg.steve.ocpp.ws.SessionContextStore;
import de.rwth.idsg.steve.ocpp.ws.ocpp15.Ocpp15TypeStore;
import de.rwth.idsg.steve.ocpp.ws.ocpp15.Ocpp15WebSocketEndpoint;
import de.rwth.idsg.steve.ocpp.ws.pipeline.OutgoingCallPipeline;
import de.rwth.idsg.steve.repository.dto.ChargePointSelect;
import ocpp.cp._2012._06.ChargePointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
* @author Sevket Goekay <[email protected]>
* @since 10.03.2018
*/
@Service
@Qualifier("ChargePointService15_Invoker")
public class ChargePointService15_InvokerImpl implements ChargePointService15_Invoker {

private final ChargePointServiceInvoker wsHelper;
private final ClientProviderWithCache<ChargePointService> soapHelper;

@Autowired
public ChargePointService15_InvokerImpl(OutgoingCallPipeline pipeline, Ocpp15WebSocketEndpoint endpoint, ClientProvider clientProvider) {
this.wsHelper = new ChargePointServiceInvoker(pipeline, endpoint, Ocpp15TypeStore.INSTANCE);
public ChargePointService15_InvokerImpl(
OutgoingCallPipeline pipeline,
@Qualifier("sessionContextStore15") SessionContextStore sessionContextStore,
ClientProvider clientProvider
) {
this.wsHelper = new ChargePointServiceInvoker(pipeline, sessionContextStore, Ocpp15TypeStore.INSTANCE);
this.soapHelper = new ClientProviderWithCache<>(clientProvider);
}

Expand Down
Loading