This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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