У меня развернуто веб-приложение на glassfish, где у меня есть тайм-аут для сеанса в 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;
};
Backend:
@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)
]]
И тайм-аутперестает работать снова полностьюКак это исправить?