I am trying to use scala.sys.process._ to send a POST request to my chronos server with curl, because there is a space in the command arguments, I use the Seq[String] cmd.!! option cmd.!!
I create a command as follows:
val cmd = Seq("curl", "-L", "-X POST", "-H 'Content-Type: application/json'", "-d " + jsonHash, args.chronosHost + "/scheduler/" + jobType)
which produces, as expected,
cmd: Seq[String] = List(curl, -L, -X POST, -H 'Content-Type: application/json', -d '{"schedule":"R/2014-02-02T00:00:00Z/PT24H", "name":"Scala-Post-Test", "command":"which scalac", "epsilon":"PT15M", "owner":"myemail@thecompany.com", "async":false}', localhost:4040/scheduler/iso8601)
however, running this function will distort the argument 'Content-Type: application/json' :
scala> cmd.!! % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 264 0 100 100 164 2157 3538 --:--:-- --:--:-- --:--:-- 54666 res21: String = "The HTTP header field "Accept" with value "*/* 'Content-Type:application/json'" could not be parsed. "
which I do not understand. On the contrary, calling cmd.mkString(" ") and copying + pasting into the terminal works as expected.
curl -L -X POST -H 'Content-Type:application/json' -d '{"schedule":"R/2014-02-02T00:00:00Z/PT24H", "name":"Scala-Post-Test", "command":"which scalac", "epsilon":"PT15M", "owner":"austin@quantifind.com", "async":false}' mapr-01.dev.quantifind.com:4040/scheduler/iso8601
I tried numerous variations on the -H argument to no avail, any understanding of using single quotes in sys.process._ !! will be greatly appreciated.
I also tried options that generate a lot of errors, including
<h2>HTTP ERROR: 415</h2> <p>Problem accessing /scheduler/iso8601. Reason: <pre> Unsupported Media Type</pre></p> <hr /><i><small>Powered by Jetty://</small></i>
(in addition to jsonHash splitting, i.e.:
[1/6]: '"schedule":"R/2014-02-02T00:00:00Z/PT24H"' --> <stdout> curl: (6) Couldn't resolve host ''"schedule"' Which makes me think it is not interpreting the -H argument correctly