views:

503

answers:

2

I have recently been working on a C# application that calls a webservice over SSL and handles the certificate security using a delegate for the ServerCertificateValidationCallback event like so:

        System.Net.ServicePointManager.ServerCertificateValidationCallback += delegate(object certsender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            bool validationResult = false;

            // if there are no SSL validation errors
            if (sslPolicyErrors == SslPolicyErrors.None)
            {
                validationResult = true;
            }

            return validationResult;
        };

Now I need to do the same thing in Java and this is where I'm stuck - I've googled for a while and not really found a straight-forward answer. How do I handle SSL certificate validation in Java?

+1  A: 

Recent java version do it for you. Just point to an HTTPS URL (https://)

Cogsy
A: 

Apache HTTPClient is the best way to handle anything more than a simple get on a URL. Here is the SSL Guide.

Clint