Skip to content

Commit

Permalink
[java] Ensure Java 11 client can send multiple websocket requests. Co…
Browse files Browse the repository at this point in the history
…llect all the received data before processing.
  • Loading branch information
pujagani committed Sep 15, 2022
1 parent 4671831 commit 7387bc9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,18 @@ public WebSocket openSocket(HttpRequest request, WebSocket.Listener listener) {
client.newWebSocketBuilder().buildAsync(
uri,
new java.net.http.WebSocket.Listener() {
final StringBuilder builder = new StringBuilder();

@Override
public CompletionStage<?> onText(java.net.http.WebSocket webSocket, CharSequence data, boolean last) {
listener.onText(data);
builder.append(data);

if (last) {
listener.onText(builder.toString());
builder.setLength(0);
}

webSocket.request(1);
return null;
}

Expand All @@ -136,6 +144,7 @@ public CompletionStage<?> onBinary(java.net.http.WebSocket webSocket, ByteBuffer
data.get(ary, 0, ary.length);

listener.onBinary(ary);
webSocket.request(1);
return null;
}

Expand All @@ -148,6 +157,7 @@ public CompletionStage<?> onClose(java.net.http.WebSocket webSocket, int statusC
@Override
public void onError(java.net.http.WebSocket webSocket, Throwable error) {
listener.onError(error);
webSocket.request(1);
}
});

Expand Down

0 comments on commit 7387bc9

Please sign in to comment.