4

I am currently in the process of moving all our Rest tests to the CI server and have noticed that all tests are failing due to the an SSL handshake, now I have successfully disabled this with the TrustManager with our Java test suite, but am unsure how to do it with Scala dispatch library, and havent been able to find many examples that could apply in this scenario.

val JSONstr = "{samplekey:samplevalue}"
val response:String = Http(url("https://www.host.com/path/to/post") 
                    << (checkInJSONstr, "application/json") as_str) 

The following exception is occuring as expected:

javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated at     com.sun.net.ssl.internal.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:352)
...

Is there a way to do it cleanly syntactically ignore SSL with the dispatch library?

Urist McDev
  • 498
  • 3
  • 14
user1697841
  • 109
  • 3
  • 11

2 Answers2

6
import dispatch._
val http = new Http with HttpsLeniency
val response:String = http(url("https://www.host.com/path/to/post") 
                   << (checkInJSONstr, "application/json") as_str) 
Kjuly
  • 34,476
  • 22
  • 104
  • 118
viktortnk
  • 2,739
  • 1
  • 19
  • 18
  • Doh! I overlooked this trait due to the "TLS", didn't know SSL/TLS were essentially the same until now. This works flawlessly, thank you. – user1697841 Sep 26 '12 at 14:34
1

viktortnk's answer doesn't work anymore with the newest version of Dispatch (0.13.2). For the newest version, you can use the following to create an http client that accepts any certificate:

val myHttp = Http.withConfiguration(config => config.setAcceptAnyCertificate(true))

Then you can use it for GET requests like this:

myHttp(url("https://www.host.com/path").GET OK as.String)

I found this out here: Why does dispatch throw "java.net.ConnectException: General SSLEngine ..." and "unexpected status" exceptions for a particular URL?

Bruno
  • 854
  • 7
  • 21