Created
January 27, 2017 22:07
-
-
Save ruescasd/b49e869548d1f7c8731797d37702bce6 to your computer and use it in GitHub Desktop.
This file contains 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 java.io.File | |
import akka.actor.ActorSystem | |
import akka.stream.ActorMaterializer | |
import play.api.libs.ws.WSClient | |
import play.api.libs.ws.WSConfigParser | |
import scala.concurrent.Future | |
import scala.util.{Success, Failure} | |
import play.api.{Environment, Mode} | |
import play.api.Configuration | |
import play.api.libs.ws.ahc.{AhcConfigBuilder, AhcWSClient, AhcWSClientConfig} | |
object WebRequest { | |
import scala.concurrent.ExecutionContext.Implicits._ | |
def main(args: Array[String]): Unit = { | |
implicit val system = ActorSystem() | |
implicit val materializer = ActorMaterializer() | |
try { | |
System.setProperty("javax.net.ssl.trustStore", "") | |
System.setProperty("javax.net.debug", "ssl") | |
val environment = Environment(new File("."), this.getClass.getClassLoader, Mode.Dev) | |
val configuration = Configuration.load(environment) | |
val parser = new WSConfigParser(configuration, environment) | |
val config = AhcWSClientConfig(wsClientConfig = parser.parse()) | |
val builder = new AhcConfigBuilder(config) | |
val ahcBuilder = builder.configure() | |
val ahcConfig = ahcBuilder.build() | |
val wsClient = new AhcWSClient(ahcConfig)(materializer) | |
call(wsClient) | |
.andThen { | |
case Success(x) => println(x) | |
case Failure(e) => e.printStackTrace() | |
} | |
.andThen { case _ => wsClient.close() } | |
.andThen { case _ => system.terminate() } | |
} | |
catch { | |
case e: Throwable => e.printStackTrace(); system.terminate() | |
} | |
system.terminate() | |
} | |
def call(wsClient: WSClient): Future[String] = { | |
wsClient.url("https://localhost/web/hello").get().map { response => | |
val statusText: String = response.statusText | |
response.body | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment