Example usage for java.lang.reflect InvocationTargetException getTargetException

List of usage examples for java.lang.reflect InvocationTargetException getTargetException

Introduction

In this page you can find the example usage for java.lang.reflect InvocationTargetException getTargetException.

Prototype

public Throwable getTargetException() 

Source Link

Document

Get the thrown target exception.

Usage

From source file:fxts.stations.util.BrowserLauncher.java

/**
 * Attempts to locate the default web browser on the local system.  Caches results so it
 * only locates the browser once for each use of this class per JVM instance.
 *
 * @return The browser for the system.  Note that this may not be what you would consider
 *         to be a standard web browser; instead, it's the application that gets called to
 *         open the default web browser.  In some cases, this will be a non-String object
 *         that provides the means of calling the default browser.
 *//*from w  w  w.  ja  v a2 s  . com*/
private static Object locateBrowser() {
    if (browser != null) {
        return browser;
    }
    switch (jvm) {
    case MRJ_2_0:
        try {
            Integer finderCreatorCode = (Integer) makeOSType.invoke(null, new Object[] { FINDER_CREATOR });
            Object aeTarget = aeTargetConstructor.newInstance(new Object[] { finderCreatorCode });
            Integer gurlType = (Integer) makeOSType.invoke(null, new Object[] { GURL_EVENT });
            Object appleEvent = appleEventConstructor.newInstance(
                    new Object[] { gurlType, gurlType, aeTarget, kAutoGenerateReturnID, kAnyTransactionID });
            // Don't set browser = appleEvent because then the next time we call
            // locateBrowser(), we'll get the same AppleEvent, to which we'll already have
            // added the relevant parameter. Instead, regenerate the AppleEvent every time.
            // There's probably a way to do this better; if any has any ideas, please let
            // me know.
            return appleEvent;
        } catch (IllegalAccessException iae) {
            browser = null;
            errorMessage = iae.getMessage();
            return browser;
        } catch (InstantiationException ie) {
            browser = null;
            errorMessage = ie.getMessage();
            return browser;
        } catch (InvocationTargetException ite) {
            browser = null;
            errorMessage = ite.getMessage();
            return browser;
        }
    case MRJ_2_1:
        File systemFolder;
        try {
            systemFolder = (File) findFolder.invoke(null, new Object[] { kSystemFolderType });
        } catch (IllegalArgumentException iare) {
            browser = null;
            errorMessage = iare.getMessage();
            return browser;
        } catch (IllegalAccessException iae) {
            browser = null;
            errorMessage = iae.getMessage();
            return browser;
        } catch (InvocationTargetException ite) {
            browser = null;
            errorMessage = ite.getTargetException().getClass() + ": " + ite.getTargetException().getMessage();
            return browser;
        }
        String[] systemFolderFiles = systemFolder.list();
        // Avoid a FilenameFilter because that can't be stopped mid-list
        for (int i = 0; i < systemFolderFiles.length; i++) {
            try {
                File file = new File(systemFolder, systemFolderFiles[i]);
                if (!file.isFile()) {
                    continue;
                }
                // We're looking for a file with a creator code of 'MACS' and
                // a type of 'FNDR'.  Only requiring the type results in non-Finder
                // applications being picked up on certain Mac OS 9 systems,
                // especially German ones, and sending a GURL event to those
                // applications results in a logout under Multiple Users.
                Object fileType = getFileType.invoke(null, new Object[] { file });
                if (FINDER_TYPE.equals(fileType.toString())) {
                    Object fileCreator = getFileCreator.invoke(null, new Object[] { file });
                    if (FINDER_CREATOR.equals(fileCreator.toString())) {
                        browser = file.toString(); // Actually the Finder, but that's OK
                        return browser;
                    }
                }
            } catch (IllegalArgumentException iare) {
                browser = browser;
                errorMessage = iare.getMessage();
                return null;
            } catch (IllegalAccessException iae) {
                browser = null;
                errorMessage = iae.getMessage();
                return browser;
            } catch (InvocationTargetException ite) {
                browser = null;
                errorMessage = ite.getTargetException().getClass() + ": "
                        + ite.getTargetException().getMessage();
                return browser;
            }
        }
        browser = null;
        break;
    case MRJ_3_0:
    case MRJ_3_1:
        browser = ""; // Return something non-null
        break;
    case WINDOWS_NT:
        browser = "cmd.exe";
        break;
    case WINDOWS_9x:
        browser = "command.com";
        break;
    case OTHER:
    default:
        browser = "netscape";
        break;
    }
    return browser;
}

From source file:com.sun.faces.el.PropertyResolverImpl.java

public Object getValue(Object base, Object property) {

    if ((base == null) || (property == null)) {
        return null;
    }//from   w  ww. jav  a  2  s . co  m
    if (base instanceof Map) {
        return (((Map) base).get(property));
    } else {
        String name = null;
        BeanInfoProperty bip = null;
        try {
            name = Coercions.coerceToString(property);
            bip = BeanInfoManager.getBeanInfoProperty(base.getClass(), name);
        } catch (Throwable t) {
            // PENDING (hans) Align with std message handling
            String message = "Error finding property '" + name + "' from bean of type "
                    + base.getClass().getName() + ": " + t;
            if (log.isDebugEnabled()) {
                log.debug(message, t);
            }
            throw new PropertyNotFoundException(message, t);
        }
        if (bip != null && bip.getReadMethod() != null) {
            try {
                return bip.getReadMethod().invoke(base, sNoArgs);
            } catch (InvocationTargetException exc) {
                // PENDING (hans) Align with std message handling
                Throwable t = exc.getTargetException();
                String message = "Error getting property '" + name + "' from bean of type "
                        + base.getClass().getName() + ": " + t;
                if (log.isDebugEnabled()) {
                    log.debug(message, t);
                }
                throw new EvaluationException(message, t);
            } catch (IllegalAccessException t) {
                // PENDING (hans) Align with std message handling
                String message = "Error getting property '" + name + "' from bean of type "
                        + base.getClass().getName() + ": " + t;
                if (log.isDebugEnabled()) {
                    log.debug(message, t);
                }
                throw new EvaluationException(message, t);
            }
        } else {
            // No readable property with this name
            String message = "Error getting property '" + name + "' from bean of type "
                    + base.getClass().getName();
            if (log.isDebugEnabled()) {
                log.debug(message);
            }
            throw new PropertyNotFoundException(message);
        }
    }

}

From source file:com.sun.faces.el.PropertyResolverImpl.java

public void setValue(Object base, Object property, Object value) {

    if ((base == null) || (property == null)) {
        String className = base == null ? "null" : base.getClass().getName();
        throw new PropertyNotFoundException(
                "Error setting property '" + property + "' in bean of type " + className);
    }//  w ww.j  a v  a2 s.  c  o  m

    if (base instanceof Map) {
        ((Map) base).put(property, value);
    } else {
        String name = null;
        BeanInfoProperty bip = null;
        try {
            name = Coercions.coerceToString(property);
            bip = BeanInfoManager.getBeanInfoProperty(base.getClass(), name);
        } catch (Throwable t) {
            // PENDING (hans) Align with std message handling
            String message = "Error finding property '" + name + "' in bean of type "
                    + base.getClass().getName() + ": " + t;
            if (log.isDebugEnabled()) {
                log.debug(message, t);
            }
            throw new PropertyNotFoundException(message, t);
        }
        if (bip != null && bip.getWriteMethod() != null) {
            try {
                bip.getWriteMethod().invoke(base, new Object[] { value });
            } catch (InvocationTargetException exc) {
                // PENDING (hans) Align with std message handling
                Throwable t = exc.getTargetException();
                String message = "Error setting property '" + name + "' in bean of type "
                        + base.getClass().getName() + ": " + t;
                if (log.isDebugEnabled()) {
                    log.debug(message, t);
                }
                throw new EvaluationException(message, t);
            } catch (IllegalAccessException t) {
                // PENDING (hans) Align with std message handling
                String message = "Error setting property '" + name + "' in bean of type "
                        + base.getClass().getName() + ": " + t;
                if (log.isDebugEnabled()) {
                    log.debug(message, t);
                }
                throw new EvaluationException(message, t);
            }
        } else {
            // No write property with this name
            String message = "Error setting property '" + name + "' in bean of type "
                    + base.getClass().getName();
            if (log.isDebugEnabled()) {
                log.debug(message);
            }
            throw new PropertyNotFoundException(message);
        }
    }

}

From source file:com.bbm.common.aspect.ExceptionTransfer.java

