0

I am able to execute the below nifi commands for retreiving system-diagnostics metrics. Is there anyway that these commands can be executed through java code by invoking nifi api using our own methods as we do in aws cloudwatch to put metrics.

read USER

read -s PASS

TOKEN=`curl -X POST --data "username=$USER&password=$PASS" -k https://nifiHostName.com:nifiPort/nifi-api/access/token`

curl -H "Authorization: Bearer $TOKEN" -k https://nifiHostName:nifiPort/nifi-api/system-diagnostics\ | python -m json.tool

If above is not possible can anyone answer how to give Authorization: Bearer $TOKEN through a simple Java code that would be great.

Or else by using simple https client is it possible to execute these commands through java. If yes could you please help me on this.

Manikya
  • 1
  • 2

1 Answers1

2

You can invoke the Apache NiFi API through any Java HTTP interaction. For example, you could use the standard URL object and execute getConnection() and openConnection() operations against it (see an extensive answer describing this process). Calling openConnection() returns a URLConnection object, on which you set headers using connection.setRequestProperty("Header name", value).

You can also use a library like jersey-client, Apache HttpClient, or OkHTTP.

Any one of these methods will allow you to set an HTTP header with the Authorization: Bearer value.

Community
  • 1
  • 1
Andy
  • 12,786
  • 1
  • 32
  • 65