气氛无法在 Glassfish 3.1.2 上获得会话
Posted
技术标签:
【中文标题】气氛无法在 Glassfish 3.1.2 上获得会话【英文标题】:Atmosphere can't get session on Glassfish 3.1.2 【发布时间】:2012-05-19 16:40:14 【问题描述】:我从 Atmosphere 获得了 chat 示例,现在我想获得会话,但我得到一个空指针异常。我的配置:
GlassFish 3.1.2 气氛 1.0.0-SNAPSHOT我的 ChatAtmosphereHandler.java 文件:
@Override
public void onRequest(AtmosphereResource r) throws IOException
AtmosphereRequest req = r.getRequest();
// First, tell Atmosphere to allow bi-directional communication by suspending.
if (req.getMethod().equalsIgnoreCase("GET"))
/* ------- ADDED LINES BY ME ------- */
double i = Math.random();
System.out.println(i);
req.getSession(true).setAttribute("user", i); //Null pointer exception
/* --------------------------------- */
// The negotiation header is just needed by the sample to list all the supported transport.
if (req.getHeader("negotiating") == null)
r.suspend();
else
r.getResponse().getWriter().write("OK");
// Second, broadcast message to all connected users.
else if (req.getMethod().equalsIgnoreCase("POST"))
r.getBroadcaster().broadcast(req.getReader().readLine().trim());
还有异常堆栈跟踪:
INFO: 18:07:19.816 [http-thread-pool-8080(4)] WARN o.a.websocket.WebSocketProcessor - Failed invoking AtmosphereFramework.doCometSupport()
java.lang.NullPointerException: null
at com.sun.grizzly.tcp.http11.GrizzlyRequest.doGetSession(GrizzlyRequest.java:2271) ~[grizzly-utils.jar:1.9.46]
at com.sun.grizzly.tcp.http11.GrizzlyRequest.getSession(GrizzlyRequest.java:2226) ~[grizzly-utils.jar:1.9.46]
at com.sun.grizzly.http.servlet.HttpServletRequestImpl.getSession(HttpServletRequestImpl.java:986) ~[grizzly-http-servlet.jar:1.9.46]
at com.sun.grizzly.http.servlet.HttpServletRequestImpl.getSession(HttpServletRequestImpl.java:1009) ~[grizzly-http-servlet.jar:1.9.46]
at org.atmosphere.cpr.AtmosphereRequest.createSession(AtmosphereRequest.java:606) ~[atmosphere-runtime-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
at org.atmosphere.cpr.AtmosphereRequest.getSession(AtmosphereRequest.java:580) ~[atmosphere-runtime-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
at org.atmosphere.cpr.AtmosphereRequest.getSession(AtmosphereRequest.java:600) ~[atmosphere-runtime-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
at org.atmosphere.samples.chat.ChatAtmosphereHandler.onRequest(ChatAtmosphereHandler.java:43) ~[ChatAtmosphereHandler.class:na]
at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:232) ~[atmosphere-runtime-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:165) ~[atmosphere-runtime-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
at org.atmosphere.container.GlassFishWebSocketSupport.service(GlassFishWebSocketSupport.java:111) ~[atmosphere-runtime-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:1125) ~[atmosphere-runtime-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
at org.atmosphere.websocket.WebSocketProcessor.dispatch(WebSocketProcessor.java:183) [atmosphere-runtime-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
at org.atmosphere.websocket.WebSocketProcessor.dispatch(WebSocketProcessor.java:112) [atmosphere-runtime-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
at org.atmosphere.container.GlassFishWebSocketSupport$GrizzlyApplication.onConnect(GlassFishWebSocketSupport.java:163) [atmosphere-runtime-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
at com.sun.grizzly.websockets.DefaultWebSocket.onConnect(DefaultWebSocket.java:128) [grizzly-websockets.jar:1.9.46]
at com.sun.grizzly.websockets.WebSocketEngine.upgrade(WebSocketEngine.java:188) [grizzly-websockets.jar:1.9.46]
at com.sun.grizzly.websockets.WebSocketAsyncFilter.doFilter(WebSocketAsyncFilter.java:54) [grizzly-websockets.jar:1.9.46]
at com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java:171) [grizzly-http.jar:1.9.46]
at com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:143) [grizzly-http.jar:1.9.46]
at com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:102) [grizzly-http.jar:1.9.46]
at com.sun.grizzly.http.TaskBase.run(TaskBase.java:193) [grizzly-http.jar:1.9.46]
at com.sun.grizzly.http.TaskBase.execute(TaskBase.java:175) [grizzly-http.jar:1.9.46]
at com.sun.grizzly.arp.DefaultAsyncHandler.handle(DefaultAsyncHandler.java:145) [grizzly-http.jar:1.9.46]
at com.sun.grizzly.arp.AsyncProtocolFilter.execute(AsyncProtocolFilter.java:210) [grizzly-http.jar:1.9.46]
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) [grizzly-framework.jar:1.9.46]
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) [grizzly-framework.jar:1.9.46]
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) [grizzly-framework.jar:1.9.46]
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) [grizzly-http.jar:1.9.46]
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) [grizzly-framework.jar:1.9.46]
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) [grizzly-framework.jar:1.9.46]
at com.sun.grizzly.ContextTask.run(ContextTask.java:71) [grizzly-framework.jar:1.9.46]
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) [grizzly-utils.jar:1.9.46]
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) [grizzly-utils.jar:1.9.46]
at java.lang.Thread.run(Thread.java:722) [na:1.7.0_03]
【问题讨论】:
【参考方案1】:从那时起,会话处理代码已被修改。请使用最新的主代码重试。
【讨论】:
是的,它现在正在工作,两者都有错误 - 灰熊和大气代码。以上是关于气氛无法在 Glassfish 3.1.2 上获得会话的主要内容,如果未能解决你的问题,请参考以下文章
Glassfish 3.1.2.2上的java.lang.NoClassDefFoundError
GlassFish 3.1.2 在部署时提供 404 而没有任何错误