Nifi invoke http how to get a value and add as Header during post data - apache-nifi

I have a NiFi flow which needs to post the data to some other server, before posting it needs to fetch a value from my internal server or Nifi Distributed cache.
And add that Value in to Http header before posting the data, also update when gets particular error code 401.
Below is the flow I am trying, all green processor I could do but stuck at getting the value and adding in invoke http header . What are other process I can make us to achieve this .

https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.9.0/org.apache.nifi.processors.standard.InvokeHTTP/
according to documentation on http code 401 InvikeHTTP routes file to No Retry relation.
also flow file should contain some response attributes including invokehttp.status.code
so, you could use RouteOnAttribute processor to redirect flow file to your external token processor only when invokehttp.status.code=401.

Related

Nifi API Authentication - Access Token

I'm attempting to collect details about all processors on two installed instances of Nifi, versions 1.19.0 and 1.20.0. I want to use Nifi to do this so I can perform some minor ETLs and save the resultant dataset in a database. Both instances are configured as standalone authentication with SSL.
However, when I configure the InvokeHTTP processor how I think it should be to aquire a token, I'm getting a 400 status code and a response.body of "The username and password must be specified." on both instances.
Here's the super basic flow:
Nifi Flow
Here's what the error looks like:
Attributes of failed response
Here's the current config of the InvokeHTTP processor on the 1.20.0 instance which we can focus on from here out since they are both responding similarly.
Postman - InvokeHTTP Config
When I run the request with Postman, I get the expected token in the response body. And I'm able to make subsequent requests (the above config was a response from https://nifi06:8443/nifi-api/processors/39870615-0186-1000-e7d7-c59fa621ca7d in Postman).
I've tried the following:
Adding dynamic attributes for username/password as in the above configuration.
I've added them as JSON to the preceding Generate FlowFile processor's custom text.
And I've also tried using the Request Username/Request Password properties of the InvokeHTTP processor.
All return with the same response.body of "The username and password must be specified."
This seems it should be really simple and I'm sure I've been staring at it too long to see what I'm missing. Can anyone tell me where I need to specify the username/password?
Thanks.

How to send a file through http post using Data Fusion

Wanted to send a file to an http end point url using Data fusion.
Making this http call as a pipeline alert at the completion of the pipeline.
This is not working. Getting 500 response from API. Can someone help me on how do I send the file?
If this can be achieved with http plugin as sink, please let me know the steps.
I doubt you can send files using HTTP. You can create a request using the HTTP plugin as I answered one of your previous question - Data Fusion - Issue with http post plugin.
In HTTP Callback you can find information:
This action can be used when you want to perform an HTTP request at the end of a pipeline run.
Using this plugin, you can send a request or text, not a file.
If you would like to send a file, you should use File like it's mentioned in this thread: Some questions about google Data fusion
Regarding Error 500
The HyperText Transfer Protocol (HTTP) 500 Internal Server Error server error response code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.
It means that there is an issue with your endpoint. It might be a firewall or HTTP server issue. Too many possibilities of what could be wrong with current details.
In addition, you can find some additional information in doc Ingest CSV data to BigQuery using Cloud Data Fusion - Batch ingestion

Handlehttp processor in nifi

I am trying to post a json request to the handlehttp processor in Nifi. Could this be achieved as currently i am getting a 0 byte file passed to the flowfile. Is there any way we can pass the json request through the flowfile?
Thanks
This the sample URL i am posting using python requests library.
requests.post(localhost:6202/sample,json={"id":1,"name":"test"}
Your flow is showing no flow files being transferred, rather than 0-byte flow files being transferred. Do you mean that you are getting a 404 response in your flow? If so, that is because you do not have a HandleHttpResponse in the flow to return a status code. I was able to get
requests.post("http://localhost:6202/sample",json={"id":1,"name":"test"})
to work with a HandleHttpRequest -> LogAttribute -> HandleHttpResponse flow.

get response from InvokeHTTP POST

New to NiFi!
I'm using InvokeHTTP nifi processor (using this link as an example to implement my flow http://www.tomaszezula.com/2016/10/30/nifi-and-http-post-configuration/). I currently need to do POST in order to authenticate against a server I am using. I am able to POST successfully. However, I need to be able to get the data returned from the response of the POST that was executed. When I look at InvokeHTTPs output into the success queue all I see is the body which I had posted. Is there anyway for me to get the response into a flowfile?
Thanks in advance!
Apache NiFi's InvokeHTTP processor sends the response content to a separate relationship from the original flowfile. You will want to separately route this response relationship.
InvokeHTTP also has a Put Response Body In Attribute property, which you can set to capture the response as a attribute, rather than a separate flowfile. This might be useful for an auth token.

Custom http request in Jmeter

I am trying to create a custom POST HTTP request in Jmeter , but when I run the script it shows request formed badly. I am taking that exact parameter as and header response, still, it is not executing.
Can anyone help? Is there any sequence to be maintained while entering names and values in HTTP header manager.

Resources