Example usage for java.lang Exception getCause

List of usage examples for java.lang Exception getCause

Introduction

In this page you can find the example usage for java.lang Exception getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:edu.washington.iam.tools.netact.NetactDNSVerifier.java

/**
 * Test if a user has ownership of a domain
 *
 * @param id user's uwnetid/*from   w w  w  .j a va2  s .com*/
 * @param domain to test
 * @param return list of owners (can be null)
 */

public boolean isOwner(String dns, String id, List<String> owners) throws DNSVerifyException {

    boolean isOwner = false;
    if (id == null)
        id = "";
    log.debug("looking for owner (" + id + ") in " + dns);

    try {
        String[] urls = { hostUrl, domainUrl };
        for (String url : urls) {
            String respString = webClient.simpleRestGet(url + dns);
            // log.debug("got: " + respString);

            JsonParser parser = new JsonParser();
            JsonElement ele = parser.parse(respString);
            if (ele.isJsonObject()) {
                JsonObject resp = ele.getAsJsonObject();
                if (resp.get("table").isJsonObject()) {
                    JsonObject tbl = resp.getAsJsonObject("table");
                    if (tbl.get("row").isJsonArray()) {
                        JsonArray ids = tbl.getAsJsonArray("row");
                        for (int i = 0; i < ids.size(); i++) {
                            JsonObject idi = ids.get(i).getAsJsonObject();
                            JsonPrimitive oidu = idi.getAsJsonPrimitive("uwnetid");
                            if (oidu == null)
                                continue;
                            String oid = oidu.getAsString();
                            if (oid.equals(id)) {
                                if (owners == null)
                                    return true; // done
                                isOwner = true;
                            }
                            if (owners != null && !owners.contains(oid))
                                owners.add(oid);
                        }
                    } else {
                        String oid = tbl.getAsJsonObject("row").getAsJsonPrimitive("uwnetid").getAsString();
                        if (oid.equals(id)) {
                            if (owners == null)
                                return true; // done
                            isOwner = true;
                        }
                        if (owners != null && !owners.contains(oid))
                            owners.add(oid);
                    }
                }
            }
        }

    } catch (Exception e) {
        log.debug("netact dns lookup error: " + e);
        throw new DNSVerifyException(e.getMessage() + " : " + e.getCause());
    }

    // do substrings too
    dns = dns.replaceFirst("[^\\.]+\\.", "");
    // log.debug("do substrings: " + dns);
    int p = dns.indexOf(".");
    if (p > 0) {
        if (isOwner(dns, id, owners)) {
            if (owners == null)
                return true; // done
            isOwner = true;
        }
    }
    return isOwner;
}

From source file:com.sina.cloudstorage.services.scs.transfer.internal.UploadMonitor.java

private List<PartETag> collectPartETags() {
    final List<PartETag> partETags = new ArrayList<PartETag>(futures.size());
    for (Future<PartETag> future : futures) {
        try {/*from   www .j a v a2s  . com*/
            partETags.add(future.get());
        } catch (Exception e) {
            throw new SCSClientException("Unable to upload part: " + e.getCause().getMessage(), e.getCause());
        }
    }
    return partETags;
}

From source file:hu.bme.mit.sette.common.model.snippet.SnippetInputFactoryContainer.java

/**
 * Validates the constructor of the class.
 *
 * @param validator//from  w  w w .  j a v  a 2 s  . c  om
 *            a validator
 */
private void validateConstructor(final AbstractValidator<?> validator) {
    if (javaClass.getDeclaredConstructors().length != 1) {
        // constructor count is validated with the class
        return;
    }

    Constructor<?> constructor = javaClass.getDeclaredConstructors()[0];
    ConstructorValidator v = new ConstructorValidator(constructor);
    v.withModifiers(Modifier.PRIVATE).parameterCount(0);
    v.synthetic(false);

    // check: constructor throws new
    // UnsupportedOperationException("Static class")

    Throwable exception = null;
    try {
        // call the private ctor
        constructor.setAccessible(true);
        constructor.newInstance();
    } catch (Exception e) {
        exception = e.getCause();
    } finally {
        // restore visibility
        constructor.setAccessible(false);
    }

    if (exception == null || !exception.getClass().equals(UnsupportedOperationException.class)
            || !exception.getMessage().equals("Static class")) {
        v.addException("The constructor must throw an " + "UnsupportedOperationException with the message "
                + "\"Static class\"");
    }

    validator.addChildIfInvalid(v);
}

