Commit 4140a0f
[java] feat: Add native Java 11 HTTP client methods to HttpClient interface (#16412)
* feat: Add native Java 11 HTTP client methods to HttpClient interface
Add sendAsyncNative() and sendNative() methods to leverage java.net.http.HttpClient
capabilities while maintaining backward compatibility with existing executeAsync().
## New Methods Added:
- sendAsyncNative(): Asynchronous HTTP requests using CompletableFuture
- sendNative(): Synchronous HTTP requests with native error handling
## Benefits:
- HTTP/2 support with automatic protocol negotiation and multiplexing
- Efficient streaming for large files without memory overhead
- Native async operations with CompletableFuture integration
- Flexible response handling via BodyHandler (String, File, Stream, Lines)
- Better error handling with specific HTTP exceptions (IOException, InterruptedException)
- Improved performance for concurrent requests
## Implementation Details:
- Added method signatures to HttpClient interface
- Implemented native delegation in JdkHttpClient using underlying java.net.http.HttpClient
- Added pass-through implementations in TracedHttpClient
- Added UnsupportedOperationException stubs in test classes and utility clients
- Maintained full backward compatibility with existing methods
## Testing:
- Created comprehensive unit tests (NativeHttpClientMethodsTest)
- Tests cover both synchronous and asynchronous operations
- Exception handling validation for IOException and InterruptedException
- Request parameter validation for different HTTP methods (GET, POST)
- BodyHandler variations testing (String, Void, Stream)
- Mock implementations for reliable testing without external dependencies
The new methods provide a migration path towards modern Java 11 HTTP APIs
without breaking current implementations, enabling developers to leverage
native HTTP/2 features, better async handling, and improved performance
when using Selenium's HTTP client infrastructure.
* feat: Add generic native Java 11 HTTP client methods to HttpClient interface
Add sendAsyncNative() and sendNative() generic methods to leverage java.net.http.HttpClient
capabilities with full BodyHandler flexibility while maintaining backward compatibility.
## New Methods Added:
- <T> sendAsyncNative(): Generic asynchronous HTTP requests using CompletableFuture
- <T> sendNative(): Generic synchronous HTTP requests with native error handling
## Key Features:
- **Full BodyHandler Support**: String, File, Stream, Lines, ByteArray, Void (discarding)
- **HTTP/2 Support**: Automatic protocol negotiation and multiplexing
- **Efficient Streaming**: Large files without memory overhead via BodyHandlers.ofFile()
- **Native Async Operations**: CompletableFuture integration with proper type safety
- **Flexible Response Handling**: Type-safe responses based on BodyHandler type
- **Better Error Handling**: Specific HTTP exceptions (IOException, InterruptedException)
- **Improved Performance**: Concurrent requests and HTTP/2 optimizations
## Implementation Details:
- Added generic method signatures to HttpClient interface with proper JavaDoc
- Implemented native delegation in JdkHttpClient using underlying java.net.http.HttpClient
- Added pass-through generic implementations in TracedHttpClient
- Added UnsupportedOperationException stubs in test classes and utility clients
- Maintained full backward compatibility with existing executeAsync() method
- Enhanced type safety with proper generic constraints
---------
Co-authored-by: Diego Molina <[email protected]>1 parent b0dade7 commit 4140a0f
File tree
8 files changed
+413
-0
lines changed- java
- src/org/openqa/selenium
- grid/web
- remote
- http
- jdk
- tracing
- test/org/openqa/selenium
- grid/testing
- remote
- http
8 files changed
+413
-0
lines changedLines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
78 | 93 | | |
79 | 94 | | |
80 | 95 | | |
| |||
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
297 | 297 | | |
298 | 298 | | |
299 | 299 | | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
300 | 317 | | |
301 | 318 | | |
302 | 319 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
42 | 67 | | |
43 | 68 | | |
44 | 69 | | |
| |||
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
509 | 509 | | |
510 | 510 | | |
511 | 511 | | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
512 | 525 | | |
513 | 526 | | |
514 | 527 | | |
| |||
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
60 | 73 | | |
61 | 74 | | |
62 | 75 | | |
| |||
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
51 | 64 | | |
52 | 65 | | |
53 | 66 | | |
| |||
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
197 | 211 | | |
198 | 212 | | |
0 commit comments