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:com.alibaba.ims.web.valve.ExceptionValve.java

@Override
public void invoke(PipelineContext pipelineContext) throws Exception {
    try {/*from ww  w  .  ja v  a2s  . co  m*/
        pipelineContext.invokeNext();
    } catch (Exception e) {
        response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        logger.error(e.getMessage(), e);
        try {
            Throwable cause = e.getCause().getCause().getCause();
            if (cause instanceof WebException) {
                response.getWriter().write(((WebException) cause).getMessage());
            } else {
                response.getWriter().write(ExceptionCode.Common.INNER_ERROR);
            }
        } catch (NullPointerException ne) {
            response.getWriter().write(ExceptionCode.Common.INNER_ERROR);
        }
    }
}

From source file:de.uzk.hki.da.cb.RegisterURNAction.java

/**
 * @author Thomas Kleinke//from   w ww.jav a2  s .  c  o m
 * @return URN if the mets file contains an URN; otherwise null
 */
private String extractURNFromMetsFile() {

    DAFile metsFile = null;

    List<DAFile> files = object.getLatestPackage().getFiles();
    for (DAFile file : files) {
        if (!file.getRelative_path().contains("XMP.rdf")) {
            if (file.getFormatPUID().equals(FFConstants.METS_PUID))
                metsFile = file;
        }

    }

    if (metsFile != null) {
        String urn = null;
        RightsSectionURNMetsXmlReader metsUrnReader = new RightsSectionURNMetsXmlReader();
        try {
            urn = metsUrnReader.readURN(metsFile.toRegularFile());
        } catch (Exception e) {
            Exception causeEx = (Exception) e.getCause();
            while (causeEx.getCause() != null) {
                causeEx = (Exception) causeEx.getCause();
            }
            ;
            throw new UserException(UserExceptionId.READ_METS_ERROR,
                    "Failed to read URN from mets file " + metsFile.toRegularFile().getAbsolutePath(),
                    causeEx.getMessage(), e);
        }

        return urn;
    }

    return null;
}

From source file:com.strandls.alchemy.rest.client.RestInterfaceAnalyzer.java

/**
 * Analyze the class and build the meta information.
 *
 * @param klass//from w  w  w.  j  a v a 2s .  co  m
 *            the class.
 * @return analyzed metadata.
 */
public RestInterfaceMetadata analyze(final Class<?> klass) throws NotRestInterfaceException {
    try {
        return metadataCache.getUnchecked(klass);
    } catch (final Exception e) {
        final Throwable cause = e.getCause();
        if (cause != null && cause instanceof NotRestInterfaceException) {
            throw (NotRestInterfaceException) cause;
        }
        throw e;
    }
}

From source file:info.novatec.testit.livingdoc.runner.CommandLineRunnerTest.java

@Test
public void testThatDebugModeAllowToSeeWholeStackTrace() throws Exception {

    String input = getResourcePath("/specs/ABankSample.html");
    File outputFile = outputFile("report.html");

    CommandLineRunner commandLineRunner = new CommandLineRunner();
    commandLineRunner.run("--debug", input, outputFile.getAbsolutePath());

    try {/*from   w  ww.  j  a v a 2  s. c o  m*/
        throw new Exception(new Throwable(""));
    } catch (Exception e) {
        assertTrue(countLines(ExceptionUtils.stackTrace(e.getCause(), "\n", 2)) > 3);
    }

}

From source file:net.bafeimao.umbrella.web.test.controller.UserControllerTests.java

@Test
public void testSubmitRegisterWithDuplicateNameException() throws Exception {
    try {//w ww . j  a  va2 s  . com
        mockMvc.perform(post("/register").param("name", "ktgu").param("email", "xxx@qq.com"));
    } catch (Exception e) {
        Assert.assertTrue(e.getCause() instanceof DuplicateNameException);
    }
}

From source file:net.bafeimao.umbrella.web.test.controller.UserControllerTests.java

@Test
public void testSubmitRegisterWithDuplicateEmailException() throws Exception {
    try {//from   ww  w . j a  va2 s . c o  m
        mockMvc.perform(post("/register").param("name", "xxx").param("email", "29283212@qq.com"));
    } catch (Exception e) {
        Assert.assertTrue(e.getCause() instanceof DuplicateEmailException);
    }
}

From source file:com.amazonaws.services.s3.transfer.internal.MultipartUploadCallable.java

private void collectPartETags(final List<Future<PartETag>> futures, final List<PartETag> partETags) {
    for (Future<PartETag> future : futures) {
        try {/* w  ww.j a v  a  2  s .  c  om*/
            partETags.add(future.get());
        } catch (Exception e) {
            throw new AmazonClientException("Unable to upload part: " + e.getCause().getMessage(),
                    e.getCause());
        }
    }
}

From source file:com.heren.turtle.server.service.impl.LisWebService.java

@Override
public String lisCharge(String message) {
    this.logger.info("lisCharge receive mnis request message:\n" + message);
    try {//  w w w  .j  a  v a 2  s  . com
        if (XmlUtils.isXml(message)) {
            Map<String, Object> params = XmlUtils.getMessage(message);
            Map<String, Object> queryMap;
            queryMap = BooleanUtils.putMapBooleanList(params, "test_no", "patient_id", "visit_id", "baby_no",
                    "operator_no", "item_flag", "item_no", "item_code");
            Map<String, Object> resultMap = lisAgent.lisCharge(queryMap);
            String resultMessage = XmlUtils.createResultMessage(resultMap);
            this.logger.info("successful operation");
            this.logger.info("lisCharge result:" + resultMessage);
            return resultMessage;
        } else {
            this.logger.info(MessageConstant.formatFailed);
            return XmlUtils.errorMessage(MessageConstant.formatFailed);
        }
    } catch (Exception e) {
        this.logger.error("exception:" + e.getCause());
        return XmlUtils.errorMessage(e.getMessage());
    }
}

From source file:com.heren.turtle.server.service.impl.LisWebService.java

@Override
public String microbeCharge(String message) {
    this.logger.info("microbeCharge receive mnis request message:\n" + message);
    try {//from  w ww . ja v  a2s. co  m
        if (XmlUtils.isXml(message)) {
            Map<String, Object> params = XmlUtils.getMessage(message);
            Map<String, Object> queryMap;
            queryMap = BooleanUtils.putMapBooleanList(params, "test_no", "patient_id", "visit_id", "baby_no",
                    "operator_no", "item_flag", "item_no", "item_code", "charge_code");
            Map<String, Object> resultMap = lisAgent.microbeCharge(queryMap);
            String resultMessage = XmlUtils.createResultMessage(resultMap);
            this.logger.info("successful operation");
            this.logger.info("microbeCharge result:" + resultMessage);
            return resultMessage;
        } else {
            this.logger.info(MessageConstant.formatFailed);
            return XmlUtils.errorMessage(MessageConstant.formatFailed);
        }
    } catch (Exception e) {
        this.logger.error("exception:" + e.getCause());
        return XmlUtils.errorMessage(e.getMessage());
    }
}

From source file:com.heren.turtle.server.service.impl.LisWebService.java

@Override
public String lisStatusChange(String message) {
    this.logger.info("lisStatusChange receive mnis request message:\n" + message);
    try {//from   ww w  .ja  v a  2s .c o m
        if (XmlUtils.isXml(message)) {
            Map<String, Object> params = XmlUtils.getMessage(message);
            Map<String, Object> queryMap;
            queryMap = BooleanUtils.putMapBooleanList(params, "test_no", "result_status", "reporter",
                    "verified_by");
            Map<String, Object> resultMap = lisAgent.lisStatusChange(queryMap);
            String resultMessage = XmlUtils.createResultMessage(resultMap);
            this.logger.info("successful operation");
            this.logger.info("lisStatusChange result:" + resultMessage);
            return resultMessage;
        } else {
            this.logger.info(MessageConstant.formatFailed);
            return XmlUtils.errorMessage(MessageConstant.formatFailed);
        }
    } catch (Exception e) {
        this.logger.error("exception:" + e.getCause());
        return XmlUtils.errorMessage(e.getMessage());
    }
}