Upgrade Jetty WebSocket client from 9.4.58 to 12.1.8#2
Conversation
Agent-Logs-Url: https://github.com/HtmlUnit/htmlunit-websocket-client/sessions/c3a39ce2-cb19-44de-87b2-47a88ddda0e0 Co-authored-by: rbri <2544132+rbri@users.noreply.github.com>
|
@copilot provide class javadoc for JettyWebSocketAdapterImpl |
Added class-level javadoc to /**
* Jetty12 based implementation of the WebSocket listener.
* Bridges Jetty12 {@link org.htmlunit.jetty.websocket.api.Session.Listener.AutoDemanding}
* callbacks to the HtmlUnit {@link WebSocketListener} interface.
*/
private class JettyWebSocketAdapterImpl
implements org.htmlunit.jetty.websocket.api.Session.Listener.AutoDemanding {Also added |
|
@copilot i think we have to use all available information to construct a complete cookie.... |
... Updated the final HttpCookie.Builder builder = HttpCookie.build(cookie.getName(), cookie.getValue());
if (cookie.getDomain() != null) {
builder.domain(cookie.getDomain());
}
if (cookie.getPath() != null) {
builder.path(cookie.getPath());
}
if (cookie.getExpires() != null) {
builder.expires(cookie.getExpires().toInstant());
}
builder.secure(cookie.isSecure());
builder.httpOnly(cookie.isHttpOnly());
if (cookie.getSameSite() != null) {
final HttpCookie.SameSite sameSite = HttpCookie.SameSite.from(cookie.getSameSite());
if (sameSite != null) {
builder.sameSite(sameSite);
}
}
cookies.add(builder.build());This maps all available fields: domain, path, expiry date (converted to |
Changes in this repository
jetty.versionfrom9.4.58.v20250814to12.1.8org.eclipse.jetty.websocket:websocket-clienttoorg.eclipse.jetty.websocket:jetty-websocket-jetty-client1.8.0to17The shaded jar continues to relocate all
org.eclipse.jetty.*classes toorg.htmlunit.jetty.*.Required changes in the HtmlUnit calling site
The Jetty 12 WebSocket API is significantly different from Jetty 9. The following changes are needed in the HtmlUnit project.
Key API differences
WebSocketAdapterbase classSession.Listenerinterface (no base class)onWebSocketConnect(Session)onWebSocketOpen(Session)onWebSocketBinary(byte[], int, int)onWebSocketBinary(ByteBuffer, Callback)onWebSocketClose(int, String)onWebSocketClose(int, String, Callback)session.getRemote().sendString(text)session.sendText(text, Callback.NOOP)session.getRemote().sendBytes(buf)session.sendBinary(buf, Callback.NOOP)WebSocketPolicyfor size configWebSocketClient(longtype)new WebSocketClient(new SslContextFactory(true), null, null)new WebSocketClient(httpClient)with pre-configuredHttpClientclient_.setExecutor(exec)client_.getHttpClient().setExecutor(exec)httpClient.setCookieStore(java.net.CookieStore)httpClient.setHttpCookieStore(HttpCookieStore)connect()returnsFuture<Session>connect()returnsCompletableFuture<Session>and throwsIOExceptionWebSocketCookieStore.javaChange the implemented interface from
java.net.CookieStoretoorg.htmlunit.jetty.http.HttpCookieStore:JettyWebSocketAdapter.javaReplace imports and update the class body:
Old imports to remove:
New imports to add:
Constructor — SSL branch (replace
new WebSocketClient(new SslContextFactory(true), null, null)):Constructor — executor (replace
client_.setExecutor(...)):Constructor — cookie store (replace
client_.getHttpClient().setCookieStore(...)):Constructor — message size config (replace
WebSocketPolicyblock):connect()method (updateFuturetoCompletableFuture, addIOExceptionto throws if not already declared viaException):send()method (replacegetRemote().sendString/sendBytes):Inner class
JettyWebSocketAdapterImpl(replaceextends WebSocketAdapterwithimplements Session.Listener.AutoDemanding, rename/update callbacks):