-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
Jetty Version
Jetty 12.1.0
Jetty Environment
ee10
Java Version
Eclipse Adoptium OpenJDK 64-Bit Server VM 17.0.14+7;
Question
I have recently upgraded my project from Jetty 9.4 to 12.
One of the features of my system spawns/removes a websocket enpoint whenever the user enables/disables it.
Previously (in Jetty 9.4) the websocket mapping was being removed with the following code snipped without any issues:
ServletContextHandler contextHandler = getContextHandler(webSocket);
if (contextHandler != null) {
ServletContext servletContext = contextHandler.getServletContext();
ServerContainer container = (ServerContainer) servletContext.getAttribute(
ServerContainer.class.getName());
if (container == null) {
return;
}
if (container instanceof ContainerLifeCycle) {
ContainerLifeCycle containerLifeCycle = (ContainerLifeCycle) container;
NativeWebSocketConfiguration configuration = containerLifeCycle.getBean(
NativeWebSocketConfiguration.class);
if (configuration != null) {
configuration.removeMapping("uri-template|" + webSocket.getPath());
}
}
}
Upon the migration to Jetty 12, I had to make a few adjustments to have it running, because NativeWebSocketConfiguration
is no longer available. Thus, my refactored code looks like the following:
ServletContextHandler contextHandler = getContextHandler(webSocket);
if (contextHandler != null) {
boolean removed = false;
WebSocketMappings webSocketMappings = contextHandler.getBean(
WebSocketMappings.class);
if (webSocketMappings != null) {
PathSpec pathSpec = new UriTemplatePathSpec(webSocket.getPath());
webSocketMappings.removeMapping(pathSpec);
}
}
This, however, does not work as I'd expect. I can confirm that the mapping is removed (by dumping the running server config), but the rest of the websocket mappings that I have on the same context do not work anymore.
I am using Jakarta rather than Jetty's implementation for the websocket container, and upon exploring a little of the code, I don't see why manually removing the mapping would break other websocket endpoints.
Is there something I am doing wrong? Is there a better way to remove such endpoints at runtime?
(Preferably, I'd like to continue using Jakarta classes, to keep the same standard throughout the project)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status