Skip to content

Instantly share code, notes, and snippets.

@aanchalsikka
Last active January 19, 2018 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aanchalsikka/f1d36ef374281732d3398d12d2aba166 to your computer and use it in GitHub Desktop.
Save aanchalsikka/f1d36ef374281732d3398d12d2aba166 to your computer and use it in GitHub Desktop.
package blog.techrevel.api;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class CurlExecutor2 {
public static void main(String[] args) {
String username = "admin";
String password = "admin";
String url = "http://localhost:4502/bin/wcmcommand";
String path = "/content/geometrixx/en/toolbar/contacts";
//cURL Command: curl -u admin:admin -X POST -F cmd="lockPage" -F path="/content/geometrixx/en/toolbar/contacts" -F "_charset_"="utf-8" http://localhost:4502/bin/wcmcommand
//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();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment