Examples of InvocationResult


Examples of org.mule.api.model.InvocationResult

    public void testMatchOnNoArgs() throws Exception
    {
        ReflectionEntryPointResolver resolver = new ReflectionEntryPointResolver();
        //This should fail because the Kiwi.bite() method has a void return type, and by default
        //void methods are ignorred
        InvocationResult result = resolver.invoke(new Kiwi(), getTestEventContext(NullPayload.getInstance()));
        assertEquals(result.getState(), InvocationResult.State.FAILED);

        resolver.setAcceptVoidMethods(true);
        result = resolver.invoke(new Kiwi(), getTestEventContext(NullPayload.getInstance()));
        assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
        assertEquals("bite", result.getMethodCalled());
    }
View Full Code Here

Examples of org.mule.api.model.InvocationResult

        e.setSuperclass(WaterMelon.class);
        e.setCallback(new DummyMethodCallback());
        Object proxy = e.create();

        MuleEventContext context = getTestEventContext("Blah");
        InvocationResult result = resolver.invoke(proxy, context);
        assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
    }
View Full Code Here

Examples of org.mule.api.model.InvocationResult

public class CustomEntryPointResolver implements EntryPointResolver
{

    public InvocationResult invoke(Object component, MuleEventContext context) throws Exception
    {
        return new InvocationResult(this,
                ((Target) component).custom(context.getMessage().getPayload()),
                Target.class.getMethod("custom", new Class[]{Object.class}));
    }
View Full Code Here

Examples of org.mule.api.model.InvocationResult

        boolean ignoreMethod = BooleanUtils.toBoolean(context.getMessage().<Boolean>getInboundProperty(MuleProperties.MULE_IGNORE_METHOD_PROPERTY));

        if (ignoreMethod)
        {
            //TODO: Removed once we have property scoping
            InvocationResult result = new InvocationResult(this, InvocationResult.State.NOT_SUPPORTED);
            result.setErrorMessage("Property: " + MuleProperties.MULE_IGNORE_METHOD_PROPERTY + " was set so skipping this resolver");
            return result;
        }

        // MULE-4874: this is needed in order to execute the transformers before determining the methodProp
        Object[] payload = getPayloadFromMessage(context);

        //TODO MULE-4953 I don't think the VM transport if managing invocation properties correctly, or maybe it is and this
        //is valid
        //Here I have to remove the 'method' property rather than just read it
        Object methodProp = context.getMessage().removeProperty(getMethodProperty(), PropertyScope.INVOCATION);
        if (methodProp == null)
        {
            methodProp = context.getMessage().getInboundProperty(getMethodProperty());
        }
        if (methodProp == null)
        {
            InvocationResult result = new InvocationResult(this, InvocationResult.State.FAILED);
            // no method for the explicit method header
            result.setErrorMessage(CoreMessages.propertyIsNotSetOnEvent(getMethodProperty()).toString());
            return result;
        }

        Method method;
        String methodName;
        if (methodProp instanceof Method)
        {
            method = (Method) methodProp;
            methodName = method.getName();
        }
        else
        {
            methodName = methodProp.toString();
            method = getMethodByName(component, methodName, context);
        }

        if (method != null && method.getParameterTypes().length == 0)
        {
            return invokeMethod(component, method, ClassUtils.NO_ARGS_TYPE);
        }

        if (method == null)
        {
            Class<?>[] classTypes = ClassUtils.getClassTypes(payload);

            method = ClassUtils.getMethod(component.getClass(), methodName, classTypes);
           
            if (method == null)
            {
                InvocationResult result = new InvocationResult(this, InvocationResult.State.FAILED);
                result.setErrorNoMatchingMethods(component, classTypes);
                return result;
            }

        }
View Full Code Here

Examples of org.mule.api.model.InvocationResult

            }
        }

        if (method == null)
        {
            InvocationResult result = new InvocationResult(this, InvocationResult.State.FAILED);
            result.setErrorNoMatchingMethods(component, classTypes);
            return result;
        }
        return invokeMethod(component, method, payload);
    }
View Full Code Here

Examples of org.mule.api.model.InvocationResult

    public InvocationResult invoke(Object component, MuleEventContext context) throws Exception
    {
        Object[] payload = getPayloadFromMessage(context);

        Method method;
        InvocationResult result;

        method = this.getMethodByArguments(component, payload);

        if (method != null)
        {
            return invokeMethod(component, method, payload);
        }

        Class<?>[] types = ClassUtils.getClassTypes(payload);

        // do any methods on the service accept a context?
        List<Method> methods = ClassUtils.getSatisfiableMethods(component.getClass(), types,
                isAcceptVoidMethods(), false, ignoredMethods, filter);

        int numMethods = methods.size();
        if (numMethods > 1)
        {
            result = new InvocationResult(this, InvocationResult.State.FAILED);
            // too many methods match the context argument
            result.setErrorTooManyMatchingMethods(component, types, StringMessageUtils.toString(methods));
            return result;

        }
        else if (numMethods == 1)
        {
            // found exact match for method with context argument
            method = this.addMethodByArguments(component, methods.get(0), payload);
        }
        else
        {
            methods = ClassUtils.getSatisfiableMethods(component.getClass(),
                ClassUtils.getClassTypes(payload), true, true, ignoredMethods);

            numMethods = methods.size();

            if (numMethods > 1)
            {
                result = new InvocationResult(this, InvocationResult.State.FAILED);
                // too many methods match the context argument
                result.setErrorTooManyMatchingMethods(component, types, StringMessageUtils.toString(methods));
                return result;
            }
            else if (numMethods == 1)
            {
                // found exact match for payload argument
                method = this.addMethodByArguments(component, methods.get(0), payload);
            }
            else
            {
                result = new InvocationResult(this, InvocationResult.State.FAILED);
                // no method for payload argument either - bail out
                result.setErrorNoMatchingMethods(component, ClassUtils.getClassTypes(payload));
                return result;
            }
        }

        return invokeMethod(component, method, payload);
View Full Code Here

Examples of org.mule.api.model.InvocationResult

    {
        Set<String> exceptions = new HashSet<String>();

        for (EntryPointResolver resolver : entryPointResolvers)
        {
            InvocationResult result = resolver.invoke(component, context);
            if (result.getState() == InvocationResult.State.SUCCESSFUL)
            {
                return result.getResult();
            }
            else
            {
                if (result.hasError())
                {
                    exceptions.add(result.getErrorMessage());
                }
            }
        }
        throw new EntryPointNotFoundException(CollectionUtils.toString(exceptions, true));
    }
View Full Code Here

Examples of org.mule.api.model.InvocationResult

        if (logger.isDebugEnabled())
        {
            logger.debug("Result of call " + methodCall + " is " + (result == null ? "null" : "not null"));
        }

        return new InvocationResult(this, result, method);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.