Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active December 20, 2015 02:38
Show Gist options
  • Save dacr/6057315 to your computer and use it in GitHub Desktop.
Save dacr/6057315 to your computer and use it in GitHub Desktop.
Check if a remote HTTP server is accessible or not (DNS resolution test only is not enough)
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment