From 1479cbe718db84b5e5aab1c6191f22c7d67ff72e Mon Sep 17 00:00:00 2001 From: Mathias Oben Date: Mon, 28 Feb 2022 13:51:30 +0100 Subject: [PATCH] Expose a client's session ID --- ocpp-common/src/main/java/eu/chargetime/ocpp/Client.java | 7 ++++++- .../main/java/eu/chargetime/ocpp/test/JSONTestClient.java | 6 ++++++ .../main/java/eu/chargetime/ocpp/test/SOAPTestClient.java | 6 ++++++ ocpp-v1_6/src/main/java/eu/chargetime/ocpp/IClientAPI.java | 4 ++++ ocpp-v1_6/src/main/java/eu/chargetime/ocpp/JSONClient.java | 6 ++++++ ocpp-v1_6/src/main/java/eu/chargetime/ocpp/SOAPClient.java | 6 ++++++ ocpp-v2_0/src/main/java/eu/chargetime/ocpp/IClientAPI.java | 4 ++++ ocpp-v2_0/src/main/java/eu/chargetime/ocpp/JSONClient.java | 6 ++++++ 8 files changed, 44 insertions(+), 1 deletion(-) diff --git a/ocpp-common/src/main/java/eu/chargetime/ocpp/Client.java b/ocpp-common/src/main/java/eu/chargetime/ocpp/Client.java index 43ca0127e..ec47b63ce 100644 --- a/ocpp-common/src/main/java/eu/chargetime/ocpp/Client.java +++ b/ocpp-common/src/main/java/eu/chargetime/ocpp/Client.java @@ -30,6 +30,7 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.Request; import java.util.Optional; +import java.util.UUID; import java.util.concurrent.CompletableFuture; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -89,7 +90,7 @@ public void handleConfirmation(String uniqueId, Confirmation confirmation) { public Confirmation handleRequest(Request request) throws UnsupportedFeatureException { Optional featureOptional = featureRepository.findFeature(request); if (featureOptional.isPresent()) { - return featureOptional.get().handleRequest(null, request); + return featureOptional.get().handleRequest(getSessionId(), request); } else { throw new UnsupportedFeatureException(); } @@ -160,4 +161,8 @@ public CompletableFuture send(Request request) session.sendRequest(featureOptional.get().getAction(), request, id); return promise; } + + public UUID getSessionId() { + return this.session.getSessionId(); + } } diff --git a/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/JSONTestClient.java b/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/JSONTestClient.java index fc2574dce..64ffe055d 100644 --- a/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/JSONTestClient.java +++ b/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/JSONTestClient.java @@ -31,6 +31,7 @@ import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.Request; import java.util.Collections; +import java.util.UUID; import java.util.concurrent.CompletionStage; import org.java_websocket.drafts.Draft; import org.java_websocket.drafts.Draft_6455; @@ -88,4 +89,9 @@ public void disconnect() { public boolean isClosed() { return transmitter.isClosed(); } + + @Override + public UUID getSessionId() { + return client.getSessionId(); + } } diff --git a/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/SOAPTestClient.java b/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/SOAPTestClient.java index 291edc77e..b0bacef53 100644 --- a/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/SOAPTestClient.java +++ b/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/SOAPTestClient.java @@ -35,6 +35,7 @@ of this software and associated documentation files (the "Software"), to deal import java.io.IOException; import java.net.InetSocketAddress; import java.net.URL; +import java.util.UUID; import java.util.concurrent.CompletionStage; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -116,6 +117,11 @@ public boolean isClosed() { return transmitter.isClosed(); } + @Override + public UUID getSessionId() { + return client.getSessionId(); + } + private int getPort() { return callback.getPort() == -1 ? 8000 : callback.getPort(); } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/IClientAPI.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/IClientAPI.java index 375c455f1..43d4a5def 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/IClientAPI.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/IClientAPI.java @@ -28,6 +28,8 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.feature.profile.Profile; import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.Request; + +import java.util.UUID; import java.util.concurrent.CompletionStage; public interface IClientAPI { @@ -41,4 +43,6 @@ CompletionStage send(Request request) void disconnect(); boolean isClosed(); + + UUID getSessionId(); } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/JSONClient.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/JSONClient.java index c70c8e2d7..9be980e3c 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/JSONClient.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/JSONClient.java @@ -8,6 +8,7 @@ import eu.chargetime.ocpp.wss.WssSocketBuilder; import java.io.IOException; import java.util.Collections; +import java.util.UUID; import java.util.concurrent.CompletionStage; import javax.net.ssl.SSLContext; import org.java_websocket.drafts.Draft; @@ -171,4 +172,9 @@ public void disconnect() { public boolean isClosed() { return transmitter.isClosed(); } + + @Override + public UUID getSessionId() { + return client.getSessionId(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/SOAPClient.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/SOAPClient.java index 0dbde5c7f..f1a2a0af3 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/SOAPClient.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/SOAPClient.java @@ -34,6 +34,7 @@ of this software and associated documentation files (the "Software"), to deal import java.io.IOException; import java.net.InetSocketAddress; import java.net.URL; +import java.util.UUID; import java.util.concurrent.CompletionStage; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -123,6 +124,11 @@ public boolean isClosed() { return transmitter.isClosed(); } + @Override + public UUID getSessionId() { + return client.getSessionId(); + } + private int getPort() { return callback.getPort() == -1 ? 8000 : callback.getPort(); } diff --git a/ocpp-v2_0/src/main/java/eu/chargetime/ocpp/IClientAPI.java b/ocpp-v2_0/src/main/java/eu/chargetime/ocpp/IClientAPI.java index c0cefdbd6..cd4c04934 100644 --- a/ocpp-v2_0/src/main/java/eu/chargetime/ocpp/IClientAPI.java +++ b/ocpp-v2_0/src/main/java/eu/chargetime/ocpp/IClientAPI.java @@ -28,6 +28,8 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.feature.Feature; import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.Request; + +import java.util.UUID; import java.util.concurrent.CompletionStage; public interface IClientAPI { @@ -41,4 +43,6 @@ CompletionStage send(Request request) void disconnect(); boolean isClosed(); + + UUID getSessionId(); } diff --git a/ocpp-v2_0/src/main/java/eu/chargetime/ocpp/JSONClient.java b/ocpp-v2_0/src/main/java/eu/chargetime/ocpp/JSONClient.java index 76424b9b6..3f8db7efa 100644 --- a/ocpp-v2_0/src/main/java/eu/chargetime/ocpp/JSONClient.java +++ b/ocpp-v2_0/src/main/java/eu/chargetime/ocpp/JSONClient.java @@ -32,6 +32,7 @@ import eu.chargetime.ocpp.wss.WssSocketBuilder; import java.io.IOException; import java.util.Collections; +import java.util.UUID; import java.util.concurrent.CompletionStage; import javax.net.ssl.SSLContext; import org.java_websocket.drafts.Draft; @@ -155,4 +156,9 @@ public void disconnect() { public boolean isClosed() { return transmitter.isClosed(); } + + @Override + public UUID getSessionId() { + return client.getSessionId(); + } }