List of usage examples for java.lang.reflect InvocationTargetException getTargetException
public Throwable getTargetException()
From source file:com.payu.ratel.proxy.monitoring.ServiceInvocationHandler.java
@Override public Object invoke(Object o, Method method, Object[] args) throws Throwable { final Object returned; ServiceCallResult serviceResult = null; ProcessContext processCtx = ProcessContext.getInstance(); ServiceCallInput input = new ServiceCallInput(method.getName(), args, this.apiClass); publishCallEvent(processCtx, input); try {//from w w w .ja v a 2 s . com returned = method.invoke(object, args); serviceResult = ServiceCallResult.success(returned); } catch (InvocationTargetException e) { // Invoked method threw a checked exception. // We must rethrow it. The client won't see the interceptor. Throwable exception = e.getTargetException(); serviceResult = createExceptionResult(exception); throw exception; } finally { publishResponseEvent(serviceResult, processCtx, input); } return returned; }
From source file:com.espertech.esper.event.bean.BeanInstantiatorByFactoryFastClass.java
public Object instantiate() { try {/*from w ww . j ava 2 s. c o m*/ return method.invoke(null, null); } catch (InvocationTargetException e) { String message = "Unexpected exception encountered invoking factory method '" + method.getName() + "' on class '" + method.getJavaMethod().getDeclaringClass().getName() + "': " + e.getTargetException().getMessage(); log.error(message, e); return null; } }
From source file:MBeanTyper.java
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (MBeanTyper.DEBUG) { System.err.println(" ++ method=" + method.getName() + ",args=" + args); }/*from w w w . ja va2 s . c o m*/ try { if (method.getDeclaringClass() == Object.class) { String name = method.getName(); if (name.equals("hashCode")) { return new Integer(this.hashCode()); } else if (name.equals("toString")) { return this.toString(); } else if (name.equals("equals")) { // FIXME: this needs to be reviewed - we should be // smarter about this ... return new Boolean(equals(args[0])); } } else if (isJMXAttribute(method) && (args == null || args.length <= 0)) { String name = method.getName().substring(3); return server.getAttribute(mbean, name); } String sig[] = (String[]) signatureCache.get(method); if (sig == null) { // get the method signature from the method argument directly // vs. the arguments passed, since there may be primitives that // are wrapped as objects in the arguments Class _args[] = method.getParameterTypes(); if (_args != null && _args.length > 0) { sig = new String[_args.length]; for (int c = 0; c < sig.length; c++) { if (_args[c] != null) { sig[c] = _args[c].getName(); } } } else { sig = new String[0]; } signatureCache.put(method, sig); } return server.invoke(mbean, method.getName(), args, sig); } catch (Throwable t) { if (MBeanTyper.DEBUG) { t.printStackTrace(); } if (t instanceof UndeclaredThrowableException) { UndeclaredThrowableException ut = (UndeclaredThrowableException) t; throw ut.getUndeclaredThrowable(); } else if (t instanceof InvocationTargetException) { InvocationTargetException it = (InvocationTargetException) t; throw it.getTargetException(); } else if (t instanceof MBeanException) { MBeanException me = (MBeanException) t; throw me.getTargetException(); } else { throw t; } } }
From source file:com.espertech.esper.epl.expression.ExprStaticMethodEvalInvoke.java
public Object evaluate(EventBean[] eventsPerStream, boolean isNewData, ExprEvaluatorContext exprEvaluatorContext) { if ((isConstantParameters) && (isCachedResult)) { return cachedResult; }/*from w ww . jav a 2s . c om*/ Object[] args = new Object[childEvals.length]; for (int i = 0; i < args.length; i++) { args[i] = childEvals[i].evaluate(eventsPerStream, isNewData, exprEvaluatorContext); } // The method is static so the object it is invoked on // can be null Object obj = null; try { Object result = staticMethod.invoke(obj, args); if (isConstantParameters) { cachedResult = result; isCachedResult = true; } if (chainEval.length == 0) { return result; } for (int i = 0; i < chainEval.length; i++) { result = chainEval[i].evaluate(result, eventsPerStream, isNewData, exprEvaluatorContext); if (result == null) { return result; } } return result; } catch (InvocationTargetException e) { String message = "Method '" + staticMethod.getName() + "' of class '" + classOrPropertyName + "' reported an exception: " + e.getTargetException(); log.error(message, e.getTargetException()); } return null; }
From source file:com.espertech.esper.epl.expression.dot.ExprDotMethodEvalNoDuck.java
public Object evaluate(Object target, EventBean[] eventsPerStream, boolean isNewData, ExprEvaluatorContext exprEvaluatorContext) { if (target == null) { return null; }/* w w w . j a v a 2 s.c o m*/ Object[] args = new Object[parameters.length]; for (int i = 0; i < args.length; i++) { args[i] = parameters[i].evaluate(eventsPerStream, isNewData, exprEvaluatorContext); } try { return method.invoke(target, args); } catch (InvocationTargetException e) { String message = JavaClassHelper.getMessageInvocationTarget(statementName, method.getJavaMethod(), target.getClass().getName(), args, e); log.error(message, e.getTargetException()); } return null; }
From source file:com.xpn.xwiki.plugin.charts.ChartingPlugin.java
public Chart generateChart(ChartParams params, XWikiContext context) throws GenerateException { try {// www. ja v a 2s . co m // Obtain the corresponding data source and wrap it into a data source object DataSource dataSource = MainDataSourceFactory.getInstance().create(params.getMap(ChartParams.SOURCE), context); String type = params.getString(ChartParams.TYPE); Plot plot; try { String factoryClassName = ChartingPlugin.class.getPackage().getName() + ".plots." + Character.toUpperCase(type.charAt(0)) + type.toLowerCase().substring(1) + "PlotFactory"; Class factoryClass = Class.forName(factoryClassName); Method method = factoryClass.getMethod("getInstance", new Class[] {}); PlotFactory factory = (PlotFactory) method.invoke(null, new Object[] {}); plot = factory.create(dataSource, params); } catch (InvocationTargetException e) { throw new GenerateException(e.getTargetException()); } catch (Throwable e) { throw new GenerateException(e); } ChartCustomizer.customizePlot(plot, params); JFreeChart jfchart = new JFreeChart(plot); ChartCustomizer.customizeChart(jfchart, params); return generatePngChart(jfchart, params, context); } catch (IOException ioe) { throw new GenerateException(ioe); } catch (DataSourceException dse) { throw new GenerateException(dse); } }
From source file:de.escidoc.core.om.business.indexer.IndexerResourceRequester.java
/** * get resource with given identifier from framework. * * @param identifier identifier/* w w w . j a v a 2s . co m*/ * @throws SystemException e */ private EscidocBinaryContent getInternalResource(final String identifier) throws SystemException { try { final BeanMethod method = methodMapper.getMethod(identifier, null, null, "GET", ""); final Object content = method.invokeWithProtocol(null); if (content != null && "EscidocBinaryContent".equals(content.getClass().getSimpleName())) { return (EscidocBinaryContent) content; } else if (content != null && "String".equals(content.getClass().getSimpleName())) { final EscidocBinaryContent escidocBinaryContent = new EscidocBinaryContent(); escidocBinaryContent.setMimeType(XmlUtility.MIME_TYPE_XML); escidocBinaryContent.setContent( new ByteArrayInputStream(((String) content).getBytes(XmlUtility.CHARACTER_ENCODING))); return escidocBinaryContent; } else { throw new SystemException("wrong object-type"); } } catch (final InvocationTargetException e) { if (!"AuthorizationException".equals(e.getTargetException().getClass().getSimpleName()) && !"InvalidStatusException".equals(e.getTargetException().getClass().getSimpleName())) { throw new SystemException(e); } } catch (final MethodNotFoundException e) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Error on caching internal resource."); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Error on caching internal resource.", e); } } catch (final Exception e) { throw new SystemException(e); } return null; }
From source file:com.chiorichan.account.AccountsKeeper.java
public Account accountConstruct(AccountLookupAdapter adapter, String userId, Object... params) throws LoginException { List<Class<?>> paramsClass = Lists.newLinkedList(); for (Object o : params) paramsClass.add(o.getClass());/*from w w w . j av a2 s . c o m*/ try { Constructor<? extends Account> constructor = adapter.getAccountClass() .getConstructor(paramsClass.toArray(new Class<?>[0])); return constructor.newInstance(params); } catch (InvocationTargetException e) { throw (LoginException) e.getTargetException(); } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | IllegalArgumentException e) { e.printStackTrace(); AccountManager.getLogger().severe("We had a problem constructing a new instance of '" + adapter.getAccountClass().getCanonicalName() + "' account class. We are not sure of the reason but this is most likely a SEVERE error. For the time being, we constructed a MemoryAccount but this is only temporary and logins will fail."); return new MemoryAccount(userId, AccountLookupAdapter.MEMORY_ADAPTER); } }
From source file:MethodCountingHandler.java
/** * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, * java.lang.reflect.Method, java.lang.Object[]) */// w ww . j a va2 s .com public Object invoke(Object proxy, Method meth, Object[] args) throws Throwable { try { this.invocationCount++; Object result = meth.invoke(impl, args); return result; } catch (final InvocationTargetException ex) { throw ex.getTargetException(); } }
From source file:com.jcraft.weirdx.XJSExtension.java
void dispatch(Client c) throws IOException { int len, i, k, m; InputOutput io = c.client;// w w w . j av a2 s.com String result = null; switch (c.data) { case 0: io.readPad(28); io.writeByte(1); io.writeByte(jswin != null ? 1 : 0); io.writeShort(c.seq); io.writePad(28); return; case 1: len = c.length * 4 - 32; io.readPad(28); if (len > 0) { io.readByte(c.bbuffer, 0, len); for (i = 0; i < len; i++) { if (c.bbuffer[i] == 0) break; c.cbuffer[i] = (char) (c.bbuffer[i] & 0xFF); } String str = new String(c.cbuffer, 0, i); try { Object a[] = new Object[1]; a[0] = str; Object r = jseval.invoke(jswin, a); if (r instanceof String) result = (String) r; else result = r.toString(); } catch (InvocationTargetException ite) { result = "" + ite.getTargetException(); } catch (Exception e) { result = "" + e; } } else { result = ""; } break; case 2: len = c.length * 4 - 32; int nargs = io.readInt(); io.readPad(24); String args[] = new String[nargs]; if (len > 0) { io.readByte(c.bbuffer, 0, len); for (i = 0; i < len; i++) { if (c.bbuffer[i] == 0) break; c.cbuffer[i] = (char) (c.bbuffer[i] & 0xFF); } String proc = new String(c.cbuffer, 0, i); ++i; for (k = 0; k < nargs; k++) { for (m = 0; i < len; i++) { if (c.bbuffer[i] == 0) break; c.cbuffer[m] = (char) (c.bbuffer[i] & 0xFF); m++; } args[k] = new String(c.cbuffer, 0, m); } try { Object[] a = new Object[2]; a[0] = proc; a[1] = args; Object r = jscall.invoke(jswin, a); if (r instanceof String) result = (String) r; else result = r.toString(); } catch (InvocationTargetException ite) { result = "" + ite.getTargetException(); } catch (Exception e) { result = "" + e; } } else { result = ""; } break; default: LOG.error("XJS: unknown code=" + c.data); } if (result != null) { io.writeByte(1); io.writePad(1); io.writeShort(c.seq); len = ((result.length() + 4) >> 2) << 2; io.writeInt(len / 4); io.writeInt(len); io.writePad(20); for (i = 0; i < result.length(); i++) { io.writeByte((byte) result.charAt(i)); } for (; i < len; i++) { io.writeByte(0); } } }