Project

General

Profile

Bug #11071

Websockets problem

Added by Henry Morgan 24 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
11/10/2022
Due date:
% Done:

0%

Estimated time:

Description

Hello,
I' trying to use websockets but it has some problems. So let me explain it step by step.

  1. I enable websockets inside servlet init by calling this: getConfiguration().setWebSocketsEnabled(true); Than's fine and it sets internal configuration variable webSocketsEnabled=true
  2. Next, when connection establishes it sends upgrade request to server with wsid parameter set to -1. Why? Because jwt servlet initialized with no websockets already. Check this out: private int idForWebSocket = -1; ... @Override public void init(ServletConfig config) throws ServletException { super.init(config); ... if (getConfiguration().webSockets()) { if (this.idForWebSocket < 0) this.idForWebSocket = WebSocketRegistry.getInstance().addServlet(this); } ... } As you can see, webSockets() returns false and idForWebSocket is always -1. And it doesn't matter whether you call setWebSocketsEnabled(true) or not.
  3. When ws connection is istablishing, it jwt checks wsid, but it is -1 and servlet never been added to WebSocketRegistry: String servletId = connection.getParameter("wsid"); if (servletId == null){ logger.debug("WebSocket message discarded: no wsid parameter present"); return null; } WtServlet servlet = WebSocketRegistry.getInstance().getServlet(Integer.valueOf(servletId)); if (servlet == null) { logger.debug("WebSocket message discarded: invalid wsid parameter"); return null; } So we have no ws sesion. Solution:
  4. Simple Recompile Jwt with ws enabled from the start by setting private boolean webSocketsEnabled = true; inside eu.webtoolkit.jwt.Configuration
  5. Normal Rewrite setWebSocketsEnabled as it executes WebSocketRegistry.getInstance().addServlet(this) by signal or something else to add servlet to registry and don't let wsid to be -1.

No data to display

Also available in: Atom PDF