1

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();

            }
        }

But always : HTTP/1.1 400 Bad Request

8
  • 1
    Can I use Java API's in Apache NiFi:If you are talking about API exposed by NiFi, NiFi exposes a REST API: nifi.apache.org/docs/nifi-docs/rest-api/index.html If you want to develop your own processor in Java, this is easy and you may find interesting the following: nifi.apache.org/docs/nifi-docs/html/developer-guide.html Commented Mar 3, 2020 at 10:32
  • @y_ug actually I did not understand how to process the java code ?! because I'm newly developer in JAVA and now I'm in an internship period so :( I have no idea how to make a java code that invokes Apache NiFi REST APIs Commented Mar 3, 2020 at 11:09
  • 1
    Then I'suggest to study examples. Google knows about at least some of them: google.com/search?q=apache+nifi+custom+processor+example Commented Mar 3, 2020 at 11:29
  • 2
    Look for any examples how to call any rest API from java. Ask your question with code example and exact endpoint that you want to call. Commented Mar 3, 2020 at 12:00
  • 1
    Put you code to the question, not to comment, please. Commented Mar 3, 2020 at 15:16

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.