<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Detect a user session is closing because of timeout</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout</link><description>&lt;p&gt;Hi everybody,&lt;/p&gt;
&lt;p&gt;Is there a way to detect a user session is closing because of a timeout?
There is the "unload" event that can be catched in an ULC Rich Dialog for performing some stuff when the user close a Dialog.
Is there something similar for a session timeout?&lt;/p&gt;
&lt;p&gt;If not it would be very usefull to have such a possibility.&lt;/p&gt;
&lt;p&gt;Thanks in advance
Emmanuel&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout" rel="self"></atom:link><language>en</language><lastBuildDate>Thu, 04 Jul 2019 04:23:58 -0400</lastBuildDate><item><title>Comment by Reguel Wermelinger on nhuuduong's answer</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#3874</link><description>&lt;p&gt;The other issue were this frequently happens is when java code runs asynch. But here we have a simple utility to face it: since the request context was once valid, but got lost during async usiage: &lt;a href="https://developer.axonivy.com/doc/latest/PublicAPI/ch/ivyteam/util/threadcontext/IvyAsyncRunner.html"&gt;https://developer.axonivy.com/doc/latest/PublicAPI/ch/ivyteam/util/threadcontext/IvyAsyncRunner.html&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Thu, 04 Jul 2019 04:23:58 -0400</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#3874</guid></item><item><title>Comment by Reguel Wermelinger on nhuuduong's answer</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#3873</link><description>&lt;p&gt;Hi &lt;a href="https://answers.axonivy.com/users/157/genzer-hawker"&gt;&lt;a href="https://answers.axonivy.com/users/157/genzer-hawker"&gt;@Genzer Hawker&lt;/a&gt;&lt;/a&gt;
This problem occurres whenever java code is being executed that was not started out of an HTTP request or another public interface that we provide to access the bpm engine. It's caused by the fact that our servlet-filters setup the valid context for a users HTTP request. And this context is used for DI later on.
So whenever pure java code calls API of the BPM engine, users must setup the context manually.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Thu, 04 Jul 2019 04:22:36 -0400</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#3873</guid></item><item><title>Comment by Genzer Hawker on nhuuduong's answer</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#3835</link><description>&lt;p&gt;Hi Reguel Wermelinger, nhuuduong, 
I've also got the problem can not access ivy environment outside when building a plugin. Howerver, I don't understand clearly your solution. Could you explain more for this? How can we use "executeWithIvyContext". Many thanks in advance.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Genzer Hawker</dc:creator><pubDate>Wed, 05 Jun 2019 05:14:11 -0400</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#3835</guid></item><item><title>Comment by Reguel Wermelinger on nhuuduong's answer</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#3393</link><description>&lt;p&gt;hi &lt;a href="https://answers.axonivy.com/users/843/nhuuduong"&gt;&lt;a href="https://answers.axonivy.com/users/843/nhuuduong"&gt;@nhuuduong&lt;/a&gt;&lt;/a&gt; glad that it helped. Please keep in mind to automate tests against such functionality and keep and eye on when migrating to newer versions of Axon.ivy. As this API is internal it could change frequently on new releases...&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Thu, 16 Aug 2018 03:11:20 -0400</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#3393</guid></item><item><title>Comment by nhuuduong on nhuuduong's answer</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#3392</link><description>&lt;p&gt;Hi Reguel Wermelinger,
This is gold!!!!
Finally, It's work
Thank you so much!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">nhuuduong</dc:creator><pubDate>Tue, 14 Aug 2018 07:25:49 -0400</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#3392</guid></item><item><title>Comment by Reguel Wermelinger on nhuuduong's answer</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#3391</link><description>&lt;p&gt;You can use internals to setup an environment. All you need is to store the IProcessModelVersion and ISession when the bean is created (and environment is available). 
Later you can execute and code by sending a callable to something like: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;private static &amp;lt;T&amp;gt; T executeWithIvyContext(Callable&amp;lt;T&amp;gt; callable, IProcessModelVersion pmv, ISession session) throws Exception
  {
    MetaData.pushRequest(RequestFactory.createRestRequest(pmv, session));
    try
    {
      return callable.call();
    }
    finally
    {
      MetaData.popRequest();
    }
  }
&lt;/code&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Tue, 14 Aug 2018 06:00:49 -0400</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#3391</guid></item><item><title>Answer by nhuuduong</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout/3390</link><description>&lt;p&gt;This is my implementation:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;@ManagedBean
@SessionScoped
public class MySesssionBean {
    @PreDestroy
    public void destroy() {
        Ivy.log().fatal("Hi there");
        }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But we still got the error:
Caused by: ch.ivyteam.ivy.environment.EnvironmentNotAvailableException: Access to ivy environment outside a process request thread is not possible.&lt;/p&gt;
&lt;p&gt;Current thread: Thread[ContainerBackgroundProcessor[StandardEngine[ivy]],6,main]
    at ch.ivyteam.ivy.environment.Ivy.getIvy(Ivy.java:577)
    at ch.ivyteam.ivy.environment.Ivy.getEnvironmentData(Ivy.java:556)
    at ch.ivyteam.ivy.environment.Ivy.getEnvironmentData(Ivy.java:551)
    at ch.ivyteam.ivy.environment.Ivy.log(Ivy.java:413)&lt;/p&gt;
&lt;p&gt;We can't get any ivy environment here :(&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">nhuuduong</dc:creator><pubDate>Tue, 14 Aug 2018 05:41:13 -0400</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout/3390</guid></item><item><title>Comment by nhuuduong on Reguel Wermelinger's answer</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#3389</link><description>&lt;p&gt;Thanks for your response quickly,
Let me try to do your suggestion, I will post the result here to discuss, is this ok for you :) ?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">nhuuduong</dc:creator><pubDate>Tue, 14 Aug 2018 04:32:44 -0400</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#3389</guid></item><item><title>Comment by Reguel Wermelinger on Reguel Wermelinger's answer</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#3387</link><description>&lt;p&gt;&lt;a href="https://answers.axonivy.com/users/843/nhuuduong"&gt;&lt;a href="https://answers.axonivy.com/users/843/nhuuduong"&gt;@nhuuduong&lt;/a&gt;&lt;/a&gt; : access to FacesContext is not possible as you have no active JSF lifecycle when the session ends. I guess you are better of when you keep the actual BusinessData on a &lt;code&gt;@SessionScoped&lt;/code&gt; bean and use a &lt;code&gt;@javax.annotation.PreDestroy&lt;/code&gt; annotated method that will store the state back to the repository. For an example see &lt;a href="https://stackoverflow.com/questions/6241249/listening-to-when-the-user-session-is-ended-in-a-jsf-managed-bean"&gt;https://stackoverflow.com/questions/6241249/listening-to-when-the-user-session-is-ended-in-a-jsf-managed-bean&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Tue, 14 Aug 2018 04:19:34 -0400</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#3387</guid></item><item><title>Comment by nhuuduong on Reguel Wermelinger's answer</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#3386</link><description>&lt;p&gt;Hi Reguel Wermelinger,&lt;/p&gt;
&lt;p&gt;I want to use the FacesContext.getCurrentInstance(); in the function destroySession(ISession session, IPersistentTransaction transaction), But It always return null&lt;/p&gt;
&lt;p&gt;Do you have any suggestion? I want to save the dossier before the session is timeout, but seem like this ways we can't do that ;(&lt;/p&gt;
&lt;p&gt;Thanks, Duong Nguyen.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">nhuuduong</dc:creator><pubDate>Tue, 14 Aug 2018 03:56:59 -0400</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#3386</guid></item><item><title>Answer by Jailson Brito</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout/2487</link><description>&lt;p&gt;Following your recommendation, I am registering my Session extension with a 'Program Start', it's properly detecting when the session is destroyed, and then my StartEventBean calls fireProcessStartEventRequest(). The 'Program Start' is being triggered but it's failing on the way to a "Login Dialog". Any ideas of what I am missing?&lt;/p&gt;
&lt;p&gt;All I need is to redirect to my "Login Dialog" on a session timeout.&lt;/p&gt;
&lt;p&gt;The error message:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;OutOfScopeException: Cannot access scoped [ch.ivyteam.ivy.dialog.execution.DialogRuntimeManager]. Either we are not currently inside an HTTP Servlet request, or you may have forgotten to apply com.google.inject.servlet.GuiceFilter as a servlet filter for this request.
ProvisionException: Unable to provision, see the following errors:

1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot access scoped [ch.ivyteam.ivy.dialog.execution.DialogRuntimeManager]. Either we are not currently inside an HTTP Servlet request, or you may have forgotten to apply com.google.inject.servlet.GuiceFilter as a servlet filter for this request.
  at ch.ivyteam.ivy.dialog.execution.DialogRuntimeManager.class(DialogRuntimeManager.java:30)
  while locating ch.ivyteam.ivy.dialog.execution.DialogRuntimeManager

