0

In my XPages application I have to call curl commands

The code is simple:

public static InputStream executeCurlCommand(String finalCurlCommand) throws IOException
{
    return Runtime.getRuntime().exec(finalCurlCommand).getInputStream();
}

However, it seems that the command isn't executed at all.

When I execute the following (in Linux terminal):

curl -k -i -X GET https://someHost/fws/api/esia/login?redirectUrl=https://redirectHost/sed/gecho/2019/gecho_apps_2019.nsf/Nav2.xsp

I get the output.

But whenever I execute it with Java nothing works. getInputStream() is empty.

At the same time, if I execute this code on my local Windows machine everything is fine. Same goes for the command executed from cmd.

But in XPages there are no exceptions, no errors, just nothing.

Is there a way to debug it?

UPD

If I change the command to something as simple as ls -la everything works fine :x

Rus9Mus9
  • 160
  • 1
  • 17
  • Is curl on the path of the user that runs the Domino task? – stwissel Dec 15 '19 at 16:58
  • No, it runs from the folder notesdata0. The command curl is accessible everywhere – Rus9Mus9 Dec 15 '19 at 17:01
  • Or probably I didn't get you right... Could you specify your question please? – Rus9Mus9 Dec 15 '19 at 17:03
  • With the Domino user? When you start an interactive session .bashrc is executed. It’s not when you start Domino as service. So you need to check your path carefully. Try env command to see the real path – stwissel Dec 15 '19 at 17:04
  • And don’t use shell curl. The Apache http client is part of Domino. Use that one – stwissel Dec 15 '19 at 17:07
  • What variable is the path which you need to know? – Rus9Mus9 Dec 15 '19 at 17:12
  • I'm forced to use it because of SSL. I explained it in my previous question. Please, take a look https://stackoverflow.com/questions/59343434/parsing-curl-response-with-java – Rus9Mus9 Dec 15 '19 at 17:12
  • Is anything written to the process's standard error stream? – Luke Woodward Dec 15 '19 at 17:18
  • You can use ssl with the Apache http client too. – stwissel Dec 15 '19 at 17:20
  • No errors or exceptions at all... – Rus9Mus9 Dec 15 '19 at 17:32
  • Is there a way to find out about it at OS level? – Rus9Mus9 Dec 15 '19 at 17:34
  • You can use the full path to curl. I.e., /bin/curl or wherever it actually is. Use whereis to find it if you don't know the location. But I agree with @stwissel that you should avoid using exec because you're either going to be dependent on the environment or on knowing the location of the binary, and that's bad over the long term if you change servers. – Richard Schwartz Dec 15 '19 at 21:52

1 Answers1

3

OK, guys, I figured it out. The thing was that I passed the full command to the shell. It doesn't work in UNUX.

So

You should NEVER use

public static InputStream executeCurlCommand(String finalCurlCommand) throws IOException
{
    return Runtime.getRuntime().exec(finalCurlCommand).getInputStream();
}

In UNIX systems. Use ProcessBuilder instead

For example:

ProcessBuilder pb = new ProcessBuilder(
"curl",
"-k",
"-i",
"-X",
"GET",
"http://host.com");
pb.redirectErrorStream(true);
Process p = pb.start();
InputStream is = p.getInputStream();
Rus9Mus9
  • 160
  • 1
  • 17
  • 1
    Glad you figured it out. Would you add the code you used. It’s a general Java issue, others will benefit from your insight – stwissel Dec 16 '19 at 06:52
  • But in this way, the output shows the URL statistics: % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 – Shai Alon Apr 11 '23 at 12:12