- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Send JSON response from HandleHTTPRequest processor
- Labels:
-
Apache NiFi
Created ‎11-30-2020 07:39 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am modifying the standard *HandleHTTPRequest* Processor in NiFi to add Oauth2 authentication. The idea is to accept scopes and client_id as part of the processor setup and validate the incoming JWT token against these scopes and client_id.
i am trying to send a JSON Response when the scope or client_id is incorrect as below
String newContent = "{ \"message\" : \"Unauthorized\" }";
container.getResponse().setStatus(HttpServletResponse.SC_UNAUTHORIZED);
container.getResponse().setContentType("application/json");
container.getResponse().getWriter().write(newContent);
return;
the request is hung and times out. Is this because HandleHttpRequest can't send the response back and I have to use HandleHTTPResponse processor to process the response?
The below code sends a HTML Response which I want to change to a proper JSON.
container.getResponse().sendError(HttpServletResponse.SC_UNAUTHORIZED,newContent);
Created ‎12-01-2020 04:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Vamshi245 Yes, HandleHttpRequest and HandleHttpResponse are used in tandem. Behind the processors is a map cache which holds connection session between request/response processors. If your flowfile (json) coming out of custom HandleHttpRequest is delivered to stock HandleHttpResponse, it will send the json to the original connecting client.
If this answer resolves your issue or allows you to move forward, please choose to ACCEPT this solution and close this topic. If you have further dialogue on this topic please comment here or feel free to private message me. If you have new questions related to your Use Case please create separate topic and feel free to tag me in your post.
Thanks,
Steven
