Is it possible to create a workflow that runs a curl command when a page gets published/un-published? | Community
Skip to main content
Level 1
January 28, 2021
Solved

Is it possible to create a workflow that runs a curl command when a page gets published/un-published?

  • January 28, 2021
  • 2 replies
  • 1436 views

Is it possible to create a workflow that gets executed when a page gets published/unpublished to run a curl command like: curl <published_page_url>

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SureshDhulipudi

yes, it is possible,

you can write a service or you can include steps as follow

 

 String[] command = { "curl", "-X", "GET", "<<URI or something here>>" };
 ProcessBuilder process = new ProcessBuilder(command);
Process executeProcess;
executeProcess = process.start();

2 replies

SureshDhulipudi
Community Advisor
SureshDhulipudiCommunity AdvisorAccepted solution
Community Advisor
January 28, 2021

yes, it is possible,

you can write a service or you can include steps as follow

 

 String[] command = { "curl", "-X", "GET", "<<URI or something here>>" };
 ProcessBuilder process = new ProcessBuilder(command);
Process executeProcess;
executeProcess = process.start();
aanchal-sikka
Community Advisor
Community Advisor
September 25, 2023

Sharing a blog with code snippets to execute Curl commands via Java program

https://techrevel.blog/2018/01/19/curl-execution-from-java-program/

//Equivalent command conversion for Java execution String[] command = { "curl", "-u", username + ":" + password, "-X", "POST", "-F", "cmd=unlockPage", "-F", "path=" + path, "-F", "_charset_=utf-8", url }; ProcessBuilder process = new ProcessBuilder(command); Process p; try { p = process.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); StringBuilder builder = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { builder.append(line); builder.append(System.getProperty("line.separator")); } String result = builder.toString(); System.out.print(result); } catch (IOException e) { System.out.print("error"); e.printStackTrace(); }

This will also hold good, when executed at end of workflow.

 

Other alternative to Curl is HTTP requests. All AEM curl commands can be converted into HTTP GET and POST .

Aanchal Sikka