当前位置: 首页>>代码示例>>Java>>正文


Java ExceptionStackUtil.getCause方法代码示例

本文整理汇总了Java中org.alfresco.error.ExceptionStackUtil.getCause方法的典型用法代码示例。如果您正苦于以下问题:Java ExceptionStackUtil.getCause方法的具体用法?Java ExceptionStackUtil.getCause怎么用?Java ExceptionStackUtil.getCause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.alfresco.error.ExceptionStackUtil的用法示例。


在下文中一共展示了ExceptionStackUtil.getCause方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import org.alfresco.error.ExceptionStackUtil; //导入方法依赖的package包/类
public void run()
{
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    
    final RetryingTransactionHelper txnHelperForTest = transactionService.getRetryingTransactionHelper();
    
    RetryingTransactionCallback<Long> callback = new RetryingTransactionCallback<Long>()
    {
        public Long execute() throws Throwable
        {
            incrementCheckValue();
            
            System.out.println("Wait started: "+Thread.currentThread()+" ("+wait+")");
            Thread.sleep(wait);
            System.out.println("Wait finished: "+Thread.currentThread()+" ("+wait+")");
            
            return getCheckValue();
        }
    };
    try
    {
        System.out.println("Txn start: "+Thread.currentThread()+" ("+wait+")");
        txnHelperForTest.doInTransaction(callback);
        System.out.println("Txn finish: "+Thread.currentThread()+" ("+wait+")");
    }
    catch (Throwable e)
    {
        Throwable validCause = ExceptionStackUtil.getCause(e, RetryingTransactionHelper.RETRY_EXCEPTIONS);
        assertNotNull("Unexpected cause of the failure", validCause);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:32,代码来源:RetryingTransactionHelperTest.java

示例2: testExecute_ResultHandlerWithError

import org.alfresco.error.ExceptionStackUtil; //导入方法依赖的package包/类
@Test public void testExecute_ResultHandlerWithError() throws Throwable
{
    final ResultHandler<String> resultHandler = new ResultHandler<String>()
    {
        @Override
        public boolean handleResult(String result)
        {
            throw new UnsupportedOperationException();
        }
    };
    
    RetryingTransactionCallback<List<String>> selectCallback = new RetryingTransactionCallback<List<String>>()
    {
        @Override
        public List<String> execute() throws Throwable
        {
            TestOneParams params = new TestOneParams(null, false);
            try
            {
            	cannedQueryDAOForTesting.executeQuery(QUERY_NS, QUERY_SELECT_MIMETYPES, params, 0, 2, resultHandler);
                fail("Expected UnsupportedOperationException");
            }
            catch (Exception e)
            {
                // Expected, but make sure that our exception is the cause
                Throwable ee = ExceptionStackUtil.getCause(e, UnsupportedOperationException.class);
                if (ee == null)
                {
                    throw e;
                }
            }
            // Now query again with success
            return cannedQueryDAOForTesting.executeQuery(QUERY_NS, QUERY_SELECT_MIMETYPES, params, 0, 2);
        }
    };
    List<String> mimetypes = txnHelper.doInTransaction(selectCallback, true);
    assertNotNull(mimetypes);
    assertTrue("Too many results", mimetypes.size() <= 2);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:40,代码来源:CannedQueryDAOTest.java

示例3: executeScript

import org.alfresco.error.ExceptionStackUtil; //导入方法依赖的package包/类
public void executeScript(WebScriptRequest scriptReq, WebScriptResponse scriptRes, final Authenticator auth)
    throws IOException
{
    try
    {
        executeScriptInternal(scriptReq, scriptRes, auth);
    }
    catch (RuntimeException e)
    {
        Throwable hideCause = ExceptionStackUtil.getCause(e, notPublicExceptions);
        Throwable displayCause = ExceptionStackUtil.getCause(e, publicExceptions);
        if (displayCause == null && hideCause != null)
        {
            AlfrescoRuntimeException alf = null;
            if (e instanceof AlfrescoRuntimeException)
            {
                alf = (AlfrescoRuntimeException) e;
            }
            else
            {
                // The message will not have a numerical identifier
                alf = new AlfrescoRuntimeException("WebScript execution failed", e);
            }
            String num = alf.getNumericalId();
            logger.error("Server error (" + num + ")", e);
            throw new RuntimeException("Server error (" + num + ").  Details can be found in the server logs.");
        }
        else
        {
            throw e;
        }
    }
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:34,代码来源:RepositoryContainer.java

示例4: extractRetryCause

import org.alfresco.error.ExceptionStackUtil; //导入方法依赖的package包/类
/**
 * Sometimes, the exception means retry and sometimes not.  The stack of exceptions is also checked
 * for any occurence of {@link DoNotRetryException} and, if found, nothing is returned.
 *
 * @param cause     the cause to examine
 * @return          Returns the original cause if it is a valid retry cause, otherwise <tt>null</tt>
 */
public static Throwable extractRetryCause(Throwable cause)
{
    Throwable retryCause = ExceptionStackUtil.getCause(cause, RETRY_EXCEPTIONS);
    
    if (retryCause == null)
    {
        return null;
    }
    else if (ExceptionStackUtil.getCause(cause, DoNotRetryException.class) != null)
    {
        // Someone decided that the txn should NOT retry
        return null;
    }
    else if (retryCause instanceof SQLGrammarException
            && ((SQLGrammarException) retryCause).getErrorCode() != 3960)
    {
       return null;
    }
    else if (retryCause instanceof UncategorizedSQLException)
    {
        // The exception will have been caused by something else, so check that instead
        if (retryCause.getCause() != null && retryCause.getCause() != retryCause)
        {
            // We dig further into this
            cause = retryCause.getCause();
            // Check for SQL-related "deadlock" messages
            if (retryCause.getMessage().toLowerCase().contains("deadlock"))
            {
                // The word "deadlock" is usually an indication that we need to resolve with a retry.
                return retryCause;
            }
            else if (retryCause.getMessage().toLowerCase().contains("constraint"))
            {
                // The word "constraint" is also usually an indication or a concurrent update
                return retryCause;
            }
            // Recurse
            return extractRetryCause(cause);
        }
        else
        {
            return null;
        }
    }
    // A simple match
    return retryCause;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:55,代码来源:RetryingTransactionHelper.java

示例5: invoke

import org.alfresco.error.ExceptionStackUtil; //导入方法依赖的package包/类
public Object invoke(MethodInvocation mi) throws Throwable
{
    try
    {
        return mi.proceed();
    }
    catch (Exception e)
    {
        // We dig into the exception to see if there is anything of interest to CMIS
        Throwable cmisAffecting = ExceptionStackUtil.getCause(e, EXCEPTIONS_OF_INTEREST);
        
        if (cmisAffecting == null)
        {
            // The exception is not something that CMIS needs to handle in any special way
            if (e instanceof CmisBaseException)
            {
                throw (CmisBaseException) e;
            }
            else
            {
                throw new CmisRuntimeException(e.getMessage(), e);
            }
        }
        // All other exceptions are carried through with full stacks but treated as the exception of interest
        else if (cmisAffecting instanceof AuthenticationException)
        {
            throw new CmisPermissionDeniedException(cmisAffecting.getMessage(), e);
        }
        else if (cmisAffecting instanceof CheckOutCheckInServiceException)
        {
            throw new CmisVersioningException("Check out failed: " + cmisAffecting.getMessage(), e);
        }
        else if (cmisAffecting instanceof FileExistsException)
        {
            throw new CmisContentAlreadyExistsException("An object with this name already exists: " + cmisAffecting.getMessage(), e);
        }
        else if (cmisAffecting instanceof IntegrityException)
        {
            throw new CmisConstraintException("Constraint violation: " + cmisAffecting.getMessage(), e);
        }
        else if (cmisAffecting instanceof AccessDeniedException)
        {
            throw new CmisPermissionDeniedException("Permission denied: " + cmisAffecting.getMessage(), e);
        }
        else if (cmisAffecting instanceof NodeLockedException)
        {
            throw new CmisUpdateConflictException("Update conflict: " + cmisAffecting.getMessage(), e);
        }
        else
        {
            // We should not get here, so log an error but rethrow to have CMIS handle the original cause
            logger.error("Exception type not handled correctly: " + e.getClass().getName());
            throw new CmisRuntimeException(e.getMessage(), e);
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:57,代码来源:AlfrescoCmisExceptionInterceptor.java

示例6: testNestedWithoutPropagationConcurrentUntilFailureMySQL

import org.alfresco.error.ExceptionStackUtil; //导入方法依赖的package包/类
/**
 * Checks nesting of two transactions with <code>requiresNew == true</code>,
 * but where the two transactions get involved in a concurrency struggle.
 * <p/>
 * Note: skip test for non-MySQL
 */
public void testNestedWithoutPropagationConcurrentUntilFailureMySQL() throws InterruptedException
{
    final RetryingTransactionHelper txnHelperForTest = transactionService.getRetryingTransactionHelper();
    txnHelperForTest.setMaxRetries(1);
    
    if (! (dialect instanceof MySQLInnoDBDialect))
    {
        // NOOP - skip test for non-MySQL DB dialects to avoid hang if concurrently "nested" (in terms of Spring)
        // since the initial transaction does not complete
        // see testConcurrencyRetryingNoFailure instead
        logger.warn("NOTE: Skipping testNestedWithoutPropogationConcurrentUntilFailureMySQLOnly for dialect: "+dialect);
    }
    else
    {
        RetryingTransactionCallback<Long> callback = new RetryingTransactionCallback<Long>()
        {
            public Long execute() throws Throwable
            {
                RetryingTransactionCallback<Long> callbackInner = new RetryingTransactionCallback<Long>()
                {
                    public Long execute() throws Throwable
                    {
                        incrementCheckValue();
                        return getCheckValue();
                    }
                };
                incrementCheckValue();
                txnHelperForTest.doInTransaction(callbackInner, false, true);
                return getCheckValue();
            }
        };
        try
        {
            txnHelperForTest.doInTransaction(callback);
            fail("Concurrent nested access not leading to failure");
        }
        catch (Throwable e)
        {
            Throwable validCause = ExceptionStackUtil.getCause(e, RetryingTransactionHelper.RETRY_EXCEPTIONS);
            assertNotNull("Unexpected cause of the failure", validCause);
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:50,代码来源:RetryingTransactionHelperTest.java


注:本文中的org.alfresco.error.ExceptionStackUtil.getCause方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。