Skip to content

Commit 4e72778

Browse files
authored
Merge branch 'trunk' into case-insensitive-hrader-name
2 parents 0524ee1 + a5de377 commit 4e72778

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module(name = "selenium")
22

33
bazel_dep(name = "apple_rules_lint", version = "0.3.2")
4-
bazel_dep(name = "aspect_bazel_lib", version = "2.7.7")
4+
bazel_dep(name = "aspect_bazel_lib", version = "2.7.9")
55
bazel_dep(name = "aspect_rules_esbuild", version = "0.20.1")
66
bazel_dep(name = "aspect_rules_js", version = "1.42.3")
77
bazel_dep(name = "aspect_rules_ts", version = "2.4.2")

java/src/org/openqa/selenium/bidi/BiDi.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public <X> long addListener(Event<X> event, Consumer<X> handler) {
6262
return connection.addListener(event, handler);
6363
}
6464

65-
public <X> void addListener(String browsingContextId, Event<X> event, Consumer<X> handler) {
65+
public <X> long addListener(String browsingContextId, Event<X> event, Consumer<X> handler) {
6666
Require.nonNull("Event to listen for", event);
6767
Require.nonNull("Browsing context id", browsingContextId);
6868
Require.nonNull("Handler to call", handler);
@@ -76,7 +76,7 @@ public <X> void addListener(String browsingContextId, Event<X> event, Consumer<X
7676
"events",
7777
Collections.singletonList(event.getMethod()))));
7878

79-
connection.addListener(event, handler);
79+
return connection.addListener(event, handler);
8080
}
8181

8282
public <X> long addListener(Set<String> browsingContextIds, Event<X> event, Consumer<X> handler) {

java/src/org/openqa/selenium/netty/server/WebSocketUpgradeHandler.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,15 @@
4444
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker;
4545
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory;
4646
import io.netty.util.AttributeKey;
47+
import java.util.Arrays;
48+
import java.util.Objects;
4749
import java.util.Optional;
4850
import java.util.function.BiFunction;
4951
import java.util.function.Consumer;
52+
import java.util.logging.Level;
53+
import java.util.logging.Logger;
5054
import org.openqa.selenium.internal.Require;
55+
import org.openqa.selenium.remote.http.CloseMessage;
5156
import org.openqa.selenium.remote.http.Message;
5257

5358
// Plenty of code in this class is taken from Netty's own
@@ -56,6 +61,7 @@
5661

5762
class WebSocketUpgradeHandler extends ChannelInboundHandlerAdapter {
5863

64+
private static final Logger LOG = Logger.getLogger(WebSocketUpgradeHandler.class.getName());
5965
private final AttributeKey<Consumer<Message>> key;
6066
private final BiFunction<String, Consumer<Message>, Optional<Consumer<Message>>> factory;
6167
private WebSocketServerHandshaker handshaker;
@@ -180,6 +186,27 @@ private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame fram
180186

181187
@Override
182188
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
183-
ctx.close();
189+
try {
190+
Consumer<Message> consumer = ctx.channel().attr(key).get();
191+
192+
if (consumer != null) {
193+
byte[] reason = Objects.toString(cause).getBytes(UTF_8);
194+
195+
// the spec defines it as max 123 bytes encoded in UTF_8
196+
if (reason.length > 123) {
197+
reason = Arrays.copyOf(reason, 123);
198+
Arrays.fill(reason, 120, 123, (byte) '.');
199+
}
200+
201+
try {
202+
consumer.accept(new CloseMessage(1011, new String(reason, UTF_8)));
203+
} catch (Exception ex) {
204+
LOG.log(Level.FINE, "failed to send the close message", ex);
205+
}
206+
}
207+
} finally {
208+
LOG.log(Level.FINE, "exception caught, close the context", cause);
209+
ctx.close();
210+
}
184211
}
185212
}

0 commit comments

Comments
 (0)