Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

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

Avatar

Level 1

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>

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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();

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

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();

Avatar

Community Advisor

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