Example usage for java.lang NoSuchMethodException getMessage

List of usage examples for java.lang NoSuchMethodException getMessage

Introduction

In this page you can find the example usage for java.lang NoSuchMethodException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.jaffa.soa.dataaccess.TransformerUtils.java

/**
 * Take a source object and try and mold it back it its domain object.
 * This is the same as updateParent, except from the way it retrieved the
 * record, and the way it creates a new record.
 *//*from   ww  w  .  jav  a2s. c o m*/
static void updateChildBean(String path, GraphDataObject source, UOW uow, ITransformationHandler handler,
        IPersistent parentDomain, GraphMapping parentMapping, String parentField, DataTransformer.Mode mode,
        GraphDataObject newGraph) throws ApplicationExceptions, FrameworkException {
    if (log.isDebugEnabled())
        log.debug("Update Child Bean " + path);
    String relationshipName = parentMapping.getDomainFieldName(parentField);
    if (relationshipName.endsWith("Array"))
        relationshipName = relationshipName.substring(0, relationshipName.length() - 5);
    if (relationshipName.endsWith("Object"))
        relationshipName = relationshipName.substring(0, relationshipName.length() - 6);

    try {

        IPersistent domainObject = null;
        GraphMapping mapping = MappingFactory.getInstance(source);
        Map keys = new LinkedHashMap();
        Class doClass = mapping.getDomainClass();
        boolean gotKeys = false;

        // The path for a one-to-many relationship ends with a "[i]". The absence of that suffix indicates a one-to-one relationship
        //// No keys, must be one-to-one
        //if (mapping.getKeyFields() == null || mapping.getKeyFields().size() == 0) {
        if (path == null || path.charAt(path.length() - 1) != ']') {
            if (log.isDebugEnabled())
                log.debug("Find 'one-to-one' object - " + path);

            // Just use the getXxxObject method to get the related domain object,
            // if there is one...
            domainObject = (IPersistent) getProperty(parentMapping.getDomainFieldDescriptor(parentField),
                    parentDomain);
            if (domainObject == null) {
                if (log.isDebugEnabled())
                    log.debug("Not Found - " + path);
            }
        } else if (mode == DataTransformer.Mode.CLONE) {
            // In CLONE mode, get the keys from the new graph, and force the creation of the domain object
            if (newGraph != null)
                fillInKeys(path, newGraph, mapping, keys);
        } else {
            // Get the key fields used in the domain object. Use the findXxxxxCriteria() method,
            // then add the extra fields to the criteria object, to get the unique record.
            gotKeys = fillInKeys(path, source, mapping, keys);

            // read DO based on key
            if (gotKeys) {

                // get the method to get the PK criteria (i.e. public Criteria findVendorSiteCriteria(); )
                Method findCriteria = null;
                String methodName = "find" + StringHelper.getUpper1(relationshipName) + "Criteria";
                try {
                    findCriteria = parentDomain.getClass().getMethod(methodName, new Class[] {});
                } catch (NoSuchMethodException e) {
                    log.error("Find method '" + methodName + "' not found!");
                }
                if (findCriteria == null)
                    throw new TransformException(TransformException.METHOD_NOT_FOUND, path, methodName);

                // Find Criteria For Related Object
                Criteria criteria = (Criteria) findCriteria.invoke(parentDomain, new Object[] {});
                // Add extra key info...
                for (Iterator it = keys.keySet().iterator(); it.hasNext();) {
                    String keyField = (String) it.next();
                    Object value = keys.get(keyField);
                    keyField = StringHelper.getUpper1(mapping.getDomainFieldName(keyField));
                    criteria.addCriteria(keyField, value);
                    if (log.isDebugEnabled())
                        log.debug(path + "- Add to criteria:" + keyField + '=' + value);
                }
                // See if we get an object :-)
                Iterator itr = uow.query(criteria).iterator();
                if (itr.hasNext())
                    domainObject = (IPersistent) itr.next();
                if (itr.hasNext()) {
                    // Error, multiple objects found
                    throw new ApplicationExceptions(new ApplicationExceptionWithContext(path,
                            new MultipleDomainObjectsFoundException(findDomainLabel(criteria.getTable()))));
                }

            } else {
                if (log.isDebugEnabled())
                    log.debug("Object " + path
                            + " has either missing or null key values - Assume Create is needed");
            }
        }

        // Create object if not found
        if (domainObject == null) {
            // In MASS_UPDATE mode, error if DO not found
            if (mode == DataTransformer.Mode.MASS_UPDATE)
                throw new ApplicationExceptions(new ApplicationExceptionWithContext(path,
                        new DomainObjectNotFoundException(TransformerUtils.findDomainLabel(doClass))));

            // NEW OBJECT, create and reflect keys
            if (log.isDebugEnabled())
                log.debug("DO '" + mapping.getDomainClassShortName()
                        + "' not found with key, create a new one...");
            // find method on parent used to create object
            Method newObject = null;
            String methodName = "new" + StringHelper.getUpper1(relationshipName) + "Object";
            try {
                newObject = parentDomain.getClass().getMethod(methodName, new Class[] {});
            } catch (NoSuchMethodException e) {
                log.error("Method '" + methodName + "()' not found!");
            }
            if (newObject == null)
                throw new TransformException(TransformException.METHOD_NOT_FOUND, path, methodName);

            // Call method to create object
            domainObject = (IPersistent) newObject.invoke(parentDomain, new Object[] {});

            // Set the key fields
            for (Iterator it = keys.keySet().iterator(); it.hasNext();) {
                String keyField = (String) it.next();
                if (mapping.isReadOnly(keyField))
                    continue;
                Object value = keys.get(keyField);
                updateProperty(mapping.getDomainFieldDescriptor(keyField), value, domainObject);
            }
        } else {
            if (log.isDebugEnabled())
                log.debug("Found DO '" + mapping.getDomainClassShortName() + "' with key,");
        }

        // Now update all domain fields
        updateBeanData(path, source, uow, handler, mapping, domainObject, mode, newGraph);

    } catch (IllegalAccessException e) {
        TransformException me = new TransformException(TransformException.ACCESS_ERROR, path, e.getMessage());
        log.error(me.getLocalizedMessage(), e);
        throw me;
    } catch (InvocationTargetException e) {
        ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
        if (appExps != null)
            throw appExps;
        FrameworkException fe = ExceptionHelper.extractFrameworkException(e);
        if (fe != null)
            throw fe;
        TransformException me = new TransformException(TransformException.INVOCATION_ERROR, path, e);
        log.error(me.getLocalizedMessage(), me.getCause());
        throw me;
    } catch (InstantiationException e) {
        TransformException me = new TransformException(TransformException.INSTANTICATION_ERROR, path,
                e.getMessage());
        log.error(me.getLocalizedMessage(), e);
        throw me;
    }
}

From source file:org.openlogics.gears.jdbc.map.BeanResultHandler.java

/**
 *
 * @param resultSet//w  w  w  .  ja  va2 s  .  c o m
 * @param useColumnLabel
 * @param instantiate
 * @return
 * @throws SQLException
 */
private T mapResultSet(ResultSet resultSet, boolean useColumnLabel, Initializer<T> instantiate)
        throws SQLException {
    try {
        //T obj = requiredType.newInstance();
        if (instantiate == null || instantiate.getType() == null) {
            throw new IllegalArgumentException("Initializer can not be null neither the type to instantiate.");
        }
        ResultSetMetaData rsmd = resultSet.getMetaData();
        Class requiredType = instantiate.getType();
        if (!Map.class.isAssignableFrom(requiredType)) {
            T obj = instantiate.newInstance(resultSet);
            //Adecuate RESULTS to BEAN struct
            List<Field> fields = getInheritedFields(requiredType);//requiredType.getDeclaredFields();
            for (Field field : fields) {
                String metName = getSetterName(field.getName());
                Method method = null;
                String columnName = "";
                try {
                    method = requiredType.getMethod(metName, field.getType());
                } catch (NoSuchMethodException ex) {
                    //LOGGER.warn("Can't bind a result to method " + metName + " of class " + requiredType.getName());
                    continue;
                } catch (SecurityException ex) {
                    //LOGGER.warn("Can't bind a result to method " + metName + " of class " + requiredType.getName());
                    continue;
                }
                Object value = null;
                try {
                    ColumnRef c = field.getAnnotation(ColumnRef.class);
                    if (c != null) {
                        columnName = c.value().trim();
                    }
                    columnName = columnName.length() > 0 ? columnName : field.getName();

                    value = resultSet.getObject(columnName);
                    method.invoke(obj, value);
                } catch (IllegalArgumentException ex) {
                    if (value == null) {
                        continue;
                    }
                    logger.debug("Type found in database is '" + value.getClass().getName()
                            + "', but target object requires '" + field.getType().getName() + "': "
                            + ex.getLocalizedMessage());
                    //if this is thrown the try to fix this error using the following:
                    //If is a big decimal, maybe pojo has double or float attributes
                    try {
                        if (value instanceof BigDecimal || value instanceof Number) {
                            if (Double.class.isAssignableFrom(field.getType())
                                    || double.class.isAssignableFrom(field.getType())) {
                                method.invoke(obj, ((BigDecimal) value).doubleValue());
                                continue;
                            } else if (Float.class.isAssignableFrom(field.getType())
                                    || float.class.isAssignableFrom(field.getType())) {
                                method.invoke(obj, ((BigDecimal) value).floatValue());
                                continue;
                            } else if (Long.class.isAssignableFrom(field.getType())
                                    || long.class.isAssignableFrom(field.getType())) {
                                method.invoke(obj, ((BigDecimal) value).longValue());
                                continue;
                            } else {
                                logger.warn("Tried to fix the mismatch problem, but couldn't: "
                                        + "Trying to inject an object of class " + value.getClass().getName()
                                        + " to an object of class " + field.getType());
                            }
                        } else if (value instanceof Date) {
                            Date dd = (Date) value;
                            if (java.sql.Date.class.isAssignableFrom(field.getType())) {
                                method.invoke(obj, new java.sql.Date(dd.getTime()));
                                continue;
                            } else if (Timestamp.class.isAssignableFrom(field.getType())) {
                                method.invoke(obj, new Timestamp(dd.getTime()));
                                continue;
                            } else if (Time.class.isAssignableFrom(field.getType())) {
                                method.invoke(obj, new Time(dd.getTime()));
                                continue;
                            }
                        }
                    } catch (IllegalArgumentException x) {
                        printIllegalArgumentException(x, field, value);
                    } catch (InvocationTargetException x) {
                        x.printStackTrace();
                    }
                    //throw new DataSourceException("Can't execute method " + method.getName() + " due to "+ex.getMessage(), ex);
                    logger.warn(
                            "Can't execute method " + method.getName() + " due to: " + ex.getMessage() + ".");
                } catch (InvocationTargetException ex) {
                    //throw new DataSourceException("Can't inject an object into method " + method.getName(), ex);
                    logger.warn("Can't inject an object into method " + method.getName() + " due to: "
                            + ex.getMessage());
                } catch (SQLException ex) {
                    logger.warn("Target object has a field '" + columnName
                            + "', this was not found in query results, "
                            + "this cause that attribute remains NULL or with default value.");
                }
            }
            return obj;
        } else {
            ImmutableMap.Builder<String, Object> obj = new ImmutableMap.Builder<String, Object>();
            //Adecuate results to BEAN
            for (int i = 1; i <= rsmd.getColumnCount(); i++) {
                String column = useColumnLabel ? rsmd.getColumnLabel(i) : rsmd.getColumnName(i);
                Object value = resultSet.getObject(i);
                obj.put(column, value);
            }
            return (T) obj.build();
        }
    } catch (IllegalAccessException ex) {
        throw new SQLException(
                "Object of class " + instantiate.getType().getName()
                        + " doesn't provide a valid access. It's possible be private or protected access only.",
                ex);
    }
}

From source file:org.wso2.carbon.user.core.common.AbstractUserStoreManager.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private UserStoreManager createSecondaryUserStoreManager(RealmConfiguration realmConfig, UserRealm realm)
        throws UserStoreException {

    if (!isSecureCall.get()) {
        Class argTypes[] = new Class[] { RealmConfiguration.class, UserRealm.class };
        Object object = callSecure("createSecondaryUserStoreManager", new Object[] { realmConfig, realm },
                argTypes);/*  w  w w  . jav  a  2 s  .c  o  m*/
        return (UserStoreManager) object;
    }

    // setting global realm configurations such as everyone role, admin role and admin user
    realmConfig.setEveryOneRoleName(this.realmConfig.getEveryOneRoleName());
    realmConfig.setAdminUserName(this.realmConfig.getAdminUserName());
    realmConfig.setAdminRoleName(this.realmConfig.getAdminRoleName());

    String className = realmConfig.getUserStoreClass();
    if (className == null) {
        String errmsg = "Unable to add user store. UserStoreManager class name is null.";
        if (log.isDebugEnabled()) {
            log.debug(errmsg);
        }
        throw new UserStoreException(errmsg);
    }

    HashMap<String, Object> properties = new HashMap<String, Object>();
    properties.put(UserCoreConstants.DATA_SOURCE, this.dataSource);
    properties.put(UserCoreConstants.FIRST_STARTUP_CHECK, false);

    Class[] initClassOpt1 = new Class[] { RealmConfiguration.class, Map.class, ClaimManager.class,
            ProfileConfigurationManager.class, UserRealm.class, Integer.class };
    Object[] initObjOpt1 = new Object[] { realmConfig, properties, realm.getClaimManager(), null, realm,
            tenantId };

    // These two methods won't be used
    Class[] initClassOpt2 = new Class[] { RealmConfiguration.class, Map.class, ClaimManager.class,
            ProfileConfigurationManager.class, UserRealm.class };
    Object[] initObjOpt2 = new Object[] { realmConfig, properties, realm.getClaimManager(), null, realm };

    Class[] initClassOpt3 = new Class[] { RealmConfiguration.class, Map.class };
    Object[] initObjOpt3 = new Object[] { realmConfig, properties };

    try {
        Class clazz = Class.forName(className);
        Constructor constructor = null;
        Object newObject = null;

        if (log.isDebugEnabled()) {
            log.debug("Start initializing class with the first option");
        }

        try {
            constructor = clazz.getConstructor(initClassOpt1);
            newObject = constructor.newInstance(initObjOpt1);
            return (UserStoreManager) newObject;
        } catch (NoSuchMethodException e) {
            // if not found try again.
            if (log.isDebugEnabled()) {
                log.debug("Cannont initialize " + className + " using the option 1");
            }
        }

        if (log.isDebugEnabled()) {
            log.debug("End initializing class with the first option");
        }

        try {
            constructor = clazz.getConstructor(initClassOpt2);
            newObject = constructor.newInstance(initObjOpt2);
            return (UserStoreManager) newObject;
        } catch (NoSuchMethodException e) {
            // if not found try again.
            if (log.isDebugEnabled()) {
                log.debug("Cannot initialize " + className + " using the option 2");
            }
        }

        if (log.isDebugEnabled()) {
            log.debug("End initializing class with the second option");
        }

        try {
            constructor = clazz.getConstructor(initClassOpt3);
            newObject = constructor.newInstance(initObjOpt3);
            return (UserStoreManager) newObject;
        } catch (NoSuchMethodException e) {
            // cannot initialize in any of the methods. Throw exception.
            String message = "Cannot initialize " + className + ". Error " + e.getMessage();
            if (log.isDebugEnabled()) {
                log.debug(message, e);
            }
            throw new UserStoreException(message, e);
        }

    } catch (Throwable e) {
        String errorMessage = "Cannot create " + className;
        if (log.isDebugEnabled()) {
            log.debug(errorMessage, e);
        }
        throw new UserStoreException(e.getMessage() + "Type " + e.getClass(), e);
    }

}

From source file:org.apache.cordova.filetransfer.FileTransfer.java

/**
 * Downloads a file form a given URL and saves it to the specified directory.
 *
 * @param source        URL of the server to receive the file
 * @param target            Full path of the file on the file system
 *///  w ww  .  ja  v a2s . c o m
private void download(final String source, final String target, JSONArray args, CallbackContext callbackContext)
        throws JSONException {
    Log.d(LOG_TAG, "download " + source + " to " + target);

    final CordovaResourceApi resourceApi = webView.getResourceApi();

    final boolean trustEveryone = args.optBoolean(2);
    final String objectId = args.getString(3);
    final JSONObject headers = args.optJSONObject(4);

    final Uri sourceUri = resourceApi.remapUri(Uri.parse(source));
    // Accept a path or a URI for the source.
    Uri tmpTarget = Uri.parse(target);
    final Uri targetUri = resourceApi
            .remapUri(tmpTarget.getScheme() != null ? tmpTarget : Uri.fromFile(new File(target)));

    int uriType = CordovaResourceApi.getUriType(sourceUri);
    final boolean useHttps = uriType == CordovaResourceApi.URI_TYPE_HTTPS;
    final boolean isLocalTransfer = !useHttps && uriType != CordovaResourceApi.URI_TYPE_HTTP;
    if (uriType == CordovaResourceApi.URI_TYPE_UNKNOWN) {
        JSONObject error = createFileTransferError(INVALID_URL_ERR, source, target, null, 0, null);
        Log.e(LOG_TAG, "Unsupported URI: " + sourceUri);
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, error));
        return;
    }

    /* This code exists for compatibility between 3.x and 4.x versions of Cordova.
     * Previously the CordovaWebView class had a method, getWhitelist, which would
     * return a Whitelist object. Since the fixed whitelist is removed in Cordova 4.x,
     * the correct call now is to shouldAllowRequest from the plugin manager.
     */
    Boolean shouldAllowRequest = null;
    if (isLocalTransfer) {
        shouldAllowRequest = true;
    }
    if (shouldAllowRequest == null) {
        try {
            Method gwl = webView.getClass().getMethod("getWhitelist");
            Whitelist whitelist = (Whitelist) gwl.invoke(webView);
            shouldAllowRequest = whitelist.isUrlWhiteListed(source);
        } catch (NoSuchMethodException e) {
        } catch (IllegalAccessException e) {
        } catch (InvocationTargetException e) {
        }
    }
    if (shouldAllowRequest == null) {
        try {
            Method gpm = webView.getClass().getMethod("getPluginManager");
            PluginManager pm = (PluginManager) gpm.invoke(webView);
            Method san = pm.getClass().getMethod("shouldAllowRequest", String.class);
            shouldAllowRequest = (Boolean) san.invoke(pm, source);
        } catch (NoSuchMethodException e) {
        } catch (IllegalAccessException e) {
        } catch (InvocationTargetException e) {
        }
    }

    if (!Boolean.TRUE.equals(shouldAllowRequest)) {
        Log.w(LOG_TAG, "Source URL is not in white list: '" + source + "'");
        JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, null, 401, null);
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, error));
        return;
    }

    final RequestContext context = new RequestContext(source, target, callbackContext);
    synchronized (activeRequests) {
        activeRequests.put(objectId, context);
    }

    cordova.getThreadPool().execute(new Runnable() {
        public void run() {
            if (context.aborted) {
                return;
            }
            HttpURLConnection connection = null;
            HostnameVerifier oldHostnameVerifier = null;
            SSLSocketFactory oldSocketFactory = null;
            File file = null;
            PluginResult result = null;
            TrackingInputStream inputStream = null;
            boolean cached = false;

            OutputStream outputStream = null;
            try {
                OpenForReadResult readResult = null;

                file = resourceApi.mapUriToFile(targetUri);
                context.targetFile = file;

                Log.d(LOG_TAG, "Download file:" + sourceUri);

                FileProgressResult progress = new FileProgressResult();

                if (isLocalTransfer) {
                    readResult = resourceApi.openForRead(sourceUri);
                    if (readResult.length != -1) {
                        progress.setLengthComputable(true);
                        progress.setTotal(readResult.length);
                    }
                    inputStream = new SimpleTrackingInputStream(readResult.inputStream);
                } else {
                    // connect to server
                    // Open a HTTP connection to the URL based on protocol
                    connection = resourceApi.createHttpConnection(sourceUri);
                    if (useHttps && trustEveryone) {
                        // Setup the HTTPS connection class to trust everyone
                        HttpsURLConnection https = (HttpsURLConnection) connection;
                        oldSocketFactory = trustAllHosts(https);
                        // Save the current hostnameVerifier
                        oldHostnameVerifier = https.getHostnameVerifier();
                        // Setup the connection not to verify hostnames
                        https.setHostnameVerifier(DO_NOT_VERIFY);
                    }

                    connection.setRequestMethod("GET");

                    // TODO: Make OkHttp use this CookieManager by default.
                    String cookie = getCookies(sourceUri.toString());

                    if (cookie != null) {
                        connection.setRequestProperty("cookie", cookie);
                    }

                    // This must be explicitly set for gzip progress tracking to work.
                    connection.setRequestProperty("Accept-Encoding", "gzip");

                    // Handle the other headers
                    if (headers != null) {
                        addHeadersToRequest(connection, headers);
                    }

                    connection.connect();
                    if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {
                        cached = true;
                        connection.disconnect();
                        Log.d(LOG_TAG, "Resource not modified: " + source);
                        JSONObject error = createFileTransferError(NOT_MODIFIED_ERR, source, target, connection,
                                null);
                        result = new PluginResult(PluginResult.Status.ERROR, error);
                    } else {
                        if (connection.getContentEncoding() == null
                                || connection.getContentEncoding().equalsIgnoreCase("gzip")) {
                            // Only trust content-length header if we understand
                            // the encoding -- identity or gzip
                            if (connection.getContentLength() != -1) {
                                progress.setLengthComputable(true);
                                progress.setTotal(connection.getContentLength());
                            }
                        }
                        inputStream = getInputStream(connection);
                    }
                }

                if (!cached) {
                    try {
                        synchronized (context) {
                            if (context.aborted) {
                                return;
                            }
                            context.connection = connection;
                        }

                        // write bytes to file
                        byte[] buffer = new byte[MAX_BUFFER_SIZE];
                        int bytesRead = 0;
                        outputStream = resourceApi.openOutputStream(targetUri);
                        while ((bytesRead = inputStream.read(buffer)) > 0) {
                            outputStream.write(buffer, 0, bytesRead);
                            // Send a progress event.
                            progress.setLoaded(inputStream.getTotalRawBytesRead());
                            PluginResult progressResult = new PluginResult(PluginResult.Status.OK,
                                    progress.toJSONObject());
                            progressResult.setKeepCallback(true);
                            context.sendPluginResult(progressResult);
                        }
                    } finally {
                        synchronized (context) {
                            context.connection = null;
                        }
                        safeClose(inputStream);
                        safeClose(outputStream);
                    }

                    Log.d(LOG_TAG, "Saved file: " + target);

                    // create FileEntry object
                    Class webViewClass = webView.getClass();
                    PluginManager pm = null;
                    try {
                        Method gpm = webViewClass.getMethod("getPluginManager");
                        pm = (PluginManager) gpm.invoke(webView);
                    } catch (NoSuchMethodException e) {
                    } catch (IllegalAccessException e) {
                    } catch (InvocationTargetException e) {
                    }
                    if (pm == null) {
                        try {
                            Field pmf = webViewClass.getField("pluginManager");
                            pm = (PluginManager) pmf.get(webView);
                        } catch (NoSuchFieldException e) {
                        } catch (IllegalAccessException e) {
                        }
                    }
                    file = resourceApi.mapUriToFile(targetUri);
                    context.targetFile = file;
                    FileUtils filePlugin = (FileUtils) pm.getPlugin("File");
                    if (filePlugin != null) {
                        JSONObject fileEntry = filePlugin.getEntryForFile(file);
                        if (fileEntry != null) {
                            result = new PluginResult(PluginResult.Status.OK, fileEntry);
                        } else {
                            JSONObject error = createFileTransferError(CONNECTION_ERR, source, target,
                                    connection, null);
                            Log.e(LOG_TAG, "File plugin cannot represent download path");
                            result = new PluginResult(PluginResult.Status.IO_EXCEPTION, error);
                        }
                    } else {
                        Log.e(LOG_TAG, "File plugin not found; cannot save downloaded file");
                        result = new PluginResult(PluginResult.Status.ERROR,
                                "File plugin not found; cannot save downloaded file");
                    }
                }

            } catch (FileNotFoundException e) {
                JSONObject error = createFileTransferError(FILE_NOT_FOUND_ERR, source, target, connection, e);
                Log.e(LOG_TAG, error.toString(), e);
                result = new PluginResult(PluginResult.Status.IO_EXCEPTION, error);
            } catch (IOException e) {
                JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, connection, e);
                Log.e(LOG_TAG, error.toString(), e);
                result = new PluginResult(PluginResult.Status.IO_EXCEPTION, error);
            } catch (JSONException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
                result = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
            } catch (Throwable e) {
                JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, connection, e);
                Log.e(LOG_TAG, error.toString(), e);
                result = new PluginResult(PluginResult.Status.IO_EXCEPTION, error);
            } finally {
                synchronized (activeRequests) {
                    activeRequests.remove(objectId);
                }

                if (connection != null) {
                    // Revert back to the proper verifier and socket factories
                    if (trustEveryone && useHttps) {
                        HttpsURLConnection https = (HttpsURLConnection) connection;
                        https.setHostnameVerifier(oldHostnameVerifier);
                        https.setSSLSocketFactory(oldSocketFactory);
                    }
                }

                if (result == null) {
                    result = new PluginResult(PluginResult.Status.ERROR,
                            createFileTransferError(CONNECTION_ERR, source, target, connection, null));
                }
                // Remove incomplete download.
                if (!cached && result.getStatus() != PluginResult.Status.OK.ordinal() && file != null) {
                    file.delete();
                }
                context.sendPluginResult(result);
            }
        }
    });
}