Example usage for java.lang NoSuchMethodException toString

List of usage examples for java.lang NoSuchMethodException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.yahoo.validatar.execution.rest.JSON.java

/**
 * Uses the user provided query to process and return a JSON columnar format of the data.
 *
 * @param data The data from the REST call.
 * @param function The function name to invoke.
 * @param query The Query object being run.
 * @return The String JSON response of the call, null if exception (query is failed).
 *//*  ww w  . j  a  va 2s  . c  om*/
String convertToColumnarJSON(String data, String function, Query query) {
    try {
        log.info("Evaluating query using Javascript function: {}\n{}", function, query.value);
        evaluator.eval(query.value);
        Invocable invocable = (Invocable) evaluator;
        String columnarJSON = (String) invocable.invokeFunction(function, data);
        log.info("Processed response using query into JSON: {}", columnarJSON);
        return columnarJSON;
    } catch (ScriptException se) {
        log.error("Exception while processing input Javascript", se);
        query.setFailure(se.toString());
        query.addMessage(se.toString());
    } catch (NoSuchMethodException nsme) {
        log.error("Method {} not found in {}\n{}", function, query.value, nsme);
        query.setFailure(nsme.toString());
    }
    return null;
}

From source file:ai.general.net.RemoteMethodTest.java

/**
 * Tests synchronous call behavior.//from  w w w  .j  av  a  2  s .  c o m
 */
@Test
public void callSync() {
    final String kHomePath = "/remote_method/sync";
    final String kMethod = "/method";
    final String kUserAccount = "sync_user";
    Directory directory = Directory.Instance;
    Assert.assertTrue(directory.createPath(kHomePath + kMethod));
    try {
        Assert.assertTrue(directory.addHandler(kHomePath + kMethod, new MethodHandler(kMethod, false, null,
                getClass().getDeclaredMethod("method", int.class, int.class, double.class, String.class))));
    } catch (NoSuchMethodException e) {
        Assert.fail(e.toString());
    }

    Uri uri = new Uri("ws", kHostname, "/remote_method_test");
    WampConnectionTest.TestSender client_sender = new WampConnectionTest.TestSender();
    WampConnectionTest.TestSender server_sender = new WampConnectionTest.TestSender();
    WampConnection client = new WampConnection(uri, kUserAccount, "", client_sender);
    WampConnection server = new WampConnection(uri, kUserAccount, kHomePath, server_sender);
    server.welcome("test-session-" + kUserAccount);
    client.process(server_sender.getOutput());

    RemoteMethod<TestBean> remote_method = new RemoteMethod<TestBean>(client, kMethod, TestBean.class);
    CallProcessor processor = new CallProcessor(client, client_sender, server, server_sender);
    CallThread call_thread = new CallThread(remote_method, true, 100, 123, -3.14159, "sync");
    processor.start();
    call_thread.start();
    synchronized (call_thread) {
        while (call_thread.isAlive()) {
            try {
                call_thread.wait();
            } catch (InterruptedException e) {
            }
        }
    }
    synchronized (processor) {
        while (processor.isAlive()) {
            try {
                processor.wait();
            } catch (InterruptedException e) {
            }
        }
    }
    TestBean result = call_thread.getResult();
    Assert.assertNotNull(result);
    assertThat(result.getNumber(), is(123));
    assertThat(result.getReal(), is(-3.14159));
    assertThat(result.getText(), is("sync"));
    if (call_thread.getThreadCompletionTimeMillis() < processor.getThreadCompletionTimeMillis()) {
        Assert.fail("Call thread completion time: " + call_thread.getThreadCompletionTimeMillis()
                + ", Processor thread completion time: " + processor.getThreadCompletionTimeMillis());
    }

    client.close();
    server.close();
}

From source file:ai.general.net.RemoteMethodTest.java

/**
 * Tests asynchronous call behavior./*from   w w  w  .j  a  va2 s .c o  m*/
 */
@Test
public void callAsync() {
    final String kHomePath = "/remote_method/async";
    final String kMethod = "/method";
    final String kUserAccount = "async_user";
    Directory directory = Directory.Instance;
    Assert.assertTrue(directory.createPath(kHomePath + kMethod));
    try {
        Assert.assertTrue(directory.addHandler(kHomePath + kMethod, new MethodHandler(kMethod, false, null,
                getClass().getDeclaredMethod("method", int.class, int.class, double.class, String.class))));
    } catch (NoSuchMethodException e) {
        Assert.fail(e.toString());
    }

    Uri uri = new Uri("ws", kHostname, "/remote_method_test");
    WampConnectionTest.TestSender client_sender = new WampConnectionTest.TestSender();
    WampConnectionTest.TestSender server_sender = new WampConnectionTest.TestSender();
    WampConnection client = new WampConnection(uri, kUserAccount, "", client_sender);
    WampConnection server = new WampConnection(uri, kUserAccount, kHomePath, server_sender);
    server.welcome("test-session-" + kUserAccount);
    client.process(server_sender.getOutput());

    RemoteMethod<TestBean> remote_method = new RemoteMethod<TestBean>(client, kMethod, TestBean.class);
    CallProcessor processor = new CallProcessor(client, client_sender, server, server_sender);
    CallThread call_thread = new CallThread(remote_method, false, 100, -123, 3.14159, "async");
    processor.start();
    call_thread.start();
    synchronized (call_thread) {
        while (call_thread.isAlive()) {
            try {
                call_thread.wait();
            } catch (InterruptedException e) {
            }
        }
    }
    synchronized (processor) {
        while (processor.isAlive()) {
            try {
                processor.wait();
            } catch (InterruptedException e) {
            }
        }
    }
    RemoteMethodCall<TestBean> method_call = call_thread.getMethodCall();
    Assert.assertNotNull(method_call);
    assertThat(method_call.getState(), is(RemoteMethodCall.State.Completed));
    Assert.assertTrue(method_call.isSuccessful());
    TestBean result = method_call.getResult();
    Assert.assertNotNull(result);
    assertThat(result.getNumber(), is(-123));
    assertThat(result.getReal(), is(3.14159));
    assertThat(result.getText(), is("async"));
    if (call_thread.getThreadCompletionTimeMillis() > processor.getThreadCompletionTimeMillis()) {
        Assert.fail("Call thread completion time: " + call_thread.getThreadCompletionTimeMillis()
                + ", Processor thread completion time: " + processor.getThreadCompletionTimeMillis());
    }

    client.close();
    server.close();
}

From source file:ai.general.net.RemoteMethodTest.java

/**
 * Tests handling of call errors.//ww w  .  java  2 s.c  o m
 */
@Test
public void callError() {
    final String kHomePath = "/remote_method/error";
    final String kMethod = "/error";
    final String kUserAccount = "error_user";
    Directory directory = Directory.Instance;
    Assert.assertTrue(directory.createPath(kHomePath + kMethod));
    try {
        Assert.assertTrue(directory.addHandler(kHomePath + kMethod, new MethodHandler(kMethod, false, null,
                getClass().getDeclaredMethod("error", String.class, TestBean.class))));
    } catch (NoSuchMethodException e) {
        Assert.fail(e.toString());
    }

    Uri uri = new Uri("ws", kHostname, "/remote_method_test");
    WampConnectionTest.TestSender client_sender = new WampConnectionTest.TestSender();
    WampConnectionTest.TestSender server_sender = new WampConnectionTest.TestSender();
    WampConnection client = new WampConnection(uri, kUserAccount, "", client_sender);
    WampConnection server = new WampConnection(uri, kUserAccount, kHomePath, server_sender);
    server.welcome("test-session-" + kUserAccount);
    client.process(server_sender.getOutput());

    RemoteMethod<TestBean> remote_method = new RemoteMethod<TestBean>(client, kMethod, TestBean.class);
    CallProcessor processor = new CallProcessor(client, client_sender, server, server_sender);
    TestBean bean = new TestBean(1010, 0.1, "details");
    CallThread call_thread = new CallThread(remote_method, true, "remote method test", bean);
    processor.start();
    call_thread.start();
    synchronized (call_thread) {
        while (call_thread.isAlive()) {
            try {
                call_thread.wait();
            } catch (InterruptedException e) {
            }
        }
    }
    synchronized (processor) {
        while (processor.isAlive()) {
            try {
                processor.wait();
            } catch (InterruptedException e) {
            }
        }
    }
    RemoteMethodCall<TestBean> method_call = call_thread.getMethodCall();
    Assert.assertNotNull(method_call);
    assertThat(method_call.getState(), is(RemoteMethodCall.State.Completed));
    Assert.assertFalse(method_call.isSuccessful());
    assertThat(method_call.getErrorUri().toString(),
            is("wamp://error_user@general.ai" + kMethod + "#logic_error"));
    assertThat(method_call.getErrorDescription(), is("remote method test"));
    ObjectMapper mapper = new ObjectMapper();
    assertThat(mapper.convertValue(method_call.getErrorDetails(), TestBean.class), is(bean));
    if (call_thread.getThreadCompletionTimeMillis() < processor.getThreadCompletionTimeMillis()) {
        Assert.fail("Call thread completion time: " + call_thread.getThreadCompletionTimeMillis()
                + ", Processor thread completion time: " + processor.getThreadCompletionTimeMillis());
    }

    client.close();
    server.close();
}

From source file:org.callimachusproject.auth.AuthorizationManager.java

