diff --git a/org.adempiere.base/src/org/compiere/model/MSession.java b/org.adempiere.base/src/org/compiere/model/MSession.java index 58bd5e6ed4..8e4e060636 100644 --- a/org.adempiere.base/src/org/compiere/model/MSession.java +++ b/org.adempiere.base/src/org/compiere/model/MSession.java @@ -53,26 +53,27 @@ public class MSession extends X_AD_Session implements ImmutablePOSupport * @param ctx context * @param createNew create if not found * @return session session - * @deprecated get (Properties ctx, boolean createNew, boolean isCache) for caching support + * @deprecated use Get and Create functions. */ public static MSession get (Properties ctx, boolean createNew) { - return get(ctx, createNew, false); + MSession session = get(ctx); + if(session == null && createNew) + return MSession.create(ctx); + return session; } // get /** - * Get existing or create local session + * Get existing local session * @param ctx context - * @param createNew create if not found - * @param isImmutable return Immutable Session Object (from Cache) * @return session session */ - public static MSession get (Properties ctx, boolean createNew, boolean isImmutable) + public static MSession get (Properties ctx) { int AD_Session_ID = Env.getContextAsInt(ctx, Env.AD_SESSION_ID); - MSession session = isImmutable ? s_sessions.get(ctx, AD_Session_ID, e -> new MSession(ctx, e)) : new MSession(ctx, AD_Session_ID, null); + MSession session = s_sessions.get(ctx, AD_Session_ID, e -> new MSession(ctx, e)); // Try to load - if (isImmutable && session == null && AD_Session_ID > 0) + if (session == null && AD_Session_ID > 0) { session = new MSession(ctx, AD_Session_ID, null); if (session.get_ID () == AD_Session_ID) @@ -83,17 +84,22 @@ public class MSession extends X_AD_Session implements ImmutablePOSupport session = null; } } - // Create New - if (session == null && createNew) - { - session = new MSession (ctx, (String)null); // local session - session.saveEx(); - AD_Session_ID = session.getAD_Session_ID(); - Env.setContext (ctx, Env.AD_SESSION_ID, AD_Session_ID); - if(isImmutable) - s_sessions.put (AD_Session_ID, session, e -> new MSession(Env.getCtx(), e)); - } - + return session; + } // get + + /** + * Get existing or create local session + * @param ctx context + * @param createNew create if not found + * @param isImmutable return Immutable Session Object (from Cache) + * @return session session + */ + public static MSession create (Properties ctx) + { + MSession session = new MSession (ctx, (String)null); // local session + session.saveEx(); + int AD_Session_ID = session.getAD_Session_ID(); + Env.setContext (ctx, Env.AD_SESSION_ID, AD_Session_ID); return session; } // get @@ -104,26 +110,11 @@ public class MSession extends X_AD_Session implements ImmutablePOSupport * @param Remote_Host remote host * @param WebSession web session * @return session - * @deprecated use get (Properties ctx, String Remote_Addr, String Remote_Host, String WebSession, boolean isCache) */ public static MSession get (Properties ctx, String Remote_Addr, String Remote_Host, String WebSession) - { - return get(ctx, Remote_Addr, Remote_Host, WebSession, false); - } // get - - /** - * Get existing or create remote session - * @param ctx context - * @param Remote_Addr remote address - * @param Remote_Host remote host - * @param WebSession web session - * @param isImmutable return Immutable Object (from Cache) - * @return session - */ - public static MSession get (Properties ctx, String Remote_Addr, String Remote_Host, String WebSession, boolean isImmutable) { int AD_Session_ID = Env.getContextAsInt(ctx, Env.AD_SESSION_ID); - MSession session = get(ctx, false, isImmutable); + MSession session = get(ctx); if (session == null) { @@ -131,8 +122,8 @@ public class MSession extends X_AD_Session implements ImmutablePOSupport session.saveEx(); AD_Session_ID = session.getAD_Session_ID(); Env.setContext(ctx, Env.AD_SESSION_ID, AD_Session_ID); - if(isImmutable) - s_sessions.put (AD_Session_ID, session, e -> new MSession(Env.getCtx(), e)); + } else { + session = new MSession(ctx, session.getAD_Session_ID(), null); } return session; diff --git a/org.adempiere.base/src/org/compiere/model/PO.java b/org.adempiere.base/src/org/compiere/model/PO.java index 3749c39411..878b8df8e7 100644 --- a/org.adempiere.base/src/org/compiere/model/PO.java +++ b/org.adempiere.base/src/org/compiere/model/PO.java @@ -2661,7 +2661,7 @@ public abstract class PO lobReset(); // Change Log - MSession session = MSession.get (p_ctx, false, true); + MSession session = MSession.get (p_ctx); if (session == null) log.fine("No Session found"); int AD_ChangeLog_ID = 0; @@ -3123,7 +3123,7 @@ public abstract class PO lobReset(); // Change Log - MSession session = MSession.get (p_ctx, false, true); + MSession session = MSession.get (p_ctx); if (session == null) log.fine("No Session found"); int AD_ChangeLog_ID = 0; @@ -3719,7 +3719,7 @@ public abstract class PO if( p_info.isChangeLog()) { // Change Log - MSession session = MSession.get (p_ctx, false, true); + MSession session = MSession.get (p_ctx); if (session == null) log.fine("No Session found"); else if (m_IDs.length == 1) diff --git a/org.adempiere.base/src/org/compiere/process/ProcessInfo.java b/org.adempiere.base/src/org/compiere/process/ProcessInfo.java index ddc15ce628..3218cde1fc 100644 --- a/org.adempiere.base/src/org/compiere/process/ProcessInfo.java +++ b/org.adempiere.base/src/org/compiere/process/ProcessInfo.java @@ -912,7 +912,7 @@ public class ProcessInfo implements Serializable } private Timestamp getLastServerRebootDate() { - MSession currentSession = MSession.get(Env.getCtx(), false, true); + MSession currentSession = MSession.get(Env.getCtx()); if (currentSession == null) return null; diff --git a/org.adempiere.base/src/org/compiere/util/Env.java b/org.adempiere.base/src/org/compiere/util/Env.java index 6f30bc2300..a72e999fdf 100644 --- a/org.adempiere.base/src/org/compiere/util/Env.java +++ b/org.adempiere.base/src/org/compiere/util/Env.java @@ -176,9 +176,11 @@ public final class Env //hengsin, avoid unncessary query of session when exit without log in if (DB.isConnected(false)) { // End Session - MSession session = MSession.get(Env.getCtx(), false, false); // finish - if (session != null) + MSession session = MSession.get(Env.getCtx()); // finish + if (session != null) { + session = new MSession(getCtx(), session.getAD_Session_ID(), null); session.logout(); + } } // reset(true); // final cache reset @@ -195,9 +197,11 @@ public final class Env public static void logout() { // End Session - MSession session = MSession.get(Env.getCtx(), false, false); // finish - if (session != null) + MSession session = MSession.get(Env.getCtx()); // finish + if (session != null) { + session = new MSession(getCtx(), session.getAD_Session_ID(), null); session.logout(); + } // reset(true); // final cache reset // diff --git a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/AdempiereActivator.java b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/AdempiereActivator.java index 6c9a2f7b92..0e4bc60350 100644 --- a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/AdempiereActivator.java +++ b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/AdempiereActivator.java @@ -98,7 +98,7 @@ public class AdempiereActivator extends AbstractActivator { MSession localSession = null; //Create Session to be able to create records in AD_ChangeLog if (Env.getContextAsInt(Env.getCtx(), Env.AD_SESSION_ID) <= 0) { - localSession = MSession.get(Env.getCtx(), true, false); + localSession = MSession.create(Env.getCtx()); localSession.setWebSession("AdempiereActivator"); localSession.saveEx(); } diff --git a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/Incremental2PackActivator.java b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/Incremental2PackActivator.java index 19a49a8be2..fb0765df59 100644 --- a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/Incremental2PackActivator.java +++ b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/Incremental2PackActivator.java @@ -212,7 +212,12 @@ public class Incremental2PackActivator extends AbstractActivator { MSession localSession = null; //Create Session to be able to create records in AD_ChangeLog if (Env.getContextAsInt(Env.getCtx(), Env.AD_SESSION_ID) <= 0) { - localSession = MSession.get(Env.getCtx(), true, false); + localSession = MSession.get(Env.getCtx()); + if(localSession == null) { + localSession = MSession.create(Env.getCtx()); + } else { + localSession = new MSession(Env.getCtx(), localSession.getAD_Session_ID(), null); + } localSession.setWebSession("Incremental2PackActivator"); localSession.saveEx(); } diff --git a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/PackInApplicationActivator.java b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/PackInApplicationActivator.java index 3aef44fd35..74f14a4f93 100644 --- a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/PackInApplicationActivator.java +++ b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/PackInApplicationActivator.java @@ -101,7 +101,12 @@ public class PackInApplicationActivator extends AbstractActivator{ if (getDBLock()) { //Create Session to be able to create records in AD_ChangeLog if (Env.getContextAsInt(Env.getCtx(), Env.AD_SESSION_ID) <= 0) { - localSession = MSession.get(Env.getCtx(), true, false); + localSession = MSession.get(Env.getCtx()); + if(localSession == null) { + localSession = MSession.create(Env.getCtx()); + } else { + localSession = new MSession(Env.getCtx(), localSession.getAD_Session_ID(), null); + } localSession.setWebSession("PackInApplicationActivator"); localSession.saveEx(); } diff --git a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/Version2PackActivator.java b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/Version2PackActivator.java index fdec2d118f..e9afaf495e 100644 --- a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/Version2PackActivator.java +++ b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/Version2PackActivator.java @@ -151,7 +151,12 @@ public class Version2PackActivator extends AbstractActivator{ if (getDBLock()) { //Create Session to be able to create records in AD_ChangeLog if (Env.getContextAsInt(Env.getCtx(), Env.AD_SESSION_ID) <= 0) { - localSession = MSession.get(Env.getCtx(), true, false); + localSession = MSession.get(Env.getCtx()); + if(localSession == null) { + localSession = MSession.create(Env.getCtx()); + } else { + localSession = new MSession(Env.getCtx(), localSession.getAD_Session_ID(), null); + } localSession.setWebSession("Version2PackActivator"); localSession.saveEx(); } diff --git a/org.adempiere.server/src/main/server/org/compiere/server/AdempiereServerMgr.java b/org.adempiere.server/src/main/server/org/compiere/server/AdempiereServerMgr.java index 9942728416..644e1ab0b5 100644 --- a/org.adempiere.server/src/main/server/org/compiere/server/AdempiereServerMgr.java +++ b/org.adempiere.server/src/main/server/org/compiere/server/AdempiereServerMgr.java @@ -119,7 +119,12 @@ public class AdempiereServerMgr implements ServiceTrackerCustomizer, IWeb String x_Forward_IP = Executions.getCurrent().getHeader("X-Forwarded-For"); MSession mSession = MSession.get (ctx, x_Forward_IP!=null ? x_Forward_IP : Executions.getCurrent().getRemoteAddr(), - Executions.getCurrent().getRemoteHost(), httpSess.getId(), false ); + Executions.getCurrent().getRemoteHost(), httpSess.getId()); if (clientInfo.userAgent != null) { mSession.setDescription(mSession.getDescription() + "\n" + clientInfo.toString()); mSession.saveEx(); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java index 01285036d9..d42c273960 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java @@ -211,7 +211,8 @@ public final class AEnv } windowCache.remove(sessionID); // End Session - MSession session = MSession.get(Env.getCtx(), false, false); // finish + int ad_Session_ID = Env.getContextAsInt(Env.getCtx(), Env.AD_SESSION_ID); + MSession session = ad_Session_ID > 0 ? new MSession(Env.getCtx(), ad_Session_ID, null) : null; // finish if (session != null) session.logout(); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/session/SessionContextListener.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/session/SessionContextListener.java index 7c10b8f498..2a586ddd98 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/session/SessionContextListener.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/session/SessionContextListener.java @@ -265,9 +265,9 @@ public class SessionContextListener implements ExecutionInit, } } - MSession mSession = MSession.get(Env.getCtx(), false, false); + MSession mSession = MSession.get(Env.getCtx()); if(mSession!=null && !mSession.isProcessed()) { - + mSession = new MSession(Env.getCtx(), mSession.getAD_Session_ID(), null); mSession.setProcessed(true); mSession.saveEx(); } @@ -318,9 +318,10 @@ public class SessionContextListener implements ExecutionInit, { setupExecutionContextFromSession(Executions.getCurrent()); } - MSession mSession = MSession.get(Env.getCtx(), false, false); + MSession mSession = MSession.get(Env.getCtx()); if(mSession!=null){ if (mSession.isProcessed()) { + mSession = new MSession(Env.getCtx(), mSession.getAD_Session_ID(), null); mSession.setProcessed(false); mSession.saveEx(); } diff --git a/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/CompiereService.java b/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/CompiereService.java index 0bc98d6c08..d5abf7e96b 100644 --- a/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/CompiereService.java +++ b/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/CompiereService.java @@ -288,11 +288,14 @@ public class CompiereService { Env.setContext(getCtx(), Env.LANGUAGE, m_language.getAD_Language()); // Create session - MSession session = MSession.get (getCtx(), false, false); + MSession session = MSession.get (getCtx()); if (session == null){ log.fine("No Session found"); - session = MSession.get (getCtx(), true, false); + session = MSession.create (getCtx()); + } else { + session = new MSession(getCtx(), session.getAD_Session_ID(), null); } + session.setWebSession("WebService"); session.setDescription(session.getDescription() + "\nUser Agent: " + getCtx().getProperty("#UserAgent"));