Skip to content

Commit

Permalink
implement onError method for websocket connection (#5730)
Browse files Browse the repository at this point in the history
Signed-off-by: Kai Kreuzer <kai@openhab.org>
  • Loading branch information
kaikreuzer authored and wborn committed Jun 16, 2019
1 parent 5008890 commit c11517a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
Expand Down Expand Up @@ -160,6 +161,12 @@ public void onClose(int statusCode, String reason) {
});
}
}

@OnWebSocketError
public void onError(Throwable error) {
onClose(0, error.getMessage());
}

}

private void sendMessage(String str) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
Expand Down Expand Up @@ -191,6 +192,11 @@ public void onClose(int statusCode, String reason) {
}
});
}

@OnWebSocketError
public void onError(Throwable error) {
onClose(0, error.getMessage());
}
}

private void sendMessage(String str) throws IOException {
Expand Down

0 comments on commit c11517a

Please sign in to comment.