private void getAnnotationValues(Class<?> cls, Set<String> roles, Set<String> set) {
    for (Annotation ann : cls.getAnnotations()) {
        try {/*from   w  w  w .  j  ava 2  s . c om*/
            Method value = ann.annotationType().getMethod("value");
            Iri iri = value.getAnnotation(Iri.class);
            if (iri != null && roles.contains(iri.value())) {
                Object obj = value.invoke(ann);
                if (obj instanceof String[]) {
                    set.addAll(Arrays.asList((String[]) obj));
                }
            }
        } catch (NoSuchMethodException e) {
            continue;
        } catch (IllegalAccessException e) {
            continue;
        } catch (IllegalArgumentException e) {
            logger.error(e.toString(), e);
        } catch (InvocationTargetException e) {
            logger.error(e.toString(), e);
        }
    }
    for (Class<?> face : cls.getInterfaces()) {
        getAnnotationValues(face, roles, set);
    }
    if (cls.getSuperclass() != null) {
        getAnnotationValues(cls.getSuperclass(), roles, set);
    }
}

From source file:org.dancres.blitz.jini.lockmgr.VotingAdapter.java

/**
 * Performs actual voting on the VoteChannel using the JGroups
 * facilities for communication./*from   ww  w. j a  va2  s.c  o m*/
 */
public boolean vote(Object decree, int consensusType, long timeout) throws ChannelException {
    if (closed)
        throw new ChannelException("Channel was closed.");

    if (log.isDebugEnabled())
        log.debug("Conducting voting on decree " + decree + ", consensus type " + getConsensusStr(consensusType)
                + ", timeout " + timeout);

    int mode = GroupRequest.GET_ALL;

    // perform the consensus mapping
    switch (consensusType) {
    case VotingAdapter.VOTE_ALL:
        mode = GroupRequest.GET_ALL;
        break;
    case VotingAdapter.VOTE_ANY:
        mode = GroupRequest.GET_FIRST;
        break;
    case VotingAdapter.VOTE_MAJORITY:
        mode = GroupRequest.GET_MAJORITY;
        break;
    default:
        mode = GroupRequest.GET_ALL;
    }

    try {
        java.lang.reflect.Method method = this.getClass().getMethod("localVote", new Class[] { Object.class });

        MethodCall methodCall = new MethodCall(method, new Object[] { decree });

        if (log.isDebugEnabled())
            log.debug("Calling remote methods...");

        // vote
        RspList responses = rpcDispatcher.callRemoteMethods(null, methodCall, mode, timeout);

        if (log.isDebugEnabled())
            log.debug("Checking responses.");

        return processResponses(responses, consensusType);

    } catch (NoSuchMethodException nsmex) {

        // UPS!!! How can this happen?!

        if (log.isErrorEnabled())
            log.error("Could not find method localVote(Object). " + nsmex.toString());

        throw new UnsupportedOperationException("Cannot execute voting because of absence of "
                + this.getClass().getName() + ".localVote(Object) method.");
    }
}

From source file:org.lsc.SimpleSynchronize.java

/**
 * Invoke the hook method whether it's a postsync or postclean
 * /*  w w w .j  a va2s .  c o m*/
 * @param taskName the task name
 * @param servicePostHook the fully qualified name of the method to invoke
 * @param taskType the TaskType used to initialize the task 
 */
private void runPostHook(String taskName, String servicePostHook, TaskType taskType) {
    if (servicePostHook != null && servicePostHook.length() > 0) {
        LOGGER.debug("Service Post Hook found: " + servicePostHook);
        String hookClass = servicePostHook.substring(0, servicePostHook.lastIndexOf('.'));
        String hookMethod = servicePostHook.substring(servicePostHook.lastIndexOf('.') + 1);

        LOGGER.debug("Hook Class: " + hookClass);
        LOGGER.debug("Hook Method: " + hookMethod);

        if (hookClass.length() > 0 && hookMethod.length() > 0) {
            try {
                Class<?> clazz = Class.forName(hookClass);
                try {
                    // Try with a TaskType parameter
                    Method hook = clazz.getMethod(hookMethod, new Class<?>[] { TaskType.class });
                    hook.invoke(null, taskType);
                } catch (NoSuchMethodException e) {
                    // Try without parameter
                    Method hook = clazz.getMethod(hookMethod, new Class<?>[] {});
                    hook.invoke(null, new Object[0]);
                }
            } catch (ClassNotFoundException e) {
                LOGGER.error("Invalid Hook Class specified " + hookClass + " for task " + taskName);
                LOGGER.debug(e.toString(), e);
            } catch (NoSuchMethodException e) {
                LOGGER.error("Invalid hook method " + hookMethod + " specified for task " + taskName);
                LOGGER.debug(e.toString(), e);
            } catch (IllegalArgumentException e) {
                LOGGER.error("Invalid argument exception for hook method " + hookClass + "." + hookMethod);
                LOGGER.debug(e.toString(), e);
            } catch (IllegalAccessException e) {
                LOGGER.error("Illegal access exception for hook method " + hookClass + "." + hookMethod);
                LOGGER.debug(e.toString(), e);
            } catch (InvocationTargetException e) {
                LOGGER.error("Invocation target exception for hook method " + hookClass + "." + hookMethod);
                LOGGER.debug(e.toString(), e);
            }
        }
    }
}

