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:org.springframework.web.servlet.mvc.multiaction.MultiActionController.java

/**
 * We've encountered an exception thrown from a handler method.
 * Invoke an appropriate exception handler method, if any.
 * @param request current HTTP request/*  w  w  w  .  j a  va 2 s.  com*/
 * @param response current HTTP response
 * @param ex the exception that got thrown
 * @return a ModelAndView to render the response
 */
private ModelAndView handleException(HttpServletRequest request, HttpServletResponse response, Throwable ex)
        throws Exception {

    Method handler = getExceptionHandler(ex);
    if (handler != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Invoking exception handler [" + handler + "] for exception: " + ex);
        }
        try {
            Object returnValue = handler.invoke(this.delegate, request, response, ex);
            return massageReturnValueIfNecessary(returnValue);
        } catch (InvocationTargetException ex2) {
            logger.error("Original exception overridden by exception handling failure", ex);
            ReflectionUtils.rethrowException(ex2.getTargetException());
        } catch (Exception ex2) {
            logger.error("Failed to invoke exception handler method", ex2);
        }
    } else {
        // If we get here, there was no custom handler or we couldn't invoke it.
        ReflectionUtils.rethrowException(ex);
    }
    throw new IllegalStateException("Should never get here");
}

From source file:org.sqsh.variables.PropertyVariable.java

@Override
public String setValue(String value) throws CannotSetValueError {

    Throwable failure = null;//from ww  w.  j  a va 2  s  .  c o  m

    if (settable == false) {

        throw new CannotSetValueError("The value of \"" + getName() + "\" is read only");
    }

    if (failure == null) {

        try {

            Object o = getManager().getBean(bean);
            BeanUtils.setProperty(o, property, value);
        } catch (InvocationTargetException e) {

            failure = e.getTargetException();
        } catch (Throwable e) {

            failure = e;
        }
    }

    if (failure != null) {

        throw new CannotSetValueError("Cannot set variable \"" + getName() + "\" (bean property " + bean + "."
                + property + ") to \"" + value + "\": " + failure.getMessage(), failure);
    }

    return null;
}

From source file:org.squale.jraf.provider.accessdelegate.ExecuteHelper.java

/**
 * Convertie une InvocationTargetException en JrafEnterpriseException
 * @param in_ac application component /*from   w  w w  .  ja v  a 2 s .c o m*/
 * @param in_method method
 * @param in_ite exception
 * @throws JrafEnterpriseException
 */
public final static void convertInvocationTargetException(IApplicationComponent in_ac, String in_method,
        InvocationTargetException in_ite) throws JrafEnterpriseException {

    Throwable t = in_ite.getTargetException();
    if (t != null) {
        if (log.isDebugEnabled()) {
            log.debug("Probleme lors de l'invocation du composant " + in_ac.getApplicationComponent() + "."
                    + in_method, t);
        }
        if (t instanceof JrafEnterpriseException) {
            // deja une JRAFEnterpriseException
            throw (JrafEnterpriseException) t;

        } else {
            // on transforme l'exception contenu en JRAFEnterpriseException
            throw new JrafEnterpriseException("Probleme lors de l'invocation du composant "
                    + in_ac.getApplicationComponent() + "." + in_method, t);

        }

    } else {
        // cas anormal: L' InvocationTargetException ne contient pas
        // d'exception.
        // ne doit pas se produire
        if (log.isDebugEnabled()) {
            log.debug("Probleme lors de l'invocation du composant : l'exception recuperee n'est pas conforme. "
                    + in_ac.getApplicationComponent() + "." + in_method, in_ite);
        }

        throw new JrafEnterpriseException(
                "Probleme lors de l'invocation du composant : l'exception recuperee n'est pas conforme. "
                        + in_ac.getApplicationComponent() + "." + in_method,
                in_ite);
    }

}

From source file:org.squale.squalix.tools.compiling.java.parser.wsad.JWSADParser.java

/**
 * Sert  parser des block du manifest qui ont la mme DTD pBlock: string1, string2, string3 (par exemple les
 * parties Bundle-Required et Export-Package)
 * //from  www . jav  a  2 s .co m
 * @param pProject le projet
 * @param pManifest le manifest
 * @param pBlock le block  trouver
 * @param pMethod la mthode  appeler pour chaque ligne trouve
 * @throws ConfigurationException si erreur
 */
private void parseManifest(JWSADProject pProject, File pManifest, String pBlock, Method pMethod)
        throws ConfigurationException {
    try {
        // On rcupre toutes les valeurs (commence par un espace et se termine par un espace)
        BufferedReader reader = new BufferedReader(new FileReader(pManifest));
        String line = reader.readLine();
        String plugin = "";

        while (null != line && !line.startsWith(pBlock)) {
            // on parse jusqu' trouver la partie qui nous intresse
            line = reader.readLine();
        }
        if (null != line) {
            boolean stop = !line.endsWith(",");
            // On rcupre chaque plugin du Require-Bundle
            line = line.replaceFirst(pBlock + ": ", "");
            String[] plugins = line.split(",");
            for (int i = 0; i < plugins.length; i++) {
                pMethod.invoke(this, new Object[] { pProject, plugins[i].trim() });
            }
            line = reader.readLine();
            while (null != line && !stop) {
                if (line.endsWith(",")) {
                    plugins = line.split(",");
                    for (int i = 0; i < plugins.length; i++) {
                        pMethod.invoke(this, new Object[] { pProject, plugins[i].trim() });
                    }
                } else {
                    stop = true;
                    pMethod.invoke(this, new Object[] { pProject, line.trim() });
                }
                line = reader.readLine();
            }
        }
    } catch (IOException ioe) {
        throw new ConfigurationException(ioe.getMessage());
    } catch (InvocationTargetException ite) {
        throw new ConfigurationException(ite.getTargetException().getMessage());
    } catch (IllegalAccessException iae) {
        throw new ConfigurationException(iae.getMessage());
    }

}

From source file:org.squale.welcom.taglib.field.util.LayoutUtils.java

/**
 * copie les properties d'un objet vers un autre
 * /* www. j ava2  s.  co  m*/
 * @param dest l'objet destination
 * @param orig l'objet origine
 * @throws JspException exception pouvant etre levee
 */
public static void copyProperties(final Object dest, final Object orig) throws JspException {
    try {
        PropertyUtils.copyProperties(dest, orig);
    } catch (final InvocationTargetException e) {
        Throwable t = e.getTargetException();

        if (t == null) {
            t = e;
        }

        System.err.println("LayoutUtils.copyProperties: ");
        System.err.println(t);
        throw new JspException("LayoutUtils.copyProperties: " + t.getMessage());
    } catch (final Throwable t) {
        System.err.println("LayoutUtils.copyProperties: ");
        System.err.println(t);
        throw new JspException("LayoutUtils.copyProperties: " + t.getMessage());
    }
}

From source file:org.squale.welcom.taglib.html.OptionsTag.java

/**
 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
 *//*from  w ww  . j  av  a 2  s  .  c o m*/
public int doEndTag() throws JspException {
    // Recupere le droit sur la page
    final SelectTag selectTag = (SelectTag) super.pageContext
            .getAttribute("org.squale.welcom.taglib.html.SELECT");

    if (selectTag == null) {
        throw new JspException(messages.getMessage("optionsTag.select"));
    }
    final String pageAccess = selectTag.getResultAccess();

    if ((selectTag.isForceReadWrite() == true) || ((pageAccess != null) && pageAccess.equals(Access.READWRITE))
            || (pageAccess == null)) {
        final StringBuffer sb = new StringBuffer();

        if (collection != null) {
            Object label;
            String stringValue;

            for (final Iterator collIterator = getIterator(collection, null); collIterator.hasNext(); addOption(
                    sb, stringValue, label.toString(), selectTag.isMatched(stringValue))) {
                final Object bean = collIterator.next();
                Object value = null;
                label = null;

                try {
                    if (bean instanceof WCouple) {
                        value = ((WCouple) bean).getValue();
                    } else {
                        value = PropertyUtils.getProperty(bean, property);
                    }

                    if (value == null) {
                        value = "";
                    }
                } catch (final IllegalAccessException _ex) {
                    throw new JspException(messages.getMessage("getter.access", property, collection));
                } catch (final InvocationTargetException e) {
                    final Throwable t = e.getTargetException();
                    throw new JspException(messages.getMessage("getter.result", property, t.toString()));
                } catch (final NoSuchMethodException _ex) {
                    throw new JspException(messages.getMessage("getter.method", property, collection));
                }

                try {
                    if (bean instanceof WCouple) {
                        label = ((WCouple) bean).getLabel();
                    }

                    if (labelProperty != null) {
                        label = PropertyUtils.getProperty(bean, labelProperty);
                    } else {
                        if (GenericValidator.isBlankOrNull((String) label)) {
                            label = value;
                        }
                    }

                    if (label == null) {
                        label = "";
                    }
                } catch (final IllegalAccessException _ex) {
                    throw new JspException(messages.getMessage("getter.access", labelProperty, collection));
                } catch (final InvocationTargetException e) {
                    final Throwable t = e.getTargetException();
                    throw new JspException(messages.getMessage("getter.result", labelProperty, t.toString()));
                } catch (final NoSuchMethodException _ex) {
                    throw new JspException(messages.getMessage("getter.method", labelProperty, collection));
                }

                stringValue = value.toString();
            }
        } else {
            final Iterator valuesIterator = getIterator(name, property);
            Iterator labelsIterator = null;

            if ((labelName == null) && (labelProperty == null)) {
                labelsIterator = getIterator(name, property);
            } else {
                labelsIterator = getIterator(labelName, labelProperty);
            }

            String value;
            String label;

            for (; valuesIterator.hasNext(); addOption(sb, value, label, selectTag.isMatched(value))) {
                value = valuesIterator.next().toString();
                label = value;

                if (labelsIterator.hasNext()) {
                    label = labelsIterator.next().toString();
                }
            }
        }

        ResponseUtils.write(super.pageContext, sb.toString());
    } else {
        if (collection != null) {
            Object label;
            String stringValue;

            for (final Iterator collIterator = getIterator(collection, null); collIterator.hasNext();) {
                final Object bean = collIterator.next();
                Object value = null;
                label = null;

                try {
                    if (bean instanceof WCouple) {
                        value = ((WCouple) bean).getValue();
                    } else {
                        value = PropertyUtils.getProperty(bean, property);
                    }

                    if (value == null) {
                        value = "";
                    }
                } catch (final IllegalAccessException _ex) {
                    throw new JspException(messages.getMessage("getter.access", property, collection));
                } catch (final InvocationTargetException e) {
                    final Throwable t = e.getTargetException();
                    throw new JspException(messages.getMessage("getter.result", property, t.toString()));
                } catch (final NoSuchMethodException _ex) {
                    throw new JspException(messages.getMessage("getter.method", property, collection));
                }

                try {
                    if (bean instanceof WCouple) {
                        label = ((WCouple) bean).getLabel();
                    }

                    if (labelProperty != null) {
                        label = PropertyUtils.getProperty(bean, labelProperty);
                    } else {
                        if (GenericValidator.isBlankOrNull((String) label)) {
                            label = value;
                        }
                    }

                    if (label == null) {
                        label = "";
                    }
                } catch (final IllegalAccessException _ex) {
                    throw new JspException(messages.getMessage("getter.access", labelProperty, collection));
                } catch (final InvocationTargetException e) {
                    final Throwable t = e.getTargetException();
                    throw new JspException(messages.getMessage("getter.result", labelProperty, t.toString()));
                } catch (final NoSuchMethodException _ex) {
                    throw new JspException(messages.getMessage("getter.method", labelProperty, collection));
                }

                stringValue = value.toString();

                if (selectTag.isMatched(stringValue)) {
                    final StringBuffer results = new StringBuffer();
                    results.append("<span class=\"normalBold\">");
                    results.append(label);
                    results.append("</span>");
                    ResponseUtils.write(super.pageContext, results.toString());
                }
            }
        } else {
            final Iterator valuesIterator = getIterator(name, property);
            Iterator labelsIterator = null;

            if ((labelName == null) && (labelProperty == null)) {
                labelsIterator = getIterator(name, property);
            } else {
                labelsIterator = getIterator(labelName, labelProperty);
            }

            String value;
            String label;

            for (; valuesIterator.hasNext();) {
                value = valuesIterator.next().toString();
                label = value;

                if (labelsIterator.hasNext()) {
                    label = labelsIterator.next().toString();
                }

                if (selectTag.isMatched(value)) {
                    final StringBuffer results = new StringBuffer();
                    results.append("<span class=\"normalBold\">");
                    results.append(label);
                    results.append("</span>");
                    ResponseUtils.write(super.pageContext, results.toString());
                }
            }
        }
    }

    return EVAL_PAGE;
}

From source file:org.squale.welcom.taglib.html.OptionsTag.java

/**
 * @param pName nom du bean/*www  .  j  a  v a 2  s.c om*/
 * @param pProperty la property
 * @return l'interator
 * @throws JspException exception pouvant etre levee
 */
protected Iterator getIterator(final String pName, final String pProperty) throws JspException {
    String beanName = pName;

    if (beanName == null) {
        beanName = "org.apache.struts.taglib.html.BEAN";
    }

    final Object bean = super.pageContext.findAttribute(beanName);

    if (bean == null) {
        throw new JspException(messages.getMessage("getter.bean", beanName));
    }

    Object col = bean;

    if (pProperty != null) {
        try {
            col = PropertyUtils.getProperty(bean, pProperty);

            if (col == null) {
                throw new JspException(messages.getMessage("getter.property", pProperty));
            }
        } catch (final IllegalAccessException _ex) {
            throw new JspException(messages.getMessage("getter.access", pProperty, pName));
        } catch (final InvocationTargetException e) {
            final Throwable t = e.getTargetException();
            throw new JspException(messages.getMessage("getter.result", pProperty, t.toString()));
        } catch (final NoSuchMethodException _ex) {
            throw new JspException(messages.getMessage("getter.method", pProperty, pName));
        }
    }

    if (col.getClass().isArray()) {
        col = Arrays.asList((Object[]) col);
    }

    if (col instanceof Collection) {
        return ((Collection) col).iterator();
    }

    if (col instanceof Iterator) {
        return (Iterator) col;
    }

    if (col instanceof WComboValueLabel) {
        return ((WComboValueLabel) col).iterator();
    }

    if (col instanceof Map) {
        return ((Map) col).entrySet().iterator();
    }

    if (col instanceof Enumeration) {
        return new EnumerationIterator((Enumeration) col);
    } else {
        throw new JspException(messages.getMessage("optionsTag.iterator", col.toString()));
    }
}

From source file:org.tangram.components.MetaLinkHandler.java

