I have a curl command that gives a JSON response. I want to use this curl command in java & parse the JSON response in java. Is it possible to do so??
With below Java code:
public static void main(String[] args) throws Throwable {
try {
InputStream stream = Runtime.getRuntime().exec("curl --globoff --insecure --silent -u username:password -X GET -H 'Content-Type: application/json' \"http://ficcjira.xyz.com/rest/api/2/search?jql=project=ABC&fields=Timetracking\"").getInputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(stream), 1);
input.readLine();
input.read();
input.read();
DataReader reader = new JsonReader(input)
.addField("TimeSpent", "//array/object/timespent")
.addRecordBreak("//array/object");
/*reader = new TransformingReader(reader)
.add(new BasicFieldTransformer("TimeSpent").stringToDouble());*/
DataWriter writer = new StreamWriter(System.out);
JobTemplate.DEFAULT.transfer(reader, writer);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I get the following error:
Cannot run program "curl": CreateProcess error=2, The system cannot find the file specified