This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.1.x by this push:
     new eabc6d0f49 Align error handling with annotation end point
eabc6d0f49 is described below

commit eabc6d0f495d23c64ba7bb767bfe3c12cae53955
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-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to