Search in sources :

Example 1 with ServerCoreEventHandler

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");
        }
    });
}
Also used : ServerCoreProfile(eu.chargetime.ocpp.feature.profile.ServerCoreProfile) ServerEvents(eu.chargetime.ocpp.ServerEvents) SessionInformation(eu.chargetime.ocpp.model.SessionInformation) ServerCoreEventHandler(eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler) UUID(java.util.UUID) SOAPServer(eu.chargetime.ocpp.SOAPServer)

Example 2 with ServerCoreEventHandler

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);
        }
    };
}
Also used : Calendar(java.util.Calendar) ServerCoreEventHandler(eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler) UUID(java.util.UUID)

Example 3 with ServerCoreEventHandler

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");
        }
    });
}
Also used : ServerCoreProfile(eu.chargetime.ocpp.feature.profile.ServerCoreProfile) ServerEvents(eu.chargetime.ocpp.ServerEvents) SessionInformation(eu.chargetime.ocpp.model.SessionInformation) ServerCoreEventHandler(eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler) UUID(java.util.UUID) JSONServer(eu.chargetime.ocpp.JSONServer)

Aggregations

ServerCoreEventHandler (eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler)3 UUID (java.util.UUID)3 ServerEvents (eu.chargetime.ocpp.ServerEvents)2 ServerCoreProfile (eu.chargetime.ocpp.feature.profile.ServerCoreProfile)2 SessionInformation (eu.chargetime.ocpp.model.SessionInformation)2 JSONServer (eu.chargetime.ocpp.JSONServer)1 SOAPServer (eu.chargetime.ocpp.SOAPServer)1 Calendar (java.util.Calendar)1