List of usage examples for java.lang.reflect InvocationTargetException getTargetException
public Throwable getTargetException()
From source file:com.quinsoft.zeidon.objectdefinition.LodDef.java
private int executeVmlConstraint(View view, ObjectConstraintType type) { Object object = getConstraintObject(view); try {/*from w ww . jav a2 s .c o m*/ Method method; try { method = object.getClass().getMethod(getConstraintOper(), ARGUMENT_TYPES1); Integer rc = (Integer) method.invoke(object, view, type.getVmlValue(), 0); return rc; } catch (NoSuchMethodException e1) { method = object.getClass().getMethod(getConstraintOper(), ARGUMENT_TYPES2); Integer rc = (Integer) method.invoke(object, view, type); return rc; } } catch (InvocationTargetException e) { Throwable target = e.getTargetException(); if (target instanceof ZeidonException) throw (ZeidonException) target; target = e.getCause(); if (target instanceof ZeidonException) throw (ZeidonException) target; throw ZeidonException.wrapException(e).appendMessage("Class = %s", object.getClass().getCanonicalName()) .appendMessage("Method name = %s", getConstraintOper()); } catch (Exception e) { throw ZeidonException.wrapException(e).appendMessage("Class = %s", object.getClass().getCanonicalName()) .appendMessage("Method name = %s", getConstraintOper()); } }
From source file:lineage2.gameserver.scripts.Scripts.java
/** * Method callScripts./*w ww . j av a 2s . c o m*/ * @param caller Player * @param className String * @param methodName String * @param args Object[] * @param variables Map<String,Object> * @return Object */ public Object callScripts(Player caller, String className, String methodName, Object[] args, Map<String, Object> variables) { Object o; Class<?> clazz; clazz = _classes.get(className); if (clazz == null) { _log.error("Script class " + className + " not found!"); return null; } try { o = clazz.newInstance(); } catch (Exception e) { _log.error("Scripts: Failed creating instance of " + clazz.getName(), e); return null; } if ((variables != null) && !variables.isEmpty()) { for (Map.Entry<String, Object> param : variables.entrySet()) { try { FieldUtils.writeField(o, param.getKey(), param.getValue()); } catch (Exception e) { _log.error("Scripts: Failed setting fields for " + clazz.getName(), e); } } } if (caller != null) { try { Field field = null; if ((field = FieldUtils.getField(clazz, "self")) != null) { FieldUtils.writeField(field, o, caller.getRef()); } } catch (Exception e) { _log.error("Scripts: Failed setting field for " + clazz.getName(), e); } } Object ret = null; try { Class<?>[] parameterTypes = new Class<?>[args.length]; for (int i = 0; i < args.length; i++) { parameterTypes[i] = args[i] != null ? args[i].getClass() : null; } ret = MethodUtils.invokeMethod(o, methodName, args, parameterTypes); } catch (NoSuchMethodException nsme) { _log.error("Scripts: No such method " + clazz.getName() + "." + methodName + "()!"); } catch (InvocationTargetException ite) { _log.error("Scripts: Error while calling " + clazz.getName() + "." + methodName + "()", ite.getTargetException()); } catch (Exception e) { _log.error("Scripts: Failed calling " + clazz.getName() + "." + methodName + "()", e); } return ret; }
From source file:de.xwic.appkit.core.dao.AbstractDAO.java
private Object getPropertyValue(IEntity entity, Property property, ValidationResult result) throws Exception { String keyPropName = entity.type().getName() + "." + property.getName(); try {/*from w w w. ja v a 2 s .co m*/ Method mRead = property.getDescriptor().getReadMethod(); if (mRead == null) { // the property is not defined on the entity class. Search for the property in the superclass // and use that. This is needed for cases where the entity is using the history and therefore // extending a base implementation PropertyDescriptor pd = new PropertyDescriptor(property.getName(), entity.getClass().getSuperclass()); mRead = pd.getReadMethod(); if (mRead == null) { throw new ConfigurationException("The property " + property.getName() + " can not be resolved on entity " + entity.getClass().getName()); } } Object value = mRead.invoke(entity, (Object[]) null); return value; } catch (Exception se) { Throwable e = se; while (e != null) { if (e instanceof SecurityException) { result.addWarning(keyPropName, ValidationResult.FIELD_REQUIRED_NOT_ACCESSABLE); break; } else if (e instanceof InvocationTargetException) { InvocationTargetException ite = (InvocationTargetException) e; e = ite.getTargetException(); if (e == ite) { break; } } else if (e instanceof UndeclaredThrowableException) { UndeclaredThrowableException ute = (UndeclaredThrowableException) e; e = ute.getUndeclaredThrowable(); if (e == ute) { break; } } else { throw se; } } } return null; }
From source file:com.taobao.itest.listener.TransactionalListener.java
/** * Run all {@link BeforeTransaction @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. * /* www.ja va2 s .c om*/ * @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()); rethrowException(ex.getTargetException()); } }
From source file:net.lightbody.bmp.proxy.jetty.xml.XmlConfiguration.java
private void configure(Object obj, XmlParser.Node cfg, int i) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { XmlParser.Node node = null;// ww w .j ava 2 s. c o m try { for (; i < cfg.size(); i++) { Object o = cfg.get(i); if (o instanceof String) continue; node = (XmlParser.Node) o; String tag = node.getTag(); if ("Set".equals(tag)) set(obj, node); else if ("Put".equals(tag)) put(obj, node); else if ("Call".equals(tag)) call(obj, node); else if ("Get".equals(tag)) get(obj, node); else if ("New".equals(tag)) newObj(obj, node); else if ("Ref".equals(tag)) refObj(obj, node); else throw new IllegalStateException("Unknown tag: " + tag); } } catch (InvocationTargetException e) { log.warn("Exception at " + node.toString(), e.getTargetException()); throw e; } catch (Error e) { log.debug(node); throw e; } catch (Exception e) { log.debug(node); if (e instanceof NoSuchMethodException) throw (NoSuchMethodException) e; if (e instanceof InvocationTargetException) throw (InvocationTargetException) e; if (e instanceof IllegalAccessException) throw (IllegalAccessException) e; if (e instanceof RuntimeException) throw (RuntimeException) e; } }
From source file:org.glowroot.central.SyntheticMonitorService.java
private SyntheticRunResult runJavaInternal(Constructor<?> defaultConstructor, Method testMethod, Object testArg, long startTick) throws Exception { long captureTime; long durationNanos; try {//from www. j av a2s.com testMethod.invoke(defaultConstructor.newInstance(), testArg); // capture time and duration before calling driver.quit() captureTime = clock.currentTimeMillis(); durationNanos = ticker.read() - startTick; } catch (InvocationTargetException e) { logger.debug(e.getMessage(), e); Throwable throwable = e.getTargetException(); if (throwable instanceof InterruptedException) { // probably shutdown requested (see close method above) throw (InterruptedException) throwable; } return ImmutableSyntheticRunResult.builder().captureTime(clock.currentTimeMillis()) .durationNanos(ticker.read() - startTick).throwable(throwable).build(); } finally { if (testArg instanceof JBrowserDriver) { // quit() can hang (easily reproducible on test that doesn't use testArg at all) ((JBrowserDriver) testArg).kill(); } } return ImmutableSyntheticRunResult.builder().captureTime(captureTime).durationNanos(durationNanos).build(); }
From source file:com.interface21.beans.BeanWrapperImpl.java
public Object invoke(String methodName, Object[] args) throws BeansException { try {// w w w. ja v a2 s.co m MethodDescriptor md = this.cachedIntrospectionResults.getMethodDescriptor(methodName); if (logger.isDebugEnabled()) logger.debug("About to invoke method [" + methodName + "]"); Object returnVal = md.getMethod().invoke(this.object, args); if (logger.isDebugEnabled()) logger.debug("Successfully invoked method [" + methodName + "]"); return returnVal; } catch (InvocationTargetException ex) { //if (ex.getTargetException() instanceof ClassCastException) // throw new TypeMismatchException(propertyChangeEvent, pd.getPropertyType(), ex); throw new MethodInvocationException(ex.getTargetException(), methodName); } catch (IllegalAccessException ex) { throw new FatalBeanException("Illegal attempt to invoke method [" + methodName + "] threw exception", ex); } catch (IllegalArgumentException ex) { throw new FatalBeanException("Illegal argument to method [" + methodName + "] threw exception", ex); } }
From source file:org.talend.mdm.repository.ui.wizards.imports.ImportServerObjectWizard.java
public void retriveServerRoot() { if (serverDef != null) { try {/*from w ww . j a va 2s . c om*/ getContainer().run(true, false, new RetriveProcess()); } catch (InvocationTargetException e) { if (!Util.handleConnectionException(getShell(), e.getTargetException(), null)) { MessageDialog.openWarning(getShell(), Messages.Common_Warning, Messages.AbstractDataClusterAction_ConnectFailed); } log.error(e); } catch (InterruptedException e) { MessageDialog.openWarning(getShell(), Messages.Common_Warning, Messages.AbstractDataClusterAction_ConnectFailed); log.error(e); } } }
From source file:com.alibaba.wasp.master.FMaster.java
/** * Utility for constructing an instance of the passed FMaster class. * * @param masterClass/*from ww w .j a va 2 s . com*/ * @param conf * @return FMaster instance. */ public static FMaster constructMaster(Class<? extends FMaster> masterClass, final Configuration conf) { try { Constructor<? extends FMaster> c = masterClass.getConstructor(Configuration.class); return c.newInstance(conf); } catch (InvocationTargetException ite) { Throwable target = ite.getTargetException() != null ? ite.getTargetException() : ite; if (target.getCause() != null) target = target.getCause(); throw new RuntimeException("Failed construction of Master: " + masterClass.toString(), target); } catch (Exception e) { throw new RuntimeException("Failed construction of Master: " + masterClass.toString() + ((e.getCause() != null) ? e.getCause().getMessage() : ""), e); } }
From source file:com.thoughtworks.go.config.GoConfigMigrationIntegrationTest.java
@Test public void shouldNotSupportedUncesseryMaterialFieldsAsPartOfMigration99() throws Exception { String configXml = "<cruise schemaVersion='99'>" + "<config-repos>\n" + " <config-repo pluginId=\"json.config.plugin\" id=\"config-repo-1\">\n" + " <git url=\"https://github.com/tomzo/gocd-json-config-example.git\" dest=\"dest\"/>\n" + " </config-repo>\n" + "</config-repos>" + "</cruise>"; String message = "Attribute 'dest' is not allowed to appear in element 'git'."; try {/*from w w w . j a v a 2 s . c o m*/ migrateXmlString(configXml, 99); fail(String.format( "Expected a failure. Reason: Cruise config file with version 98 is invalid. Unable to upgrade. Message:%s", message)); } catch (InvocationTargetException e) { assertThat(e.getTargetException().getCause().getMessage()).isEqualTo(message); } }