Mendix Autlogin Causes the whole platform to hang

0
I have called a java action that auto logins in a user; com.mendix.core.Core.login(this.Username, this.Password); But the code above causes the whole Mendix Platform to hang!
asked
1 answers
2

Well, I created a microflow that calls the java login function straight away while passing the username and password. Guess what, the login function works. Refer to code below

// BEGIN USER CODE
    try{
        //com.mendix.core.Core.logout(getContext().getSession());
        Core.getLogger("Auto login 1").info(this.getContext().toString());
        ISession currSession = com.mendix.core.Core.login(this.Username, this.Password);
        Core.getLogger("Auto login 2").info(currSession.getUser().getName());
        com.mendix.core.Core.initializeSession(this.getContext(), currSession.getUser(), getContext().getSession().getId().toString(), "");
        Core.getLogger("Auto login 3").info(currSession.getUser().getName());
        //return com.mendix.core.Core.login(this.Username, this.Password).isSystemSession();
        return true;
    }
    catch(Exception e){
        return false;
    }
    // END USER CODE

However when i am calling the login function in a microflow which does other things before login eg Best user scenerion is account set up for a new invited user, The above code causes Mendix to Hang. I was able to solve the hanging issue by the code below. What i did, i had to stop all mendix transaction in the context and then start the transaction afresh before calling Login. Bas van den Broek might give a proper technical answer as to why i had to stop the transaction and then start it afresh before calling login

// BEGIN USER CODE
    try{
        //End transaction and start it afresh to avoid mendix from hanging
        this.getContext().endTransaction();
        this.getContext().startTransaction();

        Core.getLogger("Auto login 1").info(this.getContext().toString());
        ISession currSession = com.mendix.core.Core.login(this.Username, this.Password);
        Core.getLogger("Auto login 2").info(currSession.getUser().getName());
        com.mendix.core.Core.initializeSession(this.getContext(), currSession.getUser(), getContext().getSession().getId().toString(), "");
        Core.getLogger("Auto login 3").info(currSession.getUser().getName());
        //return com.mendix.core.Core.login(this.Username, this.Password).isSystemSession();
        return true;
    }
    catch(Exception e){
        return false;
    }
    // END USER CODE
answered