Created
June 25, 2013 16:58
-
-
Save wsargent/5860224 to your computer and use it in GitHub Desktop.
Using ning async http client
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 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