# Keep session alive programmatically

51 3

Hi everyone, I've developed a web application with ZK (8.0.2) + Spring Security, that make use of EventQueue and Threads to execute a long running task in background. I've tried two solutions to prevent session expires while task is still running, but none seems to work:

1. Make a HTTP request to the server at fixed intervals
2. Modify WebApp configuration by setting TimerKeepAlive to true

Can anybody suggest me a solutions to fix this issue? Thanks in advance

delete retag edit

Sort by » oldest newest most voted

cor3000
5225 2 7

Since your descriptions are a bit incomplete it's hard to give you a solution that solves your problem. So instead I'll try to fill in the missing bits with assumptions to line out what should work.

0) Specify a session timeout (in web.xml or zk.xml) you didn't mention which so I'll just assume 5 minutes for this example

1) "make a HTTP request" (that's very vague so I can't comment on that). Just use a <timer> component which will send specific onTimer events to the server at fixed intervals (make sure those intervals are below the 5 mins configured above ... e.g. 2 minutes)

1.1) to verify the timer is firing check your browser's network console, you should see requests to /zkau containing the onTimer events

2) configure <timer-keep-alive> the documentation is quite detailed also mentioning the usage of the timer component

Last ... please test your configuration without spring security first, to verify that it works... then you can test again using spring security. If the config doesn't work anymore, you might have to check and adjust your spring security configuration.

51 3

Thanks, I've fixed removing the subscription of the thread from the event queue

[hide preview]