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.RBSystem.java

/**
 * A private helper function to get the SCM from AffineFunctions
 * in the case that SCM_TYPE = NONE/*from w ww .j  a va2s .c o  m*/
 */
protected double get_SCM_from_AffineFunction() {
    // we assume that an SCM LB function has been specified
    // in AffineFunctions.jar
    Method meth;

    try {
        Class partypes[] = new Class[1];
        partypes[0] = double[].class;

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

    Double SCM_val;
    try {
        Object arglist[] = new Object[1];
        arglist[0] = current_parameters.getArray();

        Object SCM_obj = meth.invoke(mTheta, arglist);
        SCM_val = (Double) SCM_obj;
    } catch (IllegalAccessException iae) {
        throw new RuntimeException(iae);
    } catch (InvocationTargetException ite) {
        throw new RuntimeException(ite.getCause());
    }

    return SCM_val.doubleValue();
}

From source file:rb.app.RBSystem.java

/**
 * Evaluate theta_q_f (for the q^th rhs function) at the current parameter.
 *//*  ww  w. j av a2s .  c  om*/
public double eval_theta_q_f(int q) {
    Method meth;

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

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

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

    Double theta_val;
    try {
        Object arglist[] = new Object[2];
        arglist[0] = new Integer(q);
        arglist[1] = current_parameters.getArray();

        Object theta_obj = meth.invoke(mTheta, arglist);
        theta_val = (Double) theta_obj;
    } catch (IllegalAccessException iae) {
        throw new RuntimeException(iae);
    } catch (InvocationTargetException ite) {
        throw new RuntimeException(ite.getCause());
    }

    return theta_val.doubleValue();
}

From source file:rb.app.RBSystem.java

protected void read_in_Q_uL() {
    Method meth;/*from  w  w w . j  a v a  2s  .c  o  m*/

    boolean noQ_uLdefined = false;
    try {
        // Get a reference to get_n_A_functions, which does not
        // take any arguments
        meth = mAffineFnsClass.getMethod("get_n_uL_functions", null);
    } catch (NoSuchMethodException nsme) {
        //throw new RuntimeException("getMethod for get_n_uL_functions failed", nsme);
        noQ_uLdefined = true;
        meth = null;
    }

    if (noQ_uLdefined)
        mQ_uL = 0;
    else {
        Integer Q_uL;
        try {
            Object Q_uL_obj = meth.invoke(mTheta, null);
            Q_uL = (Integer) Q_uL_obj;
        } catch (IllegalAccessException iae) {
            throw new RuntimeException(iae);
        } catch (InvocationTargetException ite) {
            throw new RuntimeException(ite.getCause());
        }

        mQ_uL = Q_uL.intValue();
    }
}

From source file:rb.app.RBSystem.java

/**
 * Evaluate theta_q_l (for the n^th output) at the current parameter.
 */// w  w  w.j  a  va2  s.c o  m
public double eval_theta_q_l(int n, int q_l) {
    Method meth;

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

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

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

    Double theta_val;
    try {
        Object arglist[] = new Object[3];
        arglist[0] = new Integer(n);
        arglist[1] = new Integer(q_l);
        arglist[2] = current_parameters.getArray();

        Object theta_obj = meth.invoke(mTheta, arglist);
        theta_val = (Double) theta_obj;
    } catch (IllegalAccessException iae) {
        throw new RuntimeException(iae);
    } catch (InvocationTargetException ite) {
        throw new RuntimeException(ite.getCause());
    }

    return theta_val.doubleValue();
}

From source file:rb.app.RBSystem.java

public float[][] get_tranformation_data() {
    Method meth = null;/*w  ww .jav a  2 s. co m*/
    boolean isOK = true;
    try {
        // Get a reference to get_n_L_functions, which does not
        // take any arguments

        Class partypes[] = new Class[1];
        partypes[0] = double[].class;

        meth = mAffineFnsClass.getMethod("get_local_transformation", partypes);
    } catch (NoSuchMethodException nsme) {
        //throw new RuntimeException("getMethod for evaluateF failed", nsme);
        isOK = false;
    }

    float[][] T_vector;
    if (isOK) {
        try {
            Object arglist[] = new Object[1];
            arglist[0] = current_parameters.getArray();

            Object theta_obj = meth.invoke(mTheta, arglist);
            T_vector = (float[][]) theta_obj;
        } catch (IllegalAccessException iae) {
            throw new RuntimeException(iae);
        } catch (InvocationTargetException ite) {
            throw new RuntimeException(ite.getCause());
        }
    } else {
        T_vector = new float[1][12];
        T_vector[0][0] = 1f;
        T_vector[0][1] = 0f;
        T_vector[0][2] = 0f;
        T_vector[0][3] = 0f;
        T_vector[0][4] = 1f;
        T_vector[0][5] = 0f;
        T_vector[0][6] = 0f;
        T_vector[0][7] = 0f;
        T_vector[0][8] = 1f;
        T_vector[0][9] = 0f;
        T_vector[0][10] = 0f;
        T_vector[0][11] = 0f;
    }

    return T_vector;
}

From source file:azkaban.viewer.reportal.ReportalServlet.java

private HadoopSecurityManager loadHadoopSecurityManager(Props props, Logger logger) throws RuntimeException {

    Class<?> hadoopSecurityManagerClass = props.getClass(HADOOP_SECURITY_MANAGER_CLASS_PARAM, true,
            ReportalServlet.class.getClassLoader());
    logger.info("Initializing hadoop security manager " + hadoopSecurityManagerClass.getName());
    HadoopSecurityManager hadoopSecurityManager = null;

    try {/*  w  w  w  . j  a va 2s . c o  m*/
        Method getInstanceMethod = hadoopSecurityManagerClass.getMethod("getInstance", Props.class);
        hadoopSecurityManager = (HadoopSecurityManager) getInstanceMethod.invoke(hadoopSecurityManagerClass,
                props);
    } catch (InvocationTargetException e) {
        logger.error("Could not instantiate Hadoop Security Manager " + hadoopSecurityManagerClass.getName()
                + e.getCause());
        throw new RuntimeException(e.getCause());
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e.getCause());
    }

    return hadoopSecurityManager;
}

From source file:org.apache.sling.models.impl.ModelAdapterFactory.java

private <ModelType> Result<ModelType> createObject(final Object adaptable,
        final ModelClass<ModelType> modelClass)
        throws InstantiationException, InvocationTargetException, IllegalAccessException {
    DisposalCallbackRegistryImpl registry = new DisposalCallbackRegistryImpl();

    ModelClassConstructor<ModelType> constructorToUse = getBestMatchingConstructor(adaptable, modelClass);
    if (constructorToUse == null) {
        return new Result<ModelType>(new ModelClassException(
                "Unable to find a useable constructor for model " + modelClass.getType()));
    }//from w  ww . j  a v a 2 s. co m

    final ModelType object;
    if (constructorToUse.getConstructor().getParameterTypes().length == 0) {
        // no parameters for constructor injection? instantiate it right away
        object = constructorToUse.getConstructor().newInstance();
    } else {
        // instantiate with constructor injection
        // if this fails, make sure resources that may be claimed by injectors are cleared up again
        try {
            Result<ModelType> result = newInstanceWithConstructorInjection(constructorToUse, adaptable,
                    modelClass, registry);
            if (!result.wasSuccessful()) {
                registry.onDisposed();
                return result;
            } else {
                object = result.getValue();
            }
        } catch (InstantiationException ex) {
            registry.onDisposed();
            throw ex;
        } catch (InvocationTargetException ex) {
            registry.onDisposed();
            throw ex;
        } catch (IllegalAccessException ex) {
            registry.onDisposed();
            throw ex;
        }
    }

    registerCallbackRegistry(object, registry);

    InjectCallback callback = new SetFieldCallback(object);

    InjectableField[] injectableFields = modelClass.getInjectableFields();
    MissingElementsException missingElements = new MissingElementsException(
            "Could not inject all required fields into " + modelClass.getType());
    for (InjectableField field : injectableFields) {
        RuntimeException t = injectElement(field, adaptable, registry, callback);
        if (t != null) {
            missingElements
                    .addMissingElementExceptions(new MissingElementException(field.getAnnotatedElement(), t));
        }
    }

    registry.seal();
    if (!missingElements.isEmpty()) {
        return new Result<ModelType>(missingElements);
    }
    try {
        invokePostConstruct(object);
    } catch (InvocationTargetException e) {
        return new Result<ModelType>(new PostConstructException(
                "Post-construct method has thrown an exception for model " + modelClass.getType(),
                e.getCause()));
    } catch (IllegalAccessException e) {
        new Result<ModelType>(new ModelClassException(
                "Could not call post-construct method for model " + modelClass.getType(), e));
    }
    return new Result<ModelType>(object);
}

From source file:org.slc.sli.api.service.BasicServiceTest.java

