n-3
n-3

Reputation: 71

How to add a apache nifi flowfile into a httpresponse

I have a working webservice with nifi where I get a httprequest and can respone to it. For test I use ReplaceText to add a specifi content to the response. This works, but my goal is to add a flowfile (or the value of it) as the content of the httpresponse.

The usecase is, that I can send information (from Kafka, HDFS, ...) as a response of an httprequest (REST Webservice).

I was searching and testing for a solution, but nothing works. Is it possbile with a standard processor of Apache NiFi (Hortonworks HDF)?

best regards n3

Upvotes: 2

Views: 2954

Answers (1)

Bryan Bende
Bryan Bende

Reputation: 18630

You should be able to send the contents of any flow file back through HandleHttpResponse. For example, to create a web service that returns files from HDFS you should be able to do something like:

HandleHttpRequest -> FetchHDFS -> HandleHttpResponse

You may need to do some more stuff before FetchHDFS, to manipulate the data, but that would be the general approach. The key is that you need a processor that accepts incoming flow files, so for Kafka you could easily do the same thing with PutKafka, but not GetKafka because it doesn't accept an incoming flow file.

This GitHub repo has an example of a web service that retrieves a file from local disk: https://github.com/bbende/nifi-streaming-examples

See the first image where it says "Handle Request for Log Levels".

Upvotes: 2

Related Questions