Example usage for javax.net.ssl SSLException getMessage

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

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.c0124.k9.mail.store.WebDavStore.java

/**
 * Makes the initial connection to Exchange for authentication. Determines the type of authentication necessary for
 * the server.//from  w  w w .  j  av a2s.c  o  m
 *
 * @throws MessagingException
 */
private ConnectionInfo doInitialConnection() throws MessagingException {
    // For our initial connection we are sending an empty GET request to
    // the configured URL, which should be in the following form:
    // https://mail.server.com/Exchange/alias
    //
    // Possible status codes include:
    // 401 - the server uses basic authentication
    // 30x - the server is trying to redirect us to an OWA login
    // 20x - success
    //
    // The latter two indicate form-based authentication.
    ConnectionInfo info = new ConnectionInfo();

    WebDavHttpClient httpClient = getHttpClient();

    HttpGeneric request = new HttpGeneric(mUrl);
    request.setMethod("GET");

    try {
        HttpResponse response = httpClient.executeOverride(request, mContext);
        info.statusCode = response.getStatusLine().getStatusCode();

        if (info.statusCode == 401) {
            // 401 is the "Unauthorized" status code, meaning the server wants
            // an authentication header for basic authentication.
            info.requiredAuthType = AUTH_TYPE_BASIC;
        } else if ((info.statusCode >= 200 && info.statusCode < 300) || // Success
                (info.statusCode >= 300 && info.statusCode < 400) || // Redirect
                (info.statusCode == 440)) { // Unauthorized
            // We will handle all 3 situations the same. First we take an educated
            // guess at where the authorization DLL is located. If this is this
            // doesn't work, then we'll use the redirection URL for OWA login given
            // to us by exchange. We can use this to scrape the location of the
            // authorization URL.
            info.requiredAuthType = AUTH_TYPE_FORM_BASED;

            if (mAuthPath != null && !mAuthPath.equals("")) {
                // The user specified their own authentication path, use that.
                info.guessedAuthUrl = getRoot() + mAuthPath;
            } else {
                // Use the default path to the authentication dll.
                info.guessedAuthUrl = getRoot() + "/exchweb/bin/auth/owaauth.dll";
            }

            // Determine where the server is trying to redirect us.
            Header location = response.getFirstHeader("Location");
            if (location != null) {
                info.redirectUrl = location.getValue();
            }
        } else {
            throw new IOException("Error with code " + info.statusCode + " during request processing: "
                    + response.getStatusLine().toString());
        }
    } catch (SSLException e) {
        throw new CertificateValidationException(e.getMessage(), e);
    } catch (IOException ioe) {
        Log.e(K9.LOG_TAG, "IOException: " + ioe + "\nTrace: " + processException(ioe));
        throw new MessagingException("IOException", ioe);
    }

    return info;
}

From source file:com.bernard.beaconportal.activities.mail.store.WebDavStore.java

/**
 * Makes the initial connection to Exchange for authentication. Determines
 * the type of authentication necessary for the server.
 * /*from   w ww.ja  v a 2s . c  o m*/
 * @throws MessagingException
 */
private ConnectionInfo doInitialConnection() throws MessagingException {
    // For our initial connection we are sending an empty GET request to
    // the configured URL, which should be in the following form:
    // https://mail.server.com/Exchange/alias
    //
    // Possible status codes include:
    // 401 - the server uses basic authentication
    // 30x - the server is trying to redirect us to an OWA login
    // 20x - success
    //
    // The latter two indicate form-based authentication.
    ConnectionInfo info = new ConnectionInfo();

    WebDavHttpClient httpClient = getHttpClient();

    HttpGeneric request = new HttpGeneric(mUrl);
    request.setMethod("GET");

    try {
        HttpResponse response = httpClient.executeOverride(request, mContext);
        info.statusCode = response.getStatusLine().getStatusCode();

        if (info.statusCode == 401) {
            // 401 is the "Unauthorized" status code, meaning the server
            // wants
            // an authentication header for basic authentication.
            info.requiredAuthType = AUTH_TYPE_BASIC;
        } else if ((info.statusCode >= 200 && info.statusCode < 300) || // Success
                (info.statusCode >= 300 && info.statusCode < 400) || // Redirect
                (info.statusCode == 440)) { // Unauthorized
            // We will handle all 3 situations the same. First we take an
            // educated
            // guess at where the authorization DLL is located. If this is
            // this
            // doesn't work, then we'll use the redirection URL for OWA
            // login given
            // to us by exchange. We can use this to scrape the location of
            // the
            // authorization URL.
            info.requiredAuthType = AUTH_TYPE_FORM_BASED;

            if (mAuthPath != null && !mAuthPath.equals("")) {
                // The user specified their own authentication path, use
                // that.
                info.guessedAuthUrl = getRoot() + mAuthPath;
            } else {
                // Use the default path to the authentication dll.
                info.guessedAuthUrl = getRoot() + "/exchweb/bin/auth/owaauth.dll";
            }

            // Determine where the server is trying to redirect us.
            Header location = response.getFirstHeader("Location");
            if (location != null) {
                info.redirectUrl = location.getValue();
            }
        } else {
            throw new IOException("Error with code " + info.statusCode + " during request processing: "
                    + response.getStatusLine().toString());
        }
    } catch (SSLException e) {
        throw new CertificateValidationException(e.getMessage(), e);
    } catch (IOException ioe) {
        Log.e(K9.LOG_TAG, "IOException: " + ioe + "\nTrace: " + processException(ioe));
        throw new MessagingException("IOException", ioe);
    }

    return info;
}