Small Hack To Check If Remote Http
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |