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.biokoframework.http.scenario.ScenarioRunner.java

public void test(String baseUrl) throws Exception {
    System.out.println("=== SCENARIO COLLECTOR: " + fScenario.scenarioName());
    for (Entry<String, ScenarioStep> eachScenario : fScenario.scenarioSteps()) {
        System.out.println("\t------ SCENARIO: " + eachScenario.getKey() + " --------");

        // Polymorphic visitor?
        try {//from ww  w . jav  a 2s.co m
            MethodUtils.invokeMethod(this, "test", new Object[] { baseUrl, eachScenario.getValue(), },
                    new Class[] { String.class, eachScenario.getValue().getClass() });
        } catch (NoSuchMethodException exception) {
            fail("[EASY MAN] '" + fScenario.scenarioName() + "' not testable, probably wrong class");
        } catch (InvocationTargetException exception) {
            if (exception.getCause() != null) {
                if (exception.getCause() instanceof Exception) {
                    throw (Exception) exception.getCause();
                } else if (exception.getCause() instanceof Error) {
                    throw (Error) exception.getCause();
                }
            } else {
                throw exception;
            }
        }
        System.out.println("\t------ END -------");
    }
    System.out.println("=== END ===");
}

From source file:org.statefulj.framework.core.actions.MethodInvocationAction.java

