简体   繁体   English

javax.websocket.Session api

[英]javax.websocket.Session api

i need to retrieve a session id but Eclipse tell me "The method getId() is undefined for the type Session" 我需要获取一个会话ID,但是Eclipse告诉我“未为Session类型定义getId()方法”

here the header : 这是标题:

import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

here the error : 这里的错误:

@OnOpen
public void onOpen(Session session){
    System.out.println(session.getId() + " has opened a connection"); 
    //session.getId() is undefined.
    try {
        session.getBasicRemote().sendText("Connection Established");
        //same here getBasicRemote is undefined
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

I build my project with gradle. 我用gradle构建我的项目。 I think i included all the depencies. 我想我包括了所有这些缺陷。

dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile 'org.glassfish.main.extras:glassfish-embedded-all:4.0-b72'
compile 'javax:javaee-api:7.0'
testCompile group: 'junit', name: 'junit', version: '4.+'
}

then i run gradle eclipse. 然后我运行gradle eclipse。 But getId() still undefined. 但是getId()仍未定义。

If someone have an idea ! 如果有人有主意! thanks. 谢谢。

It was the 'org.glassfish.main.extras:glassfish-embedded-all:4.0-b72' lib that override the javax websocket api. 覆盖javax websocket api的是“ org.glassfish.main.extras:glassfish-embedded-all:4.0-b72”库。

Worked using org.glassfish.main.extras:glassfish-embedded-all:4.1 instead. 使用org.glassfish.main.extras:glassfish-embedded-all:4.1代替。 Weird. 奇怪的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM