title: Promise timeouts and WS.get Timeout in PlayFramework 2.1 JAVA
body: <p>I am trying to access to an URL using WS on Play Framework 2.1 using JAVA api.</p>
  
  <p>Here is what I want:</p>
  
  <ol>
  <li>Some where in the code, start a WS request using <code>WS.get()</code> (I set timeout <strong>1000ms</strong>)</li>
  <li>If WS.get times out or another exception happens, I don't want my Promise throw an exception (since my flow reqiures it that way) So I use <code>Promise.recover()</code> to wrap that promise with another. Which returns a <code>null</code> Reponse object in case of failures.</li>
  <li>Some where else in code I want to "get" my Response. I wait for <strong>5000ms</strong> but what I get is <code>java.util.concurrent.TimeoutException: Futures timed out after [5000 milliseconds]</code></li>
  </ol>
  
  <p><strong>How?</strong> <code>WS.get()</code> timesout after <strong>1000ms</strong> and since it throws an <code>java.util.concurrent.TimeoutException: No response received after 1000</code> it is catched by my recover function. It returns a null response instead of an exception.</p>
  
  <p>So promise is "completed" after 1000ms at most. <strong>Why it times out and throws an exception after 5000 ms?</strong></p>
  
  <p>Code:</p>
  
  <pre><code>    Logger.info("Fetch started: " + new Date().toString());
  Promise&lt;WS.Response&gt; p1 = WS.url("http://athena.ics.forth.gr:9090/RDF/VRP/Examples/tap.rdf").setTimeout(1000).get();
  Promise&lt;WS.Response&gt; p2 = p1.recover(new Function&lt;Throwable, WS.Response&gt;() { 
    @Override
    public Response apply(Throwable a) throws Throwable {
      Logger.error("Promise thrown an exception so I will return null. " + new Date().toString() + " " + System.currentTimeMillis(), a);
      return null;
    }
  });
  
  try {
    /* This should return null or valid response but shouldn't throw an exception */
    Response r = p2.get(5000L);
    Logger.info(r.toString());
  } catch (Exception e) {
    /* Sholdn't happen! */
    Logger.error("Outer exception: " + " " + System.currentTimeMillis(), e);
  }
  Logger.error("Fetch finished: " + new Date().toString() + " " + System.currentTimeMillis());
  </code></pre>
  
  <p>Output I get:</p>
  
  <pre><code>[info] application - Fetch started: Tue Mar 19 10:04:42 EET 2013
  [error] application - Outer exception:  1363680287626
  java.util.concurrent.TimeoutException: Futures timed out after [5000 milliseconds]
      at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:96) ~[scala-library.jar:na]
      at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:58) ~[scala-library.jar:na]
      at scala.concurrent.Await$$anonfun$ready$1.apply(package.scala:86) ~[scala-library.jar:na]
      at scala.concurrent.Await$$anonfun$ready$1.apply(package.scala:86) ~[scala-library.jar:na]
      at akka.dispatch.MonitorableThreadFactory$AkkaForkJoinWorkerThread$$anon$3.block(ThreadPoolBuilder.scala:173) ~[akka-actor_2.10.jar:na]
      at scala.concurrent.forkjoin.ForkJoinPool.managedBlock(ForkJoinPool.java:2803) [scala-library.jar:na]
  [error] application - Fetch finished: Tue Mar 19 10:04:47 EET 2013 1363680287627
  [error] application - Promise thrown an exception so I will return null. Tue Mar 19 10:04:47 EET 2013 1363680287627
  java.util.concurrent.TimeoutException: No response received after 1000
      at com.ning.http.client.providers.netty.NettyAsyncHttpProvider$ReaperFuture.run(NettyAsyncHttpProvider.java:1809) ~[async-http-client.jar:na]
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) ~[na:1.7.0_11]
      at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351) ~[na:1.7.0_11]
      at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178) ~[na:1.7.0_11]
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) ~[na:1.7.0_11]
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) ~[na:1.7.0_11]
  </code></pre>
  
  <p>Even I wait for promise2 and promise2 is "recover wrapped promise1" recover function runs AFTER exception is thrown.</p>