Skip to content

Instantly share code, notes, and snippets.

@maheshkelkar
Created October 30, 2015 19:23
Show Gist options
  • Save maheshkelkar/35c9aa74883a98eae1ea to your computer and use it in GitHub Desktop.
Save maheshkelkar/35c9aa74883a98eae1ea to your computer and use it in GitHub Desktop.
Finagle HTTP question
//build.sbt
resolvers += "twttr" at "https://maven.twttr.com/"
libraryDependencies ++= Seq(
"com.twitter" %% "twitter-server" % "1.14.0",
"com.twitter" %% "finagle-httpx" % "6.28.0",
"com.twitter" %% "finagle-stats" % "6.28.0"
)
// Example.scala
import com.twitter.finagle.{Httpx, Service}
import com.twitter.finagle.httpx._
import com.twitter.util.{Await, Future}
import com.twitter.finagle.builder.ClientBuilder
object Client extends App {
// https only
val host = "10.10.10.1:443"
val ip = "10.10.10.1"
val request = Request(Method.Post, s"https://${host}/api/v1/authenticate")
request.contentType = "application/x-www-form-urlencoded"
request.contentString = Request.queryString(("e", "[email protected]"), ("p", "johndoe"), ("s", "VideoStreaming")).drop(1) /* Drop '?' */
//Option-1
//val client = Httpx.client.withTls(host)
//Option-2
val client = ClientBuilder()
.codec(Http())
.hosts(host)
//.tls(ip)
.tlsWithoutValidation()
.hostConnectionLimit(1)
.build()
val response: Future[Response] = client(request)
response.onSuccess { resp: Response =>
println("POST success: " + resp.contentString)
}
response.onFailure { exc =>
println("POST failed: " + exc.getMessage)
}
Await.result(response)
}
//***This code works fine, when run without https/tls
Case-1: Fails if ran as is
Caused by: javax.net.ssl.SSLProtocolException: handshake alert: unrecognized_name
at sun.security.ssl.ClientHandshaker.handshakeAlert(ClientHandshaker.java:1380)
at sun.security.ssl.SSLEngineImpl.recvAlert(SSLEngineImpl.java:1767)
at sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:1068)
at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:890)
at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:764)
Case-2: (comment out line #35 and enable #34)
Caused by: com.twitter.finagle.SslHostVerificationException
at com.twitter.finagle.netty3.ssl.SslConnectHandler$.sessionHostnameVerifier(SslConnectHandler.scala:167)
at com.twitter.finagle.netty3.Netty3Transporter$$anonfun$newPipeline$2$$anonfun$7$$anonfun$apply$4.apply(Netty3Transporter.scala:324)
at com.twitter.finagle.netty3.Netty3Transporter$$anonfun$newPipeline$2$$anonfun$7$$anonfun$apply$4.apply(Netty3Transporter.scala:324)
at com.twitter.finagle.netty3.ssl.SslConnectHandler$$anon$5.operationComplete(SslConnectHandler.scala:134)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment