You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2025/08/20 16:21:29 UTC
(tomcat) 01/02: Align error handling with annotation end point
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 60da1470cd0a9a89fc676cee61246cb2ddabf611
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Aug 20 17:20:34 2025 +0100
Align error handling with annotation end point
---
.../classes/websocket/echo/EchoEndpoint.java | 30 ++++++++++++++--------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.java b/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.java
index 8652861aa6..e0a2eeab28 100644
--- a/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.java
+++ b/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.java
@@ -30,17 +30,19 @@ public class EchoEndpoint extends Endpoint {
@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {
RemoteEndpoint.Basic remoteEndpointBasic = session.getBasicRemote();
- session.addMessageHandler(new EchoMessageHandlerText(remoteEndpointBasic));
- session.addMessageHandler(new EchoMessageHandlerBinary(remoteEndpointBasic));
+ session.addMessageHandler(new EchoMessageHandlerText(remoteEndpointBasic, session));
+ session.addMessageHandler(new EchoMessageHandlerBinary(remoteEndpointBasic, session));
}
private static class EchoMessageHandlerText
implements MessageHandler.Partial<String> {
private final RemoteEndpoint.Basic remoteEndpointBasic;
+ private final Session session;
- private EchoMessageHandlerText(RemoteEndpoint.Basic remoteEndpointBasic) {
+ private EchoMessageHandlerText(RemoteEndpoint.Basic remoteEndpointBasic, Session session) {
this.remoteEndpointBasic = remoteEndpointBasic;
+ this.session = session;
}
@Override
@@ -49,9 +51,12 @@ public class EchoEndpoint extends Endpoint {
if (remoteEndpointBasic != null) {
remoteEndpointBasic.sendText(message, last);
}
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ } catch (IOException ioe) {
+ try {
+ session.close();
+ } catch (IOException ignore) {
+ // Ignore
+ }
}
}
}
@@ -60,9 +65,11 @@ public class EchoEndpoint extends Endpoint {
implements MessageHandler.Partial<ByteBuffer> {
private final RemoteEndpoint.Basic remoteEndpointBasic;
+ private final Session session;
- private EchoMessageHandlerBinary(RemoteEndpoint.Basic remoteEndpointBasic) {
+ private EchoMessageHandlerBinary(RemoteEndpoint.Basic remoteEndpointBasic, Session session) {
this.remoteEndpointBasic = remoteEndpointBasic;
+ this.session = session;
}
@Override
@@ -71,9 +78,12 @@ public class EchoEndpoint extends Endpoint {
if (remoteEndpointBasic != null) {
remoteEndpointBasic.sendBinary(message, last);
}
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ } catch (IOException ioe) {
+ try {
+ session.close();
+ } catch (IOException ignore) {
+ // Ignore
+ }
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org