Sahil Saxena
Sahil Saxena

Reputation: 141

HandleHttpResponse processor throws Could not find HTTP response object for this identifier

I am using the below Nifi processors

HandleHttpRequest -> RouteOnAttribute -> HandleHttpResponse
My RouteOnAttribute property is test and value is ${http.headers.type:contains('test')}

I have attached nifi template in this url nifi template

enter image description here

Below is the sample client request which i sent to nifi server and i am getting response code as 200 same i have mentioned in HandleHttpResponse's http status code which means my configured the processor correctly

import requests
import json
import traceback

nifi_url = "http://localhost:8009/report"


def uploadLogs(fileName):
    f = open(fileName, 'rb')
    payload = {
        "this": "that"
    }

    files = {'info': (None, json.dumps(payload), 'application/json; charset=utf-8'),
             'file': ('current', f, "text/plain; charset=us-ascii")}
    headers = {'type': 'test', "Keep-Alive": "timeout=100", "Content-Transfer-Encoding": "8bit",
               "Connection": "Keep-Alive"}
    url = ''

    try:
        url = nifi_url
        response = requests.post(url, files=files, headers=headers)
        print(response.status_code)
        if (response != None and (response.status_code == 200 or response.status_code == 201)):
            return True
    except:
        traceback.print_exc()
    return False

filename = "C:\\sample.txt"
print(uploadLogs(filename))

Still i am getting below error i would like to know is this error expected if not why i am getting below error and how to fix this error. Any help is appreciated

nifi_1 | 2020-11-13 19:14:09,360 ERROR [Timer-Driven Process Thread-7] o.a.n.p.standard.HandleHttpResponse HandleHttpResponse[id=39d755ed-f825-3013-ce47-5218721d27d4] Failed to respond to HTTP request for StandardFlowFileRecord[uuid=1a422f48-41e3-4eb9-9390-73b12762c5dc,claim=StandardContentClaim [resourceClaim=StandardResourceClaim[id=1605269814303-549, container=default, section=549], offset=39642, length=16],offset=0,name=1a422f48-41e3-4eb9-9390-73b12762c5dc,size=16] because FlowFile had an 'http.context.identifier' attribute of 5e7dc338-8684-491d-a554-6392e2a0e3b9 but could not find an HTTP Response Object for this identifier

Upvotes: 1

Views: 1351

Answers (1)

daggett
daggett

Reputation: 28564

  1. usually this error occures when 'StandardHttpContextMap.Request Expiration' expired between request and response.

for example if you have StandardHttpContextMap.Request Expiration = 30sec:

  • stop the RouteOnAttribute,
  • make the request, wait for 30 sec,
  • start the RouteOnAttribute

and you'll see the the error: Failed to respond to HTTP request ...

  1. another case when you did not read the response from server fully

i don't have python, but try to read response.content after getting response.status_code and maybe better to use response.close() at the end to release resources.

Upvotes: 1

Related Questions