我正在测试一个使用Atmosphere框架的简单聊天应用程序。当我从两个浏览器连接到应用程序时,一切都像聊天应该使用 Tomcat 7.0 和 Websockets 协议。
当我降级到 Tomcat 6.0。或当我使用 Weblogic 10.3.6 时,使用长轮询(如预期的那样)。一个浏览器与自己聊天一切正常,但当我打开第二个浏览器时,两个窗口都断开连接。
我将日志级别设置为TRACE,似乎Atmosphere正在添加每个 AtmosphereResource ,并将相同的UUID设置为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}}
我的Chat.java类:
@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));
}
我正在使用 Atmosphere版本2.3.1 。 不幸的是,我需要长轮询才能工作,因为有Weblogic 10.3.6。安装在我们的生产服务器上,它不支持 Websocket ,并且只实现了 Servlet 2.5。。
修改
在第一次向服务器发出GET请求时,服务器会为给定的 AtmosphereRequest 设置 UUID ,并将其返回给带有HTTP标头的服务器
X - 大气跟踪-ID = someUUID
但在随后的请求中,客户端没有使用它。它正在发送到服务器
X - 大气跟踪-ID = 10000
不确定这是否正确...
答案 0 :(得分:0)
经过一些调试后,我能够解决这个问题。
问题在于我的 application.js 库我正在使用
trackMessageLength:true
在请求对象中,但没有定义TrackMessageSize拦截器。
Atmosphere.js 库正在解析数组,而不是1.值,它取2.value并将其设置为UUID。
[&#34; 0af719e9-4776-4af1-9925-19c2bb10b547&#34;,&#34; 10000&#34;,&#34; X&#34;,&#34;&#34; ]