/**
 * ? Exception ? ?  ??   ??  ? .//from  www.  j a  v  a 2s . c o m
 * @param thisJoinPoint joinPoint ?
 * @param exception ? Exception 
 */
public void transfer(JoinPoint thisJoinPoint, Exception exception) throws Exception {
    log.debug("execute ExceptionTransfer.transfer ");

    Class clazz = thisJoinPoint.getTarget().getClass();
    Signature signature = thisJoinPoint.getSignature();

    Locale locale = LocaleContextHolder.getLocale();
    /**
     * BizException ?  ??     ? ?.
     * Exception   ?? ? ?? Exception? ? ? ?.
     *   ?    . 
     * ?   ??  Handler     ?  ?.
     */

    String servicename = ""; //  
    String errorCode = ""; // ? 
    String errorMessage = ""; // ? 
    String classname = ""; // ??  

    int servicepos = clazz.getCanonicalName().lastIndexOf("."); //   .? 
    if (servicepos > 0) {
        String tempStr = clazz.getCanonicalName().substring(servicepos + 1);
        servicepos = tempStr.lastIndexOf("Impl"); //   Impl? 
        servicename = tempStr.substring(0, servicepos);
    } else {
        servicename = clazz.getCanonicalName();
    }
    classname = exception.getClass().getName();

    //EgovBizException ? ? 
    if (exception instanceof EgovBizException) {
        log.debug("Exception case :: EgovBizException ");

        EgovBizException be = (EgovBizException) exception;
        getLog(clazz).error(be.getMessage(), be.getCause());

        // Exception Handler ? ?? Package  Exception . (runtime ?  ExceptionHandlerService )
        processHandling(clazz, signature.getName(), exception, pm, exceptionHandlerServices);

        throw be;

        //RuntimeException ? ? ? DataAccessException ?   ?? throw  .
    } else if (exception instanceof RuntimeException) {
        log.debug("RuntimeException case :: RuntimeException ");

        RuntimeException be = (RuntimeException) exception;
        getLog(clazz).error(be.getMessage(), be.getCause());

        // Exception Handler ? ?? Package  Exception .
        processHandling(clazz, signature.getName(), exception, pm, exceptionHandlerServices);

        if (be instanceof DataAccessException) {
            /*
            log.debug("RuntimeException case :: DataAccessException ");
            DataAccessException sqlEx = (DataAccessException) be;
            throw sqlEx;
            */
            log.debug("RuntimeException case :: DataAccessException ");

            DataAccessException dataEx = (DataAccessException) be;
            Throwable t = dataEx.getRootCause();
            String exceptionname = t.getClass().getName();

            if (exceptionname.equals("java.sql.SQLException")) {
                java.sql.SQLException sqlException = (java.sql.SQLException) t;
                errorCode = String.valueOf(sqlException.getErrorCode());
                errorMessage = sqlException.getMessage();
            } else if (exception instanceof org.springframework.jdbc.BadSqlGrammarException) {
                org.springframework.jdbc.BadSqlGrammarException sqlEx = (org.springframework.jdbc.BadSqlGrammarException) exception;
                errorCode = String.valueOf(sqlEx.getSQLException().getErrorCode());
                errorMessage = sqlEx.getSQLException().toString();
            } else if (exception instanceof org.springframework.jdbc.UncategorizedSQLException) {
                org.springframework.jdbc.UncategorizedSQLException sqlEx = (org.springframework.jdbc.UncategorizedSQLException) exception;
                errorCode = String.valueOf(sqlEx.getSQLException().getErrorCode());
                errorMessage = sqlEx.getSQLException().toString();
            } else if (exception instanceof org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException) {
                org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException sqlEx = (org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException) exception;
                errorCode = String.valueOf(sqlEx.getActualRowsAffected());
                errorMessage = sqlEx.getMessage().toString();
            } else if (exception instanceof org.springframework.jdbc.SQLWarningException) {
                org.springframework.jdbc.SQLWarningException sqlEx = (org.springframework.jdbc.SQLWarningException) exception;
                errorCode = String.valueOf(sqlEx.SQLWarning().getErrorCode());
                errorMessage = sqlEx.getMessage().toString();
            } else if (exception instanceof org.springframework.jdbc.CannotGetJdbcConnectionException) {
                org.springframework.jdbc.CannotGetJdbcConnectionException sqlEx = (org.springframework.jdbc.CannotGetJdbcConnectionException) exception;
                errorCode = String.valueOf(sqlEx.getMessage());
                errorMessage = sqlEx.getMessage().toString();
            } else if (exception instanceof org.springframework.jdbc.InvalidResultSetAccessException) {
                org.springframework.jdbc.InvalidResultSetAccessException sqlEx = (org.springframework.jdbc.InvalidResultSetAccessException) exception;
                errorCode = String.valueOf(sqlEx.getSQLException().getErrorCode());
                errorMessage = sqlEx.getSQLException().toString();
            } else {

                if (exception instanceof java.lang.reflect.InvocationTargetException) {

                    java.lang.reflect.InvocationTargetException ce = (java.lang.reflect.InvocationTargetException) exception;
                    errorCode = "";
                    errorMessage = ce.getTargetException().getMessage();
                    //strErrorMessage = getValue(ce.getTargetException().toString(), "");

                }
            }

            //  , ?, ?, ,  
            String[] messages = new String[] { "DataAccessException", errorCode, errorMessage, servicename,
                    signature.getName(), classname };
            throw processException(clazz, "fail.common.msg", messages, exception, locale);
        }

        //  , ?, ?, ,  
        errorMessage = exception.getMessage();
        String[] messages = new String[] { "RuntimeException", errorCode, errorMessage, servicename,
                signature.getName(), classname };
        throw processException(clazz, "fail.common.msg", messages, exception, locale);
        //throw be;

        // ? ? Exception (: ) :: ?  ?.
    } else if (exception instanceof FdlException) {
        log.debug("FdlException case :: FdlException ");

        FdlException fe = (FdlException) exception;
        getLog(clazz).error(fe.getMessage(), fe.getCause());
        errorMessage = exception.getMessage();
        //  , ?, ?, ,  
        String[] messages = new String[] { "FdlException", errorCode, errorMessage, servicename,
                signature.getName(), classname };

        throw processException(clazz, "fail.common.msg", messages, exception, locale);
        //throw fe;

    } else {
        //? ? Exception ?  BaseException (: fail.common.msg)     ?. 
        //:: ?  ?.
        log.debug("case :: Exception ");

        getLog(clazz).error(exception.getMessage(), exception.getCause());

        errorMessage = exception.getMessage();
        //  , ?, ?, ,  
        String[] messages = new String[] { "Exception", errorCode, errorMessage, servicename,
                signature.getName(), classname };

        throw processException(clazz, "fail.common.msg", messages, exception, locale);

    }
}