1 error
BpmError: ivy:error:system
RequestException: ivy:error:system
Process Start Event Bean SessionWatcher [class=ch.ivyteam.wf.session.SessionWatcherStartEventBean, path=13EACA2A989BCC3D/eventLink.ivp] fire has been failed
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Thanks in advance!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jailson Brito</dc:creator><pubDate>Thu, 09 Mar 2017 05:14:11 -0500</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout/2487</guid></item><item><title>Comment by Reguel Wermelinger on Reguel Wermelinger's answer</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#2479</link><description>&lt;p&gt;The registration of a ISessionExtension on every server start and stop has been described in another answer: see &lt;a href="http://answers.axonivy.com/questions/2477/how-to-register-my-code-that-runs-on-every-engine-startup"&gt;http://answers.axonivy.com/questions/2477/how-to-register-my-code-that-runs-on-every-engine-startup&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Fri, 03 Mar 2017 10:33:43 -0500</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#2479</guid></item><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout/2475</link><description>&lt;p&gt;it's not public API therefore there is no documentation for it. But the simple methods of theses interfaces should speak for themselves. Anyway here is a simple implementation:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;package ch.ivyteam.sample;

import ch.ivyteam.di.restricted.DiCore;
import ch.ivyteam.ivy.persistence.IPersistentTransaction;
import ch.ivyteam.ivy.persistence.PersistencyException;
import ch.ivyteam.ivy.security.ISecurityManager;
import ch.ivyteam.ivy.security.ISession;
import ch.ivyteam.ivy.security.ISessionExtension;

public class MyDemoSessionExtension implements ISessionExtension 
{

    public static void install()
    {
        DiCore.getGlobalInjector().getInstance(ISecurityManager.class)
           .addSessionExtension(new MyDemoSessionExtension());
    }

    @Override
    public void createSession(ISession session, IPersistentTransaction transaction)
            throws PersistencyException {
        System.err.println("created session "+session);
    }

    @Override
    public void destroySession(ISession session, IPersistentTransaction transaction)
            throws PersistencyException {
        System.err.println("session destroyed "+session);
    }

    @Override
    public void logoutSession(ISession session, IPersistentTransaction transaction,
            long currentTaskId) throws PersistencyException {
        System.err.println("session logout "+session);
    }

}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The easiest way to register this Session extension is with a 'Program Start' event bean that runs when the server is up and running. &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Fri, 03 Mar 2017 09:33:30 -0500</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout/2475</guid></item><item><title>Comment by Jailson Brito on Reguel Wermelinger's answer</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#2471</link><description>&lt;p&gt;I was not able to find documentation for ch.ivyteam.ivy.security.ISessionExtension.destroySession(ISession, IPersistentTransaction) or ch.ivyteam.ivy.security.ISecurityManager.addSessionExtension(ISessionExtension). &lt;/p&gt;
&lt;p&gt;Please, could you share a link for the docs? Or a more detailed example of how to use ISessionExtension to detect session timeout would be very helpful.&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jailson Brito</dc:creator><pubDate>Tue, 28 Feb 2017 23:10:54 -0500</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#2471</guid></item><item><title>Comment by Dominik Regli on Reguel Wermelinger's answer</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#1364</link><description>&lt;p&gt;Setting the timeout in &amp;lt;Designer root&amp;gt;/webapps/ivy/WEB-INF/web.xml should do it.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Dominik Regli</dc:creator><pubDate>Mon, 15 Jun 2015 22:52:37 -0400</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#1364</guid></item><item><title>Comment by Emmanuel on Reguel Wermelinger's answer</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#1363</link><description>&lt;p&gt;Thanks a lot.
Yes it should work. &lt;/p&gt;
&lt;p&gt;I would like to test it on the designer. How can I set the session timeout in the designer? I would like to set it to a very short time so I don't have to wait a to long time...&lt;/p&gt;
&lt;p&gt;Thanks in Advance.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Emmanuel</dc:creator><pubDate>Mon, 15 Jun 2015 20:31:51 -0400</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout#1363</guid></item><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout/1362</link><description>&lt;p&gt;I did not test it: but I think that the ISessionExtension can do that job. &lt;/p&gt;
&lt;p&gt;See: ch.ivyteam.ivy.security.ISessionExtension.destroySession(ISession, IPersistentTransaction)&lt;/p&gt;
&lt;p&gt;And to register your extension: ch.ivyteam.ivy.security.ISecurityManager.addSessionExtension(ISessionExtension)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Mon, 15 Jun 2015 10:44:50 -0400</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout/1362</guid></item></channel></rss>