Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate code and reason from disconnect from server on client #212

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MIT License

Copyright (C) 2016-2018 Thomas Volden <[email protected]>

Copyright (C) 2022 Emil Melar <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
Expand Down Expand Up @@ -37,7 +37,7 @@ public WebSocketReceiver(WebSocketReceiverEvents handler) {
@Override
public void disconnect() {
receiverEvents.close();
handler.disconnected();
handler.disconnected(0, "disconnect() method called");
}

void relay(String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
MIT License

Copyright (C) 2016-2018 Thomas Volden
Copyright (C) 2022 Emil Melar <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -105,7 +106,7 @@ public void onClose(int code, String reason, boolean remote) {
logger.debug(
"On connection close (code: {}, reason: {}, remote: {})", code, reason, remote);

events.disconnected();
events.disconnected(code, reason);
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions ocpp-common/src/main/java/eu/chargetime/ocpp/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
MIT License

Copyright (C) 2016-2018 Thomas Volden
Copyright (C) 2022 Emil Melar <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -113,8 +114,8 @@ public void handleError(
}

@Override
public void handleConnectionClosed() {
if (events != null) events.connectionClosed();
public void handleConnectionClosed(int code, String reason) {
if (events != null) events.connectionClosed(code, reason);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

MIT License

Copyright (C) 2017 Emil Christopher Solli Melar
Copyright (C) 2022 Emil Melar <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -30,5 +30,5 @@ of this software and associated documentation files (the "Software"), to deal
public interface ClientEvents {
void connectionOpened();

void connectionClosed();
void connectionClosed(int code, String reason);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
MIT License

Copyright (C) 2016-2018 Thomas Volden
Copyright (C) 2022 Emil Melar <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -292,8 +293,8 @@ public void receivedMessage(Object input) {
}

@Override
public void disconnected() {
events.onDisconnected();
public void disconnected(int code, String reason) {
events.onDisconnected(code, reason);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
MIT License

Copyright (C) 2016-2018 Thomas Volden
Copyright (C) 2022 Emil Melar <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -66,8 +67,10 @@ public interface CommunicatorEvents {
*/
void onError(String id, String errorCode, String errorDescription, Object payload);

/** The connection was disconnected. */
void onDisconnected();
/** The connection was disconnected.
* @param code
* @param reason*/
void onDisconnected(int code, String reason);

/** A connection was established. */
void onConnected();
Expand Down
7 changes: 5 additions & 2 deletions ocpp-common/src/main/java/eu/chargetime/ocpp/RadioEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
MIT License

Copyright (C) 2016-2018 Thomas Volden
Copyright (C) 2022 Emil Melar <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -39,6 +40,8 @@ public interface RadioEvents {
*/
void receivedMessage(Object message);

/** Disconnected from node. */
void disconnected();
/** Disconnected from node.
* @param code
* @param reason*/
void disconnected(int code, String reason);
}
3 changes: 2 additions & 1 deletion ocpp-common/src/main/java/eu/chargetime/ocpp/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
MIT License

Copyright (C) 2016-2018 Thomas Volden <[email protected]>
Copyright (C) 2022 Emil Melar <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -143,7 +144,7 @@ public void handleError(
}

@Override
public void handleConnectionClosed() {
public void handleConnectionClosed(int code, String reason) {
Optional<UUID> sessionIdOptional = getSessionID(session);
if (sessionIdOptional.isPresent()) {
serverEvents.lostSession(sessionIdOptional.get());
Expand Down
5 changes: 3 additions & 2 deletions ocpp-common/src/main/java/eu/chargetime/ocpp/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
MIT License

Copyright (C) 2016-2018 Thomas Volden
Copyright (C) 2022 Emil Melar <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -221,8 +222,8 @@ public void onError(String id, String errorCode, String errorDescription, Object
}

@Override
public void onDisconnected() {
events.handleConnectionClosed();
public void onDisconnected(int code, String reason) {
events.handleConnectionClosed(code, reason);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
MIT License

Copyright (C) 2016-2018 Thomas Volden
Copyright (C) 2022 Emil Melar <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -59,8 +60,10 @@ public interface SessionEvents {
*/
void handleError(String uniqueId, String errorCode, String errorDescription, Object payload);

/** Handle a closed connection. */
void handleConnectionClosed();
/** Handle a closed connection.
* @param code
* @param reason*/
void handleConnectionClosed(int code, String reason);

/** Handle a opened connection. */
void handleConnectionOpened();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
MIT License

Copyright (C) 2016-2018 Thomas Volden
Copyright (C) 2022 Emil Melar <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -89,7 +90,7 @@ public void connect_connectionOpenedEvent() {

// Then
verify(events, times(1)).connectionOpened();
verify(events, never()).connectionClosed();
verify(events, never()).connectionClosed(0, null);
}

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

// When
this.eventHandler.handleConnectionClosed();
this.eventHandler.handleConnectionClosed(0, null);

// Then
verify(events, times(1)).connectionClosed();
verify(events, times(1)).connectionClosed(0, null);
verify(events, never()).connectionOpened();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Copyright (C) 2016-2018 Thomas Volden
Copyright (C) 2019 Kevin Raddatz <[email protected]>
Copyright (C) 2022 Mathias Oben <[email protected]>
Copyright (C) 2022 Emil Melar <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -307,7 +308,7 @@ public void connect() {
public void connectionOpened() {}

@Override
public void connectionClosed() {}
public void connectionClosed(int code, String reason) {}
});
} catch (Exception ex) {
ex.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
MIT License

Copyright (C) 2016-2018 Thomas Volden <[email protected]>
Copyright (C) 2022 Emil Melar <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -123,8 +124,8 @@ public void handleError(
}

@Override
public void handleConnectionClosed() {
eventHandler.handleConnectionClosed();
public void handleConnectionClosed(int code, String reason) {
eventHandler.handleConnectionClosed(code, reason);
stopTimer();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
MIT License

Copyright (C) 2016-2018 Thomas Volden <[email protected]>
Copyright (C) 2022 Emil Melar <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -57,7 +58,7 @@ public void disconnect() {
logger.info("disconnect() failed", e);
}
}
events.disconnected();
events.disconnected(0, "disconnect() method called");
receiverEvents.disconnect();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
MIT License

Copyright (C) 2016-2018 Thomas Volden <[email protected]>
Copyright (C) 2022 Emil Melar <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -55,7 +56,7 @@ public void disconnect() {
logger.info("disconnect() failed", e);
}
}
events.disconnected();
events.disconnected(0, "disconnect() method called");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
MIT License

Copyright (C) 2016-2018 Thomas Volden <[email protected]>
Copyright (C) 2022 Emil Melar <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -76,7 +77,7 @@ public void handleConnectionClosed_opened_endTimeout() throws Exception {
session.open(null, sessionEvents);

// When
sessionEvents.handleConnectionClosed();
sessionEvents.handleConnectionClosed(0, null);

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

// When
sessionEvents.handleConnectionClosed();
sessionEvents.handleConnectionClosed(0, null);

// Then
verify(timeoutTimer, times(1)).end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
MIT License

Copyright (C) 2018 Thomas Volden <[email protected]>
Copyright (C) 2022 Emil Melar <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -49,7 +50,7 @@ public void connect() {
public void connectionOpened() {}

@Override
public void connectionClosed() {}
public void connectionClosed(int code, String reason) {}
});
}

Expand Down