Context: I'm trying to setup a WebSocket using socket.io-server-java (with the code attached down below).
I recently upgraded the jetty-servlets dependency (through Maven) from 9.4.19.v20190610 to 9.4.41.v20210516 as GitHub's Dependabot suggested due to security vulnerabilities.
Unfortunately, my code (attached below) completely stopped working with a strange PathSpec error that I have never heard of. The error occurs right after a client tries to connect to the WebSocket.
I would like to know what exactly is going wrong and how to solve/fix it.
Code:
this.route = route;
this.authRequired = authRequired;
serverWrapper = new SocketWrapper(Core.getConfiguration().config().getString("socket.ip"),
Core.getConfiguration().config().getInt("socket.port"), null);
try {
serverWrapper.startServer();
} catch (Exception e) {
e.printStackTrace();
}
SocketIoServer server = serverWrapper.getSocketIoServer();
ns = server.namespace(route);
ns.on("connection", connArguments -> {
SocketIoSocket socket = (SocketIoSocket) connArguments[0];
String password = getStringWithoutBrackets(socket.getInitialHeaders().get("Authorization").toString());
String configPassword = Core.getConfiguration().config().getString("socket.password");
String ipAddr = socket.getInitialHeaders().get("remote_addr").toString();
if (authRequired && !password.equals(configPassword)) {
socket.send("message", "Incorrect Credentials");
socket.disconnect(true);
return;
}
System.out.println(socket.getId() + " with the IP " + ipAddr + " has logged in on Socket route " + route);
});
Error:
[18:27:01 WARN]: [org.eclipse.jetty.server.HttpChannel] /socket.io/
java.lang.IncompatibleClassChangeError: Found interface org.eclipse.jetty.http.pathmap.PathSpec, but class was expected
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:455) ~[?:?]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594) ~[?:?]
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) ~[?:?]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1350) ~[?:?]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) ~[?:?]
at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:59) ~[?:?]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[?:?]
at org.eclipse.jetty.server.Server.handle(Server.java:516) ~[?:?]
at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:388) ~[?:?]
at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:633) ~[?:?]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:380) ~[?:?]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277) ~[?:?]
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) ~[?:?]
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) ~[?:?]
at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) ~[?:?]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336) ~[?:?]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313) ~[?:?]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171) ~[?:?]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:135) ~[?:?]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:882) ~[?:?]
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1036) ~[?:?]
at java.lang.Thread.run(Thread.java:829) [?:?]