Skip to content

Replace Jetty WebSocket adapter with JDK HttpClient-based implementation#1109

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/modernize-websocket-handling
Draft

Replace Jetty WebSocket adapter with JDK HttpClient-based implementation#1109
Copilot wants to merge 2 commits intomasterfrom
copilot/modernize-websocket-handling

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 12, 2026

Removes the htmlunit-websocket-client (shaded Jetty 9) dependency and replaces it with a java.net.http.WebSocket implementation that ships with the JDK.

New: JdkWebSocketAdapter

  • Uses java.net.http.HttpClient + java.net.http.WebSocket (standard since JDK 11)
  • Accumulates fragmented text/binary frames before dispatching to WebSocketListener
  • Bridges WebClient cookies via a CookieHandler adapter over the existing WebSocketCookieStore
  • Supports WebClientOptions.isUseInsecureSSL() via a trust-all SSLContext

Removed

  • JettyWebSocketAdapter and the htmlunit-websocket-client Maven dependency
  • requires htmlunit.websocket.client from module-info.java (replaced with requires java.net.http)

Housekeeping

  • Renamed closeIncommingSessioncloseIncomingSession across interface and callers
  • Fixed WebSockt typos in Javadoc
  • Simplified ArchitectureTest rule now that no production code depends on org.htmlunit.jetty

Backward compatibility

The WebSocketAdapter, WebSocketAdapterFactory, and WebSocketListener interfaces are preserved. Users with custom implementations only need to rename closeIncommingSessioncloseIncomingSession.

// Default is now JDK-based — no configuration needed
WebClient client = new WebClient();

// Custom adapter still works via the factory API
client.setWebSocketAdapter(myCustomFactory);

Copilot AI and others added 2 commits April 12, 2026 17:02
- Add JdkWebSocketAdapter using java.net.http.HttpClient and java.net.http.WebSocket
- Remove JettyWebSocketAdapter and htmlunit-websocket-client dependency
- Update WebClient to default to JdkWebSocketAdapterFactory
- Update module-info.java to require java.net.http instead of htmlunit.websocket.client
- Update ArchitectureTest to remove Jetty-specific exclusions

Agent-Logs-Url: https://github.com/HtmlUnit/htmlunit/sessions/b3db8ccb-ee0a-436b-8c39-85fd25db4747

Co-authored-by: rbri <2544132+rbri@users.noreply.github.com>
…ize binary accumulation

- Rename closeIncommingSession -> closeIncomingSession in interface and all callers
- Fix 'WebSockt' typos in Javadoc
- Update error message to accurately describe supported content types
- Use ByteArrayOutputStream for efficient binary message accumulation

Agent-Logs-Url: https://github.com/HtmlUnit/htmlunit/sessions/b3db8ccb-ee0a-436b-8c39-85fd25db4747

Co-authored-by: rbri <2544132+rbri@users.noreply.github.com>
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants