Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Atmosphere Java Servlet服务器发送事件_Java_Javascript_Jquery_Servlets_Atmosphere - Fatal编程技术网

Atmosphere Java Servlet服务器发送事件

Atmosphere Java Servlet服务器发送事件,java,javascript,jquery,servlets,atmosphere,Java,Javascript,Jquery,Servlets,Atmosphere,这是我第一次在气氛中工作,对我来说这很艰难。 我想要的是,用户从我的API(Javaservlet/Tomcat)接收推送消息 我正在使用jquery.atmosphere.js和以下应用程序代码: checkForMenuUpdates: function () { var self = this; checkUpdates(); function checkUpdates() { var request = {url:

这是我第一次在气氛中工作,对我来说这很艰难。 我想要的是,用户从我的API(Javaservlet/Tomcat)接收推送消息

我正在使用jquery.atmosphere.js和以下应用程序代码:

checkForMenuUpdates: function () {
        var self = this;
        checkUpdates();
        function checkUpdates() {
            var request = {url: path.apiPath + 'user.checkUpdates?token=' + token,                    
                logLevel: 'debug',
                'enableXDR': true,
                transport: 'sse',
                trackMessageLength: "false",
                fallbackTransport: 'long-polling'};

            request.onOpen = function (response) {

            };
            request.onMessage = function (response) {

            }
            var socket = jqueryAtmosphere;
            var subSocket = socket.subscribe(request);
        }

    },
服务器端: 控制器:

  else if ("user.checkUpdates".equals(pathInfo)) {
            try {
              AtmosphereBroadcaster atmo=new AtmosphereBroadcaster();
              atmo.subscribe(response);
                //ServerSentEvents updates = new ServerSentEvents();
                //updates.establishConnection(token.getUserId(), response, callback);
            } catch (Exception ex) {
                ErrorHandler error = new ErrorHandler();
                error.Error400(response, callback);
            }
        }
“播音员”:

我从chrome控制台获得以下输出:

苏格兰和南方能源公司成功开业 jquery.atmosphere.js?bust=6539327597711.235:3171已达到最大重试次数6

对我来说,这听起来好像没有回音。我有一个非常基本的示例(),它运行良好。但对我来说,SSE不适用于大气框架

那么这有什么意义呢?我做错了什么

编辑:

我知道javascript代码很奇怪——它“正在构建”:

当然-当我将此代码添加到EventsLogger时,它正在工作:

public EventsLogger(HttpServletResponse response) {
        PrintWriter write = null;

        try {
            write = response.getWriter();
            while (true) {
                write.write("data:Test \n\n");
                write.flush();
                Thread.sleep(1000);
            }

        } catch (IOException ex) {
            Logger.getLogger(AtmosphereBroadcaster.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InterruptedException ex) {
            Logger.getLogger(AtmosphereBroadcaster.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            write.close();
        }
    }
心跳信号发送不正确是一个问题-如何解决此问题?

停止执行以下操作:

    throw new UnsupportedOperationException("Not supported yet.");
在侦听器中,这将起作用:-)

public EventsLogger(HttpServletResponse response) {
        PrintWriter write = null;

        try {
            write = response.getWriter();
            while (true) {
                write.write("data:Test \n\n");
                write.flush();
                Thread.sleep(1000);
            }

        } catch (IOException ex) {
            Logger.getLogger(AtmosphereBroadcaster.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InterruptedException ex) {
            Logger.getLogger(AtmosphereBroadcaster.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            write.close();
        }
    }
    throw new UnsupportedOperationException("Not supported yet.");