diff --git a/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jakarta-server/src/main/java/org/eclipse/jetty/ee10/websocket/jakarta/server/internal/JakartaWebSocketCreator.java b/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jakarta-server/src/main/java/org/eclipse/jetty/ee10/websocket/jakarta/server/internal/JakartaWebSocketCreator.java index 3c394e89a70..e592b70a0a5 100644 --- a/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jakarta-server/src/main/java/org/eclipse/jetty/ee10/websocket/jakarta/server/internal/JakartaWebSocketCreator.java +++ b/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jakarta-server/src/main/java/org/eclipse/jetty/ee10/websocket/jakarta/server/internal/JakartaWebSocketCreator.java @@ -166,9 +166,10 @@ public class JakartaWebSocketCreator implements WebSocketCreator Object endpoint = config.getConfigurator().getEndpointInstance(endpointClass); return new ConfiguredEndpoint(endpoint, config); } - catch (InstantiationException e) + catch (Throwable x) { - LOG.warn("Unable to create websocket: {}", config.getEndpointClass().getName(), e); + LOG.warn("Unable to create websocket: {}", config.getEndpointClass().getName(), x); + callback.failed(x); return null; } } diff --git a/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jakarta-tests/src/test/java/org/eclipse/jetty/ee10/websocket/jakarta/tests/ProgrammaticWebSocketUpgradeTest.java b/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jakarta-tests/src/test/java/org/eclipse/jetty/ee10/websocket/jakarta/tests/ProgrammaticWebSocketUpgradeTest.java index 73637a5453c..8e806398f09 100644 --- a/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jakarta-tests/src/test/java/org/eclipse/jetty/ee10/websocket/jakarta/tests/ProgrammaticWebSocketUpgradeTest.java +++ b/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jakarta-tests/src/test/java/org/eclipse/jetty/ee10/websocket/jakarta/tests/ProgrammaticWebSocketUpgradeTest.java @@ -35,16 +35,21 @@ import org.eclipse.jetty.ee10.servlet.ServletHolder; import org.eclipse.jetty.ee10.websocket.jakarta.client.JakartaWebSocketClientContainer; import org.eclipse.jetty.ee10.websocket.jakarta.server.JakartaWebSocketServerContainer; import org.eclipse.jetty.ee10.websocket.jakarta.server.config.JakartaWebSocketServletContainerInitializer; +import org.eclipse.jetty.ee10.websocket.jakarta.server.internal.JakartaWebSocketCreator; +import org.eclipse.jetty.logging.StacklessLogging; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.util.ajax.JSON; +import org.eclipse.jetty.websocket.core.exception.UpgradeException; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class ProgrammaticWebSocketUpgradeTest { @@ -97,6 +102,20 @@ public class ProgrammaticWebSocketUpgradeTest } } + public static class BrokenEndpoint extends Endpoint + { + public BrokenEndpoint() + { + throw new RuntimeException("Broken"); + } + + @Override + public void onOpen(Session session, EndpointConfig config) + { + throw new UnsupportedOperationException(); + } + } + public static class CustomUpgradeServlet extends HttpServlet { private JakartaWebSocketServerContainer container; @@ -128,6 +147,12 @@ public class ProgrammaticWebSocketUpgradeTest container.upgradeHttpToWebSocket(request, response, sec, PATH_PARAMS); break; } + case "/brokenEndpoint": + { + ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(BrokenEndpoint.class, "/").build(); + container.upgradeHttpToWebSocket(request, response, sec, PATH_PARAMS); + break; + } default: throw new IllegalStateException(); } @@ -155,6 +180,25 @@ public class ProgrammaticWebSocketUpgradeTest assertThat(socket.closeReason.getCloseCode(), is(CloseReason.CloseCodes.NORMAL_CLOSURE)); } + @Test + public void testWebSocketUpgradeFailure() throws Exception + { + try (StacklessLogging ignore = new StacklessLogging(JakartaWebSocketCreator.class);) + { + URI uri = URI.create("ws://localhost:" + connector.getLocalPort() + "/brokenEndpoint"); + EventSocket socket = new EventSocket(); + try + { + client.connectToServer(socket, uri); + fail("expected IOException"); + } + catch (IOException ioe) + { + assertInstanceOf(UpgradeException.class, ioe.getCause()); + } + } + } + @Test public void testPathParameters() throws Exception {