@SuppressWarnings("unchecked")
public void execute(Object stateful, String event, Object... parms) throws RetryException {
    try {//w  w  w  .j a v a 2 s. c  o  m

        // Parse out incoming parms to pass into the method
        //
        List<Object> parmList = new ArrayList<Object>(Arrays.asList(parms));

        // Remove the first Object in the parm list - it's our Return Value
        //
        MutableObject<Object> returnValue = (MutableObject<Object>) parmList.remove(0);

        // If there is a retry parameter object, pop it off 
        //
        popOffRetryParms(parmList);

        // Now build the list of parameters to pass into the method
        //
        List<Object> invokeParmList = buildInvokeParameters(stateful, event, parmList);

        if (invokeParmList.size() < this.parameters.length) {
            throw new RuntimeException("Incoming parameter list is incorrect, expected "
                    + this.parameters.length + " parameters, but have " + invokeParmList.size());
        }

        // Call the method on the Controller
        //
        Object retVal = invoke(stateful, event, invokeParmList);

        // If the return value is a String prefixed with "event:", then it's an event 
        // so forward the event to the FSM.  Else, return the value as-is
        //
        if (retVal instanceof String) {
            Pair<String, String> pair = this.parseResponse((String) retVal);
            if ("event".equals(pair.getLeft())) {
                this.fsm.onEvent(stateful, pair.getRight(), parms);
            } else {
                returnValue.setValue(retVal);
            }
        } else {
            returnValue.setValue(retVal);
        }
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (SecurityException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        if (e.getCause() instanceof RetryException) {
            throw (RetryException) e.getCause();
        }
    } catch (TooBusyException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.cassandra.schema.CompactionParams.java

public void validate() {
    try {/*from  w  w  w.j  a va2  s . co  m*/
        Map<?, ?> unknownOptions = (Map) klass.getMethod("validateOptions", Map.class).invoke(null, options);
        if (!unknownOptions.isEmpty()) {
            throw new ConfigurationException(format("Properties specified %s are not understood by %s",
                    unknownOptions.keySet(), klass.getSimpleName()));
        }
    } catch (NoSuchMethodException e) {
        logger.warn("Compaction strategy {} does not have a static validateOptions method. Validation ignored",
                klass.getName());
    } catch (InvocationTargetException e) {
        if (e.getTargetException() instanceof ConfigurationException)
            throw (ConfigurationException) e.getTargetException();

        Throwable cause = e.getCause() == null ? e : e.getCause();

        throw new ConfigurationException(format("%s.validateOptions() threw an error: %s %s", klass.getName(),
                cause.getClass().getName(), cause.getMessage()), e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationException("Cannot access method validateOptions in " + klass.getName(), e);
    }

    String minThreshold = options.get(Option.MIN_THRESHOLD.toString());
    if (minThreshold != null && !StringUtils.isNumeric(minThreshold)) {
        throw new ConfigurationException(
                format("Invalid value %s for '%s' compaction sub-option - must be an integer", minThreshold,
                        Option.MIN_THRESHOLD));
    }

    String maxThreshold = options.get(Option.MAX_THRESHOLD.toString());
    if (maxThreshold != null && !StringUtils.isNumeric(maxThreshold)) {
        throw new ConfigurationException(
                format("Invalid value %s for '%s' compaction sub-option - must be an integer", maxThreshold,
                        Option.MAX_THRESHOLD));
    }

    if (minCompactionThreshold() <= 0 || maxCompactionThreshold() <= 0) {
        throw new ConfigurationException(
                "Disabling compaction by setting compaction thresholds to 0 has been removed,"
                        + " set the compaction option 'enabled' to false instead.");
    }

    if (minCompactionThreshold() <= 1) {
        throw new ConfigurationException(
                format("Min compaction threshold cannot be less than 2 (got %d)", minCompactionThreshold()));
    }

    if (minCompactionThreshold() > maxCompactionThreshold()) {
        throw new ConfigurationException(format(
                "Min compaction threshold (got %d) cannot be greater than max compaction threshold (got %d)",
                minCompactionThreshold(), maxCompactionThreshold()));
    }
}

From source file:io.fabric8.maven.core.util.KubernetesResourceUtil.java

/**
 * Uses reflection to copy over default values from the defaultValues object to the targetValues
 * object similar to the following:/*from  ww  w .j  a  v  a 2s .c  o m*/
 *
 * <code>
\    * if( values.get${FIELD}() == null ) {
 *   values.(with|set){FIELD}(defaultValues.get${FIELD});
 * }
 * </code>
 *
 * Only fields that which use primitives, boxed primitives, or String object are copied.
 *
 * @param targetValues
 * @param defaultValues
 */
public static void mergeSimpleFields(Object targetValues, Object defaultValues) {
    Class<?> tc = targetValues.getClass();
    Class<?> sc = defaultValues.getClass();
    for (Method targetGetMethod : tc.getMethods()) {
        if (!targetGetMethod.getName().startsWith("get")) {
            continue;
        }

        Class<?> fieldType = targetGetMethod.getReturnType();
        if (!SIMPLE_FIELD_TYPES.contains(fieldType)) {
            continue;
        }

        String fieldName = targetGetMethod.getName().substring(3);
        Method withMethod = null;
        try {
            withMethod = tc.getMethod("with" + fieldName, fieldType);
        } catch (NoSuchMethodException e) {
            try {
                withMethod = tc.getMethod("set" + fieldName, fieldType);
            } catch (NoSuchMethodException e2) {
                continue;
            }
        }

        Method sourceGetMethod = null;
        try {
            sourceGetMethod = sc.getMethod("get" + fieldName);
        } catch (NoSuchMethodException e) {
            continue;
        }

        try {
            if (targetGetMethod.invoke(targetValues) == null) {
                withMethod.invoke(targetValues, sourceGetMethod.invoke(defaultValues));
            }
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e.getCause());
        }
    }
}

From source file:com.facebook.stetho.json.ObjectMapper.java

/**
 * Support mapping between arbitrary classes and {@link JSONObject}.
 * <note>/*from  www.ja v a  2  s . c o  m*/
 *   It is possible for a {@link Throwable} to be propagated out of this class if there is an
 *   {@link InvocationTargetException}.
 * </note>
 * @param fromValue
 * @param toValueType
 * @param <T>
 * @return
 * @throws IllegalArgumentException when there is an error converting. One of either
 * {@code fromValue.getClass()} or {@code toValueType} must be {@link JSONObject}.
 */
public <T> T convertValue(Object fromValue, Class<T> toValueType) throws IllegalArgumentException {
    if (fromValue == null) {
        return null;
    }

    if (toValueType != Object.class && toValueType.isAssignableFrom(fromValue.getClass())) {
        return (T) fromValue;
    }

    try {
        if (fromValue instanceof JSONObject) {
            return _convertFromJSONObject((JSONObject) fromValue, toValueType);
        } else if (toValueType == JSONObject.class) {
            return (T) _convertToJSONObject(fromValue);
        } else {
            throw new IllegalArgumentException("Expecting either fromValue or toValueType to be a JSONObject");
        }
    } catch (NoSuchMethodException e) {
        throw new IllegalArgumentException(e);
    } catch (IllegalAccessException e) {
        throw new IllegalArgumentException(e);
    } catch (InstantiationException e) {
        throw new IllegalArgumentException(e);
    } catch (JSONException e) {
        throw new IllegalArgumentException(e);
    } catch (InvocationTargetException e) {
        throw ExceptionUtil.propagate(e.getCause());
    }
}

From source file:org.pentaho.big.data.plugins.common.ui.VfsFileChooserHelper.java

public void setNamedCluster(NamedCluster namedCluster) {
    VfsFileChooserDialog dialog = Spoon.getInstance().getVfsFileChooserDialog(null, null);
    for (CustomVfsUiPanel currentPanel : dialog.getCustomVfsUiPanels()) {
        if (currentPanel != null) {
            try {
                Method setNamedCluster = currentPanel.getClass().getMethod("setNamedCluster",
                        new Class[] { String.class });
                setNamedCluster.invoke(currentPanel, namedCluster.getName());
            } catch (NoSuchMethodException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Couldn't set named cluster " + namedCluster.getName() + " on " + currentPanel
                            + " because it doesn't have setNamedCluster method.", e);
                }/*from   w w  w.  ja  v a  2 s .c  o m*/
            } catch (InvocationTargetException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Couldn't set named cluster " + namedCluster.getName() + " on " + currentPanel
                            + " because of exception.", e.getCause());
                }
            } catch (IllegalAccessException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Couldn't set named cluster " + namedCluster.getName() + " on " + currentPanel
                            + " because setNamedCluster method isn't accessible.", e);
                }
            }
        }
    }
}

