Example usage for java.lang NoSuchMethodException getCause

List of usage examples for java.lang NoSuchMethodException getCause

Introduction

In this page you can find the example usage for java.lang NoSuchMethodException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.ebayopensource.twin.ElementImpl.java

/** 
 * For internal use only. Creates an Element wrapping the given RemoteObject 
 * This should be used instead of new Element(), as it will instantiate the correct subclass.
 *//*from   w  ww.  ja  v  a  2  s .c  o  m*/
public static Element create(RemoteObject o) {
    if (o == null)
        return null;

    List<Class<?>> interfaces = new ArrayList<Class<?>>();
    interfaces.add(Element.class);
    interfaces.add(RemoteResourceInterface.class);

    final Class<? extends ControlType> controlTypeInterface = NameMappings
            .getTypeInterface((String) o.properties.get("controlType"));
    if (controlTypeInterface.equals(Desktop.class))
        return new DesktopImpl(o.session);
    if (controlTypeInterface != null)
        interfaces.add(controlTypeInterface);

    List<Class<? extends ControlPattern>> controlPatternInterfaces = getControlPatternInterfaces(o);
    interfaces.addAll(controlPatternInterfaces);

    final ElementImpl impl = new ElementImpl(o, controlTypeInterface, controlPatternInterfaces);
    if (interfaces.isEmpty())
        return impl;

    final HashSet<Class<?>> implementedPatterns = new HashSet<Class<?>>();
    for (Class<?> iface : interfaces)
        if (isInterfaceExtending(iface, ControlPattern.class))
            implementedPatterns.add(iface);

    return (Element) Proxy.newProxyInstance(ElementImpl.class.getClassLoader(),
            interfaces.toArray(new Class[interfaces.size()]), new InvocationHandler() {
                public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                    Method implMethod = null;
                    try {
                        implMethod = impl.getClass().getMethod(method.getName(), method.getParameterTypes());
                    } catch (NoSuchMethodException e) {
                        implMethod = impl.getClass().getDeclaredMethod(method.getName(),
                                method.getParameterTypes());
                    }
                    Require requirement = implMethod.getAnnotation(Require.class);
                    if (requirement != null) {
                        for (Class<?> pattern : requirement.pattern())
                            if (!implementedPatterns.contains(pattern))
                                throw new TwinException("This "
                                        + (impl.getControlType() == null ? "Unknown" : impl.getControlType())
                                        + " does not implement the control pattern " + pattern.getSimpleName());
                        if (requirement.type() != Void.class)
                            if (controlTypeInterface != requirement.type())
                                throw new TwinException("This "
                                        + (impl.getControlType() == null ? "Unknown" : impl.getControlType())
                                        + " is not of ControlType " + requirement.type().getSimpleName());
                    }
                    try {
                        return implMethod.invoke(impl, args);
                    } catch (InvocationTargetException e) {
                        throw e.getCause();
                    }
                }
            });
}

From source file:org.dspace.rest.providers.AbstractBaseProvider.java

public Object getEntity(EntityReference ref, String action) {

    if (action.lastIndexOf(".") > 0) {
        action = action.substring(0, action.lastIndexOf("."));
    }/* w  w w .  j ava2  s .c o  m*/

    if (func2actionMapGET_rev.containsKey(action)) {
        Object result;
        String function = getMethod(action, func2actionMapGET_rev);
        if (function == null) {
            throw new EntityException("Bad request", "Method not supported - not defined", 400);
        }

        Context context = null;
        try {
            context = new Context();
            UserRequestParams uparams = refreshParams(context);

            Object CE = entityConstructor.newInstance();
            Method method = CE.getClass().getMethod(function, funcParamsGET.get(action));
            result = method.invoke(CE, ref, uparams, context);
        } catch (NoSuchMethodException ex) {
            log.error(ex.getMessage(), ex);
            throw new EntityException("Not found", "Method not supported ", 404);
        } catch (SQLException ex) {
            log.error(ex.getMessage(), ex);
            throw new EntityException("Internal server error", "SQL error", 500);
        } catch (InvocationTargetException ex) {
            if (ex.getCause() != null) {
                log.error(ex.getCause(), ex.getCause());
                throw new EntityException(ex.getCause().toString(), "Invocation Target Exception", 500);
            } else {
                log.error(ex.getMessage(), ex);
                throw new EntityException("Internal server error", "Unknown error", 500);
            }
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            throw new EntityException("Internal server error", "Unknown error", 500);
        } finally {
            removeConn(context);
        }
        return result;
    } else {
        throw new EntityException("Bad request", "Method not supported " + action, 400);
    }
}

