Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

workflow always in RUNNING state even though the workflow process finishes

Avatar

Avatar
Validate 10
Level 2
Rui_J
Level 2

Likes

4 likes

Total Posts

39 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Affirm 1
View profile

Avatar
Validate 10
Level 2
Rui_J
Level 2

Likes

4 likes

Total Posts

39 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Affirm 1
View profile
Rui_J
Level 2

15-10-2015

Hi,

  I am writing a workflow. This is my Code, In workflow, I put a "Process Step" in a workflow called "my workflow", check "Handler Advance". Then I start the workflow on this page, The code does the job. But if I switch to http://localhost:4505/libs/cq/workflow/content/console.html Instance tab to check the workflow instance, I found that "my workflow" is still in RUNNING state. What did I miss here?

package com.mycompany.workflow; import com.adobe.granite.workflow.WorkflowException; import com.adobe.granite.workflow.WorkflowSession; import com.adobe.granite.workflow.exec.WorkItem; import com.adobe.granite.workflow.exec.WorkflowData; import com.adobe.granite.workflow.exec.WorkflowProcess; import com.adobe.granite.workflow.metadata.MetaDataMap; import org.apache.felix.scr.annotations.*; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.resource.ResourceResolverFactory; import org.osgi.framework.BundleContext; import org.osgi.framework.Constants; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference; import org.osgi.service.component.ComponentContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.jcr.RepositoryException; import javax.jcr.Session; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.Dictionary; import java.util.Enumeration; @Component(immediate = true, metatype = true, label = "Purge Cache", name = "com.mycompany.workflow.PurgingDispatcherWorkflow", description = "Purge the cache") @Service @Properties({ @Property(name = Constants.SERVICE_DESCRIPTION, value = "Implementation of cache purge"), @Property(name = Constants.SERVICE_VENDOR, value = "MyCompany"), @Property(name = "process.label", value = "Cache Purge"), @Property(name = "dispatcher.url", value = "http://localhost:80/dispatcher/invalidate.cache") }) public class PurgingDispatcherWorkflow implements WorkflowProcess { private Logger logger = LoggerFactory.getLogger(this.getClass()); private static final String TYPE_JCR_PATH = "JCR_PATH"; private String dispatcherUrl = ""; @Reference private ResourceResolverFactory resourceResolverFactory = null; @Override public void execute(WorkItem item, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException { Session jcrSession = null; try { WorkflowData workflowData = item.getWorkflowData(); if (workflowData.getPayloadType().equals(TYPE_JCR_PATH)) { String path = workflowData.getPayload().toString(); String purgeUrl = path; ResourceResolver resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null); jcrSession = resourceResolver.adaptTo(Session.class); URL url = new URL(dispatcherUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/octet-stream"); connection.setRequestProperty("CQ-Action", "DELETE"); connection.setRequestProperty("Content-Length", "0"); connection.setRequestProperty("CQ-Path", purgeUrl); connection.setRequestProperty("CQ-Handle", purgeUrl); connection.setUseCaches(false); connection.setDoInput(true); connection.setDoOutput(true); //Get Response InputStream is = connection.getInputStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; StringBuffer response = new StringBuffer(); while ((line = rd.readLine()) != null) { response.append(line); response.append('\r'); } rd.close(); logger.info("**********Purge Result***********" + response.toString()); } } catch (Exception ex) { logger.error("Error in executing Cache Purge Workflow : ", ex); } finally { if (jcrSession != null && jcrSession.isLive()) { jcrSession.logout(); jcrSession = null; } } logger.info("******************Purging Finished******************"); } @Activate protected void activate(ComponentContext context) throws RepositoryException { final Dictionary<?, ?> properties = context.getProperties(); dispatcherUrl = (String) properties.get("dispatcher.url"); } }

 

 

Regards

 

Rui

View Entire Topic

Avatar

Avatar
Validate 10
Level 2
Rui_J
Level 2

Likes

4 likes

Total Posts

39 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Affirm 1
View profile

Avatar
Validate 10
Level 2
Rui_J
Level 2

Likes

4 likes

Total Posts

39 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Affirm 1
View profile
Rui_J
Level 2

15-10-2015

Yes, I can see its statsus is RUNNING  in the instance tab. But this workflow should be completed without any manual work. How can I do that?