0

Session restarting

asked 2011-08-01 15:31:17 +0800

dastultz gravatar image dastultz
797 8

Hello all, I have a kiosk project. I know I can set a timer and configure Zk to allow the timer to keep the session alive and I can set the session so it never times out, but I'm looking for a way to smooth over a restart of Tomcat (when I deploy changes to the code). If you run any Zk app, stop your app server then restart, clicking a button for example will cause the page to reload (since the session/desktop was destroyed). I was hoping a Timer would cause this same thing to happen so users wouldn't click "go" and have the page reload and present them with the "go" button that they have to click again.

Any ideas?

Thanks.

/Daryl

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2011-08-12 05:01:33 +0800

matthewgo gravatar image matthewgo
375

Hi dastultz,
I have made a simple script as follows, you can check if it meets your needs. I also have a different solution that may check the session. Later if I have time to create a sample I will post again.

<script>
var  disconnect = 0;
var inter = setInterval(function () {

   jq.ajax({
    type: "POST",
    url: "http://localhost:8080/myapp1/",
    success: function(response ){
    if(disconnect){
    clearInterval(inter);
    window.history.go(0);
     
    }
     
    },
    error: function()
    {
     disconnect = 1 ;
    }
   });
  }, 3000);
</script>

link publish delete flag offensive edit

answered 2011-08-14 01:13:07 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

updated 2011-08-14 09:59:49 +0800

Hi Dastultz,
the sample check the session and connection is as follows,

the script put in zul page,
where the check pages 'checkSession.zul' and 'checkConnection.zul' are not exist,
just trigger the filter:

	<script type="text/javascript">
		var isChecking = false,
			disconnected = false,
			check;
		startCheck();
		function startCheck() {
			check = setInterval(function () {
				 // avoid multiple checking
				if (isChecking) return;
				isChecking = true;
				var check = disconnected? 'Connection' : 'Session';
				jq.ajax({
					type: "POST",
					url: "http://localhost:8080/SupportProj/check"+check+".zul",
					success: function(response ){
						isChecking = false;
						if (disconnected) {
							disconnected = false;
							window.history.go(0);
						}
					},
					error: function()
					{
						isChecking = false;
						disconnected = true;
					}
				});
			}, 1000);
		}
	</script>


the filter class, just response 'ok' or 'forbidden'
check both connection and session if it is triggered by 'checkSession.zul',
check connection only if it is triggered by 'checkConnection.zul':

package test;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

public class ConfirmFilter implements Filter {

	private static Logger logger = Logger.getLogger(ConfirmFilter.class);

	public ConfirmFilter(){
		super();
	}

	public void init(FilterConfig filterConfig) throws ServletException {

	}

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest)request;
		HttpServletResponse resp = (HttpServletResponse)response;
		if(doValidate(req, resp)){ //-- response ok Session is validate
			resp.sendError(resp.SC_OK);
		}
		else{ // response error if session is not valid
			resp.sendError(resp.SC_FORBIDDEN);
		}
    }

	public void destroy(){

	}

	public boolean doValidate(HttpServletRequest req, HttpServletResponse resp ) throws IOException, ServletException {
		if(req.getRequestURI().endsWith("Connection.zul")) // checkConnection.zul just check whether connectable
			return true;
		return (req.isRequestedSessionIdValid());
	}

}

the filter config in web.xml

	<filter>
		<description>Checking connect session</description>
		<display-name>ConfirmFilter</display-name>
		<filter-name>ConfirmFilter</filter-name>
		<filter-class>test.ConfirmFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>ConfirmFilter</filter-name>
		<url-pattern>checkSession.zul</url-pattern>
	</filter-mapping>
	<filter-mapping>
		<filter-name>ConfirmFilter</filter-name>
		<url-pattern>checkConnection.zul</url-pattern>
	</filter-mapping>

link publish delete flag offensive edit

answered 2011-09-08 06:36:46 +0800

dastultz gravatar image dastultz
797 8

Hi guys, thanks for the feedback. After 11 days of silence I figured no one would respond and forgot about it. I forgot to mention that I'm on the 3.6 line of Zk. It's good to know the client-side features are more advanced in 5.

Thanks again.

/Daryl

link publish delete flag offensive edit

answered 2011-09-10 10:40:22 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

It's okay, the solution above is based on javascript and JSP mechanism,
it should work fine in both ZK 3.6 and 5.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-08-01 15:31:17 +0800

Seen: 381 times

Last updated: Sep 10 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More