Skip to content

Instantly share code, notes, and snippets.

@wsargent
Created June 25, 2013 16:58
Show Gist options
  • Save wsargent/5860224 to your computer and use it in GitHub Desktop.
Save wsargent/5860224 to your computer and use it in GitHub Desktop.
Using ning async http client
import play.api.libs.ws.Response
import scala.concurrent.{Future, Promise}
import com.ning.http.client._
import com.ning.http.client.{Response => AHCResponse}
import com.ning.http.client.AsyncCompletionHandler
val url = "http://google.com"
val config = new AsyncHttpClientConfig.Builder()
val client = new AsyncHttpClient(config.build())
val request = client.prepareGet(url).build()
var result = Promise[Response]()
client.executeRequest(request, new AsyncCompletionHandler[AHCResponse]() {
override def onCompleted(response: AHCResponse) = {
result.success(Response(response))
response
}
override def onThrowable(t: Throwable) {
result.failure(t)
}
})
val getFuture = result.future
getFuture.map { result =>
logger.info("result status = " + result.getCookies())
}.recover {
case e: Throwable => {
logger.error(e, "error e = ")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment