Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] EXTERNAL- Re: websocket-jetty-server not able to upgrade request to websocket
  • From: Yash Sharma <ysharma@xxxxxxxxx>
  • Date: Tue, 12 Mar 2024 06:26:45 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=egain.com; dmarc=pass action=none header.from=egain.com; dkim=pass header.d=egain.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=DWtYfYBstt/JoFTQUvAhm9i4vcIYG2sz49pU9atJCBg=; b=bbqPxRCSjMqewfGkt/cjNSVz4b9kqUGDZX98yD74ANSQaAwr3InNCTKgCcAuehoBvLnUF5TLe31G0eHBokwWlDMm3qb8l8c/O/voCETjyusxjwruIyGnHGUEA79v51oEx31uANXlBlFjN/KgD8Jg7HVqtHTDEIROlO9fy6AxPSdCIwwewiAjcpoA+0KpHL7VIOCxDiwOXYchNuDM4rObjMkDbKWPCCY7+BZTrM5DRarEYW0sNZvg4m0PNqUsJ0XaEfsz+KF7jG5M8NeW9s4Ygf5nupzAClIxwmFwwUvKDetWGtNGRPQX9r45SoJvHHJXRAJTz37x0eh/fUs8e4FccA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Asfs5D+rqaffGMPwGSDK7srlEhGXAjRU72aRAglq4TmBLZDh+Sv+FP2MWRy8+yihZLoy4wr0CQKWWAC5oX+gK9uNNSCEvT4hkqZ/SZsnH99Z6wn2ci9H1JQ13I9+z22A2V7bildrducU25oLDoaehkLHq+e1YtP7ujkE8Z7M5cIiKBqJfN1e0yqVbx/DjDnOSb27dvtZPfCKxF/QfBwI7GlGAGQy2f7LVoKg95qeBrmFSKNDr4+GlAEf6jIQq47ImC1708BeJYKJN6F0EVrj06UrX3MvM9s6cMiOn54vRtYhURPHwzUa8m35BuYu8QveJliHgKiiE3KGKClX7I/Zlg==
  • Delivered-to: jetty-users@xxxxxxxxxxx
  • List-archive: <https://www.eclipse.org/mailman/private/jetty-users/>
  • List-help: <mailto:jetty-users-request@eclipse.org?subject=help>
  • List-subscribe: <https://www.eclipse.org/mailman/listinfo/jetty-users>, <mailto:jetty-users-request@eclipse.org?subject=subscribe>
  • List-unsubscribe: <https://www.eclipse.org/mailman/options/jetty-users>, <mailto:jetty-users-request@eclipse.org?subject=unsubscribe>
  • Thread-index: AdpxH1YdVbjW31dLS02NwRmH2nYwNwCZYWYAADAriqA=
  • Thread-topic: EXTERNAL- Re: [jetty-users] websocket-jetty-server not able to upgrade request to websocket

Thanks for the input Roberts, actually upgrade request fails for an http request made. For  ws:// request I am seeing connection failed. Do I need to add websocket-jetty related configuration in jetty.xml configuration file?

 

Can some please share a snippet of the configuration to be added ?

 

Thanks,

Yash Sharma

 

From: Lachlan Roberts <lachlan@xxxxxxxxxxx>
Sent: Monday, March 11, 2024 12:52 PM
To: JETTY user mailing list <jetty-users@xxxxxxxxxxx>
Cc: Yash Sharma <ysharma@xxxxxxxxx>
Subject: EXTERNAL- Re: [jetty-users] websocket-jetty-server not able to upgrade request to websocket

 

 

CAUTION: This email originated from outside eGain. Do not click links or open attachments unless you can verify the sender and know the content is safe.

 


These two lines do exactly the same thing btw, so might want to remove one
factory.register(MySocket.class);
factory.addMapping("/", (req,res)->new MySocket());

Can you look at the HTTP response to the websocket upgrade request.

 

You also can enable Jetty debug logging for websocket and see exactly what is happening.

 

 

On Fri, Mar 8, 2024 at 5:14PM Yash Sharma via jetty-users <jetty-users@xxxxxxxxxxx> wrote:

Hi All,

 

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 stack 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 console is “connection to 'ws://host:port/example' failed:”

 

 

Thanks,

Yash Sharma

_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users


Back to the top