Example usage for java.lang.reflect InvocationTargetException getCause

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

Introduction

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

Prototype

public Throwable getCause() 

Source Link

Document

Returns the cause of this exception (the thrown target exception, which may be null ).

Usage

From source file:rb.app.RBBase.java

public Complex complex_eval_theta_q_l(int n, int q) {
    Method meth;//  w  w  w .j a  va  2  s . c  o  m
    //Complex c;

    try {
        // Get a reference to get_n_L_functions, which does not
        // take any arguments

        Class partypes[] = new Class[4];
        partypes[0] = Integer.TYPE;
        partypes[1] = Integer.TYPE;
        partypes[2] = double[].class;
        partypes[3] = boolean.class;

        meth = mAffineFnsClass.getMethod("evaluateL", partypes);
    } catch (NoSuchMethodException nsme) {
        throw new RuntimeException("getMethod for evaluateL failed", nsme);
    }

    Double theta_val_r, theta_val_i;
    try {
        Object arglist[] = new Object[4];
        arglist[0] = new Integer(n);
        arglist[1] = new Integer(q);
        arglist[2] = current_parameters.getArray();
        arglist[3] = true;

        Object theta_obj = meth.invoke(mTheta, arglist);
        theta_val_r = (Double) theta_obj;

        arglist[3] = false;
        theta_val_i = (Double) meth.invoke(mTheta, arglist);
    } catch (IllegalAccessException iae) {
        throw new RuntimeException(iae);
    } catch (InvocationTargetException ite) {
        throw new RuntimeException(ite.getCause());
    }
    Complex c = new Complex(theta_val_r.doubleValue(), theta_val_i.doubleValue());

    return c;
}

From source file:org.acegisecurity.vote.AclEntryVoter.java

public int vote(Authentication authentication, Object object, ConfigAttributeDefinition config) {
    Iterator iter = config.getConfigAttributes();

    while (iter.hasNext()) {
        ConfigAttribute attr = (ConfigAttribute) iter.next();

        if (this.supports(attr)) {
            // Need to make an access decision on this invocation
            // Attempt to locate the domain object instance to process
            Object domainObject = getDomainObjectInstance(object);

            // Evaluate if we are required to use an inner domain object
            if (domainObject != null && internalMethod != null && (!"".equals(internalMethod))) {
                try {
                    Class clazz = domainObject.getClass();
                    Method method = clazz.getMethod(internalMethod, new Class[] {});
                    domainObject = method.invoke(domainObject, new Object[] {});
                } catch (NoSuchMethodException nsme) {
                    throw new AuthorizationServiceException("Object of class '" + domainObject.getClass()
                            + "' does not provide the requested internalMethod: " + internalMethod);
                } catch (IllegalAccessException iae) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("IllegalAccessException", iae);

                        if (iae.getCause() != null) {
                            logger.debug("Cause: " + iae.getCause().getMessage(), iae.getCause());
                        }//from ww  w. ja v  a  2  s.co m
                    }

                    throw new AuthorizationServiceException("Problem invoking internalMethod: " + internalMethod
                            + " for object: " + domainObject);
                } catch (InvocationTargetException ite) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("InvocationTargetException", ite);

                        if (ite.getCause() != null) {
                            logger.debug("Cause: " + ite.getCause().getMessage(), ite.getCause());
                        }
                    }

                    throw new AuthorizationServiceException("Problem invoking internalMethod: " + internalMethod
                            + " for object: " + domainObject);
                }
            }

            // If domain object is null, vote to abstain
            if (domainObject == null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Voting to abstain - domainObject is null");
                }

                return AccessDecisionVoter.ACCESS_ABSTAIN;
            }

            // Obtain the OID applicable to the domain object
            ObjectIdentity objectIdentity = objectIdentityRetrievalStrategy.getObjectIdentity(domainObject);

            // Obtain the SIDs applicable to the principal
            Sid[] sids = sidRetrievalStrategy.getSids(authentication);

            Acl acl;

            try {
                // Lookup only ACLs for SIDs we're interested in
                acl = aclService.readAclById(objectIdentity, sids);
            } catch (NotFoundException nfe) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Voting to deny access - no ACLs apply for this principal");
                }

                return AccessDecisionVoter.ACCESS_DENIED;
            }

            try {
                if (acl.isGranted(requirePermission, sids, false)) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Voting to grant access");
                    }

                    return AccessDecisionVoter.ACCESS_GRANTED;
                } else {
                    if (logger.isDebugEnabled()) {
                        logger.debug(
                                "Voting to deny access - ACLs returned, but insufficient permissions for this principal");
                    }

                    return AccessDecisionVoter.ACCESS_DENIED;
                }
            } catch (NotFoundException nfe) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Voting to deny access - no ACLs apply for this principal");
                }

                return AccessDecisionVoter.ACCESS_DENIED;
            }
        }
    }

    // No configuration attribute matched, so abstain
    return AccessDecisionVoter.ACCESS_ABSTAIN;
}

From source file:org.sonatype.nexus.test.booter.Jetty8NexusBooter.java

/**
 * Stops, and cleans up the started Nexus instance. May be invoked any times, it will NOOP if not needed to do
 * anything. Will try to ditch the used classloader. The {@link #clean()} method will be invoked on every invocation
 * of this method, making it more plausible for JVM to recover/GC all the stuff from memory in case of any glitch.
 * //from w ww .  ja  v a  2  s.  c  om
 * @throws Exception
 */
public void stopNexus() throws Exception {
    try {
        log.info("Stopping Nexus");

        if (jetty8 != null) {
            jetty8.getClass().getMethod("stopJetty").invoke(jetty8);
        }
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof IllegalStateException) {
            // swallow it, it is Jetty8 that throws this when we stop but did not start...
        } else {
            throw (Exception) e.getCause();
        }
    } finally {
        clean();
    }
}

From source file:org.apache.velocity.tools.ToolInfo.java

protected void invoke(Method method, Object tool, Object param) {
    try {/*from w  w  w.j  a  va 2  s . c o  m*/
        // call the setup method on the instance
        method.invoke(tool, new Object[] { param });
    } catch (IllegalAccessException iae) {
        String msg = "Unable to invoke " + method + " on " + tool;
        // restricting access to this method by this class ist verboten
        throw new IllegalStateException(msg, iae);
    } catch (InvocationTargetException ite) {
        String msg = "Exception when invoking " + method + " on " + tool;
        // convert to a runtime exception, and re-throw
        throw new RuntimeException(msg, ite.getCause());
    }
}

From source file:org.acegisecurity.vote.BasicAclEntryVoter.java

public int vote(Authentication authentication, Object object, ConfigAttributeDefinition config) {
    Iterator iter = config.getConfigAttributes();

    while (iter.hasNext()) {
        ConfigAttribute attr = (ConfigAttribute) iter.next();

        if (this.supports(attr)) {
            // Need to make an access decision on this invocation
            // Attempt to locate the domain object instance to process
            Object domainObject = getDomainObjectInstance(object);

            // If domain object is null, vote to abstain
            if (domainObject == null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Voting to abstain - domainObject is null");
                }//from  w  ww.  j  a  v  a2 s  .  c o m

                return AccessDecisionVoter.ACCESS_ABSTAIN;
            }

            // Evaluate if we are required to use an inner domain object
            if ((internalMethod != null) && !"".equals(internalMethod)) {
                try {
                    Class clazz = domainObject.getClass();
                    Method method = clazz.getMethod(internalMethod, new Class[] {});
                    domainObject = method.invoke(domainObject, new Object[] {});
                } catch (NoSuchMethodException nsme) {
                    throw new AuthorizationServiceException("Object of class '" + domainObject.getClass()
                            + "' does not provide the requested internalMethod: " + internalMethod);
                } catch (IllegalAccessException iae) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("IllegalAccessException", iae);

                        if (iae.getCause() != null) {
                            logger.debug("Cause: " + iae.getCause().getMessage(), iae.getCause());
                        }
                    }

                    throw new AuthorizationServiceException("Problem invoking internalMethod: " + internalMethod
                            + " for object: " + domainObject);
                } catch (InvocationTargetException ite) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("InvocationTargetException", ite);

                        if (ite.getCause() != null) {
                            logger.debug("Cause: " + ite.getCause().getMessage(), ite.getCause());
                        }
                    }

                    throw new AuthorizationServiceException("Problem invoking internalMethod: " + internalMethod
                            + " for object: " + domainObject);
                }
            }

            // Obtain the ACLs applicable to the domain object
            AclEntry[] acls = aclManager.getAcls(domainObject, authentication);

            // If principal has no permissions for domain object, deny
            if ((acls == null) || (acls.length == 0)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Voting to deny access - no ACLs returned for this principal");
                }

                return AccessDecisionVoter.ACCESS_DENIED;
            }

            // Principal has some permissions for domain object, check them
            for (int i = 0; i < acls.length; i++) {
                // Locate processable AclEntrys
                if (acls[i] instanceof BasicAclEntry) {
                    BasicAclEntry processableAcl = (BasicAclEntry) acls[i];

                    // See if principal has any of the required permissions
                    for (int y = 0; y < requirePermission.length; y++) {
                        if (processableAcl.isPermitted(requirePermission[y])) {
                            if (logger.isDebugEnabled()) {
                                logger.debug("Voting to grant access");
                            }

                            return AccessDecisionVoter.ACCESS_GRANTED;
                        }
                    }
                }
            }

            // No permissions match
            if (logger.isDebugEnabled()) {
                logger.debug(
                        "Voting to deny access - ACLs returned, but insufficient permissions for this principal");
            }

            return AccessDecisionVoter.ACCESS_DENIED;
        }
    }

    // No configuration attribute matched, so abstain
    return AccessDecisionVoter.ACCESS_ABSTAIN;
}

