Search code examples
javaajaxcometd

How to know whether cometd client is connected to http or https?


I am trying to know whether cometd client is connected to http or https, I need to log this information.

I am new to cometd and have not much idea about doing this.

One way I was thinking is to check for https in bayeuxContext.getURL(), but am not sure whether it will work or not.

Can somebody suggest on how to achieve this.

Thanks


Solution

  • Calling BayeuxContext.getURL() will return the full URI the client used to connect to the server, and therefore will contain also the scheme that you can check whether it's http or https.

    This will work for both HTTP-based and WebSocket-based transports. For WebSocket, the URI reported will be the URI of the initial HTTP upgrade request.