Nifi Content Viewer - apache-nifi

I'm in the process of upgrading to NiFi 1.2 and have noticed something with the InvokeHTTP on 1.2 where the content view is unable to display the Content of a response.... This same flow is working fine in our 1.1.x cluster. We're doing a GET that returns a JSON response. I look at the Flowfile Attributes in the paused queue, and the Content-Type seems to be set correctly to application/json. I've even tried to send downstream to an UpdateAttribute and change the mime.type to text/plain.
I'm able to download the file and it looks fine...
Is there some setting/configuration in 1.2 that I need to set to allow the viewer to view the JSON Content?
Below is some screenshots of the viewer.

Related

How to pass error from a processor to PutEmail processor in NiFi

In the below image we can clearly see the error in the Conversion_Batching processor. How can this error be transmitted to PutEmail so that the email recipients can clearly understand the error.
Below is the PutEmail configuration:
But ${error} is not getting the error from the previous processor and I am getting an empty mail with the subject correctly set as expected.
How can I do this?
NiFi currently does not have a feature where we can capture and pass exceptions/errors to the subsequent processors as attribute or flowfile content.
You can configure SiteToSiteBulletinReportingTask which Publishes Bulletin events using the Site To Site protocol. This will give you information such as bulletinsourceid, bulletinsourcename, bulletingroupname, bulletinmessage etc and based on this you can then send out alert notification emails.
Another way is like in your process group Conversion_Batching introduce attribute ${error} and set custom error messages wherever failure happens, and then you can use this attribute value in PutEmail processor, something like below,

How to set properties for AMQ message

I am sending XML message to AMQ queue. XML has header section. I need to set child nodes of header as properties of AMQ message. I am using NodeJS stompit package.
Currently message shows only one property which is JMSXDeliveryCount.
The stompit documentation has an example where the destination and content-type headers are set when using the client.send method. You can add whatever other headers you want there.

Problems Deleting Descriptors in Apache Nifi Using Rest API

I am trying to use the rest API to dynamically update and control my Apache NiFi Flow. I am using Postman to explore the REST API but am having trouble deleting properties/descriptors.
My current process is to call a GET to this address - http://localhost:8080/nifi-api/processors/{ID}
I then modify the response as desired and do a PUT with the modified response as the body. If I add a descriptor or change the content of a descriptor it works ok. But if I try to delete a descriptor by removing it from the properties and descriptors area then nothing happens.
I still get a 200 OK response, but it is the same as the original.
I am using NiFi 1.1.2 on Windows.
The PropertyDescriptors are specified by the Processor in question. These are read-only values and describe the properties the Processor currently supports. In you want to remove a property, and it is optional, you should be able to remove the value for it by setting it's entry to null in properties object in your request.

Talend tRESTClient does not work

I have a Talend job which has an input CSV file which needs to be converted to a JSON format and then using a tRESTclient/tREST , make a HTTP call request and post data.
In the current job, I have an Elasticsearch server installed on my local machine and provided that URL.
I was able to convert the files to JSON format and also verified with a tlogrow component but unable to post data.
(P.S: I was able to post data using a bulk Java code, loading jar files and making HTTP call and sending parameters using a tJAVArow component. So no issue with my localhost and posting data.)
After converting the data from input file to JSON format, set the context variable with your JSON data and then make the rest call. You can add the context variable in the HHTP Body. example : context.json_post without double quotes.

Servlet send image from server and save in client

I'm new and just developing on J2EE.
I am modifying an existing application (an OpenSource project).
I need to save an image on a client sent by the server, but I do not know how.
This activity must be done in a transparent manner without affecting the existing operation of the application.
From the tests done I get this error:
java.lang.IllegalStateException: getWriter () has Already Been Called for this response.
How should carry out this task, according to your own opinion?
How do I save on the client, locally, the image?
Update:
Thanks for the answers.
My problem is that:
the image is generated on the server, but not for direct client request (there is no link to click on web page), the picture is composed using other services on the Internet.
reconstruct the image on the server.
This image must be sent to the client to be saved locally.
so I'd like it to appear a window where you assign the destination image
plus I'd like the rest of the application were not affected by this activity.
The application is yet on production.
Thank you very much for your response.
From the tests done I get this error: java.lang.IllegalStateException: getWriter () has Already Been Called for this response.
In other words, you were trying to mix the binary data of the image with the character data of the HTML output, or you were trying to do this in a JSP instead of a Servlet. This is indeed not going to work. You need to send either the image or the HTML page exclusively in response to fully separate requests.
In your JSP/HTML page just have a link to the image, like so:
click to download image
Then, in a servlet listening on an url-pattern of /imageservlet/*, you just get the image as InputStream from some datasource (e.g. from local disk file system as FileInputStream) and then write it to the OutputStream of the response the usual Java IO way.
You only need to set at least the Content-Disposition response header to attachment to make sure that the client get a Save As popup dialogue, else it will be displayed straight in the browser. Setting the Content-Type and Content-Length are also important so that the browser knows what the server is sending and can predict how long the download may take.
response.setHeader("Content-Type", getServletContext().getMimeType(file.getName()));
response.setHeader("Content-Length", String.valueOf(file.length()));
response.setHeader("Content-Disposition", "attachment;filename=\"" + file.getName() + "\"");
You can find complete basic servlet example in this article.
Note: you cannot control where the client would save the image, this would be a security hole. This way websites would be able to write malicious files on client's disk unaskingly.
Update: as per your update, there are two options:
You need to let the client itself fire two HTTP requests (I've answered this in your subsequent question)
Create a client side application which does all the task directly at the client side and then embed this in your webpage, for example a Java Applet. With an applet you have full control over the client environment. You can execute almost all Java code you'd like to execute and you can write files to disk directly without asking client for the location to save. You only need to sign the applet by a 3rd party company or the client needs to confirm a security warning before running.
Its up to the browser how all types of output are handled. Web pages are given a content type of html which the browser understands and ends up rendering ass a page that we can see. Images are given content type of image/jpeg etc which are rendered as images when in a page etc. To force a download prompt one needs to use a content type of a binary file rather than that of an image so the browser forces the download rather than shows the image. To ensure this use something like "application/octetstream"... i cant recall exactly but its easy to google for.

Resources