Skip to content

Instantly share code, notes, and snippets.

@Allan-Gong
Last active November 30, 2015 04:52
Show Gist options
  • Save Allan-Gong/f113d54ef19342a6bcfd to your computer and use it in GitHub Desktop.
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 ?
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