websocket-jetty-server not able to upgrade request to websocket [message #1863940] |
Thu, 07 March 2024 11:46  |
Eclipse User |
|
|
|
I am trying to make websocket connection using html and javascript.
My client is as follows
const socketUrl = "ws://host:port/example";
const socket = new WebSocket(socketUrl);[
And I have Servlet as follows
@WebServlet(name = "WebSocket Servlet", urlPatterns = { "/example" })
public class MyWSServlet extends JettyWebSocketServlet
{
@Override
public void configure(JettyWebSocketServletFactory factory) {
factory.setIdleTimeout(Duration.ofSeconds(1000));
factory.register(MySocket.class);
factory.addMapping("/", (req,res)->new MySocket());
}
}
@WebSocket
public class MySocket{
@OnWebSocketConnect
public void onConnect(Session session) {
System.out.println("Connect: " + session.getRemoteAddress());
}
}
I am using websocket-jetty-server dependency in pom.xml
When I try to hit the ws api, at server side I see that in upgradeRequest() validateNegotiation returns false and hence request is not upgraded to websocket.
As per chat gpt negotiateHeaders() is responsible to add Upgrade:websocket in request headers. But I do not see that happening in jetty.
I have attached network trace for reference. Can someone please help me with this problem to establish a websocket connection using jetty?
The message that I see in browser is
connection to 'ws://host:port/example' failed:
|
|
|
|
Powered by
FUDForum. Page generated in 0.09838 seconds