Reputation: 453
I'm still learning programming Apache NiFi using java and I wonder if anyone could explain to me how to instantiate a NiFi platform using NiFi REST APIs & java? Any solution to create processor using Apache NiFi REST API and java.
UPDATES So I was trying this out :
import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
public class HttpClientTest {
public static void main(String[] args) throws IOException {
CloseableHttpClient client = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("http://localhost:8080/nifi-api/process-groups/5f577c63-0170-1000-deb5-b53c37656ad4/template-instance");
CloseableHttpResponse response = client.execute(httpPost);
System.out.println(response.getStatusLine());
client.close();
}
}
Upvotes: 1
Views: 1847
Reputation: 1269
NiFi provides a swagger definition for working with the REST API, so you can generate your own client for your preferred language using Swagger Codegen. Here are instructions on how to do this for Python as a part of my Python client for NiFi, it should be a good beginner step to modify them for Java rather than working with the raw JSON/REST calls.
Here's the main part of the process:
mkdir -p ~/tmp && \
echo '{ "packageName": "nifi" }' > ~/tmp/swagger-nifi-python- config.json && \
rm -rf ~/tmp/nifi-python-client && \
swagger-codegen generate \
--lang python \
--config swagger-nifi-python-config.json \
--api-package apis \
--model-package models \
--template-dir /path/to/nipyapi/swagger_templates \
--input-spec /path/to/nifi/nifi-nar-bundles/nifi-framework- bundle/nifi-framework/nifi-web/nifi-web-api/target/swagger-ui/swagger.json \
--output ~/tmp/nifi-python-client
Upvotes: 2