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.thoughtworks.go.server.database.DbDeployMigration.java

private void upgradeWithDbDeploy() {
    LOG.info("Upgrading database at {}. This might take a while depending on the size of the database.",
            dataSource);//  ww w  .  ja v a2s .  c o m

    List<String> messages = Arrays.asList(StringUtils.repeat("*", "", 72),
            "WARNING: Shutting down your server at this point will lead to a database corruption. Please wait until the database upgrade completes.",
            StringUtils.repeat("*", "", 72));
    for (String message : messages) {
        System.err.println(message);
        LOG.info(message);
    }

    File upgradePath = env.getDBDeltasPath();
    bombUnless(upgradePath.exists(),
            "Database upgrade scripts do not exist in directory " + upgradePath.getAbsolutePath());
    InMemory dbDeploy = new InMemory(dataSource, new HsqlDbmsSyntax(), upgradePath, "DDL");
    try {
        String migrationSql = dbDeploy.migrationSql();
        new JdbcTemplate(dataSource).execute(migrationSql);

        System.err.println("Database upgrade completed successfully.");
        LOG.info("Database upgrade completed.");

    } catch (Exception e) {
        String message = "Unable to create database upgrade script for database " + dataSource.getUrl()
                + ". The problem was: " + e.getMessage();
        if (e.getCause() != null) {
            message += ". The cause was: " + e.getCause().getMessage();
        }
        LOG.error(message, e);
        System.err.println(message);
        e.printStackTrace(System.err);
        throw bomb(message, e);
    }
}

From source file:org.openiot.gsn.http.ac.GSNClient.java

public String sendQuery(String scheme, String path, String query, String fragment) {
    String message = "";
    try {/*from ww  w  . j av a2  s .  c  o m*/
        int queryport = 0;
        if (scheme.equals("http")) {
            queryport = this.gsnhttpport;
        } else if (scheme.equals("https")) {
            queryport = this.gsnhttpsport;
        }
        URI uri = URIUtils.createURI(scheme, this.host, queryport, path, query, fragment);
        //HttpGet httpget = new HttpGet("http://localhost:22001/gsn?REQUEST=116&name=remotepushtest");
        HttpGet httpget = new HttpGet(uri);

        logger.info("executing request" + httpget.getRequestLine());

        HttpResponse response = httpclient.execute(httpget);
        HttpEntity firstentity = response.getEntity();

        logger.info("----------------------------------------");
        logger.info(response.getStatusLine());
        if (firstentity != null) {
            logger.info("Response content length: " + firstentity.getContentLength());
            message = EntityUtils.toString(firstentity);
        }
        if (firstentity != null) {
            firstentity.consumeContent();
        }

    } catch (Exception e) {
        message = "Exception in sendQuery : " + e.getMessage() + " The cause : " + e.getCause();

    }
    return message;
}

From source file:com.qcloud.component.snaker.access.mybatis.MybatisAccess.java

/**
 * JDBC?BLOB/* ww  w  .  j  a v  a 2 s .c om*/
 */
public void saveProcess(Process process) {

    super.saveProcess(process);
    SqlSession sqlSession = getSession();
    if (process.getBytes() != null) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        try {
            conn = sqlSession.getConnection();
            pstmt = conn.prepareStatement(PROCESS_UPDATE_BLOB);
            pstmt.setBytes(1, process.getBytes());
            pstmt.setString(2, process.getId());
            pstmt.execute();
        } catch (Exception e) {
            throw new SnakerException(e.getMessage(), e.getCause());
        } finally {
            try {
                JdbcHelper.close(pstmt);
                SqlSessionUtils.closeSqlSession(sqlSession, getSqlSessionFactory());
            } catch (SQLException e) {
                throw new SnakerException(e.getMessage(), e.getCause());
            }
        }
    }
}

From source file:com.qcloud.component.snaker.access.mybatis.MybatisAccess.java

/**
 * JDBC?BLOB/* ww  w  .  j av  a2  s.c o  m*/
 */
public void updateProcess(Process process) {

    super.updateProcess(process);
    SqlSession sqlSession = getSession();
    if (process.getBytes() != null) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        try {
            conn = sqlSession.getConnection();
            pstmt = conn.prepareStatement(PROCESS_UPDATE_BLOB);
            pstmt.setBytes(1, process.getBytes());
            pstmt.setString(2, process.getId());
            pstmt.execute();
        } catch (Exception e) {
            throw new SnakerException(e.getMessage(), e.getCause());
        } finally {
            try {
                JdbcHelper.close(pstmt);
                SqlSessionUtils.closeSqlSession(sqlSession, getSqlSessionFactory());
            } catch (SQLException e) {
                throw new SnakerException(e.getMessage(), e.getCause());
            }
        }
    }
}

From source file:com.castlemock.web.basis.web.mvc.controller.LoginController.java

/**
 * The method is used to extract the error message from the request
 * @param request The request that contains the exception and error message
 * @param key The key is used to find the exception attribute in the request.
 * @return Returns the error message that will be displayed to the user on the login page.
 *//*  w  w w  .  j av  a2  s .c o m*/
private String getErrorMessage(final HttpServletRequest request, final String key) {

    final Exception exception = (Exception) request.getSession().getAttribute(key);

    String error = "";
    if (exception instanceof BadCredentialsException || exception.getCause() instanceof NullPointerException
            || exception.getCause() instanceof IllegalArgumentException) {
        LOGGER.debug("Invalid username or password");
        error = messageSource.getMessage("general.login.label.invalidcredentials", null,
                LocaleContextHolder.getLocale());
    } else if (exception instanceof LockedException) {
        LOGGER.debug("User has been locked");
        error = messageSource.getMessage("general.login.label.userlocked", null,
                LocaleContextHolder.getLocale());
    } else if (exception instanceof CredentialsExpiredException) {
        LOGGER.debug("User has been inactive");
        error = messageSource.getMessage("general.login.label.userinactive", null,
                LocaleContextHolder.getLocale());
    } else {
        LOGGER.error("Unable to login due to unknown reasons");
        LOGGER.error(exception.getMessage(), exception);
        error = messageSource.getMessage("general.login.label.unknownreason", null,
                LocaleContextHolder.getLocale());
    }

    return error;
}

From source file:com.leo.cattle.data.net.RestApiImpl.java

@Override
public Observable<UserEntity> askForSignup(String userName, String userEmail, String userPassword) {
    return Observable.create(subscriber -> {
        if (isThereInternetConnection()) {
            try {
                String responseUserDetails = sigUp(userName, userEmail, userPassword);
                if (responseUserDetails != null) {
                    subscriber.onNext(userEntityJsonMapper.transformUserEntity(responseUserDetails));
                    subscriber.onCompleted();
                } else {
                    subscriber.onError(new NetworkConnectionException());
                }/* w  ww.ja v a2 s. c  o m*/
            } catch (Exception e) {
                subscriber.onError(new NetworkConnectionException(e.getCause()));
            }
        } else {
            subscriber.onError(new NetworkConnectionException());
        }
    });
}

From source file:com.leo.cattle.data.net.RestApiImpl.java

@Override
public Observable<UserEntity> askForSignIn(String userEmail, String userPassword) {
    return Observable.create(subscriber -> {
        if (isThereInternetConnection()) {
            try {
                String responseUserDetails = sigIn(userEmail, userPassword);
                if (responseUserDetails != null) {
                    subscriber.onNext(userEntityJsonMapper.transformUserEntity(responseUserDetails));
                    subscriber.onCompleted();
                } else {
                    subscriber.onError(new NetworkConnectionException());
                }/*  w  ww . j a v  a  2  s.c o m*/
            } catch (Exception e) {
                subscriber.onError(new NetworkConnectionException(e.getCause()));
            }
        } else {
            subscriber.onError(new NetworkConnectionException());
        }
    });
}

From source file:podd.dataaccess.hibernate.DeadlockInterceptorUnitTest.java

private void checkOneMethod(Method mtd) throws Exception {
    StringWriter writer = new StringWriter();

    // FIXME: Should not be doing this in code
    Appender appender = new WriterAppender(new SimpleLayout(), writer);
    LOGGER.addAppender(appender);//from  w  w w  .ja  v a 2  s. com

    try {
        if (mtd.isAnnotationPresent(Idempotent.class)) {
            Object[] params = new Object[] { null };
            try {
                mtd.invoke(dao, params);
            } catch (Exception e) {
                if (!interceptor.getExceptionClass().isInstance(e.getCause())) {
                    throw e;
                }
            }
            checkInterceptorLog(writer, null);
        }
    } finally {
        LOGGER.removeAppender(appender);
    }
}

From source file:com.leo.cattle.data.net.RestApiImpl.java

@RxLogObservable
@Override//from   ww w .  ja va 2  s  .  co m
public Observable<List<UserEntity>> userEntityList(String token) {
    return Observable.create(subscriber -> {
        if (isThereInternetConnection()) {
            try {
                String responseUserEntities = getUserEntitiesFromApi(token);
                if (responseUserEntities != null) {
                    subscriber.onNext(userEntityJsonMapper.transformUserEntityCollection(responseUserEntities));
                    subscriber.onCompleted();
                } else {
                    subscriber.onError(new NetworkConnectionException());
                }
            } catch (Exception e) {
                subscriber.onError(new NetworkConnectionException(e.getCause()));
            }
        } else {
            subscriber.onError(new NetworkConnectionException());
        }
    });
}

From source file:com.leo.cattle.data.net.RestApiImpl.java

@RxLogObservable
@Override/*from   ww w  .j ava 2s.c  o  m*/
public Observable<UserEntity> userEntityById(final int userId) {
    return Observable.create(subscriber -> {
        if (isThereInternetConnection()) {
            try {
                String responseUserDetails = getUserDetailsFromApi(userId);
                if (responseUserDetails != null) {
                    subscriber.onNext(userEntityJsonMapper.transformUserEntity(responseUserDetails));
                    subscriber.onCompleted();
                } else {
                    subscriber.onError(new NetworkConnectionException());
                }
            } catch (Exception e) {
                subscriber.onError(new NetworkConnectionException(e.getCause()));
            }
        } else {
            subscriber.onError(new NetworkConnectionException());
        }
    });
}