@SuppressWarnings({ "unchecked", "unused" })
@Test//from ww  w. j a v  a  2s .  c  o m
public void testGetResponseEntitiesNoAccess() throws SecurityException, NoSuchFieldException,
        IllegalArgumentException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
    securityContextInjector.setDualContext();
    SecurityUtil.setUserContext(SecurityUtil.UserContext.DUAL_CONTEXT);

    List<Entity> entities = new ArrayList<Entity>();
    Map<String, SecurityUtil.UserContext> studentContext = new HashMap<String, SecurityUtil.UserContext>();
    for (int i = 0; i < 30; i++) {
        String id = "student" + i;
        entities.add(
                new MongoEntity("student", id, new HashMap<String, Object>(), new HashMap<String, Object>()));
        studentContext.put(id, SecurityUtil.UserContext.DUAL_CONTEXT);
    }
    Mockito.when(mockRepo.findAll(Mockito.eq("student"), Mockito.any(NeutralQuery.class))).thenReturn(entities);
    Mockito.when(mockRepo.count(Mockito.eq("student"), Mockito.any(NeutralQuery.class))).thenReturn(50L);

    ContextValidator mockContextValidator = Mockito.mock(ContextValidator.class);
    Field contextValidator = BasicService.class.getDeclaredField("contextValidator");
    contextValidator.setAccessible(true);
    contextValidator.set(service, mockContextValidator);
    Mockito.when(mockContextValidator.getValidatedEntityContexts(Matchers.any(EntityDefinition.class),
            Matchers.any(Collection.class), Matchers.anyBoolean(), Matchers.anyBoolean()))
            .thenReturn(studentContext);

    RightAccessValidator mockAccessValidator = Mockito.mock(RightAccessValidator.class);
    Field rightAccessValidator = BasicService.class.getDeclaredField("rightAccessValidator");
    rightAccessValidator.setAccessible(true);
    rightAccessValidator.set(service, mockAccessValidator);
    Mockito.when(mockAccessValidator.getContextualAuthorities(Matchers.anyBoolean(), Matchers.any(Entity.class),
            Matchers.eq(SecurityUtil.UserContext.DUAL_CONTEXT), Matchers.anyBoolean()))
            .thenReturn(new HashSet<GrantedAuthority>());
    Mockito.doThrow(new AccessDeniedException("")).when(mockAccessValidator).checkAccess(Mockito.anyBoolean(),
            Mockito.anyBoolean(), Mockito.any(Entity.class), Mockito.anyString(), Mockito.anyCollection());
    Mockito.doThrow(new AccessDeniedException("")).when(mockAccessValidator).checkFieldAccess(
            Mockito.any(NeutralQuery.class), Mockito.any(Entity.class), Mockito.anyString(),
            Mockito.anyCollection());

    NeutralQuery query = new NeutralQuery();
    query.setLimit(ApiQuery.API_QUERY_DEFAULT_LIMIT);

    Method method = BasicService.class.getDeclaredMethod("getResponseEntities", NeutralQuery.class,
            boolean.class);
    method.setAccessible(true);

    try {
        RequestUtil.setCurrentRequestId();
        Collection<Entity> accessibleEntities = (Collection<Entity>) method.invoke(service, query, false);
    } catch (InvocationTargetException itex) {
        Assert.assertEquals(APIAccessDeniedException.class, itex.getCause().getClass());
        Assert.assertEquals("Access to resource denied.", itex.getCause().getMessage());
    }
}

From source file:org.occiware.clouddesigner.occi.docker.connector.dockerjava.DockerContainerManager.java