From source file:org.dspace.rest.providers.AbstractBaseProvider.java

public void updateEntity(EntityReference ref, Object entity, Map<String, Object> params) {
    Map<String, Object> inputVar = (HashMap<String, Object>) entity;
    String segments[] = getSegments(params);

    String action = "";
    if (segments.length > 3) {
        action = segments[3];//  w ww .  j  a  va2  s. c  om
        if (action.lastIndexOf(".") > 0) {
            action = action.substring(0, action.lastIndexOf("."));
        }
    }

    if (func2actionMapPUT_rev.containsKey(action)) {
        String function = getMethod(action, func2actionMapPUT_rev);
        if (function == null) {
            throw new EntityException("Bad request", "Method not supported - not defined", 400);
        }

        Context context = null;
        try {
            context = new Context();
            refreshParams(context);

            Object CE = entityConstructor.newInstance();
            Method method = CE.getClass().getMethod(function, funcParamsPUT.get(action));
            method.invoke(CE, ref, inputVar, context);
        } catch (NoSuchMethodException ex) {
            log.error(ex.getMessage(), ex);
            throw new EntityException("Not found", "Meethod not supported " + segments[3], 404);
        } catch (SQLException ex) {
            log.error(ex.getMessage(), ex);
            throw new EntityException("Internal server error", "SQL error", 500);
        } catch (InvocationTargetException ex) {
            if (ex.getCause() != null) {
                log.error(ex.getCause(), ex.getCause());
                throw new EntityException(ex.getCause().toString(), "Invocation Target Exception", 500);
            } else {
                log.error(ex.getMessage(), ex);
                throw new EntityException("Internal server error", "Unknown error", 500);
            }
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            throw new EntityException("Internal server error", "Unknown error", 500);
        } finally {
            removeConn(context);
        }
    } else {
        throw new EntityException("Bad request", "Maethod not supported " + action, 400);
    }
}

From source file:org.dspace.rest.providers.AbstractBaseProvider.java

public String createEntity(EntityReference ref, Object entity, Map<String, Object> params) {
    String result;//  w  ww .j a v a  2  s . co m
    Map<String, Object> inputVar = new HashMap<String, Object>();
    if (entity instanceof Map) {
        inputVar = (HashMap<String, Object>) entity;
    }

    String function;
    String[] mandatory_params;

    String action = "";
    String segments[] = getSegments(params);
    if (segments.length > 2) {
        action = segments[segments.length - 1];
        if (action.lastIndexOf(".") > 0) {
            action = action.substring(0, action.lastIndexOf("."));
        }
    }

    if (func2actionMapPOST_rev.containsKey(action)) {
        function = func2actionMapPOST_rev.get(action);
        if (function == null) {
            throw new EntityException("Bad request", "Method not supported - not defined", 400);
        }
        mandatory_params = inputParamsPOST.get(function);
        if (mandatory_params != null) {
            for (String param : mandatory_params) {
                if (inputVar.get(param) == null) {
                    throw new EntityException("Bad request", "Incomplete request [mandatory param]", 400);
                }
            }
        }

        Context context = null;
        try {
            context = new Context();
            refreshParams(context);

            Object CE = entityConstructor.newInstance();
            Method method = CE.getClass().getMethod(function, funcParamsPOST.get(action));
            if (entity instanceof Map) {
                result = (String) method.invoke(CE, ref, inputVar, context);
            } else {
                result = (String) method.invoke(CE, ref, entity, context);
            }
        } catch (NoSuchMethodException ex) {
            log.error(ex.getMessage(), ex);
            throw new EntityException("Not found", "Method not supported ", 404);
        } catch (SQLException ex) {
            log.error(ex.getMessage(), ex);
            throw new EntityException("Internal server error", "SQL error", 500);
        } catch (InvocationTargetException ex) {
            if (ex.getCause() != null) {
                log.error(ex.getCause(), ex.getCause());
                throw new EntityException(ex.getCause().toString(), "Invocation Target Exception", 500);
            } else {
                log.error(ex.getMessage(), ex);
                throw new EntityException("Internal server error", "Unknown error", 500);
            }
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            throw new EntityException("Internal server error", "Unknown error", 500);
        } finally {
            removeConn(context);
        }
        return result;
    } else {
        throw new EntityException("Bad request", "Method not supported " + action, 400);
    }
}

From source file:org.dspace.rest.providers.AbstractBaseProvider.java

public void deleteEntity(EntityReference ref, Map<String, Object> params) {
    String segments[] = getSegments(params);
    String action = "";
    Map<String, Object> inputVar = new HashMap<String, Object>();

    for (int x = 0; x < segments.length; x++) {
        switch (x) {
        case 1://from w  ww .  j  av a  2s. c om
            inputVar.put("base", segments[x]);
            break;
        case 2:
            inputVar.put("id", segments[x]);
            break;
        case 3:
            inputVar.put("element", segments[x]);
            break;
        case 4:
            String s = segments[x];
            if (s != null && !"".equals(s)) {
                if (s.lastIndexOf(".") > 0) {
                    s = s.substring(0, s.lastIndexOf("."));
                }
            }
            inputVar.put("eid", s);
            break;
        case 5:
            inputVar.put("trail", segments[x]);
            break;
        default:
            break;
        }
    }

    if (segments.length > 3) {
        action = segments[3];
    }

    if (func2actionMapDELETE_rev.containsKey(action)) {
        String function = getMethod(action, func2actionMapDELETE_rev);
        if (function == null) {
            throw new EntityException("Bad request", "Method not supported - not defined", 400);
        }
        Context context = null;
        try {
            context = new Context();
            refreshParams(context);

            Object CE = entityConstructor.newInstance();
            Method method = CE.getClass().getMethod(function, funcParamsDELETE.get(action));
            method.invoke(CE, ref, inputVar, context);
        } catch (NoSuchMethodException ex) {
            log.error(ex.getMessage(), ex);
            throw new EntityException("Not found", "Meethod not supported " + segments[3], 404);
        } catch (SQLException ex) {
            log.error(ex.getMessage(), ex);
            throw new EntityException("Internal server error", "SQL error", 500);
        } catch (InvocationTargetException ex) {
            if (ex.getCause() != null) {
                log.error(ex.getCause(), ex.getCause());
                throw new EntityException(ex.getCause().toString(), "Invocation Target Exception", 500);
            } else {
                log.error(ex.getMessage(), ex);
                throw new EntityException("Internal server error", "Unknown error", 500);
            }
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            throw new EntityException("Internal server error", "Unknown error", 500);
        } finally {
            removeConn(context);
        }
    } else {
        throw new EntityException("Bad request", "Method not supported " + action, 400);
    }
}

From source file:com.atlassian.jira.functest.framework.AdministrationImpl.java

