- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
how to get error response like 400 and 500 using InvokeHTTP processor in Apache NiFi?
- Labels:
-
Apache NiFi
Created ‎12-16-2024 10:14 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello sir,
I am using the InvokeHTTP processor in Apache NiFi to call an API. I am writing the response using the PutFile processor. When the API returns a 200 status code, it works fine and writes the response. However, when the API returns a 400 or 500 status code, it writes the original input file instead. I want to capture and write the actual response body for 400 or 500 status codes instead of the input file. here is process:
here is InvokeHTTP processor:
Here is putfile processor:
if status 200 it write the response . I want write all response from api instead of input file if it has any status from api.
Please help me
Created ‎12-19-2024 11:07 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@enam
I see you have used the correct InvokeHTTP processor which is used to send API requests and handle responses, including error codes 400, 500 etc.
Configuration for InvokeHTTP:
Set Required Properties:
- HTTP Method: POST
- Remote URL: http://192.168.200.162:2031/nostroliquidity........
- Return Code: Ensure Success Codes includes only 2xx responses by default.
To enable Error Responses add the following settings:
- "Always Output Response": Set to true.
- Output Response Attributes: Include attributes such as status.code and status.message to capture response metadata.
- This ensures that the processor outputs responses regardless of status code.
Now route Responses Based on Status Code
Use the RouteOnAttribute processor to differentiate between success and error responses add two conditions:
- Success Route: Check for status.code >= 200 AND status.code < 300.
- Error Route: Check for status.code >= 400.
Connect the InvokeHTTP processor's Response relationship to the RouteOnAttribute processor.
To write Responses to Appropriate Locations
- Use a PutFile or PutHDFS processor for both success and error routes:
- Success Route:
- Write successful responses to a specific directory.
- Error Route:
- Write error responses 400, 500 to a separate directory.
Include response details for debugging.
Important Configuration Notes
Configure Failure Handling in InvokeHTTP:
- Connect the InvokeHTTP processor’s Original relationship to a LogMessage processor or another flow to avoid losing the original flowfile.
Customize Filenames or Attributes:
- Use UpdateAttribute to set filenames or directories dynamically based on attributes like status.code or status.message.
Capture Full API Responses:
- Ensure that Response Body from the API is written as the content of the output file.
Can you run the above flow and revert
Happy hadooping
Created ‎12-25-2024 09:50 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Shelton sorry for late reply:
Here is my json response 400:
Here is invoke HTTP: I have used below properties in invokhttp like below:
- Always Output Response : Set to true.
- Output Response Attributes: 400 and 500
Here is RouteOnAttribute:
Is it like that?
