Skip to content

Commit 9980299

Browse files
committed
Propagate code and reason from disconnect from server on client
1 parent 44def2e commit 9980299

File tree

17 files changed

+50
-29
lines changed

17 files changed

+50
-29
lines changed

OCPP-J/src/main/java/eu/chargetime/ocpp/WebSocketReceiver.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
MIT License
66
77
Copyright (C) 2016-2018 Thomas Volden <[email protected]>
8-
8+
Copyright (C) 2022 Emil Melar <[email protected]>
99
Permission is hereby granted, free of charge, to any person obtaining a copy
1010
of this software and associated documentation files (the "Software"), to deal
1111
in the Software without restriction, including without limitation the rights
@@ -37,7 +37,7 @@ public WebSocketReceiver(WebSocketReceiverEvents handler) {
3737
@Override
3838
public void disconnect() {
3939
receiverEvents.close();
40-
handler.disconnected();
40+
handler.disconnected(0, "disconnect() method called");
4141
}
4242

4343
void relay(String message) {

OCPP-J/src/main/java/eu/chargetime/ocpp/WebSocketTransmitter.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
MIT License
77
88
Copyright (C) 2016-2018 Thomas Volden
9+
Copyright (C) 2022 Emil Melar <[email protected]>
910
1011
Permission is hereby granted, free of charge, to any person obtaining a copy
1112
of this software and associated documentation files (the "Software"), to deal
@@ -105,7 +106,7 @@ public void onClose(int code, String reason, boolean remote) {
105106
logger.debug(
106107
"On connection close (code: {}, reason: {}, remote: {})", code, reason, remote);
107108

108-
events.disconnected();
109+
events.disconnected(code, reason);
109110
}
110111

111112
@Override

ocpp-common/src/main/java/eu/chargetime/ocpp/Client.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
MIT License
77
88
Copyright (C) 2016-2018 Thomas Volden
9+
Copyright (C) 2022 Emil Melar <[email protected]>
910
1011
Permission is hereby granted, free of charge, to any person obtaining a copy
1112
of this software and associated documentation files (the "Software"), to deal
@@ -113,8 +114,8 @@ public void handleError(
113114
}
114115

115116
@Override
116-
public void handleConnectionClosed() {
117-
if (events != null) events.connectionClosed();
117+
public void handleConnectionClosed(int code, String reason) {
118+
if (events != null) events.connectionClosed(code, reason);
118119
}
119120

120121
@Override

ocpp-common/src/main/java/eu/chargetime/ocpp/ClientEvents.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
MIT License
88
9-
Copyright (C) 2017 Emil Christopher Solli Melar
9+
Copyright (C) 2022 Emil Melar <[email protected]>
1010
1111
Permission is hereby granted, free of charge, to any person obtaining a copy
1212
of this software and associated documentation files (the "Software"), to deal
@@ -30,5 +30,5 @@ of this software and associated documentation files (the "Software"), to deal
3030
public interface ClientEvents {
3131
void connectionOpened();
3232

33-
void connectionClosed();
33+
void connectionClosed(int code, String reason);
3434
}

ocpp-common/src/main/java/eu/chargetime/ocpp/Communicator.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
MIT License
77
88
Copyright (C) 2016-2018 Thomas Volden
9+
Copyright (C) 2022 Emil Melar <[email protected]>
910
1011
Permission is hereby granted, free of charge, to any person obtaining a copy
1112
of this software and associated documentation files (the "Software"), to deal
@@ -292,8 +293,8 @@ public void receivedMessage(Object input) {
292293
}
293294

294295
@Override
295-
public void disconnected() {
296-
events.onDisconnected();
296+
public void disconnected(int code, String reason) {
297+
events.onDisconnected(code, reason);
297298
}
298299
}
299300

ocpp-common/src/main/java/eu/chargetime/ocpp/CommunicatorEvents.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
MIT License
88
99
Copyright (C) 2016-2018 Thomas Volden
10+
Copyright (C) 2022 Emil Melar <[email protected]>
1011
1112
Permission is hereby granted, free of charge, to any person obtaining a copy
1213
of this software and associated documentation files (the "Software"), to deal
@@ -66,8 +67,10 @@ public interface CommunicatorEvents {
6667
*/
6768
void onError(String id, String errorCode, String errorDescription, Object payload);
6869

69-
/** The connection was disconnected. */
70-
void onDisconnected();
70+
/** The connection was disconnected.
71+
* @param code
72+
* @param reason*/
73+
void onDisconnected(int code, String reason);
7174

7275
/** A connection was established. */
7376
void onConnected();

ocpp-common/src/main/java/eu/chargetime/ocpp/RadioEvents.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
MIT License
88
99
Copyright (C) 2016-2018 Thomas Volden
10+
Copyright (C) 2022 Emil Melar <[email protected]>
1011
1112
Permission is hereby granted, free of charge, to any person obtaining a copy
1213
of this software and associated documentation files (the "Software"), to deal
@@ -39,6 +40,8 @@ public interface RadioEvents {
3940
*/
4041
void receivedMessage(Object message);
4142

42-
/** Disconnected from node. */
43-
void disconnected();
43+
/** Disconnected from node.
44+
* @param code
45+
* @param reason*/
46+
void disconnected(int code, String reason);
4447
}

ocpp-common/src/main/java/eu/chargetime/ocpp/Server.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
MIT License
66
77
Copyright (C) 2016-2018 Thomas Volden <[email protected]>
8+
Copyright (C) 2022 Emil Melar <[email protected]>
89
910
Permission is hereby granted, free of charge, to any person obtaining a copy
1011
of this software and associated documentation files (the "Software"), to deal
@@ -143,7 +144,7 @@ public void handleError(
143144
}
144145

145146
@Override
146-
public void handleConnectionClosed() {
147+
public void handleConnectionClosed(int code, String reason) {
147148
Optional<UUID> sessionIdOptional = getSessionID(session);
148149
if (sessionIdOptional.isPresent()) {
149150
serverEvents.lostSession(sessionIdOptional.get());

ocpp-common/src/main/java/eu/chargetime/ocpp/Session.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
MIT License
77
88
Copyright (C) 2016-2018 Thomas Volden
9+
Copyright (C) 2022 Emil Melar <[email protected]>
910
1011
Permission is hereby granted, free of charge, to any person obtaining a copy
1112
of this software and associated documentation files (the "Software"), to deal
@@ -221,8 +222,8 @@ public void onError(String id, String errorCode, String errorDescription, Object
221222
}
222223

223224
@Override
224-
public void onDisconnected() {
225-
events.handleConnectionClosed();
225+
public void onDisconnected(int code, String reason) {
226+
events.handleConnectionClosed(code, reason);
226227
}
227228

228229
@Override

ocpp-common/src/main/java/eu/chargetime/ocpp/SessionEvents.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
MIT License
1111
1212
Copyright (C) 2016-2018 Thomas Volden
13+
Copyright (C) 2022 Emil Melar <[email protected]>
1314
1415
Permission is hereby granted, free of charge, to any person obtaining a copy
1516
of this software and associated documentation files (the "Software"), to deal
@@ -59,8 +60,10 @@ public interface SessionEvents {
5960
*/
6061
void handleError(String uniqueId, String errorCode, String errorDescription, Object payload);
6162

62-
/** Handle a closed connection. */
63-
void handleConnectionClosed();
63+
/** Handle a closed connection.
64+
* @param code
65+
* @param reason*/
66+
void handleConnectionClosed(int code, String reason);
6467

6568
/** Handle a opened connection. */
6669
void handleConnectionOpened();

ocpp-common/src/test/java/eu/chargetime/ocpp/test/ClientTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
MIT License
77
88
Copyright (C) 2016-2018 Thomas Volden
9+
Copyright (C) 2022 Emil Melar <[email protected]>
910
1011
Permission is hereby granted, free of charge, to any person obtaining a copy
1112
of this software and associated documentation files (the "Software"), to deal
@@ -89,7 +90,7 @@ public void connect_connectionOpenedEvent() {
8990

9091
// Then
9192
verify(events, times(1)).connectionOpened();
92-
verify(events, never()).connectionClosed();
93+
verify(events, never()).connectionClosed(0, null);
9394
}
9495

9596
@Test
@@ -98,10 +99,10 @@ public void connect_connectionClosedEvent() {
9899
client.connect(null, events);
99100

100101
// When
101-
this.eventHandler.handleConnectionClosed();
102+
this.eventHandler.handleConnectionClosed(0, null);
102103

103104
// Then
104-
verify(events, times(1)).connectionClosed();
105+
verify(events, times(1)).connectionClosed(0, null);
105106
verify(events, never()).connectionOpened();
106107
}
107108

ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeChargePoint.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Copyright (C) 2016-2018 Thomas Volden
1010
Copyright (C) 2019 Kevin Raddatz <[email protected]>
1111
Copyright (C) 2022 Mathias Oben <[email protected]>
12+
Copyright (C) 2022 Emil Melar <[email protected]>
1213
1314
Permission is hereby granted, free of charge, to any person obtaining a copy
1415
of this software and associated documentation files (the "Software"), to deal
@@ -307,7 +308,7 @@ public void connect() {
307308
public void connectionOpened() {}
308309

309310
@Override
310-
public void connectionClosed() {}
311+
public void connectionClosed(int code, String reason) {}
311312
});
312313
} catch (Exception ex) {
313314
ex.printStackTrace();

ocpp-v1_6/src/main/java/eu/chargetime/ocpp/TimeoutSessionDecorator.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
MIT License
66
77
Copyright (C) 2016-2018 Thomas Volden <[email protected]>
8+
Copyright (C) 2022 Emil Melar <[email protected]>
89
910
Permission is hereby granted, free of charge, to any person obtaining a copy
1011
of this software and associated documentation files (the "Software"), to deal
@@ -123,8 +124,8 @@ public void handleError(
123124
}
124125

125126
@Override
126-
public void handleConnectionClosed() {
127-
eventHandler.handleConnectionClosed();
127+
public void handleConnectionClosed(int code, String reason) {
128+
eventHandler.handleConnectionClosed(code, reason);
128129
stopTimer();
129130
}
130131

ocpp-v1_6/src/main/java/eu/chargetime/ocpp/WebServiceReceiver.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
MIT License
66
77
Copyright (C) 2016-2018 Thomas Volden <[email protected]>
8+
Copyright (C) 2022 Emil Melar <[email protected]>
89
910
Permission is hereby granted, free of charge, to any person obtaining a copy
1011
of this software and associated documentation files (the "Software"), to deal
@@ -57,7 +58,7 @@ public void disconnect() {
5758
logger.info("disconnect() failed", e);
5859
}
5960
}
60-
events.disconnected();
61+
events.disconnected(0, "disconnect() method called");
6162
receiverEvents.disconnect();
6263
}
6364

ocpp-v1_6/src/main/java/eu/chargetime/ocpp/WebServiceTransmitter.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
MIT License
1414
1515
Copyright (C) 2016-2018 Thomas Volden <[email protected]>
16+
Copyright (C) 2022 Emil Melar <[email protected]>
1617
1718
Permission is hereby granted, free of charge, to any person obtaining a copy
1819
of this software and associated documentation files (the "Software"), to deal
@@ -55,7 +56,7 @@ public void disconnect() {
5556
logger.info("disconnect() failed", e);
5657
}
5758
}
58-
events.disconnected();
59+
events.disconnected(0, "disconnect() method called");
5960
}
6061

6162
@Override

ocpp-v1_6/src/test/java/eu/chargetime/ocpp/test/TimeoutSessionTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
MIT License
2020
2121
Copyright (C) 2016-2018 Thomas Volden <[email protected]>
22+
Copyright (C) 2022 Emil Melar <[email protected]>
2223
2324
Permission is hereby granted, free of charge, to any person obtaining a copy
2425
of this software and associated documentation files (the "Software"), to deal
@@ -76,7 +77,7 @@ public void handleConnectionClosed_opened_endTimeout() throws Exception {
7677
session.open(null, sessionEvents);
7778

7879
// When
79-
sessionEvents.handleConnectionClosed();
80+
sessionEvents.handleConnectionClosed(0, null);
8081

8182
// Then
8283
verify(timeoutTimer, times(1)).end();
@@ -100,7 +101,7 @@ public void handleConnectionClosed_accepted_endTimeout() throws Exception {
100101
session.accept(sessionEvents);
101102

102103
// When
103-
sessionEvents.handleConnectionClosed();
104+
sessionEvents.handleConnectionClosed(0, null);
104105

105106
// Then
106107
verify(timeoutTimer, times(1)).end();

ocpp-v2_0-test/src/main/java/eu/chargetime/ocpp/test/FakeChargePoint.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
MIT License
66
77
Copyright (C) 2018 Thomas Volden <[email protected]>
8+
Copyright (C) 2022 Emil Melar <[email protected]>
89
910
Permission is hereby granted, free of charge, to any person obtaining a copy
1011
of this software and associated documentation files (the "Software"), to deal
@@ -49,7 +50,7 @@ public void connect() {
4950
public void connectionOpened() {}
5051

5152
@Override
52-
public void connectionClosed() {}
53+
public void connectionClosed(int code, String reason) {}
5354
});
5455
}
5556

0 commit comments

Comments
 (0)