Search in sources :

Example 1 with SessionInformation

use of eu.chargetime.ocpp.model.SessionInformation in project Java-OCA-OCPP by ChargeTimeEU.

the class WebSocketListener method open.

@Override
public void open(String hostname, int port, ListenerEvents handler) {
    server = new WebSocketServer(new InetSocketAddress(hostname, port), drafts) {

        @Override
        public void onOpen(WebSocket webSocket, ClientHandshake clientHandshake) {
            WebSocketReceiver receiver = new WebSocketReceiver(message -> webSocket.send(message));
            sockets.put(webSocket, receiver);
            SessionInformation information = new SessionInformation.Builder().Identifier(clientHandshake.getResourceDescriptor()).InternetAddress(webSocket.getRemoteSocketAddress()).build();
            handler.newSession(sessionFactory.createSession(new JSONCommunicator(receiver)), information);
        }

        @Override
        public void onClose(WebSocket webSocket, int i, String s, boolean b) {
            sockets.get(webSocket).disconnect();
            sockets.remove(webSocket);
        }

        @Override
        public void onMessage(WebSocket webSocket, String s) {
            sockets.get(webSocket).relay(s);
        }

        @Override
        public void onError(WebSocket webSocket, Exception e) {
        }

        @Override
        public void onStart() {
        }
    };
    server.start();
}
Also used : SSLContext(javax.net.ssl.SSLContext) Arrays(java.util.Arrays) ClientHandshake(org.java_websocket.handshake.ClientHandshake) WebSocketServer(org.java_websocket.server.WebSocketServer) HashMap(java.util.HashMap) Draft(org.java_websocket.drafts.Draft) InetSocketAddress(java.net.InetSocketAddress) SessionInformation(eu.chargetime.ocpp.model.SessionInformation) List(java.util.List) Logger(org.apache.logging.log4j.Logger) WebSocket(org.java_websocket.WebSocket) DefaultSSLWebSocketServerFactory(org.java_websocket.server.DefaultSSLWebSocketServerFactory) LogManager(org.apache.logging.log4j.LogManager) WebSocketServer(org.java_websocket.server.WebSocketServer) InetSocketAddress(java.net.InetSocketAddress) ClientHandshake(org.java_websocket.handshake.ClientHandshake) WebSocket(org.java_websocket.WebSocket) SessionInformation(eu.chargetime.ocpp.model.SessionInformation)

Example 2 with SessionInformation

use of eu.chargetime.ocpp.model.SessionInformation 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 3 with SessionInformation

use of eu.chargetime.ocpp.model.SessionInformation 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

SessionInformation (eu.chargetime.ocpp.model.SessionInformation)3 ServerEvents (eu.chargetime.ocpp.ServerEvents)2 ServerCoreEventHandler (eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler)2 ServerCoreProfile (eu.chargetime.ocpp.feature.profile.ServerCoreProfile)2 UUID (java.util.UUID)2 JSONServer (eu.chargetime.ocpp.JSONServer)1 SOAPServer (eu.chargetime.ocpp.SOAPServer)1 InetSocketAddress (java.net.InetSocketAddress)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 SSLContext (javax.net.ssl.SSLContext)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 WebSocket (org.java_websocket.WebSocket)1 Draft (org.java_websocket.drafts.Draft)1 ClientHandshake (org.java_websocket.handshake.ClientHandshake)1 DefaultSSLWebSocketServerFactory (org.java_websocket.server.DefaultSSLWebSocketServerFactory)1 WebSocketServer (org.java_websocket.server.WebSocketServer)1