From source file:gemlite.shell.service.batch.ImportService.java

private void checkContextInitialized() {
    if (initializedFlag.get() == false || batchContext == null || batchContext.isActive() == false) {
        try {/*from  w  w w .  j  a  va 2s. c  o m*/
            generator.initializeEngine();

            batchContext = Util.initContext("batch/batch-context.xml");
            jobLauncher = batchContext.getBean(JobLauncher.class);
            if (LogUtil.getCoreLog().isDebugEnabled())
                LogUtil.getCoreLog().debug("Context initialized success:" + batchContext);
        } catch (Exception e) {
            if (e.getCause() instanceof DataAccessResourceFailureException) {
                LogUtil.getCoreLog().info("-> Spring batch reposity database error.");
            }
            if (LogUtil.getCoreLog().isErrorEnabled())
                LogUtil.getCoreLog().error("Context initailized failed", e);
            throw new GemliteException(e);
        }
        initializedFlag.set(true);
    } else if (LogUtil.getCoreLog().isDebugEnabled())
        LogUtil.getCoreLog().debug("Context already initialized:" + batchContext);
}

From source file:com.sisrni.service.FreeMarkerMailServiceImpl.java

private MimeMessagePreparator getMessagePreparator(final Object obj) throws Exception {

    try {/*from ww w  .j a v a2s.co  m*/

        MimeMessagePreparator preparator = new MimeMessagePreparator() {

            public void prepare(MimeMessage mimeMessage) throws Exception {
                MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);

                helper.setSubject(getSubJect());
                //helper.setFrom("tgraduacion01@gmail.com" );
                helper.setTo(getSetToMail());
                helper.setSentDate(new Date());

                Map<String, Object> model = new HashMap<String, Object>();
                model.put("obj", obj);

                String text = geFreeMarkerTemplateContent(model);
                System.out.println("Contenido de plantilla : " + text);

                // use the true flag to indicate you need a multipart message
                helper.setText(text, true);

                //Additionally, let's add a resource as an attachment as well.
                //helper.addAttachment("cutie.png", new ClassPathResource("linux-icon.png"));
            }
        };
        return preparator;
    } catch (Exception ex) {
        throw new Exception(
                "Error class  FreeMarkerMailServiceImpl - getMessagePreparator()\n" + ex.getMessage(),
                ex.getCause());
    }

}

From source file:com.capitalone.dashboard.client.project.ProjectDataClientImpl.java

/**
 * Updates the MongoDB with a JSONArray received from the source system
 * back-end with story-based data.// w  w w . j av a  2  s .c  o m
 *
 * @param tmpMongoDetailArray
 *            A JSON response in JSONArray format from the source system
 * @param featureCollector
 * @return
 * @return
 */
@SuppressWarnings("unchecked")
protected void updateMongoInfo(JSONArray tmpMongoDetailArray) {
    try {
        JSONObject dataMainObj = new JSONObject();
        for (int i = 0; i < tmpMongoDetailArray.size(); i++) {
            if (dataMainObj != null) {
                dataMainObj.clear();
            }
            dataMainObj = (JSONObject) tmpMongoDetailArray.get(i);
            Scope scope = new Scope();

            @SuppressWarnings("unused") // ?
            boolean deleted = this
                    .removeExistingEntity(TOOLS.sanitizeResponse((String) dataMainObj.get("_oid")));

            // collectorId
            scope.setCollectorId(featureCollectorRepository.findByName(Constants.VERSIONONE).getId());

            // ID;
            scope.setpId(TOOLS.sanitizeResponse((String) dataMainObj.get("_oid")));

            // name;
            scope.setName(TOOLS.sanitizeResponse((String) dataMainObj.get("Name")));

            // beginDate;
            scope.setBeginDate(
                    TOOLS.toCanonicalDate(TOOLS.sanitizeResponse((String) dataMainObj.get("BeginDate"))));

            // endDate;
            scope.setEndDate(
                    TOOLS.toCanonicalDate(TOOLS.sanitizeResponse((String) dataMainObj.get("EndDate"))));

            // changeDate;
            scope.setChangeDate(
                    TOOLS.toCanonicalDate(TOOLS.sanitizeResponse((String) dataMainObj.get("ChangeDate"))));

            // assetState;
            scope.setAssetState(TOOLS.sanitizeResponse((String) dataMainObj.get("AssetState")));

            // isDeleted;
            scope.setIsDeleted(TOOLS.sanitizeResponse((String) dataMainObj.get("IsDeleted")));

            // path;
            String projPath = new String(scope.getName());
            List<String> projList = (List<String>) dataMainObj.get("ParentAndUp.Name");
            if (projList != null) {
                for (String proj : projList) {
                    projPath = proj + "-->" + projPath;
                }
                projPath = "All-->" + projPath;
            } else {
                projPath = "All-->" + projPath;
            }
            scope.setProjectPath(TOOLS.sanitizeResponse(projPath));

            try {
                projectRepo.save(scope);
            } catch (Exception e) {
                LOGGER.error("Unexpected error caused when attempting to save data\nCaused by: " + e.getCause(),
                        e);
            }
        }
    } catch (Exception e) {
        LOGGER.error("FAILED: " + e.getMessage() + ", " + e.getClass());
    }
}

From source file:info.magnolia.imaging.caching.CachingImageStreamer.java

/**
 * Unwrap ExecutionExceptions wrapping a RuntimeException wrapping an ImagingException or IOException,
 * as thrown by the Function of the computing map.
 * @see #currentJobs/*from  w ww  .  j  av  a 2s .co m*/
 */
private void unwrapRuntimeException(Exception e) throws ImagingException, IOException {
    final Throwable cause = e.getCause();
    if (cause instanceof ImagingException) {
        throw (ImagingException) cause;
    } else if (cause instanceof IOException) {
        throw (IOException) cause;
    } else if (cause instanceof RuntimeException) {
        unwrapRuntimeException((RuntimeException) cause);
    } else if (cause == null) {
        // This really, really, should not happen... but we'll let this exception bubble up
        throw new IllegalStateException(
                "Unexpected and unhandled exception: " + (e.getMessage() != null ? e.getMessage() : ""), e);
    } else {
        // this shouldn't happen either, actually.
        throw new ImagingException(e.getMessage(), cause);
    }
}

From source file:com.duroty.application.admin.actions.UpdateUserAction.java

protected ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    ActionMessages errors = new ActionMessages();

    try {/* w  w  w.j a  va  2s .com*/
        DynaActionForm _form = (DynaActionForm) form;

        Admin adminInstance = getAdminInstance(request);

        UserObj userObj = new UserObj();

        String password = (String) _form.get("password");
        String confirmPassword = (String) _form.get("confirmPassword");

        if (!StringUtils.isBlank(password)) {
            adminInstance.confirmPassword(password, confirmPassword);
            userObj.setPassword(password);
        }

        userObj.setIdint(((Integer) _form.get("idint")).intValue());

        Boolean active = new Boolean(false);

        if (_form.get("active") != null) {
            active = (Boolean) _form.get("active");
        }

        userObj.setActive(active.booleanValue());

        userObj.setEmail((String) _form.get("email"));
        userObj.setEmailIdentity((String) _form.get("emailIdentity"));

        Boolean htmlMessages = new Boolean(false);

        if (_form.get("htmlMessages") != null) {
            htmlMessages = (Boolean) _form.get("htmlMessages");
        }

        userObj.setHtmlMessages(htmlMessages.booleanValue());

        userObj.setLanguage((String) _form.get("language"));
        userObj.setMessagesByPage(((Integer) _form.get("byPage")).intValue());
        userObj.setName((String) _form.get("name"));
        userObj.setQuotaSize(((Integer) _form.get("quotaSize")).intValue());
        userObj.setRegisterDate(new Date());
        userObj.setRoles((Integer[]) _form.get("roles"));
        userObj.setSignature((String) _form.get("signature"));

        Boolean spamTolerance = new Boolean(false);

        if (_form.get("spamTolerance") != null) {
            spamTolerance = (Boolean) _form.get("spamTolerance");
        }

        userObj.setSpamTolerance(spamTolerance.booleanValue());

        userObj.setVacationBody((String) _form.get("vacationBody"));
        userObj.setVacationSubject((String) _form.get("vacationSubject"));

        Boolean vacationActive = new Boolean(false);

        if (_form.get("vacationActive") != null) {
            vacationActive = (Boolean) _form.get("vacationActive");
        }

        userObj.setVactionActive(vacationActive.booleanValue());

        adminInstance.updateUser(userObj);
    } catch (Exception ex) {
        if (ex instanceof ChatException) {
            if (ex.getCause() instanceof NotOnlineException) {
                request.setAttribute("result", "not_online");
            } else if (ex.getCause() instanceof NotLoggedInException) {
                request.setAttribute("result", "not_logged_in");
            } else if (ex.getCause() instanceof NotAcceptChatException) {
                request.setAttribute("result", "not_accept_chat");
            } else {
                request.setAttribute("result", ex.getMessage());
            }
        } else {
            String errorMessage = ExceptionUtilities.parseMessage(ex);

            if (errorMessage == null) {
                errorMessage = "NullPointerException";
            }

            request.setAttribute("result", errorMessage);

            errors.add("general",
                    new ActionMessage(ExceptionCode.ERROR_MESSAGES_PREFIX + "general", errorMessage));
            request.setAttribute("exception", errorMessage);
            doTrace(request, DLog.ERROR, getClass(), errorMessage);
        }
    } finally {
    }

    if (errors.isEmpty()) {
        doTrace(request, DLog.INFO, getClass(), "OK");

        return mapping.findForward(Constants.ACTION_SUCCESS_FORWARD);
    } else {
        saveErrors(request, errors);

        return mapping.findForward(Constants.ACTION_FAIL_FORWARD);
    }
}

From source file:ddf.content.plugin.video.TestVideoThumbnailPlugin.java

@Test
public void testCorruptedVideo() {
    try {// w  w  w  .  j  a  v a 2s.  c  om
        getCreatedItemThumbnail("corrupted.mp4");
        fail("The video thumbnail plugin should have thrown an exception.");
    } catch (Exception e) {
        assertThat(e, instanceOf(PluginExecutionException.class));
        assertThat(e.getCause(), instanceOf(ExecuteException.class));
    }
}

From source file:com.hazelcast.qasonar.codecoverage.CodeCoverageAnalyzer.java

private void checkFileWithoutCoverage(FileContainer fileContainer, String gitFileName) {
    if (fileContainer.coverage != null || fileContainer.ideaCoverage > COVERAGE_MARGIN) {
        return;/*w w  w. j a va 2  s . co m*/
    }

    String fileContents;
    try {
        if (localGitRoot == null) {
            fileContents = getFileContentsFromGitHub(repo, gitFileName);
        } else {
            fileContents = readFromFile(localGitRoot + gitFileName);
        }
    } catch (FileNotFoundException ignored) {
        fileContainer.pass("deleted in newer PR");
        return;
    } catch (Exception e) {
        fileContainer.fail("Could not get contents for file " + gitFileName + ": " + e.getCause());
        debugRed("Failed with file content not retrievable %s: %s", gitFileName, e.getCause());
        return;
    }

    String baseName = getBaseName(gitFileName);
    if (fileContents.contains("@interface " + baseName)) {
        fileContainer.pass("Annotation");
        return;
    }
    if (fileContents.contains("interface " + baseName)) {
        fileContainer.pass("Interface");
        return;
    }
    if (fileContents.contains("enum " + baseName)) {
        fileContainer.pass("Enum");
        return;
    }

    fileContainer.fail("code coverage not found");
    debugRed("Failed with code coverage not found %s", gitFileName);
}