title: How to handle asynchronous callbacks in a synchronous way in Java?
body: <p>I have an architechture related question. This is a language independent question, but as I come from Java background, it will be easier for me if someone guides me in the Java way.</p>
  <p>Basically, the middleware I'm writing communicates with a SOAP based third party service. The calls are async - in a way that, when a service is called, it returns with a response 01 - processing; meaning that the third party has successfully received the request. In the original SOAP request, one callback URL has to be submitted each time, where third party actually sends the result. So, calling a particular service doesn't actually return the result immediately; the result is received in a separate HTTP endpoint in the middleware.</p>
  <p>Now in our frontend, we don't want to complicate the user experience. We want our users to call a middleware function (via menu items/buttons), and get the result immediately; and leave the dirty work to the middleware.</p>
  <p>Please note that the middleware function (lets say X()) which was invoked from the front end and the middleware endpoint URL(lets call it Y)  where third party pushes the result are completely separate from each other. X() somehow has to wait and then fetch the result grabbed in Y and then return the result to the frontend.</p>
  <p><a href="https://i.stack.imgur.com/bXL4E.png" rel="noreferrer"><img src="https://i.stack.imgur.com/bXL4E.png" alt="enter image description here" /></a></p>
  <p>How can I build a robust solution to achieve the above mentioned behavior?
  The picture depicts my case perfectly. Any suggestions will be highly appreciated.</p>