Servlet 2.5的Atmosphere长轮询问题 [英] Long-polling with Atmosphere issue with Servlet 2.5

查看:281
本文介绍了Servlet 2.5的Atmosphere长轮询问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试一个使用Atmosphere框架的简单聊天应用程序.当我从两个浏览器连接到应用程序时,一切工作都像聊天一样,应在 Tomcat 7.0 上起作用,并使用 Websockets 协议.

I'm testing a simple chat application which is using Atmosphere framework. When I connect to the application from two browsers everything works like chat should work with Tomcat 7.0 and Websockets protocol is used.

当我降级到 Tomcat 6.0.或使用 Weblogic 10.3.6 时(如预期的那样),将使用长轮询.一个浏览器与自己聊天时,一切正常,但是当我打开第二个浏览器时,两个窗口都断开了.

When I downgrade to Tomcat 6.0. or when I use Weblogic 10.3.6 long-polling is used (as expected). With one browser chatting with itself everything works but when I open second browser both windows are disconnected.

我将日志级别设置为TRACE,看来Atmosphere正在添加每个 AtmosphereResource ,并且将UUID设置为10000:

I set the log level to TRACE and it seems that Atmosphere is adding every AtmosphereResource with the same UUID set to 10000:

TRACE [http-8080-6] o.a.c.DefaultAtmosphereResourceFactory [DefaultAtmosphereResourceFactory.java:309] Adding: AtmosphereResource{ uuid=10000, transport=LONG_POLLING, isInScope=true, isResumed=false, isCancelled=false, isSuspended=true, broadcasters=/chat, isClosedByClient=false, isClosedByApplication=false, action=Action{timeout=-1, type=SUSPEND}}

TRACE [http-8080-6] o.a.c.DefaultAtmosphereResourceFactory [DefaultAtmosphereResourceFactory.java:309] Adding: AtmosphereResource{ uuid=10000, transport=LONG_POLLING, isInScope=true, isResumed=false, isCancelled=false, isSuspended=true, broadcasters=/chat, isClosedByClient=false, isClosedByApplication=false, action=Action{timeout=-1, type=SUSPEND}}

我的Chat.java类:

My Chat.java class:

    @AtmosphereHandlerService(path = "/chat", 
broadcasterCache = UUIDBroadcasterCache.class,
                interceptors = {
                        AtmosphereResourceLifecycleInterceptor.class,
                        BroadcastOnPostAtmosphereInterceptor.class,
                        SuspendTrackerInterceptor.class,
                        HeartbeatInterceptor.class
                },
                broadcaster = SimpleBroadcaster.class
        )
        public class Chat extends OnMessage<String> {
            private final Logger logger = LoggerFactory.getLogger(Chat.class);
            private final JacksonDecoder decoder = new JacksonDecoder();
            private final JacksonEncoder encoder = new JacksonEncoder();


        @Override
        public void onMessage(AtmosphereResponse response, String message) throws IOException {
            Message mes = decoder.decode(message);
            logger.info("{} just send {}", mes.getAuthor(), mes.getMessage());
            response.write(encoder.encode(mes));
        }

我正在使用大气层版本2.3.1 . 不幸的是,我需要长时间轮询才能工作,因为那里有Weblogic 10.3.6.安装在我们的生产服务器上,它不支持 Websocket ,并且仅实现 Servlet 2.5..

I'm using Atmosphere version 2.3.1. Unfortunately I need long-polling to work because there Weblogic 10.3.6. installed on our production server and it doesn't support Websocket and has implementation of Servlet 2.5. only.

在向服务器的第一个GET请求期间,服务器将为给定的 AtmosphereRequest 设置 UUID ,并将其返回给带有HTTP标头的服务器

It looks like that during the first GET request to the server, server will set UUID for given AtmosphereRequest and returns it to the server with HTTP header

X-Atmosphere-tracking-id = someUUID

,但是在随后的请求中,客户端未使用它.它正在发送到服务器

but in the subsequent requsts the client is not using it. It is sending to the server

X-Atmosphere-tracking-id = 10000

不确定这是否正确...

Not sure if this is correct...

推荐答案

经过调试后,我能够解决此问题.

After some debuggin I was able to resolve this.

问题在于我正在使用的 application.js 库中

The problem was that in my application.js library I was using

trackMessageLength:是

在请求对象中,但未定义TrackMessageSize拦截器.

in request object but there was no TrackMessageSize interceptor defined.

Atmosphere.js 库正在解析以下数组,而不是1. value,而是采用2.value并将其设置为UUID.

The Atmosphere.js library was parsing following array and instead of 1. value it was taking 2.value and setting it as UUID.

["0af719e9-4776-4af1-9925-19c2bb10b547","10000","X","]

["0af719e9-4776-4af1-9925-19c2bb10b547", "10000", "X", "" ]

这篇关于Servlet 2.5的Atmosphere长轮询问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