Java Code Examples for org.apache.commons.lang.exception.ExceptionUtils#indexOfThrowable()
The following examples show how to use
org.apache.commons.lang.exception.ExceptionUtils#indexOfThrowable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HiveClient.java From garmadon with Apache License 2.0 | 6 votes |
protected void execute(String query) throws SQLException { LOGGER.debug("Execute hql: {}", query); int maxAttempts = 5; for (int retry = 1; retry <= maxAttempts; ++retry) { try { stmt.execute(query); } catch (SQLException sqlException) { if (ExceptionUtils.indexOfThrowable(sqlException, TTransportException.class) != -1) { String exMsg = String.format("Retry connecting to hive (%d/%d)", retry, maxAttempts); if (retry <= maxAttempts) { LOGGER.warn(exMsg, sqlException); try { Thread.sleep(1000 * retry); connect(); } catch (Exception ignored) { } } else { LOGGER.error(exMsg, sqlException); throw sqlException; } } else { throw sqlException; } } } }
Example 2
Source File: BasicAuthenticationEntryPoint.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void commence( HttpServletRequest request, HttpServletResponse response, AuthenticationException authException ) throws IOException { String message; if ( ExceptionUtils.indexOfThrowable( authException, LockedException.class ) != -1 ) { message = "Account locked" ; } else { message = "Unauthorized"; } response.setStatus( HttpServletResponse.SC_UNAUTHORIZED ); response.setContentType( MediaType.APPLICATION_JSON_VALUE ); renderService.toJson( response.getOutputStream(), WebMessageUtils.unathorized( message ) ); }
Example 3
Source File: CustomExceptionMappingAuthenticationFailureHandler.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void onAuthenticationFailure( HttpServletRequest request, HttpServletResponse response, AuthenticationException exception ) throws IOException, ServletException { final String username = request.getParameter( "j_username" ); request.getSession().setAttribute( "username", username ); I18n i18n = i18nManager.getI18n(); if ( ExceptionUtils.indexOfThrowable( exception, LockedException.class ) != -1) { request.getSession().setAttribute( "LOGIN_FAILED_MESSAGE", i18n.getString( "authentication.message.account.locked" ) ); } else { request.getSession().setAttribute( "LOGIN_FAILED_MESSAGE", i18n.getString( "authentication.message.account.invalid" ) ); } super.onAuthenticationFailure( request, response, exception ); }
Example 4
Source File: ExpectedConstraintViolation.java From testfun with Apache License 2.0 | 4 votes |
public boolean matches(Object argument) { return ExceptionUtils.indexOfThrowable((Throwable) argument, throwableClass) >= 0; }