use of eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler in project Java-OCA-OCPP by ChargeTimeEU.
the class SOAPServerSample method started.
public void started() throws Exception {
if (server != null)
return;
// The core profile is mandatory
core = new ServerCoreProfile(new ServerCoreEventHandler() {
@Override
public AuthorizeConfirmation handleAuthorizeRequest(UUID sessionIndex, AuthorizeRequest request) {
System.out.println(request);
return new AuthorizeConfirmation();
}
@Override
public BootNotificationConfirmation handleBootNotificationRequest(UUID sessionIndex, BootNotificationRequest request) {
System.out.println(request);
// returning null means unsupported feature
return null;
}
@Override
public DataTransferConfirmation handleDataTransferRequest(UUID sessionIndex, DataTransferRequest request) {
System.out.println(request);
// returning null means unsupported feature
return null;
}
@Override
public HeartbeatConfirmation handleHeartbeatRequest(UUID sessionIndex, HeartbeatRequest request) {
System.out.println(request);
// returning null means unsupported feature
return null;
}
@Override
public MeterValuesConfirmation handleMeterValuesRequest(UUID sessionIndex, MeterValuesRequest request) {
System.out.println(request);
// returning null means unsupported feature
return null;
}
@Override
public StartTransactionConfirmation handleStartTransactionRequest(UUID sessionIndex, StartTransactionRequest request) {
System.out.println(request);
// returning null means unsupported feature
return null;
}
@Override
public StatusNotificationConfirmation handleStatusNotificationRequest(UUID sessionIndex, StatusNotificationRequest request) {
System.out.println(request);
// returning null means unsupported feature
return null;
}
@Override
public StopTransactionConfirmation handleStopTransactionRequest(UUID sessionIndex, StopTransactionRequest request) {
System.out.println(request);
// returning null means unsupported feature
return null;
}
});
server = new SOAPServer(core);
server.open("localhost", 8887, new ServerEvents() {
@Override
public void newSession(UUID sessionIndex, SessionInformation information) {
// sessionIndex is used to send messages.
System.out.println("New session " + sessionIndex + ": " + information.getIdentifier());
}
@Override
public void lostSession(UUID sessionIndex) {
System.out.println("Session " + sessionIndex + " lost connection");
}
});
}
use of eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler in project Java-OCA-OCPP by ChargeTimeEU.
the class DummyHandlers method createServerCoreEventHandler.
public ServerCoreEventHandler createServerCoreEventHandler() {
return new ServerCoreEventHandler() {
@Override
public AuthorizeConfirmation handleAuthorizeRequest(UUID sessionIndex, AuthorizeRequest request) {
receivedRequest = request;
AuthorizeConfirmation confirmation = new AuthorizeConfirmation();
IdTagInfo tagInfo = new IdTagInfo();
tagInfo.setStatus(AuthorizationStatus.Accepted);
Calendar calendar = Calendar.getInstance();
calendar.set(2018, 1, 1, 1, 1, 1);
tagInfo.setExpiryDate(calendar);
confirmation.setIdTagInfo(tagInfo);
return failurePoint(confirmation);
}
@Override
public BootNotificationConfirmation handleBootNotificationRequest(UUID sessionIndex, BootNotificationRequest request) {
receivedRequest = request;
BootNotificationConfirmation confirmation = new BootNotificationConfirmation();
try {
confirmation.setInterval(1);
} catch (Exception e) {
e.printStackTrace();
}
confirmation.setCurrentTime(Calendar.getInstance());
confirmation.setStatus(RegistrationStatus.Accepted);
return failurePoint(confirmation);
}
@Override
public DataTransferConfirmation handleDataTransferRequest(UUID sessionIndex, DataTransferRequest request) {
receivedRequest = request;
DataTransferConfirmation confirmation = new DataTransferConfirmation();
confirmation.setStatus(DataTransferStatus.Accepted);
return failurePoint(confirmation);
}
@Override
public HeartbeatConfirmation handleHeartbeatRequest(UUID sessionIndex, HeartbeatRequest request) {
receivedRequest = request;
HeartbeatConfirmation confirmation = new HeartbeatConfirmation();
confirmation.setCurrentTime(Calendar.getInstance());
return failurePoint(confirmation);
}
@Override
public MeterValuesConfirmation handleMeterValuesRequest(UUID sessionIndex, MeterValuesRequest request) {
receivedRequest = request;
return failurePoint(new MeterValuesConfirmation());
}
@Override
public StartTransactionConfirmation handleStartTransactionRequest(UUID sessionIndex, StartTransactionRequest request) {
receivedRequest = request;
IdTagInfo tagInfo = new IdTagInfo();
tagInfo.setStatus(AuthorizationStatus.Accepted);
StartTransactionConfirmation confirmation = new StartTransactionConfirmation();
confirmation.setIdTagInfo(tagInfo);
return failurePoint(confirmation);
}
@Override
public StatusNotificationConfirmation handleStatusNotificationRequest(UUID sessionIndex, StatusNotificationRequest request) {
receivedRequest = request;
StatusNotificationConfirmation confirmation = new StatusNotificationConfirmation();
return failurePoint(confirmation);
}
@Override
public StopTransactionConfirmation handleStopTransactionRequest(UUID sessionIndex, StopTransactionRequest request) {
receivedRequest = request;
StopTransactionConfirmation confirmation = new StopTransactionConfirmation();
return failurePoint(confirmation);
}
};
}
use of eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler in project Java-OCA-OCPP by ChargeTimeEU.
the class JSONServerSample method started.
public void started() throws Exception {
if (server != null)
return;
// The core profile is mandatory
core = new ServerCoreProfile(new ServerCoreEventHandler() {
@Override
public AuthorizeConfirmation handleAuthorizeRequest(UUID sessionIndex, AuthorizeRequest request) {
System.out.println(request);
return new AuthorizeConfirmation();
}
@Override
public BootNotificationConfirmation handleBootNotificationRequest(UUID sessionIndex, BootNotificationRequest request) {
System.out.println(request);
// returning null means unsupported feature
return null;
}
@Override
public DataTransferConfirmation handleDataTransferRequest(UUID sessionIndex, DataTransferRequest request) {
System.out.println(request);
// returning null means unsupported feature
return null;
}
@Override
public HeartbeatConfirmation handleHeartbeatRequest(UUID sessionIndex, HeartbeatRequest request) {
System.out.println(request);
// returning null means unsupported feature
return null;
}
@Override
public MeterValuesConfirmation handleMeterValuesRequest(UUID sessionIndex, MeterValuesRequest request) {
System.out.println(request);
// returning null means unsupported feature
return null;
}
@Override
public StartTransactionConfirmation handleStartTransactionRequest(UUID sessionIndex, StartTransactionRequest request) {
System.out.println(request);
// returning null means unsupported feature
return null;
}
@Override
public StatusNotificationConfirmation handleStatusNotificationRequest(UUID sessionIndex, StatusNotificationRequest request) {
System.out.println(request);
// returning null means unsupported feature
return null;
}
@Override
public StopTransactionConfirmation handleStopTransactionRequest(UUID sessionIndex, StopTransactionRequest request) {
System.out.println(request);
// returning null means unsupported feature
return null;
}
});
server = new JSONServer(core);
server.open("localhost", 8887, new ServerEvents() {
@Override
public void newSession(UUID sessionIndex, SessionInformation information) {
// sessionIndex is used to send messages.
System.out.println("New session " + sessionIndex + ": " + information.getIdentifier());
}
@Override
public void lostSession(UUID sessionIndex) {
System.out.println("Session " + sessionIndex + " lost connection");
}
});
}
Aggregations