From source file:it.openutils.mgnlaws.magnolia.init.ClasspathProviderImpl.java

/**
 * @see info.magnolia.repository.Provider#registerNodeTypes(java.io.InputStream)
 *///from  w ww.  ja v a 2s.c  o  m
public void registerNodeTypes(InputStream xmlStream) throws RepositoryException {
    SimpleCredentials credentials = new SimpleCredentials(ContentRepository.REPOSITORY_USER,
            ContentRepository.REPOSITORY_PSWD.toCharArray());
    Session jcrSession = this.repository.login(credentials);

    try {

        Workspace workspace = jcrSession.getWorkspace();

        // should never happen
        if (xmlStream == null) {
            throw new MissingNodetypesException();
        }

        // Use Objects so that it works both with jackrabbit 1.x (NodeTypeDef) and jackrabbit 2
        // (QNodeTypeDefinition)
        Object[] types;

        try {
            types = (Object[]) NodeTypeReader.class.getMethod("read", new Class[] { InputStream.class })
                    .invoke(null, new Object[] { xmlStream });
        } catch (Exception e) {
            throw new RepositoryException(e.getMessage(), e);
        } finally {
            IOUtils.closeQuietly(xmlStream);
        }

        NodeTypeManager ntMgr = workspace.getNodeTypeManager();
        NodeTypeRegistry ntReg;
        try {
            ntReg = ((NodeTypeManagerImpl) ntMgr).getNodeTypeRegistry();
        } catch (ClassCastException e) {
            // this could happen if the repository provider does not have proper Shared API for the
            // application server like at the moment in Jackrabbit
            log.debug("Failed to get NodeTypeRegistry: ", e);
            return;
        }

        for (int j = 0; j < types.length; j++) {
            Object def = types[j];

            Name ntname;
            try {
                ntname = (Name) PropertyUtils.getProperty(def, "name");
            } catch (Exception e) {
                throw new RepositoryException(e.getMessage(), e);
            }

            try {

                // return value has changed in jackrabbit 2, we still have to use reflection here
                // ntReg.getNodeTypeDef(ntname);

                Method method = ntReg.getClass().getMethod("getNodeTypeDef", Name.class);
                method.invoke(ntReg, ntname);
            } catch (IllegalArgumentException e) {
                throw new RepositoryException(e.getMessage(), e);
            } catch (IllegalAccessException e) {
                throw new RepositoryException(e.getMessage(), e);
            } catch (SecurityException e) {
                throw new RepositoryException(e.getMessage(), e);
            } catch (NoSuchMethodException e) {
                throw new RepositoryException(e.getMessage(), e);
            } catch (InvocationTargetException ite) {
                if (ite.getTargetException() instanceof NoSuchNodeTypeException) {
                    log.info("Registering nodetype {} on repository {}", ntname, repositoryMapping.getName()); //$NON-NLS-1$

                    try {
                        // reflection for jackrabbit 1+2 compatibility
                        getMethod(NodeTypeRegistry.class, "registerNodeType").invoke(ntReg,
                                new Object[] { def });
                    } catch (Exception e) {
                        throw new RepositoryException(e.getMessage(), e);
                    }
                }
            }
        }

    } finally {
        jcrSession.logout();
    }
}

From source file:py.una.pol.karaku.test.cucumber.TransactionalTestCucumberExecutionListener.java

/**
 * Run all {@link AfterTransaction &#064;AfterTransaction methods} for the
 * specified {@link TestContext test context}. If one of the methods fails,
 * the caught exception will be logged as an error, and the remaining
 * methods will be given a chance to execute. After all methods have
 * executed, the first caught exception, if any, will be rethrown.
 * //  w ww  .  j  a  v  a 2 s.  co m
 * @param testContext
 *            the current test context
 */
protected void runAfterTransactionMethods(TestContext testContext) throws Exception {

    Throwable afterTransactionException = null;

    List<Method> methods = getAnnotatedMethods(testContext.getTestClass(), AfterTransaction.class);
    for (Method method : methods) {
        try {
            if (logger.isDebugEnabled()) {
                logger.debug("Executing @AfterTransaction method [" + method + "] for test context ["
                        + testContext + "]");
            }
            method.invoke(testContext.getTestInstance());
        } catch (InvocationTargetException ex) {
            Throwable targetException = ex.getTargetException();
            if (afterTransactionException == null) {
                afterTransactionException = targetException;
            }
            logger.error("Exception encountered while executing @AfterTransaction method [" + method
                    + "] for test context [" + testContext + "]", targetException);
        } catch (Exception ex) {
            if (afterTransactionException == null) {
                afterTransactionException = ex;
            }
            logger.error("Exception encountered while executing @AfterTransaction method [" + method
                    + "] for test context [" + testContext + "]", ex);
        }
    }

    if (afterTransactionException != null) {
        ReflectionUtils.rethrowException(afterTransactionException);
    }
}

From source file:edu.umich.flowfence.sandbox.ResolvedQM.java

@Override
public void call(int flags, IQMCallback callback, List<CallParam> params) throws RemoteException {
    try {//from   w  w  w .  ja v  a  2s.c o m
        if (localLOGD) {
            Log.d(TAG, String.format("Incoming sandbox call for %s, %d parameters:", mOriginalDescriptor,
                    params.size()));
            for (CallParam param : params) {
                Log.d(TAG, param.toString(mContext.getClassLoader()));
            }
        }
        if (localLOGV) {
            Log.v(TAG, String.format("Callback %s, flags %d", callback, flags));
        }
        // Sanity check.
        final int numParams = params.size();
        if (numParams != mMemberData.countParameters()) {
            throw new IllegalArgumentException("Wrong number of arguments supplied");
        }

        boolean hasReturn = (flags & CallFlags.NO_RETURN_VALUE) == 0;

        final ArrayList<Object> args = new ArrayList<>();
        final SparseArray<IBinder> outs = new SparseArray<>();

        mContext.beginQM();
        try {
            if (hasReturn) {
                outs.append(CallResult.RETURN_VALUE, null);
            }

            for (int i = 0; i < numParams; i++) {
                CallParam param = params.get(i);
                int paramHeader = param.getHeader();
                if (param.getType() == CallParam.TYPE_HANDLE
                        && (paramHeader & CallParam.HANDLE_SYNC_ONLY) != 0) {
                    Log.w(TAG, "HANDLE_SYNC_ONLY in sandbox for " + mOriginalDescriptor);
                    continue;
                }
                // Deserialize argument, marshaling as necessary.
                Object arg = unpack(param);
                // TODO: FLAG_BY_REF
                args.add(arg);
                // Put together the out parameter for inout params.
                if ((paramHeader & CallParam.FLAG_RETURN) != 0) {
                    if (localLOGV) {
                        Log.v(TAG, String.format("Adding out param %d", i));
                    }
                    outs.append(i, SandboxObject.binderForObject(this, arg));
                }
            }

            // Actually do the call.
            Object[] argArray = args.toArray();
            if (localLOGD) {
                Log.d(TAG, "Preparing to call " + mOriginalDescriptor.printCall(argArray));
            }

            Object retval = mMemberData.call(argArray);

            if (localLOGD) {
                Log.d(TAG, "Call returned: " + Objects.toString(retval));
            }

            // Bundle up handle for return value.
            if (hasReturn) {
                IBinder retvalObj = SandboxObject.binderForObject(this, retval);
                outs.put(CallResult.RETURN_VALUE, retvalObj);
            }

            // DEBUG: print out params
            if (localLOGV) {
                for (int i = 0; i < outs.size(); i++) {
                    Log.v(TAG, String.format("out[%d] = %s", outs.keyAt(i), outs.valueAt(i)));
                }
            }
            // Post results to caller.
            if (localLOGD) {
                Log.d(TAG, "Posting results to caller");
            }
            callback.onResult(new CallResult(outs));
        } catch (InvocationTargetException ioe) {
            Throwable t = ioe.getTargetException();
            if (t instanceof Exception) {
                throw ((Exception) t);
            }
            throw ioe;
        } finally {
            // Clear our ambient context.
            if (localLOGD) {
                Log.d(TAG, "Clearing call token");
            }
            mContext.endQM();
        }
    } catch (Exception e) {
        //Log.e(TAG, String.format("Error invoking %s", mOriginalDescriptor), e);
        callback.onResult(new CallResult(e));
    }
}

From source file:edu.umich.oasis.sandbox.ResolvedSoda.java

@Override
public void call(int flags, ISodaCallback callback, List<CallParam> params) throws RemoteException {
    try {//from  w  w  w . j a v  a 2s.  c o m
        if (localLOGD) {
            Log.d(TAG, String.format("Incoming sandbox call for %s, %d parameters:", mOriginalDescriptor,
                    params.size()));
            for (CallParam param : params) {
                Log.d(TAG, param.toString(mContext.getClassLoader()));
            }
        }
        if (localLOGV) {
            Log.v(TAG, String.format("Callback %s, flags %d", callback, flags));
        }
        // Sanity check.
        final int numParams = params.size();
        if (numParams != mMemberData.countParameters()) {
            throw new IllegalArgumentException("Wrong number of arguments supplied");
        }

        boolean hasReturn = (flags & CallFlags.NO_RETURN_VALUE) == 0;

        final ArrayList<Object> args = new ArrayList<>();
        final SparseArray<IBinder> outs = new SparseArray<>();

        mContext.beginSoda();
        try {
            if (hasReturn) {
                outs.append(CallResult.RETURN_VALUE, null);
            }

            for (int i = 0; i < numParams; i++) {
                CallParam param = params.get(i);
                int paramHeader = param.getHeader();
                if (param.getType() == CallParam.TYPE_HANDLE
                        && (paramHeader & CallParam.HANDLE_SYNC_ONLY) != 0) {
                    Log.w(TAG, "HANDLE_SYNC_ONLY in sandbox for " + mOriginalDescriptor);
                    continue;
                }
                // Deserialize argument, marshaling as necessary.
                Object arg = unpack(param);
                // TODO: FLAG_BY_REF
                args.add(arg);
                // Put together the out parameter for inout params.
                if ((paramHeader & CallParam.FLAG_RETURN) != 0) {
                    if (localLOGV) {
                        Log.v(TAG, String.format("Adding out param %d", i));
                    }
                    outs.append(i, SandboxObject.binderForObject(this, arg));
                }
            }

            // Actually do the call.
            Object[] argArray = args.toArray();
            if (localLOGD) {
                Log.d(TAG, "Preparing to call " + mOriginalDescriptor.printCall(argArray));
            }

            Object retval = mMemberData.call(argArray);

            if (localLOGD) {
                Log.d(TAG, "Call returned: " + Objects.toString(retval));
            }

            // Bundle up handle for return value.
            if (hasReturn) {
                IBinder retvalObj = SandboxObject.binderForObject(this, retval);
                outs.put(CallResult.RETURN_VALUE, retvalObj);
            }

            // DEBUG: print out params
            if (localLOGV) {
                for (int i = 0; i < outs.size(); i++) {
                    Log.v(TAG, String.format("out[%d] = %s", outs.keyAt(i), outs.valueAt(i)));
                }
            }
            // Post results to caller.
            if (localLOGD) {
                Log.d(TAG, "Posting results to caller");
            }
            callback.onResult(new CallResult(outs));
        } catch (InvocationTargetException ioe) {
            Throwable t = ioe.getTargetException();
            if (t instanceof Exception) {
                throw ((Exception) t);
            }
            throw ioe;
        } finally {
            // Clear our ambient context.
            if (localLOGD) {
                Log.d(TAG, "Clearing call token");
            }
            mContext.endSoda();
        }
    } catch (Exception e) {
        //Log.e(TAG, String.format("Error invoking %s", mOriginalDescriptor), e);
        callback.onResult(new CallResult(e));
    }
}

