<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic &amp;quot;Token is required&amp;quot; error when executing curl command from Java's ProcessBuilder in Security</title>
    <link>https://community.splunk.com/t5/Security/quot-Token-is-required-quot-error-when-executing-curl-command/m-p/378094#M15488</link>
    <description>&lt;P&gt;I am using Java's ProcessBuilder to execute curl from Java.  The same command being executed in bash works just fine, but I get a {"text": "Token is required", "code":2} error from Java.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;public String call() throws IOException, InterruptedException {
    List&amp;lt;String&amp;gt; command = new ArrayList&amp;lt;&amp;gt;();

    command.add("curl");
    command.add("-X");
    command.add(method.name());
    command.add("-k");
    command.add(endpoint);

    if (headers != null &amp;amp;&amp;amp; !headers.isEmpty()) {
        StringBuilder builder = new StringBuilder();
        headers.keySet().forEach(s -&amp;gt; {
            builder.replace(0, builder.length(), "");
            builder.append("'").append(s).append(":").append(headers.get(s)).append("'");
            command.add("-H");
            command.add(builder.toString());
        });
    }

    if (data != null) {
        command.add("-d");
        command.add("'" + data + "'");
    }

    System.out.println(StringUtils.join(command, " "));

    return doCurl(command.toArray(new String[0]));
}

private String doCurl(String[] args) throws IOException, InterruptedException {
    Process process = new ProcessBuilder(args)
            .redirectErrorStream(true)
            .start();

    String lines;
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"))) {
        lines = reader.lines().collect(Collectors.joining("\n"));
    }
    process.waitFor();
    return lines;
}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 17 May 2019 20:02:40 GMT</pubDate>
    <dc:creator>angrydead</dc:creator>
    <dc:date>2019-05-17T20:02:40Z</dc:date>
    <item>
      <title>"Token is required" error when executing curl command from Java's ProcessBuilder</title>
      <link>https://community.splunk.com/t5/Security/quot-Token-is-required-quot-error-when-executing-curl-command/m-p/378094#M15488</link>
      <description>&lt;P&gt;I am using Java's ProcessBuilder to execute curl from Java.  The same command being executed in bash works just fine, but I get a {"text": "Token is required", "code":2} error from Java.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;public String call() throws IOException, InterruptedException {
    List&amp;lt;String&amp;gt; command = new ArrayList&amp;lt;&amp;gt;();

    command.add("curl");
    command.add("-X");
    command.add(method.name());
    command.add("-k");
    command.add(endpoint);

    if (headers != null &amp;amp;&amp;amp; !headers.isEmpty()) {
        StringBuilder builder = new StringBuilder();
        headers.keySet().forEach(s -&amp;gt; {
            builder.replace(0, builder.length(), "");
            builder.append("'").append(s).append(":").append(headers.get(s)).append("'");
            command.add("-H");
            command.add(builder.toString());
        });
    }

    if (data != null) {
        command.add("-d");
        command.add("'" + data + "'");
    }

    System.out.println(StringUtils.join(command, " "));

    return doCurl(command.toArray(new String[0]));
}

private String doCurl(String[] args) throws IOException, InterruptedException {
    Process process = new ProcessBuilder(args)
            .redirectErrorStream(true)
            .start();

    String lines;
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"))) {
        lines = reader.lines().collect(Collectors.joining("\n"));
    }
    process.waitFor();
    return lines;
}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 May 2019 20:02:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/quot-Token-is-required-quot-error-when-executing-curl-command/m-p/378094#M15488</guid>
      <dc:creator>angrydead</dc:creator>
      <dc:date>2019-05-17T20:02:40Z</dc:date>
    </item>
  </channel>
</rss>

