Logging JSON Payload in Apache NiFi from Java Application POST request - java

I'm new to Apache NiFi, and I developed an application to send JSON data to a NiFi endpoint via HTTP POST request.
In Apache NiFi, I have a HandleHTTPRequest processor connected to a PutFile processor then a HandleHTTPResponse processor. I've also tried using a LogAttribute processor. The response code and HTTP message from the NiFi web service is working properly, but I'm trying to make sure my JSON payload is being sent properly. Post is enabled in the HTTPRequest handler. Yet, the only files it's generating are blank and 0kb in size. Any ideas?

Based on the comments above the conclusion is that there was no problem on the side of Nifi.
It's definitely an issue with the Java code, I used postman again after changing some local firewall configurations and it successfully logs any POST requests that are sent to it and puts it in a file
The key step towards resolving the issue was trying to connect with something like Postman as #Binary Nerd and #Brian Bende suggested.

Related

Java library for async 'multipart-form' file upload?

I am trying to upload a file (and additional fields) using single REST POST request. This request has to be processed asynchronous and form has to be submitted using multipart-form content type (because beside file I am sending few other text fields with certain metadata).
I tried with Apache's org.apache.http.impl.nio.client.CloseableHttpAsyncClient but until now I didn't succeed (when request arrives on the server, fields from the form are not presented). When I do the same using org.apache.commons.httpclient.HttpClient request is processed without problems, so the issue is not on the server side.
Does anybody know how this async 'multipart-form' request could be made? If not possible with CloseableHttpAsyncClient, do you have some other library to suggest?
Thanks in advance...
I just want to give an update. I did some investigation and was able to fulfill my requirements with AsyncHttpClient (AHC)
It works very fast and is based on Netty Framework and NIO Java API.

Implementing a client to download file over HTTPS using commons-httpclient

I'm trying to implement a client application over https using commons-httpclient.
I have implemented a servlet at the server end to send data to client as blocks (chunks of data). each block contains 4MB. now my problem is, If i download using http url, i.e like http://localhost:8080/DownloadServlet/post it works fine. If I use https, some times I'm receiving 500 error and download stops in the middle. Can some one tell me what might be the problem.
thanks.

Viewing HTTP POST requests send to local server

I'm sending JSON data from my Java application to my local webserver with my PHP script that is receiving this message. Now as far as I know I can only view what has been received by for example inserting the data in a database. Is there a way/application to view the live POST requests sent to my PHP webserver?
I like to use fiddler for these kinds of tasks if the java HTTP library has support for proxies. Fiddler will list all information about the HTTP requests that is available. It will by default log all HTTP requests across your system, but can be told to limit to one application.
You can try setting your httpd logging level to verbose or (depending on what httpd it is) try to use extension that would do log all the data send in requests
For debugging purposes why not just write the POST data to a file?
i.e.
file_put_contents(<some filename>, $HTTP_RAW_POST_DATA);

glassfish response not getting in gzip compressed

i am working on java with Netbeans IDE and glassfish 3.1.2 i have created in rest services using jaxrs. when request from client is made ,i need to send json data in compressed format.to do this i have enabled the compression in glassfish as shown the following picture
but response got from the server is not compressed using gzip. it is receiving as normal json data. what should i do to overcome this issue
This is a solution for GF 3.1.2.2.
Responses to HTTP requests in version 1.0 are not compressed. You must send your requests in HTTP 1.1 to get gzipped responses from your glassfish server.
More over, you must add the header "Accept-Encoding: gzip" in your http requests.
To get a compressed response you need to have both sides agree to use it. You have configured GlassFish to send compressed responses. I can see that from the picture.
You need to make sure that your request to the services tells GlassFish that it can accept a compressed response. You normally do this by adding the following header to your HTTP requests: Accept-Encoding. You can read about the header in the RFC document that defines HTTP 1.1 request headers.
You can also get a lot of info from reading though SO questions about Accept-Encoding.

Java WCF Read Time Out

I have a WCF REST service that I want to connect to using a Java client. The service basically returns data from a database in the form of a list of objects, and I've configured the service to return the data in JSON format.
The problem is that when the response content-length passes a certain threshold, somewhere around 10500, the client fails to read the response body, resulting in a read time out.
I tried multiple REST clients, including the Jersey library and the Wiztools.org RESTClient application. I noticed that even using the Apache HttpClient class directly to send a post request and read the response gives the same error. Interestingly, the Jersey client returns a 200 response, but hangs on attempting the response body.
Fiddler, on the other hand, works fine, as does a C# client that I made using the Microsoft WCF Rest Kit DLL's.
Thank you for your time.

Categories