Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ public HttpResponse execute(HttpRequest request) throws UncheckedIOException {
public WebSocket openSocket(HttpRequest request, WebSocket.Listener listener) {
throw new UnsupportedOperationException("openSocket");
}

@Override
public <T>
java.util.concurrent.CompletableFuture<java.net.http.HttpResponse<T>> sendAsyncNative(
java.net.http.HttpRequest request,
java.net.http.HttpResponse.BodyHandler<T> handler) {
throw new UnsupportedOperationException("sendAsyncNative is not supported");
}

@Override
public <T> java.net.http.HttpResponse<T> sendNative(
java.net.http.HttpRequest request, java.net.http.HttpResponse.BodyHandler<T> handler)
throws java.io.IOException, InterruptedException {
throw new UnsupportedOperationException("sendNative is not supported");
}
};
}

Expand Down
17 changes: 17 additions & 0 deletions java/src/org/openqa/selenium/remote/RemoteWebDriverBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,23 @@ public WebSocket openSocket(HttpRequest request, WebSocket.Listener listener) {
public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
return handler.execute(req);
}

@Override
public <T>
java.util.concurrent.CompletableFuture<java.net.http.HttpResponse<T>>
sendAsyncNative(
java.net.http.HttpRequest request,
java.net.http.HttpResponse.BodyHandler<T> handler) {
throw new UnsupportedOperationException("sendAsyncNative is not supported");
}

@Override
public <T> java.net.http.HttpResponse<T> sendNative(
java.net.http.HttpRequest request,
java.net.http.HttpResponse.BodyHandler<T> handler)
throws java.io.IOException, InterruptedException {
throw new UnsupportedOperationException("sendNative is not supported");
}
};
}
};
Expand Down
25 changes: 25 additions & 0 deletions java/src/org/openqa/selenium/remote/http/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@ default CompletableFuture<HttpResponse> executeAsync(HttpRequest req) {

default void close() {}

/**
* Sends an HTTP request using java.net.http.HttpClient and allows specifying the BodyHandler.
*
* @param <T> the response body type
* @param request the HTTP request to send
* @param handler the BodyHandler that determines how to handle the response body
* @return a CompletableFuture containing the HTTP response
*/
<T> CompletableFuture<java.net.http.HttpResponse<T>> sendAsyncNative(
java.net.http.HttpRequest request, java.net.http.HttpResponse.BodyHandler<T> handler);

/**
* Sends an HTTP request using java.net.http.HttpClient and allows specifying the BodyHandler.
*
* @param <T> the response body type
* @param request the HTTP request to send
* @param handler the BodyHandler that determines how to handle the response body
* @return the HTTP response
* @throws java.io.IOException if an I/O error occurs
* @throws InterruptedException if the operation is interrupted
*/
<T> java.net.http.HttpResponse<T> sendNative(
java.net.http.HttpRequest request, java.net.http.HttpResponse.BodyHandler<T> handler)
throws java.io.IOException, InterruptedException;

interface Factory {

/**
Expand Down
13 changes: 13 additions & 0 deletions java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,19 @@ private HttpResponse execute0(HttpRequest req) throws UncheckedIOException {
}
}

@Override
public <T> CompletableFuture<java.net.http.HttpResponse<T>> sendAsyncNative(
java.net.http.HttpRequest request, java.net.http.HttpResponse.BodyHandler<T> handler) {
return client.sendAsync(request, handler);
}

@Override
public <T> java.net.http.HttpResponse<T> sendNative(
java.net.http.HttpRequest request, java.net.http.HttpResponse.BodyHandler<T> handler)
throws IOException, InterruptedException {
return client.send(request, handler);
}

@Override
public void close() {
if (this.client == null) {
Expand Down
13 changes: 13 additions & 0 deletions java/src/org/openqa/selenium/remote/tracing/TracedHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ public HttpResponse execute(HttpRequest req) {
}
}

@Override
public <T> java.util.concurrent.CompletableFuture<java.net.http.HttpResponse<T>> sendAsyncNative(
java.net.http.HttpRequest request, java.net.http.HttpResponse.BodyHandler<T> handler) {
return delegate.sendAsyncNative(request, handler);
}

@Override
public <T> java.net.http.HttpResponse<T> sendNative(
java.net.http.HttpRequest request, java.net.http.HttpResponse.BodyHandler<T> handler)
throws java.io.IOException, InterruptedException {
return delegate.sendNative(request, handler);
}

@Override
public void close() {
delegate.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ public WebSocket openSocket(HttpRequest request, WebSocket.Listener listener) {
throw new UnsupportedOperationException("openSocket");
}

@Override
public <T> java.util.concurrent.CompletableFuture<java.net.http.HttpResponse<T>> sendAsyncNative(
java.net.http.HttpRequest request, java.net.http.HttpResponse.BodyHandler<T> handler) {
throw new UnsupportedOperationException("sendAsyncNative");
}

@Override
public <T> java.net.http.HttpResponse<T> sendNative(
java.net.http.HttpRequest request, java.net.http.HttpResponse.BodyHandler<T> handler)
throws java.io.IOException, InterruptedException {
throw new UnsupportedOperationException("sendNative");
}

public static class Factory implements HttpClient.Factory {

private final Routable handler;
Expand Down
14 changes: 14 additions & 0 deletions java/test/org/openqa/selenium/remote/ProtocolHandshakeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,19 @@ String getRequestPayload() {
public WebSocket openSocket(HttpRequest request, WebSocket.Listener listener) {
throw new UnsupportedOperationException("openSocket");
}

@Override
public <T>
java.util.concurrent.CompletableFuture<java.net.http.HttpResponse<T>> sendAsyncNative(
java.net.http.HttpRequest request, java.net.http.HttpResponse.BodyHandler<T> handler) {
throw new UnsupportedOperationException("sendAsyncNative");
}

@Override
public <T> java.net.http.HttpResponse<T> sendNative(
java.net.http.HttpRequest request, java.net.http.HttpResponse.BodyHandler<T> handler)
throws java.io.IOException, InterruptedException {
throw new UnsupportedOperationException("sendNative");
}
}
}
Loading