Package org.mule.api.model

Examples of org.mule.api.model.InvocationResult


        {
            initCache(component, context);
        }
        catch (Exception e)
        {
            InvocationResult result = new InvocationResult(this, InvocationResult.State.NOT_SUPPORTED);
            result.setErrorMessage(e.toString());
            return result;
        }

        ConcurrentHashMap methodCache = getMethodCache(component);
        if(methodCache.size()==0)
        {
            InvocationResult result = new InvocationResult(this, InvocationResult.State.NOT_SUPPORTED);
            result.setErrorMessage("Component: " + component + " doesn't have any annotated methods, skipping.");
            return result;
        }

        Object[] payload;
        Method method = null;
        //We remove the property here as a workaround to MULE-4769
        Object tempMethod = context.getMessage().removeProperty(MuleProperties.MULE_METHOD_PROPERTY, PropertyScope.INVOCATION);
        String methodName = null;
        if (tempMethod != null && tempMethod instanceof Method)
        {
            method = (Method) tempMethod;
        }
        else
        {
            methodName = (String)tempMethod;
        }

        //If a method param is set use that over anything else. This is used by the @Reply Callbacks and where annotations are set
        //on the method
        if (methodName != null)
        {
            method = getMethodByName(component, methodName, context);
            if (method == null)
            {
                InvocationResult result = new InvocationResult(this, InvocationResult.State.NOT_SUPPORTED);
                result.setErrorMessage("Method not found: " + methodName + " on object: " + component.getClass() + ". If the component is a proxy there needs to be an interface on the proxy that defines this method");
                return result;
                //TODO i18n
            }
            payload = getPayloadForMethod(method, component, context);
        }
        else if (method != null)
        {
            payload = getPayloadForMethod(method, component, context);
        }
        else if (methodCache.size() == 1)
        {
            method = (Method) methodCache.values().iterator().next();
            payload = getPayloadForMethod(method, component, context);
        }
        else
        {
            InvocationResult result = new InvocationResult(this, InvocationResult.State.FAILED);
            result.setErrorMessage("Component: " + component + " has more than one method annotated, which means the target method name needs to be set on the event");
            return result;
        }
        return invokeMethod(component, method,
                (method.getParameterTypes().length == 0 ? ClassUtils.NO_ARGS : payload));
    }
View Full Code Here


        AnnotatedEntryPointResolver resolver = new AnnotatedEntryPointResolver();
        AnnotatedComponent component = new AnnotatedComponent();
        MuleEventContext context = getTestEventContext(TEST_PAYLOAD);
        //Since AnnotatedComponent2 has two annotated methods we need to set the method to call
        context.getMessage().setProperty(MuleProperties.MULE_METHOD_PROPERTY, "doStuff", PropertyScope.INVOCATION);
        InvocationResult result = resolver.invoke(component, context);
        assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
        assertTrue(result.getResult() instanceof Map);
        Map<?, ?> map = (Map<?, ?>)result.getResult();
        assertEquals(3, map.size());
        assertTrue(map.get("foo") instanceof Element);
        assertTrue((Boolean)map.get("isBarValue"));
        assertEquals("4", map.get("bar"));
    }
View Full Code Here

        AnnotatedEntryPointResolver resolver = new AnnotatedEntryPointResolver();
        AnnotatedComponent component = new AnnotatedComponent();
        MuleEventContext context = getTestEventContext(TEST_PAYLOAD);
        //Since AnnotatedComponent2 has two annotated methods we need to set the method to call
        context.getMessage().setProperty(MuleProperties.MULE_METHOD_PROPERTY, "doStuff2", PropertyScope.INVOCATION);
        InvocationResult result = resolver.invoke(component, context);
        assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
        assertTrue(result.getResult() instanceof Map);
        Map<?, ?> map = (Map<?, ?>)result.getResult();
        assertEquals(3, map.size());
        assertTrue(map.get("foo") instanceof Document);
        assertTrue((Boolean)map.get("isBarValue"));
        assertEquals(new Double(8), map.get("bar"));
    }
View Full Code Here

        AnnotatedEntryPointResolver resolver = new AnnotatedEntryPointResolver();
        AnnotatedComponent component = new AnnotatedComponent();
        MuleEventContext context = getTestEventContext(TEST_PAYLOAD);
        //Since AnnotatedComponent2 has two annotated methods we need to set the method to call
        context.getMessage().setProperty(MuleProperties.MULE_METHOD_PROPERTY, "doStuff3", PropertyScope.INVOCATION);
        InvocationResult result = resolver.invoke(component, context);
        assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
        assertTrue(result.getResult() instanceof Map);
        Map<?, ?> map = (Map<?, ?>)result.getResult();
        assertEquals(2, map.size());
        assertTrue(map.get("foo") instanceof Node);
        assertTrue(map.get("bar") instanceof NodeList);
        assertEquals(2, ((NodeList)map.get("bar")).getLength());
    }
View Full Code Here

        AnnotatedEntryPointResolver resolver = new AnnotatedEntryPointResolver();
        AnnotatedComponent component = new AnnotatedComponent();
        MuleEventContext context = getTestEventContext(TEST_PAYLOAD);
        //Since AnnotatedComponent2 has two annotated methods we need to set the method to call
        context.getMessage().setProperty(MuleProperties.MULE_METHOD_PROPERTY, "doStuff5", PropertyScope.INVOCATION);
        InvocationResult result = resolver.invoke(component, context);
        assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
        assertTrue(result.getResult() instanceof Map);
        Map<?, ?> map = (Map<?, ?>)result.getResult();
        assertEquals(1, map.size());
        assertNull(map.get("foo"));
    }
View Full Code Here

    public InvocationResult invoke(Object component, MuleEventContext context) throws Exception
    {
        if (component instanceof Callable)
        {
            Object result = ((Callable) component).onCall(context);
            return new InvocationResult(this, result, callableMethod);
        }
        else
        {
            InvocationResult result = new InvocationResult(this, InvocationResult.State.NOT_SUPPORTED);
            result.setErrorMessage(CoreMessages.objectDoesNotImplementInterface(component, Callable.class).toString());
            return result;
        }
    }
View Full Code Here

        AnnotatedEntryPointResolver resolver = new AnnotatedEntryPointResolver();
        AnnotatedComponent component = new AnnotatedComponent();
        MuleEventContext context = getTestEventContext(TEST_PAYLOAD);
        //Since AnnotatedComponent2 has two annotated methods we need to set the method to call
        context.getMessage().setProperty(MuleProperties.MULE_METHOD_PROPERTY, "doStuff", PropertyScope.INVOCATION);
        InvocationResult result = resolver.invoke(component, context);
        assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
        assertTrue(result.getResult() instanceof Map);
        Map<?, ?> map = (Map<?, ?>)result.getResult();
        assertEquals(3, map.size());
        assertTrue(map.get("foo") instanceof JsonNode);
        assertTrue((Boolean)map.get("isBarValue"));
        assertEquals("4", map.get("bar"));
    }
View Full Code Here

        AnnotatedEntryPointResolver resolver = new AnnotatedEntryPointResolver();
        AnnotatedComponent component = new AnnotatedComponent();
        MuleEventContext context = getTestEventContext(TEST_PAYLOAD);
        //Since AnnotatedComponent2 has two annotated methods we need to set the method to call
        context.getMessage().setProperty(MuleProperties.MULE_METHOD_PROPERTY, "doStuff2", PropertyScope.INVOCATION);
        InvocationResult result = resolver.invoke(component, context);
        assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
        assertTrue(result.getResult() instanceof Map);
        Map<?, ?> map = (Map<?, ?>)result.getResult();
        assertEquals(3, map.size());
        assertTrue(map.get("foo") instanceof JsonNode);
        assertTrue((Boolean)map.get("isBarValue"));
        assertEquals(new Double(8), map.get("bar"));
    }
View Full Code Here

        AnnotatedEntryPointResolver resolver = new AnnotatedEntryPointResolver();
        AnnotatedComponent component = new AnnotatedComponent();
        MuleEventContext context = getTestEventContext(TEST_PAYLOAD);
        //Since AnnotatedComponent2 has two annotated methods we need to set the method to call
        context.getMessage().setProperty(MuleProperties.MULE_METHOD_PROPERTY, "doStuff3", PropertyScope.INVOCATION);
        InvocationResult result = resolver.invoke(component, context);
        assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
        assertTrue(result.getResult() instanceof Map);
        Map<?, ?> map = (Map<?, ?>)result.getResult();
        assertEquals(2, map.size());
        assertTrue(map.get("foo") instanceof JsonNode);
        assertTrue(map.get("bar") instanceof List);
        assertEquals(2, ((List)map.get("bar")).size());
    }
View Full Code Here

        AnnotatedEntryPointResolver resolver = new AnnotatedEntryPointResolver();
        AnnotatedComponent component = new AnnotatedComponent();
        MuleEventContext context = getTestEventContext(TEST_PAYLOAD);
        //Since AnnotatedComponent2 has two annotated methods we need to set the method to call
        context.getMessage().setProperty(MuleProperties.MULE_METHOD_PROPERTY, "doStuff5", PropertyScope.INVOCATION);
        InvocationResult result = resolver.invoke(component, context);
        assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
        assertTrue(result.getResult() instanceof Map);
        Map<?, ?> map = (Map<?, ?>)result.getResult();
        assertEquals(1, map.size());
        assertNull(map.get("foo"));
    }
View Full Code Here

TOP

Related Classes of org.mule.api.model.InvocationResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.