0

I'm using curl for certificate-based/x509 authentication `

String command = "curl --cert " +certificateFilePath+" --key "+ certificateKeyFilePath+" --insecure "+authUrl;

          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 ------------------:  "+result);

            }catch(Exception e){
                e.printStackTrace();
            }

`

but getting exception `

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:247)
        at java.lang.ProcessImpl.start(ProcessImpl.java:134)
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)

`

given that the application and auth service are running inside docker-container on Ubuntu and works fine when I manually go inside the application docker-container and execute the above curl command. Please help

David Maze
  • 130,717
  • 29
  • 175
  • 215
RITESH GUPTA
  • 93
  • 2
  • 11
  • Possible duplicate of [How to make curl available in Docker image based java:8-jdk-alpine and keep the image clean?](https://stackoverflow.com/questions/51192713/how-to-make-curl-available-in-docker-image-based-java8-jdk-alpine-and-keep-the) – David Maze Jul 31 '18 at 11:50

2 Answers2

0

From process builder docs:

https://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html

The proper way to do it is to call it with the parameters passed as separate strings otherwise it won't work. Also in order to run system commands like curl in linux or dir in windows you need to call the command interpreter - sh for linux. So your command should become something like:

ProcessBuilder process = new ProcessBuilder("sh", "-c","curl","--cert", certificationPath......); 

Or you can try:

Runtime.getRuntime().exec(command);  //Here you pass the whole command as a string  
Veselin Davidov
  • 7,031
  • 1
  • 15
  • 23
0

Could you try to run a JVM under root or with sudo java.... It may not have enough permissions for JVM.

Denys
  • 31
  • 5