Example usage for javax.net.ssl SSLProtocolException getMessage

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

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.openremote.android.console.util.AsyncResourceLoader.java

/** 
 * Download resources in background.//from  w  w w  . ja va 2 s  . c o m
 * 
 * @see android.os.AsyncTask#doInBackground(Params[])
 */
@Override
protected AsyncResourceLoaderResult doInBackground(Void... params) {
    AsyncResourceLoaderResult result = new AsyncResourceLoaderResult();
    boolean isDownloadSuccess = false;
    String panelName = AppSettingsModel.getCurrentPanelIdentity(activity);
    publishProgress("panel: " + panelName);

    Log.i("OpenRemote/DOWNLOAD", "Getting panel: " + panelName);

    String serverUrl = AppSettingsModel.getSecuredServer(activity);

    HttpResponse checkResponse = null;

    try {
        checkResponse = ORNetworkCheck.verifyControllerURL(activity,
                AppSettingsModel.getCurrentServer(activity));
    } catch (SSLProtocolException e) {
        //Probably no access
        result.setAction(TO_SETTING_SSL_PROTOCOL_ERROR);
        Log.e(LOG_CATEGORY, "AsyncReSourceLoader: ", e);

        // Delete & create a new keystore
        orKeyStore.delete();
        orKeyStore.create();
        return result;
    } catch (SSLException e) {
        //Probably no access
        result.setAction(TO_SETTING_SSL_ERROR);
        Log.e(LOG_CATEGORY, "AsyncReSourceLoader: ", e);
        return result;
    } catch (IOException e) {
        // TODO :
        //   right now still not doing anything with this, user is still completely in the dark
        //   what went wrong, need to untangle the async loader mess before can propagate info
        //   back to user
        //
        //   So for now, an empty catch block, until I can build proper test cases for these
        //                                                                                    [JPL]
        //
        if (e != null) {
            Log.e(LOG_CATEGORY, "AsyncReSourceLoader: ", e);
            Log.e("OpenRemote/DOWNLOAD", e.getMessage());
        }
    }

    isDownloadSuccess = checkResponse != null
            && checkResponse.getStatusLine().getStatusCode() == Constants.HTTP_SUCCESS;

    if (isDownloadSuccess) {
        int downLoadPanelXMLStatusCode = HTTPUtil.downLoadPanelXml(activity, serverUrl, panelName);
        if (downLoadPanelXMLStatusCode != Constants.HTTP_SUCCESS) { // download panel xml fail.
            Log.i("OpenRemote/DOWNLOAD", "Download file panel.xml fail.");
            if (downLoadPanelXMLStatusCode == ControllerException.UNAUTHORIZED) {
                result.setAction(TO_LOGIN);
                result.setStatusCode(downLoadPanelXMLStatusCode);
                return result;
            }

            if (activity.getFileStreamPath(Constants.PANEL_XML).exists()) {
                Log.i("OpenRemote/DOWNLOAD", "Download file panel.xml fail, so use local cache.");
                FileUtil.parsePanelXML(activity);
                result.setCanUseLocalCache(true);
                result.setStatusCode(downLoadPanelXMLStatusCode);
                result.setAction(TO_GROUP);
            } else {
                Log.i("OpenRemote/DOWNLOAD", "No local cache is available, ready to switch controller.");
                result.setAction(SWITCH_TO_OTHER_CONTROLER);
                return result;
            }
        } else { // download panel xml success.
            Log.i("OpenRemote/DOWNLOAD", "Download file panel.xml successfully.");
            if (activity.getFileStreamPath(Constants.PANEL_XML).exists()) {
                FileUtil.parsePanelXML(activity);
                result.setAction(TO_GROUP);
            } else {
                Log.i("OpenRemote/DOWNLOAD",
                        "No local cache is available authouth downloaded file panel.xml successfully, ready to switch controller.");
                result.setAction(SWITCH_TO_OTHER_CONTROLER);
                return result;
            }

            Iterator<String> images = XMLEntityDataBase.imageSet.iterator();
            String imageName = "";
            while (images.hasNext()) {
                imageName = images.next();
                publishProgress(imageName);
                HTTPUtil.downLoadImage(activity, AppSettingsModel.getSecuredServer(activity), imageName);
            }
        }
    } else { // Download failed.
        if (checkResponse != null
                && checkResponse.getStatusLine().getStatusCode() == ControllerException.UNAUTHORIZED) {
            String html = "";

            try {
                html = StringUtil.stringFromInputStream(checkResponse.getEntity().getContent());
            } catch (IllegalStateException e) {
                Log.e(LOG_CATEGORY, e.getMessage());
            } catch (IOException e) {
                Log.e(LOG_CATEGORY, e.getMessage());
            }

            if (AppSettingsModel.isSSLEnabled(activity) || html.contains("client certificate chain")) {
                result.setAction(TO_SETTING_SSL_ERROR);
            } else {
                result.setAction(TO_LOGIN);
                result.setStatusCode(ControllerException.UNAUTHORIZED);
            }
            return result;
        }

        if (checkResponse != null && checkResponse.getStatusLine().getStatusCode() == 403) {
            result.setAction(TO_SETTING_SSL_ERROR);
            return result;
        }

        if (activity.getFileStreamPath(Constants.PANEL_XML).exists()) {
            Log.i("OpenRemote/DOWNLOAD", "Download failed, so use local cache.");
            FileUtil.parsePanelXML(activity);
            result.setCanUseLocalCache(true);
            result.setAction(TO_GROUP);
            if (checkResponse == null) {
                result.setStatusCode(ControllerException.CONTROLLER_UNAVAILABLE);
            } else {
                result.setStatusCode(checkResponse.getStatusLine().getStatusCode());
            }
        } else {
            Log.i("OpenRemote/DOWNLOAD", "No local cache is available, ready to switch controller.");
            result.setAction(SWITCH_TO_OTHER_CONTROLER);
            return result;
        }
    }

    new Thread(new Runnable() {
        public void run() {
            ORControllerServerSwitcher.detectGroupMembers(activity);
        }
    }).start();

    if (result.getAction() == TO_GROUP && !groupLoader.isDone()) {
        synchronized (groupLoader) {
            try {
                groupLoader.wait();
            } catch (InterruptedException e) {
                Log.e("OpenRemote/DOWNLOAD", "Waiting for groupLoader interrupted");
            }
        }
    }

    return result;
}