SSL - pford68/groovy-examples GitHub Wiki
Using the HTTPBuilder library, which appears to be dead now.1
@Grab( 'org.ccil.cowan.tagsoup:tagsoup:1.2.1' )
@Grab( 'org.codehaus.groovy.modules.http-builder:http-builder:0.7' )
import org.ccil.cowan.tagsoup.Parser
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
// Using an https url
new HTTPBuilder( 'https://twitter.com' ).with {
// Get from the given path as TEXT
get( path:'/philip_ford', contentType:TEXT ) { resp, reader ->
// Pass the html through tagsoup and generate a parser
new XmlParser( new Parser() ).parseText( reader.text ).with {
// print the title text from inside the head section
println head.title.text()
}
}
}
References
- https://github.com/jgritman/httpbuilder/wiki/SSL
- http://nerd-ability.blogspot.co.uk/2013/01/tech-how-to-fix-sslpeerunverifiedexcept.html
- http://stackoverflow.com/questions/23692780/grailsgroovysslpeerunverifiedexception-peer-not-authenticated?noredirect=1&lq=1
- http://stackoverflow.com/questions/3242335/how-to-use-ssl-with-a-self-signed-certificate-in-groovy
- http://stackoverflow.com/questions/11638005/is-there-an-easier-way-to-tell-httpbuilder-to-ignore-an-invalid-cert?rq=1
- http://humbleprogrammer.wikidot.com/groovy-ssl
- http://stackoverflow.com/questions/32332326/enable-java-groovy-url-connection-to-ignore-ssl-cert-errors-w-o-setting-setdefau
- https://dzone.com/articles/reading-https-url-self-signed
- https://github.com/noamt/rest-gradle-plugin
Notes
- Using HTTPBuilder, I received RuntimeExceptions stating that commons-lang:2.4 could not be downloaded. I resolved these by both deleting commons-lang from ~/.m2 and deleting ~/.groovy/grapes. See this article for more information.