public CreateNetworkResponse createNetwork(final Machine machine, final Network network) {
    boolean _equals = Objects.equal(DockerContainerManager.dockerClient, null);
    if (_equals) {
        String _name = machine.getName();
        DockerClient _setConfig = this.setConfig(_name, this.properties);
        DockerContainerManager.dockerClient = _setConfig;
    } else {//from ww w.j  a v  a 2 s  . c  o  m
        String _name_1 = machine.getName();
        boolean _equalsIgnoreCase = DockerContainerManager.currentMachine.equalsIgnoreCase(_name_1);
        boolean _not = (!_equalsIgnoreCase);
        if (_not) {
            String _name_2 = machine.getName();
            DockerClient _setConfig_1 = this.setConfig(_name_2, this.properties);
            DockerContainerManager.dockerClient = _setConfig_1;
        }
    }
    List<com.github.dockerjava.api.model.Network.Ipam.Config> ipamConfigs = CollectionLiterals.<com.github.dockerjava.api.model.Network.Ipam.Config>newArrayList();
    com.github.dockerjava.api.model.Network.Ipam ipam = null;
    String _subnet = network.getSubnet();
    boolean _isNotBlank = StringUtils.isNotBlank(_subnet);
    if (_isNotBlank) {
        com.github.dockerjava.api.model.Network.Ipam.Config _config = new com.github.dockerjava.api.model.Network.Ipam.Config();
        String _subnet_1 = network.getSubnet();
        com.github.dockerjava.api.model.Network.Ipam.Config _withSubnet = _config.withSubnet(_subnet_1);
        ipamConfigs.add(_withSubnet);
    } else {
        com.github.dockerjava.api.model.Network.Ipam.Config _config_1 = new com.github.dockerjava.api.model.Network.Ipam.Config();
        com.github.dockerjava.api.model.Network.Ipam.Config _withSubnet_1 = _config_1
                .withSubnet("10.67.79.0/24");
        ipamConfigs.add(_withSubnet_1);
    }
    String _gateway = network.getGateway();
    boolean _isNotBlank_1 = StringUtils.isNotBlank(_gateway);
    if (_isNotBlank_1) {
        com.github.dockerjava.api.model.Network.Ipam.Config _config_2 = new com.github.dockerjava.api.model.Network.Ipam.Config();
        String _gateway_1 = network.getGateway();
        com.github.dockerjava.api.model.Network.Ipam.Config _withGateway = _config_2.withGateway(_gateway_1);
        ipamConfigs.add(_withGateway);
    }
    String _ip_range = network.getIp_range();
    boolean _isNotBlank_2 = StringUtils.isNotBlank(_ip_range);
    if (_isNotBlank_2) {
        com.github.dockerjava.api.model.Network.Ipam.Config _config_3 = new com.github.dockerjava.api.model.Network.Ipam.Config();
        String _ip_range_1 = network.getIp_range();
        com.github.dockerjava.api.model.Network.Ipam.Config _withIpRange = _config_3.withIpRange(_ip_range_1);
        ipamConfigs.add(_withIpRange);
    }
    try {
        com.github.dockerjava.api.model.Network _network = new com.github.dockerjava.api.model.Network();
        com.github.dockerjava.api.model.Network.Ipam _ipam = _network.getIpam();
        com.github.dockerjava.api.model.Network.Ipam _withConfig = _ipam.withConfig(ipamConfigs);
        ipam = _withConfig;
    } catch (final Throwable _t) {
        if (_t instanceof InvocationTargetException) {
            final InvocationTargetException exception = (InvocationTargetException) _t;
            Throwable _cause = exception.getCause();
            String _message = _cause.getMessage();
            String _plus = (" InvocationTargetException: " + _message);
            DockerContainerManager.LOGGER.error(_plus);
        } else if (_t instanceof Exception) {
            final Exception e = (Exception) _t;
            String _message_1 = e.getMessage();
            String _plus_1 = ("Exception:" + _message_1);
            DockerContainerManager.LOGGER.error(_plus_1);
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
    CreateNetworkCmd _createNetworkCmd = DockerContainerManager.dockerClient.createNetworkCmd();
    CreateNetworkCmd createNetworkCmd = _createNetworkCmd.withIpam(ipam);
    String _name_3 = network.getName();
    boolean _isNotBlank_3 = StringUtils.isNotBlank(_name_3);
    if (_isNotBlank_3) {
        String _name_4 = network.getName();
        CreateNetworkCmd _withName = createNetworkCmd.withName(_name_4);
        createNetworkCmd = _withName;
    }
    String _driver = network.getDriver();
    boolean _isNotBlank_4 = StringUtils.isNotBlank(_driver);
    if (_isNotBlank_4) {
        String _driver_1 = network.getDriver();
        CreateNetworkCmd _withDriver = createNetworkCmd.withDriver(_driver_1);
        createNetworkCmd = _withDriver;
    }
    CreateNetworkResponse createNetworkResponse = createNetworkCmd.exec();
    return createNetworkResponse;
}

From source file:org.apache.sqoop.mapreduce.hcat.SqoopHCatUtilities.java

public void executeHCatProgramInProcess(String[] argv) throws IOException {
    SubprocessSecurityManager subprocessSM = null;

    try {/*from ww w .j a va  2 s  . c o  m*/
        Class<?> cliDriverClass = Class.forName(HCAT_CLI_MAIN_CLASS);
        subprocessSM = new SubprocessSecurityManager();
        subprocessSM.install();
        Method mainMethod = cliDriverClass.getMethod("main", argv.getClass());
        mainMethod.invoke(null, (Object) argv);
    } catch (ClassNotFoundException cnfe) {
        throw new IOException("HCatalog class not found", cnfe);
    } catch (NoSuchMethodException nsme) {
        throw new IOException("Could not access HCatCli.main()", nsme);
    } catch (IllegalAccessException iae) {
        throw new IOException("Could not access HatCli.main()", iae);
    } catch (InvocationTargetException ite) {
        // This may have been the ExitSecurityException triggered by the
        // SubprocessSecurityManager.
        Throwable cause = ite.getCause();
        if (cause instanceof ExitSecurityException) {
            ExitSecurityException ese = (ExitSecurityException) cause;
            int status = ese.getExitStatus();
            if (status != 0) {
                throw new IOException("HCatCli  exited with status=" + status);
            }
        } else {
            throw new IOException("Exception thrown from HCatCli", ite);
        }
    } finally {
        if (null != subprocessSM) {
            subprocessSM.uninstall();
        }
    }
}