title: Connection refused exception when using HttpURLConnection in Play framework
body: <p>I'm using play 2.0.4, I need to connect to an url to see whether it's alive or not to make redirect decision.</p>
  
  <pre><code>public boolean checkServer(String strUrl){
      try {
          URL url = new URL(strUrl);
          HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
          urlConn.connect();
  
          if(HttpURLConnection.HTTP_OK == urlConn.getResponseCode()){
              urlConn.disconnect();
              return true;
          }else{
              urlConn.disconnect();
              return false;
          }
  
      } catch (IOException e) {
          System.err.println("Error creating HTTP connection:" + e.getMessage());
          return false;
      }
  }
  </code></pre>
  
  <p>In this case, the url that i use is localhost:9001, which is another play application. But then I received this error : Connection refused
  <br>Stack trace:</p>
  
  <pre><code>Error creating HTTP connection:Connection refused
  java.net.ConnectException: Connection refused
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
      at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
      at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
      at java.net.Socket.connect(Socket.java:579)
      at java.net.Socket.connect(Socket.java:528)
      at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
      at sun.net.www.http.HttpClient.openServer(HttpClient.java:378)
      at sun.net.www.http.HttpClient.openServer(HttpClient.java:473)
      at sun.net.www.http.HttpClient.&lt;init&gt;(HttpClient.java:203)
      at sun.net.www.http.HttpClient.New(HttpClient.java:290)
      at sun.net.www.http.HttpClient.New(HttpClient.java:306)
      at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:995)
      at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:931)
      at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:849)
      at models.Backend.checkServer(Backend.java:19)
      at controllers.Application.index(Application.java:22)
      at Routes$$anonfun$routes$1$$anonfun$apply$1$$anonfun$apply$2.apply(routes_routing.scala:32)
      at Routes$$anonfun$routes$1$$anonfun$apply$1$$anonfun$apply$2.apply(routes_routing.scala:32)
      at play.core.Router$HandlerInvoker$$anon$5$$anon$1.invocation(Router.scala:1090)
      at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:33)
      at play.core.j.JavaAction$class.apply(JavaAction.scala:74)
      at play.core.Router$HandlerInvoker$$anon$5$$anon$1.apply(Router.scala:1089)
      at play.core.ActionInvoker$$anonfun$receive$1$$anonfun$6.apply(Invoker.scala:126)
      at play.core.ActionInvoker$$anonfun$receive$1$$anonfun$6.apply(Invoker.scala:126)
      at play.utils.Threads$.withContextClassLoader(Threads.scala:17)
      at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:125)
      at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115)
      at akka.actor.Actor$class.apply(Actor.scala:318)
      at play.core.ActionInvoker.apply(Invoker.scala:113)
      at akka.actor.ActorCell.invoke(ActorCell.scala:626)
      at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197)
      at akka.dispatch.Mailbox.run(Mailbox.scala:179)
      at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:516)
      at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259)
      at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975)
      at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1479)
      at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)
  </code></pre>
  
  <p>Can somebody please show me what was wrong here?
  <br>Thank you very much.</p>