Small hack to check if a remote HTTP server is accessible or not. Relying on just DNS resolution test is not enough, it is mandatory to try to get the content.

import scala.concurrent._
import ExecutionContext.Implicits.global
val f = future { new java.net.URL("http://mvnrepository.com/artifact/com.jcraft/jsch").openConnection() }
.map { cnx =>
cnx.setConnectTimeout(5000)
cnx.setReadTimeout(5000)
cnx.setAllowUserInteraction(false)
cnx.setUseCaches(false)
cnx }
.map { _.getInputStream }
.map { io.Source.fromInputStream(_) }
.collect { case x => println("then download latest release") }
.recover { case _ => println("then only use local backup") }
//Await.ready(f, duration.Duration.Inf)
view raw gistfile1.scala hosted with ❤ by GitHub