Reputation: 1175
I'm using a java WebService to send a curl request, this is my request :
curl -d "input = a b c d" 'localhost:8090/jobs?appName=Test40&classPath=fr.aid.cim.spark.JavaWord&sync=true&timeout=1000000000'
I don't know which library I should use and how I can write it in java. Can you please show me how to do it?
Upvotes: 1
Views: 21268
Reputation: 2266
If you need execute console command (curl in this case):
Runtime runtime = Runtime.getRuntime();
try {
Process process = runtime.exec("curl -d \"input = a b c d\" 'localhost:8090/jobs?appName=Test40&classPath=fr.aid.cim.spark.JavaWord&sync=true&timeout=1000000000'");
int resultCode = process.waitFor();
if (resultCode == 0) {
// all is good
}
} catch (Throwable cause) {
// process cause
}
UPDATE (according to your comment): Add folowing lines:
System.out.println("is: " + IOUtils.toString(process.getInputStream()));
System.out.println("es: " + IOUtils.toString(process.getErrorStream()));
What is the output? IOUtils can be found here.
Upvotes: 6
Reputation: 1203
You should take look Apache HttpClient library. With HC Fluent component you can write something like:
Request.Post("http://localhost:8090/jobs?appName=Test40&classPath=fr.aid.cim.spark.JavaWord&sync=true&timeout=1000000000")
.execute().returnContent();
Upvotes: 3