Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » websocket-jetty-server not able to upgrade request to websocket(On making websocket api call jetty server is not able to update request header to upgrade:websocket.)
websocket-jetty-server not able to upgrade request to websocket [message #1863940] Thu, 07 March 2024 11:46 Go to next message
Yash Sharma is currently offline Yash SharmaFriend
Messages: 1
Registered: March 2024
Junior Member
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:

Re: websocket-jetty-server not able to upgrade request to websocket [message #1863947 is a reply to message #1863940] Thu, 07 March 2024 15:27 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
I don't think the Jetty folks will help you on this forum. Look here for better places to ask:

https://eclipse.dev/jetty/support.php


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Frequent UI Freeze, more than 20 Seconds
Next Topic:Can't open ecliplse IDE
Goto Forum:
  


Current Time: Sat Apr 27 14:47:46 GMT 2024

Powered by FUDForum. Page generated in 0.09017 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top