diff --git a/org.adempiere.base/src/org/compiere/util/Env.java b/org.adempiere.base/src/org/compiere/util/Env.java index f3f75276d8..1182442673 100644 --- a/org.adempiere.base/src/org/compiere/util/Env.java +++ b/org.adempiere.base/src/org/compiere/util/Env.java @@ -232,7 +232,8 @@ public final class Env } /** - * Set Context + * Replace the contents of the current session/process context. + * Don't use this to setup a new session/process context, use ServerContext.setCurrentInstance instead. * @param ctx context */ public static void setCtx (Properties ctx) diff --git a/org.adempiere.server/src/main/server/org/compiere/server/Scheduler.java b/org.adempiere.server/src/main/server/org/compiere/server/Scheduler.java index fbfddc204d..a456aada48 100644 --- a/org.adempiere.server/src/main/server/org/compiere/server/Scheduler.java +++ b/org.adempiere.server/src/main/server/org/compiere/server/Scheduler.java @@ -23,6 +23,7 @@ import java.text.SimpleDateFormat; import java.util.Properties; import java.util.logging.Level; +import org.adempiere.util.ServerContext; import org.compiere.model.MAttachment; import org.compiere.model.MClient; import org.compiere.model.MNote; @@ -106,8 +107,7 @@ public class Scheduler extends AdempiereServer Timestamp ts = new Timestamp(System.currentTimeMillis()); SimpleDateFormat dateFormat4Timestamp = new SimpleDateFormat("yyyy-MM-dd"); Env.setContext(m_schedulerctx, "#Date", dateFormat4Timestamp.format(ts)+" 00:00:00" ); // JDBC format - Properties currentctx = Env.getCtx(); - Env.setCtx(m_schedulerctx); + ServerContext.setCurrentInstance(m_schedulerctx); MProcess process = new MProcess(m_schedulerctx, m_model.getAD_Process_ID(), null); try @@ -129,8 +129,8 @@ public class Scheduler extends AdempiereServer m_trx.close(); } - // Restore system context - Env.setCtx(currentctx); + // clear thread local context + ServerContext.dispose(); // int no = m_model.deleteLog(); diff --git a/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/ExecuteProcessCommand.java b/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/ExecuteProcessCommand.java index b9c7df3f6c..f80cbeeda3 100644 --- a/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/ExecuteProcessCommand.java +++ b/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/ExecuteProcessCommand.java @@ -18,6 +18,7 @@ import java.util.Properties; import org.adempiere.exceptions.AdempiereException; import org.adempiere.util.RestletUtil; +import org.adempiere.util.ServerContext; import org.compiere.interfaces.impl.ServerBean; import org.compiere.model.MRole; import org.compiere.process.ProcessInfo; @@ -61,12 +62,9 @@ public class ExecuteProcessCommand extends ServerResource { } ServerBean bean = new ServerBean(); - //back up properties - Properties backup = new Properties(); - backup.putAll(Env.getCtx()); try { - Env.setCtx(context); + ServerContext.setCurrentInstance(context); if (procedureName != null && procedureName.trim().length() > 0) return bean.dbProcess(context, pi, procedureName); else @@ -74,7 +72,7 @@ public class ExecuteProcessCommand extends ServerResource { } finally { - Env.setCtx(backup); + ServerContext.dispose(); } } diff --git a/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/ExecuteTaskCommand.java b/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/ExecuteTaskCommand.java index be39be01de..a3cf5b482c 100644 --- a/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/ExecuteTaskCommand.java +++ b/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/ExecuteTaskCommand.java @@ -18,6 +18,7 @@ import java.util.Properties; import org.adempiere.exceptions.AdempiereException; import org.adempiere.util.RestletUtil; +import org.adempiere.util.ServerContext; import org.compiere.interfaces.impl.ServerBean; import org.compiere.model.MRole; import org.compiere.util.Env; @@ -57,17 +58,14 @@ public class ExecuteTaskCommand extends ServerResource { } ServerBean bean = new ServerBean(); - //back up properties - Properties backup = new Properties(); - backup.putAll(Env.getCtx()); try { - Env.setCtx(context); + ServerContext.setCurrentInstance(context); return bean.executeTask(context, AD_Task_ID); } finally { - Env.setCtx(backup); + ServerContext.dispose(); } } } diff --git a/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/ExecuteWorkflowCommand.java b/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/ExecuteWorkflowCommand.java index bc7eb9148a..f4f477b9a8 100644 --- a/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/ExecuteWorkflowCommand.java +++ b/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/ExecuteWorkflowCommand.java @@ -18,6 +18,7 @@ import java.util.Properties; import org.adempiere.exceptions.AdempiereException; import org.adempiere.util.RestletUtil; +import org.adempiere.util.ServerContext; import org.compiere.interfaces.impl.ServerBean; import org.compiere.model.MRole; import org.compiere.process.ProcessInfo; @@ -60,17 +61,14 @@ public class ExecuteWorkflowCommand extends ServerResource { } ServerBean bean = new ServerBean(); - //back up properties - Properties backup = new Properties(); - backup.putAll(Env.getCtx()); try { - Env.setCtx(context); + ServerContext.setCurrentInstance(context); return bean.workflow(context, pi, AD_Workflow_ID); } finally { - Env.setCtx(backup); + ServerContext.dispose(); } } } diff --git a/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/PostDocumentCommand.java b/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/PostDocumentCommand.java index eb4bb68315..71a2302f59 100644 --- a/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/PostDocumentCommand.java +++ b/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/PostDocumentCommand.java @@ -18,6 +18,7 @@ import java.util.Properties; import org.adempiere.exceptions.AdempiereException; import org.adempiere.util.RestletUtil; +import org.adempiere.util.ServerContext; import org.compiere.interfaces.impl.ServerBean; import org.compiere.util.Env; import org.restlet.representation.Representation; @@ -57,17 +58,14 @@ public class PostDocumentCommand extends ServerResource { boolean force = (Boolean) entity.get("force"); ServerBean bean = new ServerBean(); - //back up properties - Properties backup = new Properties(); - backup.putAll(Env.getCtx()); try { - Env.setCtx(context); + ServerContext.setCurrentInstance(context); msg = bean.postImmediate(context, AD_Client_ID, AD_Table_ID, Record_ID, force); } finally { - Env.setCtx(backup); + ServerContext.dispose(); } return msg; } diff --git a/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/ResetCacheCommand.java b/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/ResetCacheCommand.java index 9b445a5c31..86c66c2c63 100644 --- a/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/ResetCacheCommand.java +++ b/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/ResetCacheCommand.java @@ -18,6 +18,7 @@ import java.util.Properties; import org.adempiere.exceptions.AdempiereException; import org.adempiere.util.RestletUtil; +import org.adempiere.util.ServerContext; import org.compiere.interfaces.impl.ServerBean; import org.compiere.util.Env; import org.restlet.representation.Representation; @@ -53,17 +54,14 @@ public class ResetCacheCommand extends ServerResource { String tableName = (String) entity.get("tableName"); ServerBean bean = new ServerBean(); - //back up properties - Properties backup = new Properties(); - backup.putAll(Env.getCtx()); try { - Env.setCtx(context); + ServerContext.setCurrentInstance(context); return bean.cacheReset(context, tableName, Record_ID); } finally { - Env.setCtx(backup); + ServerContext.dispose(); } } } diff --git a/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/SendEmailCommand.java b/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/SendEmailCommand.java index bd292b56ec..50b58c4746 100644 --- a/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/SendEmailCommand.java +++ b/org.adempiere.server/src/main/servlet/org/adempiere/web/server/command/SendEmailCommand.java @@ -18,6 +18,7 @@ import java.util.Properties; import org.adempiere.exceptions.AdempiereException; import org.adempiere.util.RestletUtil; +import org.adempiere.util.ServerContext; import org.compiere.interfaces.impl.ServerBean; import org.compiere.util.EMail; import org.compiere.util.Env; @@ -53,17 +54,14 @@ public class SendEmailCommand extends ServerResource { EMail email = (EMail) entity.get("email"); ServerBean bean = new ServerBean(); - //back up properties - Properties backup = new Properties(); - backup.putAll(Env.getCtx()); try { - Env.setCtx(context); + ServerContext.setCurrentInstance(context); return bean.sendEMail(context, email); } finally { - Env.setCtx(backup); + ServerContext.dispose(); } } } 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 dc2b6bc6f1..1e9ae64852 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 @@ -8,6 +8,7 @@ import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.Properties; +import org.adempiere.util.ServerContext; import org.compiere.model.MUser; import org.compiere.util.CLogger; import org.compiere.util.DB; @@ -113,7 +114,7 @@ public class CompiereService { { CompiereUtil.initWeb(); - Env.setCtx(m_ctx); + ServerContext.setCurrentInstance(m_ctx); Env.setContext( m_ctx, "#AD_Language", "en_US" ); m_lang = Language.getLanguage("en_US");