From source file:com.app.test.util.UserUtilTest.java

@Test
public void testValidatePasswordWithNullPassword() throws Exception {
    Method validatePassword = _clazz.getDeclaredMethod("_validatePassword", String.class);

    validatePassword.setAccessible(true);

    try {/* w  w w  .j  a v a2  s .  c o  m*/
        validatePassword.invoke(_classInstance, "");

        Assert.fail();
    } catch (InvocationTargetException ite) {
        Assert.assertTrue(ite.getCause() instanceof PasswordLengthException);
    }
}

From source file:com.app.test.util.UserUtilTest.java

@Test
public void testValidatePasswordWithShortPassword() throws Exception {
    Method validatePassword = _clazz.getDeclaredMethod("_validatePassword", String.class);

    validatePassword.setAccessible(true);

    try {/*  w  w w . ja v  a  2  s .  c o  m*/
        validatePassword.invoke(_classInstance, "short");

        Assert.fail();
    } catch (InvocationTargetException ite) {
        Assert.assertTrue(ite.getCause() instanceof PasswordLengthException);
    }
}

From source file:com.app.test.util.UserUtilTest.java

@Test
public void testValidateEmailAddressWithInvalidEmailAddress() throws Exception {

    Method validateEmailAddress = _clazz.getDeclaredMethod("_validateEmailAddress", int.class, String.class);

    validateEmailAddress.setAccessible(true);

    try {/*from  w  ww .  ja v  a2  s  . c  om*/
        validateEmailAddress.invoke(_classInstance, _USER_ID, "test");

        Assert.fail();
    } catch (InvocationTargetException ite) {
        Assert.assertTrue(ite.getCause() instanceof InvalidEmailAddressException);
    }
}

From source file:com.app.test.util.UserUtilTest.java

@Test
public void testValidateEmailAddressWithDuplicateEmailAddress() throws Exception {

    User user = UserUtil.addUser("test@test.com", "password");

    Method validateEmailAddress = _clazz.getDeclaredMethod("_validateEmailAddress", int.class, String.class);

    validateEmailAddress.setAccessible(true);

    try {/*from   w ww  .jav a 2s.  c  o  m*/
        validateEmailAddress.invoke(_classInstance, user.getUserId() + 1, "test@test.com");

        Assert.fail();
    } catch (InvocationTargetException ite) {
        Assert.assertTrue(ite.getCause() instanceof DuplicateEmailAddressException);
    }
}

From source file:com.app.test.util.UserUtilTest.java

@Test
public void testValidateCredentialsWithIncorrectPassword() throws Exception {

    User user = UserUtil.addUser("test@test.com", "password");

    Method validateCredentials = _clazz.getDeclaredMethod("_validateCredentials", String.class, String.class,
            String.class, String.class);

    validateCredentials.setAccessible(true);

    try {//  w  w  w  . j  a  v a2  s.  c  o  m
        validateCredentials.invoke(_classInstance, "test@test.com", user.getPassword(), "incorrectPassword",
                user.getSalt());

        Assert.fail();
    } catch (InvocationTargetException ite) {
        Assert.assertTrue(ite.getCause() instanceof CredentialsException);
    }
}