@@ -93,18 +93,12 @@ private static URI uri(final int port, final String path) {
9393 return URI .create ("ws://localhost:" + port + path );
9494 }
9595
96- /**
97- * Build a client and ensure it is started before use.
98- */
9996 private static CloseableWebSocketClient newClient () {
10097 final CloseableWebSocketClient client = WebSocketClientBuilder .create ().build ();
10198 client .start (); // start reactor threads
10299 return client ;
103100 }
104101
105- /**
106- * Standard echo (uncompressed); ensures basic end-to-end is healthy.
107- */
108102 @ Test
109103 void echo_uncompressed () throws Exception {
110104 final URI uri = uri (port , "/echo" );
@@ -263,12 +257,13 @@ void max_message_1009() throws Exception {
263257 client .connect (u , new WebSocketListener () {
264258 @ Override
265259 public void onOpen (final WebSocket ws ) {
266- // Client sends nothing; server pushes an oversized message.
260+ // Trigger the server to send an oversized text message.
261+ ws .sendText ("trigger-too-big" , true );
267262 }
268263
269264 @ Override
270265 public void onText (final CharBuffer text , final boolean last ) {
271- // Depending on timing, we may or may not see text before the 1009 close.
266+ // We may or may not see some text before the 1009 close.
272267 }
273268
274269 @ Override
@@ -325,8 +320,6 @@ public void onError(final Throwable ex) {
325320 }
326321 }
327322
328- // -------------------- Embedded servlets/sockets ---------------------------
329-
330323 public static final class EchoServlet extends WebSocketServlet {
331324 @ Override
332325 public void configure (final WebSocketServletFactory factory ) {
@@ -401,17 +394,20 @@ public void configure(final WebSocketServletFactory factory) {
401394
402395 public static final class TooBigSocket extends WebSocketAdapter {
403396 @ Override
404- public void onWebSocketConnect (final Session sess ) {
405- super .onWebSocketConnect (sess );
397+ public void onWebSocketText (final String msg ) {
398+ final Session sess = getSession ();
399+ if (sess == null || !sess .isOpen ()) {
400+ return ;
401+ }
406402 final StringBuilder sb = new StringBuilder ();
407403 final String chunk = "1234567890abcdef-" ;
408404 // Build something comfortably larger than the maxMessage (2 KiB in the test)
409405 while (sb .length () <= 8192 ) {
410406 sb .append (chunk );
411407 }
412- final String msg = sb .toString ();
413- sess .getRemote ().sendString (msg , null );
414- // Do not send CLOSE here; the client should close with 1009.
408+ final String big = sb .toString ();
409+ sess .getRemote ().sendString (big , null );
410+ // No CLOSE here; the client must decide to close with 1009.
415411 }
416412 }
417413}
0 commit comments