protected static int getFreePort() throws IOException {
    ServerSocket s = new ServerSocket(0);
    try {
      s.setReuseAddress(true);
      int port = s.getLocalPort();
      return port;
    } finally {
      if (null != s) {
        s.close();
      }
    }
  }
Picks a free port on the host by binding a Socket to '0'.
hbase-http/src/test/java/org/apache/hadoop/hbase/http/HttpServerFunctionalTest.java