title: Waiting for POST to finish processing before calling GET Request
body: <p>I am doing an integration test where I call a POST request that send a file to the server. Immediately after the POST, I call a GET request that retrieves the document and get a response that gives me the attributes of that document. However, sometimes I would get a 404 error, saying that the document does not exist until I run it again a few seconds after. </p>
  
  <p>I am thinking the POST has not finished processing yet so I have implement a Thread.sleep to wait 10 seconds but this way does not seem good as it might wait longer than it needs to or might not wait long enough. Is there some kind of 'implicit wait' that allows the POST to finish processing before requesting the GET?</p>
  
  <p>Below is a code snippet:</p>
  
  <pre><code>@Test
  public void PostDocumentThenCheckIfDocumentExistThenRemove() throws IOException, InterruptedException {     
      try {
          String str = fileToStringProcessing("C:/Users/Linh/Desktop/file.xml");
          ResponseEntity&lt;Message&gt; postResponse = getRestTemplate().exchange(getUri() + "documents", HttpMethod.POST, new HttpEntity(str, getHeaders()), Message.class);
          Thread.sleep(10000);
          ResponseEntity&lt;Account&gt; getResponse = getRestTemplate().exchange(getUri() + "account/7452616052/documents?start=2015-01-01&amp;end=2016-03-31", HttpMethod.GET, getHttpEntity(), Account.class);
          ResponseEntity&lt;Message&gt; deleteResponse = getRestTemplate().exchange(getUri() + "documents/file.xml", HttpMethod.DELETE, getHttpEntity(), Message.class);
  
          assertThat(postResponse.getStatusCode(), is(HttpStatus.CREATED));
          assertThat(getResponse.getStatusCode(), is(HttpStatus.OK));
          assertThat(deleteResponse.getStatusCode(), is(HttpStatus.OK));
      }catch(HttpClientErrorException e) {
          fail("Error! Status code " + e.getStatusCode());
      }   
  }
  </code></pre>
  
  <p>Here is the 404 error in the console. You can see here that the POST is successful but the GET is not. Doing a GET afterwards, after a few seconds, will show a successful </p>
  
  <pre><code>11:56:32.700 [main] DEBUG o.s.web.client.RestTemplate - POST request for "https://dpdev.billing.com/tf/dp/documents" resulted in 201 (Created)
  11:56:32.700 [main] DEBUG o.s.web.client.RestTemplate - Reading [com.digitalplatform.model.Message] as "application/xml" using [org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter@1dac5ef]
  11:56:32.904 [main] DEBUG o.s.web.client.RestTemplate - Created GET request for "https://dpdev.billing.com/tf/dp/account/7452616052/documents?start=2015-01-01&amp;end=2016-03-31"
  11:56:32.914 [main] DEBUG o.s.web.client.RestTemplate - Setting request Accept header to [application/xml, text/xml, application/json, application/*+xml, application/*+json]
  11:56:33.690 [main] DEBUG o.s.web.client.RestTemplate - GET request for "https://dpdev.billing.com/tf/dp/account/7452616052/documents?start=2015-01-01&amp;end=2016-03-31" resulted in 404 (Not Found); invoking error handler
  </code></pre>
  
  <p>GET and DELETE request right after the 404:</p>
  
  <pre><code>12:00:21.383 [main] DEBUG o.s.web.client.RestTemplate - Created GET request for "https://dpdev.billing.com/tf/dp/account/7452616052/documents?start=2015-01-01&amp;end=2016-03-31"
  12:00:21.444 [main] DEBUG o.s.web.client.RestTemplate - Setting request Accept header to [application/xml, text/xml, application/json, application/*+xml, application/*+json]
  12:00:23.176 [main] DEBUG o.s.web.client.RestTemplate - GET request for "https://dpdev.billing.com/tf/dp/account/7452616052/documents?start=2015-01-01&amp;end=2016-03-31" resulted in 200 (OK)
  12:00:23.176 [main] DEBUG o.s.web.client.RestTemplate - Reading [com.digitalplatform.model.Account] as "application/xml" using [org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter@37271612]
  12:00:23.380 [main] DEBUG o.s.web.client.RestTemplate - Created DELETE request for "https://dpdev.billing.com/tf/dp/documents/file.xml"
  12:00:23.381 [main] DEBUG o.s.web.client.RestTemplate - Setting request Accept header to [application/xml, text/xml, application/json, application/*+xml, application/*+json]
  12:00:25.120 [main] DEBUG o.s.web.client.RestTemplate - DELETE request for "https://dpdev.billing.com/tf/dp/documents/file.xml" resulted in 200 (OK)
  12:00:25.120 [main] DEBUG o.s.web.client.RestTemplate - Reading [com.digitalplatform.model.Message] as "application/xml" using [org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter@37271612]
  </code></pre>