0

In our project there is a requirement, when ever we will click on rollout on parent page it will trigger one workflow and once approver approves the workflow, it will update live copy(locale) automatically or programmatically.

To achieve this we are using below code (adding [1],[2],[3],[4] in code)

@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException {

   try {
      ResourceResolverTemplate.execute(DAM_SERVICE, resolver -> {
      if (workItem.getWorkflowData().getMetaDataMap().get("rollout_status").toString().equals("approved")) {

         WorkflowData workflowData = workItem.getWorkflowData();
         Map<String, Object> params = new HashMap<>();
         for (Entry<String, Object> entry : workflowData.getMetaDataMap().entrySet()) {
            if (entry.getKey().contains("-")) {
               // replacing '-' with ':' for properties having colon eg msm:targetPath,
               // msm:async.
               params.put(entry.getKey().replaceFirst("-", ":"), entry.getValue());
            } else {
               params.put(entry.getKey(), entry.getValue());
            }
         }

         [1]HttpServletRequest req = requestResponseFactory.createRequest("POST", "/bin/wcmcommand", params);
         [2]ByteArrayOutputStream out = new ByteArrayOutputStream();
         [3]HttpServletResponse response = requestResponseFactory.createResponse(out);
         [4]requestProcessor.processRequest(req, response, resolver); 
         //rollout
       }
    });
   } catch (Exception e) {
      log.error("Dentsply rollout process step exception: {}", e.getMessage());
   }
}

I am able to get req[1] and response[3] but in last step [4] requestprocessor.processRequest it is breaking.

Same functionality is working fine in our on-prem environment but in cloud it is breaking.

So my ask here is SlingRequestProcessor supports in AEM cloud? Because I have checked in debug mode once code came in below step and tried to execute processRequest() nothing is happening.

I am not able to rollout the page programmatically using processRequest() method, do we have any other option?

Alexander Berndt
  • 1,628
  • 9
  • 17
  • Assuming you are handling all this in author, a regular post request via web requires authentication, csrf and referrer checks. Your request will probably have to cater to all that. – Ameesh Trikha Oct 25 '21 at 01:04
  • Also, add sling package/ processor specific logging configuration to see what is happening to your flow. – Ameesh Trikha Oct 25 '21 at 01:05
  • Hi @AmeeshTrikha, Thanks for your help, yes I am handling all this in author. – sachin pandey Oct 25 '21 at 12:11
  • Sling package: org.apache.sling.engine :::::: org.apache.sling.engine.SlingRequestProcessor; – sachin pandey Oct 25 '21 at 12:37
  • yes, org.apache.sling.engine – Ameesh Trikha Oct 25 '21 at 12:39
  • Also, I would suggest to keep things simple and manageable, move away from POST Servlet implementation with workflow. Instead, implement a service layer that extends MSM API to meet your requirements. Refer here - https://experienceleague.adobe.com/docs/experience-manager-65/developing/extending-aem/extending-msm.html?lang=en – Ameesh Trikha Oct 25 '21 at 12:43

0 Answers0