Skip to content

Instantly share code, notes, and snippets.

@zikolach
Last active June 2, 2017 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zikolach/b1cc837b33456b98d3fd2d6d8b4b7a4c to your computer and use it in GitHub Desktop.
Save zikolach/b1cc837b33456b98d3fd2d6d8b4b7a4c to your computer and use it in GitHub Desktop.
import akka.actor.ActorSystem
import akka.event.Logging
import akka.http.scaladsl.Http
import akka.http.scaladsl.client.RequestBuilding._
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.stream.ActorMaterializer
import scala.concurrent.Await
import scala.concurrent.duration.Duration.Inf
object MainError {
private implicit val system = ActorSystem()
private implicit val materializer = ActorMaterializer()
private implicit val executionContext = system.dispatcher
val log = Logging(system, getClass)
def main(args: Array[String]): Unit = {
try {
val request = Get("https://example.com")
val bytesFuture = Http(system).singleRequest(request).flatMap(response => {
Unmarshal(response.entity.withoutSizeLimit()).to[Array[Byte]]
})
val bytes = Await.result(bytesFuture, Inf)
log.info(s"Size ${bytes.length}")
} catch {
case err: Throwable => log.error(err.getMessage)
} finally {
Await.ready(Http().shutdownAllConnectionPools(), Inf)
Await.ready(system.terminate(), Inf)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment