Example usage for javax.net.ssl SSLException getLocalizedMessage

List of usage examples for javax.net.ssl SSLException getLocalizedMessage

Introduction

In this page you can find the example usage for javax.net.ssl SSLException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:org.rhq.plugins.www.util.WWWUtils.java

/**
 * Sends a HEAD request for the passed URL and returns true if the URL was reachable.
 *
 * @param  httpURL a http or https URL to check
 * @return true if connecting to the URL succeeds, or false otherwise
 *//*w  w  w .j  a  va2 s  . co  m*/
public static boolean isAvailable(URL httpURL) {
    String failMsg = "URL [" + httpURL + "] returned unavailable";
    try {
        HttpURLConnection connection = (HttpURLConnection) httpURL.openConnection();
        connection.setRequestMethod("HEAD");
        connection.setConnectTimeout(3000);
        connection.setReadTimeout(1000);

        if (connection instanceof HttpsURLConnection) {
            disableCertificateVerification((HttpsURLConnection) connection);
        }

        connection.connect();
        // get the response code to actually trigger sending the Request.
        connection.getResponseCode();
    } catch (SSLException e) {
        Log log = LogFactory.getLog(WWWUtils.class);
        log.warn(failMsg + " due to: " + e.getLocalizedMessage(), e);
        return false;
    } catch (IOException e) {
        Log log = LogFactory.getLog(WWWUtils.class);
        log.debug(failMsg + " due to: " + e.getLocalizedMessage(), e);
        return false;
    }

    return true;
}