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.
Related
I have rest client API accessing data through /read endpoint from my server. However, I have an internal batch service that calls my server's /write endpoint which updates the data. So from time to time the data from the server gets updated. How will I tell the client that the data is updated and ask it to call the /read endpoint again to get the latest data?
Below is a highlevel diagram on the scenario.
Try learning webhooks? Basically, the client will "subscribe" to your webhook, or to make it easier, the client will provide an endpoint to the server. Whenever there's an update, your server just sends a request to the client. The client should simply call a service that, whenever it receives a request from the webhook, fetches read.
It basically goes like this
Client subscribes to server
The client gives the server an endpoint /updateAvailable
When there's an update, the server sends a request to client's endpoint /updateAvailable
'/updateAvailable' invokes a service that calls on '/read'
The '/updateAvailable' endpoint could invoke a service that updates content. Let's say the request sent has a parameter
{
"updateFound":true
}
So whenever the client's '/updateAvailable' is called and receives a request, you do something like this (pseudo code)
if (updateBody.updateFound.message=true)
then call read()
Edit
By creating an endpoint for client, you can also do automatic updates. So client has an /updateAvailable endpoint. The server sends the update to the /updateAvailable endpoint, which from the client side invokes whatever service is used for /read
There are two solutions for your question:
Using timer on restful client to request to restful server in every N seconds/minutes... However, it's really bad idea because it has to request to server many times even though there's no updated data.
Using third party publish-subscribe-based messaging protocol solutions to implement push notification feature whenever there is new data updated. These solutions are: Google FCM,MQTT,AMQP
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.
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.
I wrote some Java program working on iSeries server. It can handle all Http requests to this server.
I also wrote Html page which is opened on local computer and I use some jQuery (Ajax) requests to iSeries server and I want to get some data from program which is running on it.
My server program sees that it gets some requests (POST and GET) with all parameters etc. and responses to it.
Unfortunately jQuery can't read answer data while simple Java program written and run on my local computer connects to iSeries server can read all responses from this server.
How can I write response in Java which will be avaiable to be read by jQuery?
It's very easy to process data in JSON format in the client side with jQuery. Try to program your server-side to return your data in JSON format.
I am developing a software which will be communicating with a server using HTTP (but it is not a web browser). Since the server part is not ready yet, I would like to debug my client software by sending HTTP messages to it. I know that I can send HTTP requests using Curl. But I am not sure if that is sufficient here.
I'm imagining an environment where I send a request from my application, check that it is correct using Wireshark and then reply to the request using some software. Using Curl, I think I would have open a listening port..?
I'd use a simple node.js server for this. You can write your own HTTP server in a few lines of code an simulate various return codes, response headers or response entities easily: http://nodejs.org/
PS: There are proxies that simply print out the HTTP messages. This might be helpful for you too, because you don't have to deal with WireShark anymore just for HTTP-level logging.
You can't do that with cURL. It is an http client, not a server.
The simplest way to do this is to actually implement a mock server application that just returns a static (i.e. hardcoded) message every time. You can do this using any server-side language you like (php, python, ruby, ...), or, you can even do it without a server side language, using just static files served by a webserver such as apache or nginx.
For example, if the server part (the API) would respond to /articles.json with something relevant (a JSON object containing some articles), you could put a file named articles.json that contains some hand-written data in your server's root. Then, your application would think it's calling an API when it's actually just downloading a static file.
You can use firebug addon of firefox browser to see content of HTTP request/response.
It does't require any server (but of course, if you dont have server which process requests from browser and send responses to browser, you 'll always see response "unable to connect").
If you still need to mock response, you can create simple server which is able to respond with mock responses, for example java servlet at tomcat server, with code like this:
public class MyMockServlet extends HttpServlet {
..
private String mockHeaders = "...";
private String mockResponse = "my response";
public void service(HttpRequest request, HttpResponse response){
setHeaderAndBodyInResponse(response);//your method
}
}