Last active
November 30, 2015 04:52
-
-
Save Allan-Gong/f113d54ef19342a6bcfd to your computer and use it in GitHub Desktop.
How to use databinder dispatch to invoke HTTP request against a web server with self-signed certificate ?
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 com.ning.http.client._ | |
import dispatch._, Defaults._ | |
val requestTimeoutInMs = 5000 | |
val allowSelfSignedSSLCertificate = true | |
val builder = new AsyncHttpClientConfig.Builder() | |
builder | |
.setAllowPoolingConnections(true) | |
.setRequestTimeout(requestTimeoutInMs) | |
.setCompressionEnforced(true) | |
.setExecutorService(Executors.newCachedThreadPool()) // Specifically set a threadpool so the spawned HTTP threads can be terminated by calling shutdown on the HTTP client | |
.setAcceptAnyCertificate(allowSelfSignedSSLCertificate) // Allow to HTTP client to connect to a server with self-signed SSL certificate | |
lazy val client = new AsyncHttpClient(builder.build()) | |
val myDispatchHttp = dispatch.Http(client) | |
// Do your stuff with myDispatchHttp | |
// Remember to shut down the thread pool | |
myDispatchHttp.shutdown() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment