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:info.magnolia.cms.servlets.MVCServletHandlerImpl.java

/**
 * Call the method through reflection/*w  ww. j a v  a  2  s  .  c  o  m*/
 * @param command
 * @return the name of the view to show (used in renderHtml)
 */
public String execute(String command) {
    String view = VIEW_ERROR;
    Method method;

    try {
        method = this.getClass().getMethod(command, new Class[] {});
        // method.setAccessible(true);
        view = (String) method.invoke(this, new Object[] {});
    } catch (InvocationTargetException e) {
        log.error("can't call command: " + command, e.getTargetException()); //$NON-NLS-1$
    } catch (Exception e) {
        log.error("can't call command: " + command, e); //$NON-NLS-1$
    }

    return view;
}

From source file:com.espertech.esper.event.bean.BeanInstantiatorByNewInstanceFastClass.java

public Object instantiate() {
    try {//from  w  ww.  j  av  a 2  s  . c  o  m
        return fastClass.newInstance();
    } catch (InvocationTargetException e) {
        String message = "Unexpected exception encountered invoking newInstance on class '"
                + fastClass.getJavaClass().getName() + "': " + e.getTargetException().getMessage();
        log.error(message, e);
        return null;
    }
}

From source file:com.workplacesystems.utilsj.UtilsjException.java

/**
 *
 * @param response/*from   w w w. ja v  a  2  s .  c  om*/
 * @param e
 */
public UtilsjException(String response, Exception e) {
    super(response, e);

    String message = getMessage();

    Throwable traced_exception = e;
    while (traced_exception instanceof InvocationTargetException) {
        InvocationTargetException ite = (InvocationTargetException) traced_exception;
        traced_exception = ite.getTargetException();
    }
    if (traced_exception instanceof UtilsjException)
        return;

    StringWriter sw = new StringWriter();
    PrintWriter pr = new PrintWriter(sw);
    printStackTrace(pr);
    message += new_line + new_line + sw.toString();

    log.fatal(message);

    (new IterativeCallback<Handler, Void>() {
        @Override
        protected void nextObject(Handler h) {
            h.handle(UtilsjException.this);
        }
    }).iterate(handlers);
}

From source file:de.openknowledge.extensions.jsf.model.ModelMethod.java

@Override
public void updateModel(FacesContext context) {
    ValueExpression expression = getValueExpression("value");
    SimpleMethodExpressionParser parser = new SimpleMethodExpressionParser(expression.getExpressionString());
    SimpleMethodExpression methodExpression = parser.parse();
    ExpressionFactory expressionFactory = notNull(context, "context may not be null").getApplication()
            .getExpressionFactory();/*from   w  ww  . j a va 2  s.  c  om*/
    ValueExpression baseExpression = expressionFactory.createValueExpression(context.getELContext(),
            "#{" + methodExpression.getBase() + '}', Object.class);
    Object baseValue = baseExpression.getValue(context.getELContext());
    Class<? extends Object> baseType = baseValue.getClass();
    UIInput[] parameterComponents = findComponents(methodExpression);
    Class<?>[] parameterTypes = findParameterTypes(context, methodExpression, expressionFactory,
            parameterComponents);
    Method method = findMethod(baseType, methodExpression.getMethodName(), parameterTypes);
    Object[] parameters = findParameters(context, methodExpression, expressionFactory, parameterComponents,
            parameterTypes);
    try {
        method.invoke(baseValue, parameters);
    } catch (InvocationTargetException e) {
        throw new ELException(e.getTargetException());
    } catch (Exception e) {
        throw new ELException(e);
    }
}

From source file:com.watchrabbit.executor.spring.ExecutorAnnotationBeanPostProcessor.java

private Callable<Object> prepareExtractingInvocationExCallable(Callable<Object> callable) {
    return () -> {
        try {//from   w w  w  .  jav  a  2  s . com
            return callable.call();
        } catch (InvocationTargetException ex) {
            LOGGER.debug("Extracting orginally thrown exception");
            if (ex.getTargetException() instanceof Exception) {
                throw (Exception) ex.getTargetException();
            } else {
                throw ex;
            }
        }
    };
}

From source file:de.mpg.escidoc.services.fledgeddata.webservice.oaiServlet.java

