Grails:Groovy:SSLPeerUnverifiedException: peer not authenticated
Asked Answered
S

2

7

I want to hit an xml request to a url while running the code in my local system it is working well i have created a war file and deployed the same in server,but while running in server getting an exception 'javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated' i have used groovy http builder

def http = new HTTPBuilder(url)
          http.auth.basic('username', 'password')
        try {               
            http.request(Method.POST, ContentType.TEXT) {
                        req->
                            headers.accept = "application/xml"
                            body = request //xml request
                            response.success = {
                                        resp,reader ->
                                            Response =  reader.text
                            }
            }
        }
        catch(HttpResponseException ex) {
             println ex;
        }

how can i solve this problem in this case..?

Scruff answered 16/5, 2014 at 4:44 Comment(1)
Try this blog and following links having similar exception. Groovy http builder SO1, SO2, SO3.Ashien
A
6

Workaround: The following answer provides a workaround for this issue: https://mcmap.net/q/560724/-is-there-an-easier-way-to-tell-httpbuilder-to-ignore-an-invalid-cert

Just found out that new version (0.7.1) of HttpBuilder introduces method:

ignoreSSLIssues()

This solves all problems regarding invalid SSL certificates (of course you have to be aware that it also decrease security).

More information about this method: http://groovy.codehaus.org/modules/http-builder/doc/ssl.html (section at the bottom)

i.e.

def http = new HTTPBuilder(url)
http.ignoreSSLIssues()

Solution: If you want to do things the 'proper' way, checkout the other solutions regarding importing the server's certificates. e.g. SSLPeerUnverifiedException: peer not authenticated

Alcoholize answered 13/1, 2015 at 1:56 Comment(1)
I'm using ignoreSSLIssues() and still getting the SSLPeerUnverifiedException.Colobus
R
3

If you use ignoreSSLIssues() but still get same exception.

Just add latest httpclient into Gradle/Maven

compile 'org.apache.httpcomponents:httpclient:4.5.3'

Can't use ignoreSSLIssues in HttpBuilder version 0.7.1

Rodge answered 10/5, 2017 at 9:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.