0

I am trying to run the following curl command through java.This runs properly from the command line, but throws error when i run it using java

curl -XPOST -H'Content-type: application/json' "http://localhost:8084/druid/v2/?pretty" -d'{"queryType":"timeBoundary","dataSource":"wikipedia"}'

This is the java code using processbuilder:

ProcessBuilder pb1 = new ProcessBuilder(
            "-XPOST",
            "-H", "Content-Type:application/json",
            "http://localhost:8084/druid/v2/?pretty",
            "-d", "{\"queryType\":\"timeBoundary\",\"dataSource\":\"wikipedia\"}"

        );

Process shell = pb1.start();

This is the error i am getting.

Exception in thread "main" java.io.IOException: Cannot run program "-XPOST": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
at com.druid.DruidConnection.main(DruidConnection.java:69)

Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:187)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
... 1 more
2
  • You need to have a space between X and POST. The same applies to other options as well Commented Jan 4, 2016 at 7:03
  • "-X POST" and "X","POST" . I have tried. both throws error. Commented Jan 4, 2016 at 7:06

1 Answer 1

3

You need to add curl.exe as a 1st parameter:

ProcessBuilder pb1 = new ProcessBuilder(
            "curl.exe",
            "-XPOST",
            "-H", "Content-Type:application/json",
            "http://localhost:8084/druid/v2/?pretty",
            "-d", "{\"queryType\":\"timeBoundary\",\"dataSource\":\"wikipedia\"}"

        );

Also you need to be sure that folder with curl.exe is in your PATH

PS. Of course it is for Windows, for *NIX just "curl"

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, didn't notice.Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.