Skip to content

HandshakeWebSocketService assumes jakarta websocket is present #33970

@MFAshby

Description

@MFAshby

HandshakeWebSocketService#initUpgradeStrategy does not check for the availability of relevant classes before attempting to instanciate StandardWebSocketUpgradeStrategy.

static RequestUpgradeStrategy initUpgradeStrategy() { if (tomcatWsPresent) { return new TomcatRequestUpgradeStrategy();	} else if (jettyWsPresent) { return new JettyRequestUpgradeStrategy();	} else if (undertowWsPresent) { return new UndertowRequestUpgradeStrategy();	} else if (reactorNettyPresent) { // As late as possible (Reactor Netty commonly used for WebClient) return ReactorNettyStrategyDelegate.forReactorNetty1();	} else if (reactorNetty2Present) { // As late as possible (Reactor Netty commonly used for WebClient) return ReactorNettyStrategyDelegate.forReactorNetty2();	} else { // Let's assume Jakarta WebSocket API 2.1+ return new StandardWebSocketUpgradeStrategy();	}	}

This breaks when you attempt to load a context without a dependency on jakarta.websocket-client-api.

It looks like it should be handled gracefully by the following code in WebFluxConfigurationSupport:

private WebSocketService initWebSocketService() { WebSocketService service = getWebSocketService(); if (service == null) { try { service = new HandshakeWebSocketService();	} catch (IllegalStateException ex) { // Don't fail, test environment perhaps service = new NoUpgradeStrategyWebSocketService();	}	} return service;	}

but because a ClassNotFoundException is thrown instead of IllegalStateException; the context simply fails to load instead of falling back to NoUpgradeStrategyWebSocketService

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions