Example usage for java.lang Throwable getCause

List of usage examples for java.lang Throwable getCause

Introduction

In this page you can find the example usage for java.lang Throwable 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.taobao.diamond.server.service.DefaultPersistService.java

public void initDataSource(DataSource dataSource) {
    System.out.println("#initDataSource");
    if (dataSource == null) {
        System.out.println("dataSource is null.");
    }/*from  w w  w. j  av  a2  s .c o  m*/
    String mode = System.getProperty("diamond.server.mode");
    System.out.println("-Ddiamond.server.mode:" + mode);
    String[] attrNames = new String[] { "offline", "flying", "lostDB", "xx" };
    for (String key : attrNames) {
        if (key.equals(mode)) {
            SystemConfig.setOffline();
        }
    }
    int timeout = 3;// seconds
    boolean dsValid = false;
    Connection conn = null;
    if (dataSource != null)
        try {
            BasicDataSource bds = (BasicDataSource) dataSource;
            bds.isPoolPreparedStatements();
            conn = dataSource.getConnection();

            Statement stmt = conn.createStatement();
            stmt.setQueryTimeout(timeout);
            dsValid = true;
            try {
                ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM config_info");
                if (rs.next()) {
                    rs.getInt(1);
                } else {
                    dsValid = false;
                }
                rs = stmt.executeQuery("select count(*) from group_info");
                if (rs.next()) {
                    rs.getInt(1);
                } else {
                    dsValid = false;
                }
            } catch (Exception e) {
                dsValid = false;
            }

        } catch (Throwable t) {
            log.error(t.getMessage(), t.getCause());
        }

    if (dsValid == false) {
        // 
        if (SystemConfig.isOnlineMode()) {
            System.out.println("#########################################################");
            System.out.println("DataSource .");
            System.out.println("error occured in DataSource initilizing,connection timeout or refuse conn.");
            System.out.println("#########################################################");
            SystemConfig.system_pause();
            System.exit(0);
        }
        // 
        if (SystemConfig.isOfflineMode()) {
            String msg = "#########################################################";
            System.out.println(msg);
            log.info(msg);
            OfflinePersistService ps = new OfflinePersistService();
            persistService = ps;

        }
    } else {
        DBPersistService ps = new DBPersistService();
        ps.setDataSource(dataSource);
        persistService = ps;
    }
    System.out.println("#########################################################");
    System.out.println("Current Persist Service");
    System.out.println("persistService:" + persistService);
    System.out.println("DBPersistService:" + (persistService instanceof DBPersistService));
    System.out.println("OfflinePersistService:" + (persistService instanceof OfflinePersistService));
    System.out.println("#########################################################");
}

From source file:de.berlios.gpon.wui.actions.data.ItemEditAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    ItemForm itemForm = (ItemForm) form;

    GponDataDao data = (GponDataDao) getObjectForBeanId("txGponDataDao");

    // this is a newly created hibernate session
    Item item = data.findItemById(itemForm.getItemId());

    // Create a mapped item and
    // inject all form values

    ItemMappedByName itmbn = new ItemMappedByName(item);

    Map map = itemForm.getMap();/*  w  w  w . ja v  a  2 s.  co  m*/

    Iterator it = map.keySet().iterator();

    while (it.hasNext()) {
        String propName = (String) it.next();

        ItemProperty ip = (ItemProperty) map.get(propName);

        String value = ip.getValue();

        if (value != null && value.trim().length() > 0) {
            try {
                itmbn.setValue(propName, value, ItemMappedByName.INPUT_FORM);
            } catch (Exception ex) {
                saveErrors(request, convertException(ex));
                return mapping.getInputForward();
            }
        } else {
            itmbn.removeValue(propName);
        }
    }

    List associationList = null;

    if (itemForm.getAssMap() != null && itemForm.getAssMap().keySet() != null) {
        associationList = getAssociationList(itmbn.getItem(), itemForm.getAssMap());
    }

    try {
        data.updateItem(itmbn.getItem(), associationList);
    } catch (GponDataDaoException ex) {
        if (ex.getValidationErrors() != null) {
            saveErrors(request, convertValidationErrors(ex.getValidationErrors()));
            return mapping.getInputForward();
        } else {
            // volley
            throw new Exception("Throwing forward.", ex);
        }
    } catch (Throwable t) {
        log.error("Throwable: " + t.getClass().getName() + " m: " + t.getMessage());

        while (t.getCause() != null) {
            t = t.getCause();
            log.error("Throwable: " + t.getClass().getName() + " m: " + t.getMessage());
        }
    }

    return mapping.findForward("success");

}

From source file:io.fabric8.maven.enricher.fabric8.AbstractLiveEnricher.java

/**
 * Creates an Iterable to walk the exception from the bottom up
 * (the last caused by going upwards to the root exception).
 *
 * @param exception the exception//from  w  w  w  .  ja v  a 2s.c  om
 * @return the Iterable
 * @see java.lang.Iterable
 */
protected Stack<Throwable> unfoldExceptions(Throwable exception) {
    Stack<Throwable> throwables = new Stack<>();

    Throwable current = exception;
    // spool to the bottom of the caused by tree
    while (current != null) {
        throwables.push(current);
        current = current.getCause();
    }
    return throwables;
}

From source file:io.wcm.caravan.io.http.impl.ribbon.RibbonHttpClientTest.java

@Test(expected = ClientException.class)
public void test_retryOnOneServerThrowing500() throws ClientException {
    context.registerInjectActivateService(new CaravanHttpServiceConfig(),
            ImmutableMap.<String, Object>builder()
                    .put(CaravanHttpServiceConfig.SERVICE_ID_PROPERTY, SERVICE_NAME)
                    .put(CaravanHttpServiceConfig.RIBBON_HOSTS_PROPERTY, defectServer1Host)
                    .put(CaravanHttpServiceConfig.RIBBON_MAXAUTORETRIES_PROPERTY, 4)
                    .put(CaravanHttpServiceConfig.RIBBON_MAXAUTORETRIESNEXTSERVER_PROPERTY, 0).build());
    try {//from   w ww .  j  a  v a  2s.c om
        client.execute(new CaravanHttpRequestBuilder(SERVICE_NAME).append(HTTP_200_URI).build()).toBlocking()
                .single();
    } catch (Throwable ex) {
        defectServer1.verify(5, WireMock.getRequestedFor(WireMock.urlEqualTo(HTTP_200_URI)));
        throw (ClientException) ex.getCause();
    }
}

From source file:jp.co.opentone.bsol.linkbinder.view.exception.LinkBinderExceptionHandler.java

public void handleException(HttpServletRequest req, HttpServletResponse res, Throwable e) {
    if (e.getCause() != null && e.getCause() instanceof InvalidOperationRuntimeException) {
        log.warn("invalid operation occurred. request was failed.");
    }/*w w w  .  j  a v a 2s . co  m*/

    // ViewExpiredException??
    if (isViewExpiredException(e)) {
        if (isLogViewExpiredException()) {
            logRequest(req);
            logViewMap();
        } else {
            log.warn("no logging for ViewExpiredException");
        }
    }

    setMessage(e);
    req.getSession().setAttribute("jp.co.opentone.bsol.exception", e);
    try {
        res.sendRedirect(req.getContextPath() + errorPage);
    } catch (IOException ex) {
        log.error("redirect failed.", ex);
    }

}

From source file:com.migratebird.launch.ant.BaseAntTask.java

private String getAllMessages(Throwable throwable) {
    StringBuilder stringBuilder = new StringBuilder();

    Throwable t = throwable;
    while (t != null) {
        String message = t.getMessage();
        if (message != null) {
            stringBuilder.append(message);
            stringBuilder.append("\n");
        }// www . ja  v a  2 s  . c om
        t = t.getCause();
    }
    return stringBuilder.toString();
}

From source file:cz.lbenda.coursing.client.GlobalExceptionHandler.java

@Override
public void publish(LogRecord record) {
    boolean noCredential = false;
    Throwable tw = record.getThrown();
    while (tw != null) {
        LOG.trace("tw", tw);
        if (tw instanceof AuthenticationCredentialsNotFoundException) {
            noCredential = true;//from  w  ww . j  ava  2  s  .c  om
        }
        tw = tw.getCause();
    }
    if (noCredential) {
        LOG.debug("noCredential");
        LoginForm.showLoginDialog();
        /*
        LoginDialog dialog = new LoginDialog(WindowManager.getDefault().getMainWindow(), true);
        dialog.setVisible(true);
                */
    } else if (record.getThrown() != null) {
        newFunctionActionListener.setLogRecord(record);
        // TODO show dialog
    }
}

From source file:com.greplin.gec.GecAppender.java

/**
 * Writes a formatted exception to the given writer.
 *
 * @param message   the log message// ww  w  .  j  a va2s  .c  o m
 * @param throwable the exception
 * @param out       the destination
 * @throws IOException if there are IO errors in the destination
 */
void writeFormattedException(final String message, final Throwable throwable, final Writer out)
        throws IOException {
    JsonGenerator generator = new JsonFactory().createJsonGenerator(out);

    Throwable rootThrowable = throwable;
    while (passthroughExceptions.contains(rootThrowable.getClass()) && rootThrowable.getCause() != null) {
        rootThrowable = rootThrowable.getCause();
    }

    generator.writeStartObject();
    generator.writeStringField("project", project);
    generator.writeStringField("environment", environment);
    generator.writeStringField("serverName", serverName);
    generator.writeStringField("backtrace", ExceptionUtils.getStackTrace(throwable));
    generator.writeStringField("message", rootThrowable.getMessage());
    generator.writeStringField("logMessage", message);
    generator.writeStringField("type", rootThrowable.getClass().getName());
    writeContext(generator);
    generator.writeEndObject();
    generator.close();
}

From source file:fi.helsinki.opintoni.aop.logging.LoggingAspect.java

@AfterThrowing(pointcut = "loggingPointcut()", throwing = "e")
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
    if (env.acceptsProfiles(Constants.SPRING_PROFILE_DEVELOPMENT)) {
        log.error("Exception in {}.{}() with cause = {}", joinPoint.getSignature().getDeclaringTypeName(),
                joinPoint.getSignature().getName(), e.getCause(), e);
    } else {/*  w  ww. j a va  2s  . c  o  m*/
        log.error("Exception in {}.{}() with cause = {}", joinPoint.getSignature().getDeclaringTypeName(),
                joinPoint.getSignature().getName(), e.getCause());
    }
}

From source file:it.geosolutions.opensdi2.userexpiring.ExpiringTest.java

/**
 * check GeoStore to see if the test can run
 * //from   ww  w  .j a v a2 s .  c  om
 * @param client
 * @return
 */
protected boolean pingGeoStore(GeoStoreClient client) {
    try {
        client.getCategories();
        return true;
    } catch (Exception ex) {
        LOGGER.error("Error connecting geostore", ex);
        // ... and now for an awful example of heuristic.....
        Throwable t = ex;
        while (t != null) {
            if (t instanceof ConnectException) {
                LOGGER.warn("Testing GeoStore is offline");
                return false;
            }
            t = t.getCause();
        }

    }
    return false;
}