I have a web service I want to POST to. With curl I can do this:
curl --cacert ~/ca.pem [...]
which works fine.
In Groovy I'm doing this:
def post = new URL("$endpoint").openConnection()
post.setRequestMethod("POST")
post.setDoOutput(true)
post.setRequestProperty("Content-Type", "application/json")
post.setRequestProperty("Authorization", "Bearer $token")
post.getOutputStream().write(json.getBytes("UTF-8"))
That last line fails with:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Is there a simple way of setting my ca cert (which is a user configurable path)? That doesn't involve shelling out?
I saw this answer: https://stackoverflow.com/a/48173910/675083 But is that relevant to me and is it really that complicated?