In my Spring application I use RESTTemplate to get some information from external API. This API require that when you make a request you must to wait for response of it until you make another request. That’s why I am wondering how to do this. Of course cannot use timer or something like that because response time from this API is different every time.
Unfortunately, RESTTemplate is required for this app and i cannot change it.
Normaly you should wait for a response when you make the request but you can open a server socket that is listening for incoming data and when you receive a response, check what kind of response it is then accept or reject it. So you make requests with a client socket and receive responses with a server socket.
http://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html
http://docs.oracle.com/javase/6/docs/api/java/net/ServerSocket.html