Skip to content

Commit 7904a1f

Browse files
committed
Add getLastError() API to MultiProtocolJSONClient
To allow determining the cause of a disconnection, add a new API to MultiProtocolJSONClient to retrieve the Exception passed from the WebSocket library in the onError() callback. This is required to allow logging the OCPP 2.0.1 Security Events "InvalidTLSVersion" and "InvalidTLSCipherSuite", by examining the type of Exception and its message string.
1 parent 63fe226 commit 7904a1f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

ocpp-v2/src/main/java/eu/chargetime/ocpp/MultiProtocolJSONClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ public void disconnect() {
206206
client.disconnect();
207207
}
208208

209+
public Exception getLastError() {
210+
return transmitter.getLastError();
211+
}
212+
209213
@Override
210214
public boolean isClosed() {
211215
return transmitter.isClosed();

ocpp-v2/src/main/java/eu/chargetime/ocpp/MultiProtocolWebSocketTransmitter.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class MultiProtocolWebSocketTransmitter implements Transmitter {
5454
private final JSONConfiguration configuration;
5555
private final Draft draft;
5656

57+
private volatile Exception lastError = null;
5758
private volatile boolean closed = true;
5859
private volatile WebSocketClient client;
5960
private WssSocketBuilder wssSocketBuilder;
@@ -71,6 +72,7 @@ public MultiProtocolWebSocketTransmitter(
7172
public void connect(String uri, RadioEvents events) {
7273
final URI resource = URI.create(uri);
7374

75+
lastError = null;
7476
Map<String, String> httpHeaders = new HashMap<>();
7577
String username = configuration.getParameter(JSONConfiguration.USERNAME_PARAMETER);
7678
Object password = configuration.getParameter(JSONConfiguration.PASSWORD_PARAMETER);
@@ -120,6 +122,7 @@ public void onClose(int code, String reason, boolean remote) {
120122

121123
@Override
122124
public void onError(Exception ex) {
125+
lastError = ex;
123126
if (ex instanceof ConnectException) {
124127
logger.error("On error triggered caused by:", ex);
125128
} else {
@@ -261,6 +264,10 @@ public void send(Object request) throws NotConnectedException {
261264
}
262265
}
263266

267+
public Exception getLastError() {
268+
return lastError;
269+
}
270+
264271
public boolean isClosed() {
265272
return closed;
266273
}

0 commit comments

Comments
 (0)