From source file:org.unitils.core.reflect.ClassWrapper.java

/**
 * Creates an instance of this class using the default (no-arg) constructor.
 * An exception is raised when there is no such constructor
 *
 * @return An instance of this type, not null
 */// ww w.  j  a  v  a  2  s.  c o m
public Object createInstance() {
    if (wrappedClass.isMemberClass() && !isStatic(wrappedClass.getModifiers())) {
        throw new UnitilsException("Unable to create instance of type " + getName()
                + ". Type is a non-static inner class which is only know in the context of an instance of the enclosing class. Declare the inner class static to make construction possible.");
    }
    try {
        Constructor<?> constructor = wrappedClass.getDeclaredConstructor();
        constructor.setAccessible(true);
        return constructor.newInstance();

    } catch (NoSuchMethodException e) {
        throw new UnitilsException("Unable to create instance of type " + getName()
                + ". No default (no-argument) constructor found.", e);

    } catch (InstantiationException e) {
        throw new UnitilsException(
                "Unable to create instance of type " + getName() + ". Type is an abstract class.", e);

    } catch (Exception e) {
        Throwable cause = (e instanceof InvocationTargetException) ? e.getCause() : e;
        throw new UnitilsException("Unable to create instance of type " + getName() + ".", cause);
    }
}

From source file:com.krawler.br.exp.Variable.java

