Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-dev] facing issue while using subprotocol with jetty websocket 10.0.15
  • From: Poonam Wandile <pwandile@xxxxxxxxx>
  • Date: Fri, 7 Jun 2024 07:51:21 +0000
  • Accept-language: en-IN, 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=2suRtCZY+D7QPrSLW0JDNSviIX8CHdKzvhCT4BNdryM=; b=GAASIRVJI624U3JtltU5kkpMiFtnPSzJ/F8945EfQlSlagcVx/Vxnf1Dv+yEqm0aBR+l2xD8QyOONDZGbyDOYbdraKkBjjKehPHx7s29Zv7JX+pyM7WzVreEgBl1hOHWGglpzdB4ihrlB7JCtWakMV9d/fMnoU+yvYSbp54PboLnZeq9PHBvaOTwE3ddaBdVQi02irp1/V/ytW848UVukQ966dbgCkt5pyAsPhgMj50Th/bELBubCjjRTEdCctiQ1s7dwXhH8qIjgfyHt3GVE5Zmm4mrjXEVcbe+fneRhV8IukHz3wTCLQmeP7jBV9mOhURc1bys+0a9DCdhgtN2KQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XLV9oEEkw788Xqft6KX2guBnsugLtaMUB8w+QHIfhyIq6Ri0tgASoo0N2y8KMJH4Su/j8Q17KDL+BvMY2Ba6Xtyg1Mp45cqx8YKunPpwlhj1PIIqhJV8jdmGdTdE++bpSeQIK2/t8KCaxrUccm1m9nHu5C1Z+EpUQYr3fbA8nHDP8bnliNKUg3Urz6g2k5gOX1bRNAQ0KnpG+F0HfOI8E2Ij1oJ8c6hN8awQs69i3mEH4RWUi0e+l/xcJR499hl7zk07FCFO5a1X/11eZ6TNVK7akHhcemjq8l6ljYfDBBHOeZkbFLMNCD3YINQAS2YprPIzlYsNsjdhvBShS+99aw==
  • Delivered-to: jetty-dev@xxxxxxxxxxx
  • List-archive: <https://www.eclipse.org/mailman/private/jetty-dev/>
  • List-help: <mailto:jetty-dev-request@eclipse.org?subject=help>
  • List-subscribe: <https://www.eclipse.org/mailman/listinfo/jetty-dev>, <mailto:jetty-dev-request@eclipse.org?subject=subscribe>
  • List-unsubscribe: <https://www.eclipse.org/mailman/options/jetty-dev>, <mailto:jetty-dev-request@eclipse.org?subject=unsubscribe>
  • Thread-index: Adq4rqJhuaw7pERUQ6OHmYfvQGIMHQ==
  • Thread-topic: facing issue while using subprotocol with jetty websocket 10.0.15

Hi All,

 

I am trying to use subprotocol in my websocket application having client in _javascript_ and server in java. But websocket connection is not establishes when trying to use subprotocol. Can you please help me understand what I am missing out.

 

Client code:
const createConnection = () => {

                                                                        console.log("initiating connection request",Date.now());

                                                                       

                    socket = new WebSocket(socketUrl,['chat','superchat']);

 

                    socket._onopen_ = (event) => {

                                                                        debugger;

                        console.log('WebSocket connection established.',Date.now());

                    };

Server :

 

@OnWebSocketConnect
  
public void onConnect(Session session) {
      
long currentTimestamp = System.currentTimeMillis();
      
List<String> header = session.getUpgradeRequest().getSubProtocols();
      
logger.log(Level.ERROR, CallerContext.DEFAULT_CONTEXT, srcInfo, "header is", header);
      
String token = null;
       if
(header != null) {
          
for (String part : header) {
              
if (part.contains("chat")) {
                   token = part.trim()
;
                  
// Do something with the token...
                  
System.out.println("Access token: " + token);
                   break;
              
}
           }
       }
      
//session.getUpgradeResponse().getHeaders().put("Sec-WebSocket-Protocol",header);
       //System.out.println("Connect: " + session.getRemoteAddress());
       
String connectionId = UUID.randomUUID().toString();
       this
.setConnectionId(connectionId);
      
SessionCache.addToSessionMap(this);
      
// sending connectionId to client
      
this.session = session;
      
//this.getSession()//.get
/*           try
              {
                             session.getRemote().sendString("Sec-WebSocket-Protocol: " + token);
              }
              catch (IOException e)
              {
           System.out.println(e);
              }*/

             
try {
           JSONObject jsonObject =
new JSONObject();
          
jsonObject.put("connectionId", connectionId);
      
//   jsonObject.put("timestamp when reached server", currentTimestamp);
          // jsonObject.put("Sec-WebSocket-Protocol:", "abc");
          
session.getRemote().sendString(jsonObject.toString());
      
} catch (IOException e) {
           System.
out.println("IO Exception");
      
}
   }

 

 

Thanks,

Poonam


Back to the top