From source file:TestModelBuilder.java

void setProperty(String name, Object target, Object value) throws SAXException {
    Method method = null;/*  w ww  .  j  a  v  a2 s .  c om*/
    try {
        method = target.getClass().getMethod("add" + name, value.getClass());
    } catch (NoSuchMethodException e) {
    }
    if (method == null)
        try {
            method = target.getClass().getMethod("set" + name, value.getClass());
        } catch (NoSuchMethodException e) {
        }
    if (method == null)
        try {
            value = ((SimpleElement) value).getText();
            method = target.getClass().getMethod("add" + name, String.class);
        } catch (NoSuchMethodException e) {
        }
    try {
        if (method == null)
            method = target.getClass().getMethod("set" + name, String.class);
        method.invoke(target, value);
    } catch (Exception e) {
        throw new SAXException(e.toString());
    }
}

From source file:org.evosuite.testcarver.testcase.EvoTestCaseCodeGenerator.java

@Override
public void createMethodCallStmt(final CaptureLog log, final int logRecNo) {
    if (log == null)
        throw new IllegalArgumentException("captured log must not be null");
    if (logRecNo <= -1)
        throw new IllegalArgumentException("log record number is invalid: " + logRecNo);
    if (isMaximumLengthReached())
        return;/*from  w ww.  j  a  v a 2s.c  o m*/

    // assumption: all necessary statements are created and there is one variable for each referenced object
    final int oid = log.objectIds.get(logRecNo);
    final Object[] methodArgs = log.params.get(logRecNo);
    final String methodName = log.methodNames.get(logRecNo);
    Class<?> type;
    try {
        final String typeName = log.getTypeName(oid);
        type = getClassForName(typeName);

        logger.debug("Creating method call statement for call to method {}.{}", typeName, methodName);

        final Class<?>[] methodParamTypeClasses = getMethodParamTypeClasses(log, logRecNo);
        final ArrayList<VariableReference> args = getArguments(methodArgs, methodParamTypeClasses);

        if (CaptureLog.OBSERVED_INIT.equals(methodName)) {
            // Person var0 = new Person();
            final ConstructorStatement constStmt = new ConstructorStatement(testCase,
                    new GenericConstructor(type.getDeclaredConstructor(methodParamTypeClasses), type), args);

            this.oidToVarRefMap.put(oid, testCase.addStatement(constStmt));
        } else {
            //------------------ handling for ordinary method calls e.g. var1 = var0.doSth();
            final Object returnValue = log.returnValues.get(logRecNo);

            if (CaptureLog.RETURN_TYPE_VOID.equals(returnValue)) {

                GenericMethod genericMethod = new GenericMethod(
                        this.getDeclaredMethod(type, methodName, methodParamTypeClasses), type);

                MethodStatement m = new MethodStatement(testCase, genericMethod, this.oidToVarRefMap.get(oid),
                        args);

                testCase.addStatement(m);
            } else {
                // final org.objectweb.asm.Type returnType = org.objectweb.asm.Type.getReturnType(methodDesc);
                logger.debug("Callee: {} ({})", this.oidToVarRefMap.get(oid), this.oidToVarRefMap.keySet());
                // Person var0 = var.getPerson();
                final MethodStatement m = new MethodStatement(testCase,
                        new GenericMethod(this.getDeclaredMethod(type, methodName, methodParamTypeClasses),
                                type),

                        this.oidToVarRefMap.get(oid), args);
                final Integer returnValueOID = (Integer) returnValue;
                this.oidToVarRefMap.put(returnValueOID, testCase.addStatement(m));
            }
        }
    } catch (NoSuchMethodException e) {
        logger.info("Method not found; this may happen e.g. if an exception is thrown in the constructor");
        return;
    } catch (final Exception e) {
        logger.info("Error at log record number {}: {}", logRecNo, e.toString());
        logger.info("Test case so far: " + testCase.toCode());
        logger.info(log.toString());

        CodeGeneratorException.propagateError(e,
                "[logRecNo = %s] - an unexpected error occurred while creating method call stmt for %s.",
                logRecNo, methodName);
    }
}