2

We have a REST based server and the issue is that some resources take long time to create - take couple of minutes<10m.

The problem: is that by the time the resource is created I am getting request timeout error on the client instead getting the resource back.

I thought of couple of possibilities

  • Create the resource with the POST request and add it to the session/db and then send a GET request to get the resource back. I dont like this solution: it is not "REST", and I will have to send couple of get requests that will return 404 until the resource is fully created

  • Set my server (Tomcat 7 & Spring 3.2) with a longer session time out duration - I dont really know how to do it.

  • Is there a way for the server to send a response to client saying "Hold it" until he returns the final answer? - Dont really know how to do that

  • Is there a way to send a request that simply "waits" longer to the server to respond? Dont really know how to do that

What is the best practice around this issue?

Thanks

special0ne
  • 6,063
  • 17
  • 67
  • 107
  • We can increase the value please refer -http://stackoverflow.com/questions/7145131/tomcat-request-timeout – VKPRO Jun 14 '14 at 15:55
  • @Kumar Which one? I tried the accepted answer and the answer below it but it didnt work. – special0ne Jun 19 '14 at 10:34
  • @specialOne Please post the server error log. Is it session timeout / Request timeout / Database transaction time out?. The solution in the above link will work for Server request timeout problem. – VKPRO Jun 19 '14 at 10:55
  • @Kumar It is because I am using Openshift. They put haproxy on the front with out any ability to configure. Which throws the exception. Thanks anyway – special0ne Jun 21 '14 at 02:47

1 Answers1

1

If you know that it will take a long time to create the resource tell it immediately to the client. Don't block him for minutes.

A common way is to answer with the status code 202 (Accepted). Add a Location header with a URI that points to a second resource the client can poll to get more information about the current status.

This second resource should answer with a 200 (OK) and the current status ("still pending, please try again in 30 seconds"). If the creation of the first resource is finished the second one should answer with a 303 (See Other) and the URI of the first resource in the Location header.

lefloh
  • 10,653
  • 3
  • 28
  • 50