下面列出了javax.websocket.Session#getId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void initializeNativeSession(Session session) {
super.initializeNativeSession(session);
this.id = session.getId();
this.uri = session.getRequestURI();
this.acceptedProtocol = session.getNegotiatedSubprotocol();
List<Extension> source = getNativeSession().getNegotiatedExtensions();
this.extensions = new ArrayList<WebSocketExtension>(source.size());
for (Extension ext : source) {
this.extensions.add(new StandardToWebSocketExtensionAdapter(ext));
}
if (this.user == null) {
this.user = session.getUserPrincipal();
}
}
/**
* Sends message to the WebSocket server.
*
* @param endpoint The server endpoint
* @param msg The message
* @return a return message
*/
private String sendMessage(String endpoint, String msg) {
LOGGER.config(() -> "Sending message: " + msg);
String returnValue = "-1";
try {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
String uri = serviceUrl + endpoint;
Session session = container.connectToServer(this, URI.create(uri));
session.getBasicRemote().sendText(msg != null ? msg : "");
returnValue = session.getId();
} catch (DeploymentException | IOException ex) {
LOGGER.warning(ex.getMessage());
}
return returnValue;
}
public StandardWebSocketSession(Session session, HandshakeInfo info, DataBufferFactory factory,
@Nullable MonoProcessor<Void> completionMono) {
super(session, session.getId(), info, factory, completionMono);
}
public StandardWebSocketSession(Session session, HandshakeInfo info, DataBufferFactory factory,
@Nullable MonoProcessor<Void> completionMono) {
super(session, session.getId(), info, factory, completionMono);
}
private void updateId(Session session) {
sid = session.getId();
id = null;
}
/**
* SCIPIO: getLogIdStr.
* <p>
* WARN: TODO: REVIEW: Unclear if truly good idea security-wise to print these IDs in log,
* but for this example currently do not see a risk. For real applications, you may
* want to honor the <code>requestHandler.properties#show-sessionId-in-log</code> setting.
*/
private static String getLogIdStr(Session session) {
return "'" + session.getId() + "'";
}