From source file:py.una.pol.karaku.test.cucumber.TransactionalTestCucumberExecutionListener.java

/**
 * Run all {@link BeforeTransaction &#064;BeforeTransaction methods} for the
 * specified {@link TestContext test context}. If one of the methods fails,
 * however, the caught exception will be rethrown in a wrapped
 * {@link RuntimeException}, and the remaining methods will
 * <strong>not</strong> be given a chance to execute.
 * //from  w w  w .  jav  a2s. co m
 * @param testContext
 *            the current test context
 */
protected void runBeforeTransactionMethods(TestContext testContext) throws Exception {

    try {
        List<Method> methods = getAnnotatedMethods(testContext.getTestClass(), BeforeTransaction.class);
        Collections.reverse(methods);
        for (Method method : methods) {
            if (logger.isDebugEnabled()) {
                logger.debug("Executing @BeforeTransaction method [" + method + "] for test context ["
                        + testContext + "]");
            }
            method.invoke(testContext.getTestInstance());
        }
    } catch (InvocationTargetException ex) {
        logger.error("Exception encountered while executing @BeforeTransaction methods for test context ["
                + testContext + "]", ex.getTargetException());
        ReflectionUtils.rethrowException(ex.getTargetException());
    }
}

From source file:com.taobao.itest.listener.TransactionalListener.java

/**
 * Run all {@link AfterTransaction @AfterTransaction methods} for the
 * specified {@link TestContext test context}. If one of the methods fails,
 * the caught exception will be logged as an error, and the remaining
 * methods will be given a chance to execute. After all methods have
 * executed, the first caught exception, if any, will be rethrown.
 * /*www .jav a2  s . com*/
 * @param testContext
 *            the current test context
 */
protected void runAfterTransactionMethods(TestContext testContext) throws Exception {
    Throwable afterTransactionException = null;

    List<Method> methods = getAnnotatedMethods(testContext.getTestClass(), AfterTransaction.class);
    for (Method method : methods) {
        try {
            if (logger.isDebugEnabled()) {
                logger.debug("Executing @AfterTransaction method [" + method + "] for test context ["
                        + testContext + "]");
            }
            method.invoke(testContext.getTestInstance());
        } catch (InvocationTargetException ex) {
            Throwable targetException = ex.getTargetException();
            if (afterTransactionException == null) {
                afterTransactionException = targetException;
            }
            logger.error("Exception encountered while executing @AfterTransaction method [" + method
                    + "] for test context [" + testContext + "]", targetException);
        } catch (Exception ex) {
            if (afterTransactionException == null) {
                afterTransactionException = ex;
            }
            logger.error("Exception encountered while executing @AfterTransaction method [" + method
                    + "] for test context [" + testContext + "]", ex);
        }
    }

    if (afterTransactionException != null) {
        rethrowException(afterTransactionException);
    }
}