From 4259e5eccd3aca332734a5cdbb21768c234f5f9c Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Mon, 10 Apr 2023 19:15:58 +0200 Subject: [PATCH] Handle reception of partial data in WS client. --- .../pandacube/lib/ws/client/AbstractClientWS.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pandalib-ws-client/src/main/java/fr/pandacube/lib/ws/client/AbstractClientWS.java b/pandalib-ws-client/src/main/java/fr/pandacube/lib/ws/client/AbstractClientWS.java index d103d7d..c6a1014 100644 --- a/pandalib-ws-client/src/main/java/fr/pandacube/lib/ws/client/AbstractClientWS.java +++ b/pandalib-ws-client/src/main/java/fr/pandacube/lib/ws/client/AbstractClientWS.java @@ -43,13 +43,20 @@ public abstract class AbstractClientWS implements AbstractWS { Listener.super.onOpen(webSocket); } + StringBuilder partialData = new StringBuilder(); + @Override public CompletionStage onText(WebSocket webSocket, CharSequence data, boolean last) { - try { - AbstractClientWS.this.handleReceivedMessage(data.toString()); - } catch (Exception e) { - logError("Error handling reception of text.", e); + partialData.append(data.toString()); + if (last) { + try { + AbstractClientWS.this.handleReceivedMessage(partialData.toString()); + } catch (Exception e) { + logError("Error handling reception of text.", e); + } + partialData = new StringBuilder(); } + return Listener.super.onText(webSocket, data, last); }