public String getResult(HttpServletRequest request, HttpServletResponse response, HashMap serverVerbs)
        throws Throwable {
    try {/*ww w .  java2 s .c  o m*/
        String verb = request.getParameter("verb");
        String result;
        Class verbClass = null;
        verbClass = (Class) serverVerbs.get(verb);
        if (verbClass == null) {
            verbClass = (Class) serverVerbs.get("BadVerb");
        }

        Method construct = verbClass.getMethod("construct",
                new Class[] { Properties.class, HttpServletRequest.class, HttpServletResponse.class });
        try {
            result = (String) construct.invoke(null, new Object[] { properties, request, response });
        } catch (InvocationTargetException e) {
            throw e.getTargetException();
        }
        return result;

    } catch (NoSuchMethodException e) {
        throw new OAIInternalServerError(e.getMessage());
    } catch (IllegalAccessException e) {
        throw new OAIInternalServerError(e.getMessage());
    }
}

From source file:Command.java

/**
 * This method implements the ActionListener interface. It is like invoke()
 * except that it catches the exceptions thrown by that method and rethrows
 * them as an unchecked RuntimeException
 *//*ww w.ja  va 2s .c  om*/
public void actionPerformed(ActionEvent e) {
    try {
        invoke(); // Call the invoke method
    } catch (InvocationTargetException ex) { // but handle the exceptions
        throw new RuntimeException("Command: " + ex.getTargetException().toString());
    } catch (IllegalAccessException ex) {
        throw new RuntimeException("Command: " + ex.toString());
    }
}

From source file:com.payu.ratel.proxy.UnicastingInvocationHandler.java

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    String serviceAddress = fetchStrategy.fetchServiceAddress(serviceApi.getName());

    if (StringUtils.isEmpty(serviceAddress)) {
        LOGGER.error("No instance named{}", serviceApi.getName());
        throw new NoServiceInstanceFound(serviceApi);
    }//w ww.j av  a 2  s.  c om

    final Object clientProxy = clientProxyGenerator.generate(serviceApi, serviceAddress, timeout);

    LOGGER.debug("Calling {} on address {}", serviceApi.getName(), serviceAddress);

    try {
        return method.invoke(clientProxy, args);
    } catch (InvocationTargetException e) {
        // Invoked method threw a checked exception.
        // We must rethrow it. The client won't see the interceptor.
        throw e.getTargetException();
    }
}

From source file:sh.scrap.scrapper.functions.StringFunctionFactory.java

@Override
public DataScrapperFunction create(String name, DataScrapperFunctionLibrary library, Object mainArgument,
        Map<String, Object> annotations) {
    return context -> subscription -> {
        Class<?> targetClass = stringUtils.contains(name) ? StringUtils.class : StringEscapeUtils.class;
        try {//from   w w w . j  av  a2 s . co  m
            Method method = findMethod(targetClass, name, mainArgument, annotations);
            if (method == null) {
                subscription.onError(new IllegalArgumentException("Unknown function [string:" + name + "]"));
                subscription.onComplete();
                return;
            }
            String[] paramIndexes = discoverer.getParameterNames(method);
            subscription.onSubscribe(new Subscription() {
                @Override
                public void request(long n) {
                    Object data = context.data();
                    context.objectProcessed(data);
                    Object[] invokeArgs = new Object[method.getParameterCount()];
                    invokeArgs[0] = data;
                    if (method.getParameterCount() > 1)
                        invokeArgs[1] = mainArgument;
                    for (int idx = method.getParameterCount() > 1 ? 2 : 1; idx < paramIndexes.length; idx++)
                        invokeArgs[idx] = annotations.get(paramIndexes[idx]);

                    try {
                        try {
                            data = method.invoke(method.getDeclaringClass(), invokeArgs);
                        } catch (InvocationTargetException e) {
                            throw e.getTargetException();
                        }
                    } catch (Throwable e) {
                        subscription.onError(e);
                        subscription.onComplete();
                        return;
                    }

                    subscription.onNext(context.withData(data));
                    subscription.onComplete();
                }

                @Override
                public void cancel() {
                }
            });
        } catch (IllegalArgumentException e) {
            subscription.onError(e);
            subscription.onComplete();
        }
    };
}

From source file:com.liferay.wsrp.proxy.ServiceHandler.java

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

    try {/*from  w ww  . j a  va2s  .c o  m*/
        return doInvoke(proxy, method, args);
    } catch (InvocationTargetException ite) {
        throw ite.getTargetException();
    }
}