我已经在glassfish上部署了一个Web应用程序,在那里我在web.xml中有一个会话超时:
<session-config>
<session-timeout>
1
</session-timeout>
</session-config>
在我添加WebSockets之前一切正常
前端:
var webSocket = new WebSocket('#{authenticationJSFBean.webSocketURL}');
webSocket.onmessage = function(message){
switch(message.data) {
case 'sendRegistrationRequest':
updateNewRegistrationRequestCount();
break;
case 'sendStageRequest':
updateSourceAndTargetParticipatingCompaniesDataTables();
break;
};
后端:
@ServerEndpoint("/websocket/{login}")
public class WebSocketEndpoint {
private static final Set<Session> sessions = new CopyOnWriteArraySet<>();
private static final Logger LOG = LogManager.getLogger(WebSocketEndpoint.class);
@OnOpen
public void onOpen(@PathParam("login") String login, Session peer) {
sessions.add(peer);
}
@OnClose
public void onClose(Session peer) {
if(sessions.contains(peer)) {
sessions.remove(peer);
}
}
public static void sendMessage(String message) {
for(Session session : sessions) {
RemoteEndpoint.Basic endpoint = session.getBasicRemote();
try {
endpoint.sendText(message);
} catch(IOException ioe) {
LOG.warn("Unable to send message to session\n Message:" + ioe.getMessage());
}
}
}
}
添加此内容后,会话超时停止工作。我试图在websocket会话中设置超时时间:
peer.setMaxIdleTimeout(60 * 60 * 1000);
起初看起来很有帮助,但是在第二或第三次会议上我遇到了错误:
[2018-12-27T10:01:30.833+0300] [glassfish 4.1] [WARNING] [] [org.glassfish.grizzly.filterchain.DefaultFilterChain] [tid: _ThreadID=120 _ThreadName=http-listener-1(1)] [timeMillis: 1545894090833] [levelValue: 900] [[
GRIZZLY0013: Exception during FilterChain execution
java.lang.NullPointerException
at org.glassfish.grizzly.attributes.Attribute.remove(Attribute.java:227)
at org.glassfish.grizzly.http.server.HttpServerFilter.afterService(HttpServerFilter.java:383)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:260)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
]]
[2018-12-27T10:02:11.395+0300] [glassfish 4.1] [WARN] [] [org.jboss.weld.Servlet] [tid: _ThreadID=120 _ThreadName=http-listener-1(1)] [timeMillis: 1545894131395] [levelValue: 900] [[
WELD-000714: HttpContextLifecycle guard leak detected. The Servlet container is not fully compliant. The value was 1]]
[2018-12-27T10:02:11.396+0300] [glassfish 4.1] [WARNING] [] [javax.enterprise.web.core] [tid: _ThreadID=120 _ThreadName=http-listener-1(1)] [timeMillis: 1545894131396] [levelValue: 900] [[
Error invoking requestInitialized method on ServletRequestListener org.jboss.weld.servlet.WeldListener
java.lang.IllegalStateException: WELD-000335: Context is already active
at org.jboss.weld.context.http.LazyHttpConversationContextImpl.activate(LazyHttpConversationContextImpl.java:57)
at org.jboss.weld.servlet.ConversationContextActivator.activate(ConversationContextActivator.java:107)
at org.jboss.weld.servlet.ConversationContextActivator.activateConversationContext(ConversationContextActivator.java:93)
at org.jboss.weld.servlet.HttpContextLifecycle.requestInitialized(HttpContextLifecycle.java:225)
at org.jboss.weld.servlet.WeldInitialListener.requestInitialized(WeldInitialListener.java:156)
at org.apache.catalina.core.StandardContext.fireRequestInitializedEvent(StandardContext.java:5257)
at org.apache.catalina.core.StandardHostValve.preInvoke(StandardHostValve.java:655)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:166)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
]]
并且超时完全停止工作。如何解决?