Is it possible to detect on what server the current AEM Workbench Process is running in an Adobe AEM Workflow? We want to watermark the documents only if the Workflow is running on non-production server and we want to have the same workflows on both production and non-production servers.
3 Answers
The recommended way is to use runmodes for this server/environment level segregation.
See: https://docs.adobe.com/docs/en/aem/6-2/deploy/configuring/configure-runmodes.html
In short, you pass a runmode runtime parameter to your instance on startup and the API exposes the runmodes to your logic which can be changed for specific runmoded. This is how AEM differentiate between author and publishers. You can pass as many runmodes as you want. For example an instance can have production and author or production and publish modes.

- 3,414
- 1
- 16
- 27
-
OK, but how can I detect what runmode is set within an AEM process? I don't see anything about that in your link. – Björn Feb 17 '17 at 11:49
-
Several ways of doing that. You can see some examples in this old thread: http://stackoverflow.com/q/12245751/797375 – Imran Saeed Feb 17 '17 at 11:58
-
Hmm, I still don't get it.I don't know of JSP in this contect. It might be because I have used the wrong terminology. I'm new to this area. Maybe my updated post (with image) sheds some light on what I try to acomplish. – Björn Feb 17 '17 at 12:23
-
AFAIK, conditonal steps in workflows are very primitive and invoking service is not an easy option. You can write a custom workflow step as described here: https://helpx.adobe.com/experience-manager/using/creating-custom-aem-workflow-steps.html in which you can check the runmodes (using relevant API from above post). Then you can advance or stop the workflow based on the result. – Imran Saeed Feb 17 '17 at 12:53
You can get this done by using the org.apache.sling.settings.SlingSettingsService
Example code snippet that can print the run modes in your JSP shown below, same can be used in your OSGI JAVA logic.
<%@page import="org.apache.sling.settings.SlingSettingsService%>
<%
pageContext.setAttribute("runModes", sling.getService(SlingSettingsService.class).getRunModes().toString());
%>
<%= pageContext.getAttribute("runModes") %>
above code snippet prints output in JSP as [samplecontent, author, crx3tar, crx3]
where my local instance is running in author mode with samplecontent. which can be found in your instance at /system/console/status-slingsettings.

- 2,551
- 1
- 27
- 40
Use "SlingSettingsService". It can be referenced within your process step like so:
@Component(service = WorkflowProcess.class)
public class YourWorkflow implements WorkflowProcess{
@Reference private SlingSettingsService slingSettings; ...
You can check your environment using this:
@Override
public void execute(WorkItem workItem, WorkflowSession wfSession, MetaDataMap args) throws WorkflowException {
if(slingSettings.getRunModes().contains("non-production-run-mode-name")) {
//TODO: apply watermark
}
}

- 11
- 2