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();
}
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");
}
});
}
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");
}
});
}
Aggregations