private TargetDescriptor callAction(HttpServletRequest request, HttpServletResponse response, Matcher matcher,
        Method method, TargetDescriptor descriptor, Object target) throws Throwable, IllegalAccessException {
    TargetDescriptor result = null;/*from  w w w  .  jav a  2s .  c om*/
    LOG.debug("callAction() {} @ {}", method, target);

    if (method != null) {
        descriptor.action = null;
        List<Object> parameters = new ArrayList<>();
        Annotation[][] allAnnotations = method.getParameterAnnotations();
        Class<? extends Object>[] parameterTypes = method.getParameterTypes();
        for (int typeIndex = 0; typeIndex < parameterTypes.length; typeIndex++) {
            Annotation[] annotations = allAnnotations[typeIndex];
            Class<? extends Object> type = parameterTypes[typeIndex];
            if (type.equals(HttpServletRequest.class)) {
                parameters.add(request);
            } // if
            if (type.equals(HttpServletResponse.class)) {
                parameters.add(response);
            } // if
            Map<String, String[]> parameterMap = null;
            for (Annotation annotation : annotations) {
                if (annotation instanceof LinkPart) {
                    String valueString = matcher.group(((LinkPart) annotation).value());
                    LOG.debug("callAction() parameter #{}='{}' should be of type {}", typeIndex, valueString,
                            type.getName());
                    parameters.add(propertyConverter.getStorableObject(null, valueString, type, request));
                } // if
                if (annotation instanceof ActionParameter) {
                    String parameterName = ((ActionParameter) annotation).value();
                    if ("--empty--".equals(parameterName)) {
                        parameterName = type.getSimpleName().toLowerCase();
                    } // if
                    if (parameterMap == null) {
                        parameterMap = viewUtilities.createParameterAccess(request).getParameterMap();
                    } // if
                    LOG.debug("callAction() parameter {} should be of type {}", parameterName, type.getName());
                    Object value = propertyConverter.getStorableObject(null,
                            request.getParameter(parameterName), type, request);
                    parameters.add(value);
                } // if
                if (annotation instanceof ActionForm) {
                    try {
                        Object form = type.newInstance();
                        JavaBean wrapper = new JavaBean(form);
                        for (String propertyName : wrapper.propertyNames()) {
                            String valueString = request.getParameter(propertyName);
                            Object value = propertyConverter.getStorableObject(null, valueString,
                                    wrapper.getType(propertyName), request);
                            wrapper.set(propertyName, value);
                        } // for
                        parameters.add(form);
                    } catch (Exception e) {
                        LOG.error("callAction() cannot create and fill form " + type.getName());
                    } // try/catch
                } // if
            } // for
        } // for

        LOG.info("callAction() calling method {} with {} parameters", method.getName(), parameters.size());
        try {
            descriptor = (TargetDescriptor) method.invoke(target, parameters.toArray());
        } catch (InvocationTargetException ite) {
            throw ite.getTargetException();
        } // try/catch
        LOG.info("callAction() result is {}", descriptor);
        result = descriptor;
    } // if
    LOG.info("callAction() link={}", result);
    return result;
}

From source file:org.tinygroup.template.rumtime.TemplateUtil.java

/**
 * //  ww  w . ja v  a2 s.  c o m
 *
 * @param object
 * @param methodName
 * @param parameters
 * @return
 * @throws TemplateException
 */
public static Object callMethod(Template template, TemplateContext context, Object object, String methodName,
        Object... parameters) throws TemplateException {
    try {
        TemplateFunction function = template.getTemplateEngine().getTemplateFunction(object, methodName);
        if (function != null) {
            return executeExtendFunction(template, context, object, function, parameters);
        } else {
            //?
            return executeClassMethod(object, methodName, parameters);
        }
    } catch (Exception e) {
        //??
        if (e instanceof InvocationTargetException) {
            InvocationTargetException e1 = (InvocationTargetException) e;
            throw new TemplateException(e1.getTargetException());
        }
        throw new TemplateException(e);
    }
}

From source file:org.unitime.timetable.solver.jgroups.CourseSolverContainerRemote.java

@Override
public Object invoke(String method, String user, Class[] types, Object[] args) throws Exception {
    try {/*w w w.  j  a v a2 s . c  o m*/
        SolverProxy solver = iCourseSolvers.get(user);
        if ("exists".equals(method) && types.length == 0)
            return solver != null;
        if (solver == null)
            throw new Exception("Solver " + user + " does not exist.");
        return solver.getClass().getMethod(method, types).invoke(solver, args);
    } catch (InvocationTargetException e) {
        if (e.getTargetException() != null && e.getTargetException() instanceof Exception)
            throw (Exception) e.getTargetException();
        else
            throw e;
    } finally {
        _RootDAO.closeCurrentThreadSessions();
    }
}