private void reflectivelyInvoke(final Object self, final Class<?> clazz, final String methodName,
        final Class[] paramType, final Object[] params) {
    Preconditions.checkNotNull(self, "cannot invoke %s on null object", methodName);
    Method method = null;//  ww w  . java 2s  .  com
    try {
        method = clazz.getDeclaredMethod(methodName, paramType);
        method.setAccessible(true);
        method.invoke(self, params);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(String.format(
                "Error getting method '%s(%s)' for %s : possibly a library update has changed this method",
                methodName, Arrays.toString(paramType), clazz.getName()), e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException(String.format(
                "Error invoking method '%s(%s)' for %s : exception raised during method invocation : %s",
                e.getCause().getMessage(), methodName, Arrays.toString(paramType), clazz.getName()),
                e.getCause());
    } catch (IllegalAccessException e) {
        throw new RuntimeException(String.format(
                "Error invoking method '%s(%s)' for %s : possibly a security manager has prevented access to this method",
                methodName, Arrays.toString(paramType), clazz.getName()), e);
    } finally {
        if (method != null) {
            method.setAccessible(false);
        }
    }
}

From source file:org.sakaiproject.cheftool.VelocityPortletPaneledAction.java

/**
 * Dispatch to a "processAction" method based on reflection.
 * /*from w  w w . j  av  a 2  s  .co  m*/
 * @param methodBase
 *        The base name of the method to call.
 * @param methodExt
 *        The end name of the method to call.
 * @param req
 *        The HttpServletRequest.
 * @param res
 *        The HttpServletResponse
 * @throws PortletExcption,
 *         IOException, just like the "do" methods.
 */
protected void actionDispatch(String methodBase, String methodExt, HttpServletRequest req,
        HttpServletResponse res) {
    String methodName = null;
    try {
        // the method signature
        Class[] signature = new Class[2];
        signature[0] = RunData.class;
        signature[1] = Context.class;

        // the method name
        methodName = methodBase + methodExt;

        // find a method of this class with this name and signature
        Method method = getClass().getMethod(methodName, signature);

        // parameters - the context for a "do" should not be used, so we will send in null
        Object[] args = new Object[2];
        args[0] = (JetspeedRunData) req.getAttribute(ATTR_RUNDATA);
        args[1] = null;

        // make the call
        method.invoke(this, args);
    } catch (NoSuchMethodException e) {
        // try for a single parameter call
        try {
            // the method signature
            Class[] signature = new Class[1];
            signature[0] = RunData.class;

            // the method name
            methodName = methodBase + methodExt;

            // find a method of this class with this name and signature
            Method method = getClass().getMethod(methodName, signature);

            // parameters - the context for a "do" should not be used, so we will send in null
            Object[] args = new Object[1];
            args[0] = (JetspeedRunData) req.getAttribute(ATTR_RUNDATA);

            // make the call
            method.invoke(this, args);
        } catch (NoSuchMethodException e2) {
            M_log.warn("Exception calling method " + methodName + " " + e2);
        } catch (IllegalAccessException e2) {
            M_log.warn("Exception calling method " + methodName + " " + e2);
        } catch (InvocationTargetException e2) {
            String xtra = "";
            if (e2.getCause() != null)
                xtra = " (Caused by " + e2.getCause() + ")";
            M_log.warn("Exception calling method " + methodName + " " + e2 + xtra, e2);

        }
    } catch (IllegalAccessException e) {
        M_log.warn("Exception calling method " + methodName + " " + e);
    } catch (InvocationTargetException e) {
        String xtra = "";
        if (e.getCause() != null)
            xtra = " (Caused by " + e.getCause() + ")";
        M_log.warn("Exception calling method " + methodName + " " + e + xtra, e);
    }

}

From source file:com.tesora.dve.tools.CLIBuilder.java

public void parseLine(String line) {
    if (StringUtils.isBlank(line)) {
        return;// w  w  w.  j a  va 2s  .  c  o  m
    }

    final CommandType command = findCommand(line);

    if (command != null) {

        // We need to create a new scanner based on the command we found.
        try (final Scanner scanner = new Scanner(line)) {

            // And skip the length of the command to get to the args.
            for (int i = 0; i < command.getCmdLength(); i++) {
                scanner.next();
            }

            // Try the currentCommandMap first to map this command to a method name.
            String methodName = currentCommandMap.buildMethodName(command);

            if (methodName == null) {
                methodName = globalCommandMap.buildMethodName(command);
            }

            try {
                final Class<? extends CLIBuilder> cls = this.getClass();

                try {
                    final Method method = cls.getMethod(methodName);
                    method.invoke(this);
                } catch (final NoSuchMethodException e) {
                    final Method method = cls.getMethod(methodName, Scanner.class);
                    method.invoke(this, scanner);
                }
            } catch (final NoSuchMethodException nsme) {
                println("Error: Failed to locate method for '" + methodName + "'");
                returnCode = 3;
            } catch (final Throwable e) {
                println("Error: Failed to execute '" + line + "'"
                        + (e.getMessage() != null ? " - " + e.getMessage() : ""));
                final Throwable cause = e.getCause();
                if (cause != null) {
                    printlnIndent("Caused by: " + cause.getMessage());
                    if (debugMode && (printStream != null)) {
                        cause.printStackTrace(printStream);
                    }
                }
                returnCode = 2;
            }
        }
    } else {
        println("Error: Failed to find matching command for '" + line + "'");
        returnCode = 1;
    }
}

From source file:jef.tools.reflect.ClassEx.java

Object innerInvoke(Object obj, String method, boolean isStatic, Object... params) throws ReflectionException {
    try {/*  ww  w .  j  a va  2  s .  c om*/
        if (obj == null && !isStatic)
            obj = newInstance();
        List<Class<?>> list = new ArrayList<Class<?>>();
        for (Object pobj : params) {
            list.add(pobj.getClass());
        }
        MethodEx me = BeanUtils.getCompatibleMethod(cls, method, list.toArray(new Class[list.size()]));
        if (me == null) {
            NoSuchMethodException e = new NoSuchMethodException("Method:[" + cls.getName() + "::" + method
                    + "] not found with param count:" + params.length);
            throw new ReflectionException(e);
        }
        if (!Modifier.isPublic(me.getModifiers()) || !Modifier.isPublic(cls.getModifiers())) {
            try {
                me.setAccessible(true);
            } catch (SecurityException e) {
                System.out.println(me.toString() + "\n" + e.getMessage());
            }
        }
        return me.invoke(obj, params);
    } catch (IllegalAccessException e) {
        throw new ReflectionException(e);
    } catch (SecurityException e) {
        throw new ReflectionException(e);
    } catch (IllegalArgumentException e) {
        throw new ReflectionException(e);
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof Exception) {
            throw new ReflectionException((Exception) e.getCause());
        } else {
            throw new ReflectionException(e);
        }

    }
}

From source file:de.jwic.base.Control.java

public void actionPerformed(String actionId, String parameter) {

    String methodName;/*from w  ww.j av  a  2 s. c  o m*/
    if (actionId.length() == 0) {
        return;
    } else if (actionId.length() == 1) {
        methodName = ACTION_PREFIX + actionId.toUpperCase();
    } else {
        methodName = ACTION_PREFIX + actionId.substring(0, 1).toUpperCase() + actionId.substring(1);
    }

    // try to find a method of the implementing control class that
    // equals the actionId

    Method actionMethod = null;
    Object[] arguments = new Object[] { parameter };
    try {
        actionMethod = getClass().getMethod(methodName, new Class[] { String.class });
    } catch (NoSuchMethodException e) {
        // if the parameter is empty, try to find a method without arguments
        if (parameter.length() == 0) {
            arguments = null;
            try {
                actionMethod = getClass().getMethod(methodName, (Class[]) null);
            } catch (NoSuchMethodException e1) {
                // no method exists -> will be handled later
            }
        }
    }
    if (actionMethod == null) {
        // FLI: I do now throw an exception if the desired method was not found. It should
        // not break existing applications because this method was abstract in earlier versions 
        // so it can not be called accidently.
        log.error("A method to handle the action '" + actionId + "' does not exist in this control. ("
                + methodName + ")");
        throw new IllegalArgumentException("A method to handle the action '" + actionId
                + "' does not exist in this control. (" + methodName + ")");
    } else {
        try {
            actionMethod.invoke(this, arguments);
        } catch (IllegalArgumentException e) {
            log.error("Error invoking method " + actionMethod.getName(), e);
        } catch (IllegalAccessException e) {
            log.error("Error invoking method " + actionMethod.getName(), e);
        } catch (InvocationTargetException e) {
            Throwable t = e.getCause();
            if (t instanceof RuntimeException) {
                // forward the exception
                throw (RuntimeException) t;
            } else if (t != null) {
                String msg = "Error during invocation of action method " + actionMethod.getName();
                log.error(msg, t);
                throw new RuntimeException(msg, t);
            }
            String msg = "Unexpected InvocationTargetException";
            log.error(msg, e);
            throw new RuntimeException(msg);
        }
    }

}