Hi everybody,

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?

If not it would be very usefull to have such a possibility.

Thanks in advance Emmanuel

asked 13.06.2015 at 10:22

Emmanuel's gravatar image

Emmanuel
(suspended)
accept rate: 66%


I did not test it: but I think that the ISessionExtension can do that job.

See: ch.ivyteam.ivy.security.ISessionExtension.destroySession(ISession, IPersistentTransaction)

And to register your extension: ch.ivyteam.ivy.security.ISecurityManager.addSessionExtension(ISessionExtension)

link

answered 15.06.2015 at 10:44

Reguel%20Wermelinger's gravatar image

Reguel Werme... ♦♦
9.4k31958
accept rate: 70%

Thanks a lot. Yes it should work.

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...

Thanks in Advance.

(15.06.2015 at 20:31) Emmanuel Emmanuel's gravatar image

Setting the timeout in <Designer root>/webapps/ivy/WEB-INF/web.xml should do it.

(15.06.2015 at 22:52) Dominik Regli ♦ Dominik%20Regli's gravatar image

I was not able to find documentation for ch.ivyteam.ivy.security.ISessionExtension.destroySession(ISession, IPersistentTransaction) or ch.ivyteam.ivy.security.ISecurityManager.addSessionExtension(ISessionExtension).

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.

Thanks!

(28.02.2017 at 23:10) Jailson Brito Jailson%20Brito's gravatar image
1

The registration of a ISessionExtension on every server start and stop has been described in another answer: see http://answers.axonivy.com/questions/2477/how-to-register-my-code-that-runs-on-every-engine-startup

(03.03.2017 at 10:33) Reguel Werme... ♦♦ Reguel%20Wermelinger's gravatar image

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:

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);
    }

}

The easiest way to register this Session extension is with a 'Program Start' event bean that runs when the server is up and running.

link

answered 03.03.2017 at 09:33

Reguel%20Wermelinger's gravatar image

Reguel Werme... ♦♦
9.4k31958
accept rate: 70%

edited 03.03.2017 at 09:34

Hi Reguel Wermelinger,

I want to use the FacesContext.getCurrentInstance(); in the function destroySession(ISession session, IPersistentTransaction transaction), But It always return null

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 ;(

Thanks, Duong Nguyen.

(14.08.2018 at 03:56) nhuuduong nhuuduong's gravatar image
1

@nhuuduong : 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 @SessionScoped bean and use a @javax.annotation.PreDestroy annotated method that will store the state back to the repository. For an example see https://stackoverflow.com/questions/6241249/listening-to-when-the-user-session-is-ended-in-a-jsf-managed-bean

(14.08.2018 at 04:19) Reguel Werme... ♦♦ Reguel%20Wermelinger's gravatar image

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 :) ?

(14.08.2018 at 04:32) nhuuduong nhuuduong's gravatar image

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?

All I need is to redirect to my "Login Dialog" on a session timeout.

The error message:

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

Thanks in advance!

link

answered 09.03.2017 at 05:14

Jailson%20Brito's gravatar image

Jailson Brito
(suspended)
accept rate: 50%

This is my implementation:

@ManagedBean
@SessionScoped
public class MySesssionBean {
    @PreDestroy
    public void destroy() {
        Ivy.log().fatal("Hi there");
        }
}

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.

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)

We can't get any ivy environment here :(

link

answered 14.08.2018 at 05:41

nhuuduong's gravatar image

nhuuduong
(suspended)
accept rate: 0%

edited 14.08.2018 at 05:58

Reguel%20Wermelinger's gravatar image

Reguel Werme... ♦♦
9.4k31958

1

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:

private static <T> T executeWithIvyContext(Callable<T> callable, IProcessModelVersion pmv, ISession session) throws Exception
  {
    MetaData.pushRequest(RequestFactory.createRestRequest(pmv, session));
    try
    {
      return callable.call();
    }
    finally
    {
      MetaData.popRequest();
    }
  }
(14.08.2018 at 06:00) Reguel Werme... ♦♦ Reguel%20Wermelinger's gravatar image

Hi Reguel Wermelinger, This is gold!!!! Finally, It's work Thank you so much!

(14.08.2018 at 07:25) nhuuduong nhuuduong's gravatar image
1

hi @nhuuduong 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...

(16.08.2018 at 03:11) Reguel Werme... ♦♦ Reguel%20Wermelinger's gravatar image

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.

(05.06.2019 at 05:14) Genzer Hawker Genzer%20Hawker's gravatar image

Hi @Genzer Hawker 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.

(04.07.2019 at 04:22) Reguel Werme... ♦♦ Reguel%20Wermelinger's gravatar image

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: https://developer.axonivy.com/doc/latest/PublicAPI/ch/ivyteam/util/threadcontext/IvyAsyncRunner.html

(04.07.2019 at 04:23) Reguel Werme... ♦♦ Reguel%20Wermelinger's gravatar image
showing 5 of 6 show 1 more comments
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×14
×10
×4

Asked: 13.06.2015 at 10:22

Seen: 11,495 times

Last updated: 04.07.2019 at 04:23