public void setValue(Object val, boolean insert) throws ProcessException {
    try {/*  w  ww.j av a 2 s  .  co m*/
        if (path != null) {
            Object container = scope.getScopeValue(name);
            String[] props = getPathProperties();
            int lastIdx = props.length - 1;
            int i = 0;
            while (i < lastIdx) {
                container = getProperty(container, props[i]);
                i++;
                container = getIndexedElement(container, i);
            }
            if (indices != null && indices.containsKey(lastIdx + 1)) {
                container = getProperty(container, props[lastIdx]);
                setIndexedElement(container, lastIdx + 1, val, insert);
            } else
                setProperty(container, props[lastIdx], val);
        } else {
            if (indices != null && indices.containsKey(0)) {
                Object container = scope.getScopeValue(name);
                setIndexedElement(container, 0, val, insert);
            } else
                scope.setScopeValue(name, val);
        }
    } catch (NoSuchMethodException ex) {
        throw new ProcessException("property not found: " + this, ex);
    } catch (IllegalAccessException ex) {
        throw new ProcessException("property not accessible: " + this, ex);
    } catch (InvocationTargetException ex) {
        throw new ProcessException("exception occured in accessing property: " + this, ex.getCause());
    }
}

From source file:com.qualogy.qafe.business.integration.java.JavaServiceProcessor.java

/**
 * The actual method calll is processed in this method
 * @param clazz/*w w w.j  a  v  a  2  s  .c o m*/
 * @param parameterTypes
 * @param instance
 * @param parameters
 * @param context 
 * @throws thrown when anything goes wrong upon calling the method
 * @return the outcome
 */
private Object executeMethod(JavaClass resource, String actualMethodName, Class[] parameterClasses,
        Object[] parameters, ApplicationContext context) throws ExternalException {
    Object instance = resource.getInstance();
    Object result = null;
    try {
        result = resource.getMethod(actualMethodName, parameterClasses).invoke(instance, parameters);
        if (instance instanceof HasMessage) {
            HasMessage hasMessage = (HasMessage) instance;
            List<String> messages = hasMessage.getMessages();
            for (String message : messages) {
                context.getWarningMessages().add(message);
            }
        }
    } catch (NoSuchMethodException e) {
        String errorMessage = resolveErrorMessage(e);
        throw new ExternalException(errorMessage, errorMessage, e);
    } catch (InvocationTargetException e) {
        String errorMessage = resolveErrorMessage(e.getTargetException());
        throw new ExternalException(e.getMessage(), errorMessage, e.getTargetException());
    } catch (IllegalAccessException e) {
        String errorMessage = resolveErrorMessage(e);
        throw new ExternalException(e.getMessage(), errorMessage, e.getCause());
    } catch (Exception e) {
        String errorMessage = resolveErrorMessage(e);
        throw new ExternalException(e.getMessage(), errorMessage, e.getCause());
    }
    return result;
}

From source file:pt.webdetails.cpf.SimpleContentGenerator.java

@Override
public void createContent() throws Exception {
    IParameterProvider pathParams = getPathParameters();// parameterProviders.get("path");

    try {/*from   ww  w  .  java 2s.c  o  m*/

        String path = pathParams.getStringParameter("path", null);
        String[] pathSections = StringUtils.split(path, "/");

        if (pathSections == null || pathSections.length == 0) {
            String method = getDefaultPath(path);
            if (!StringUtils.isEmpty(method)) {
                logger.warn("No method supplied, redirecting.");
                redirect(method);
            } else {
                logger.error("No method supplied.");
            }
        } else {

            final String methodName = pathSections[0];

            try {

                final Method method = getMethod(methodName);
                invokeMethod(methodName, method);

            } catch (NoSuchMethodException e) {
                String msg = "couldn't locate method: " + methodName;
                logger.warn(msg);
                getResponse().sendError(HttpServletResponse.SC_NOT_FOUND, msg);
            } catch (InvocationTargetException e) {
                // get to the cause and log properly
                Throwable cause = e.getCause();
                if (cause == null)
                    cause = e;
                handleError(methodName, cause);
            } catch (Exception e) {
                handleError(methodName, e);
            }

        }
    } catch (SecurityException e) {
        logger.warn(e.toString());
    }
}