Package org.mule.api.component

Examples of org.mule.api.component.InterfaceBinding


        MuleMessage message = createMuleMessage(args);

        // Some transports such as Axis, RMI and EJB can use the method information
        message.setInvocationProperty(MuleProperties.MULE_METHOD_PROPERTY, method.getName());

        InterfaceBinding router = routers.get(method.getName());
        if (router == null)
        {
            router = routers.get(DEFAULT_METHOD_NAME_TOKEN);
        }

        if (router == null)
        {
            throw new IllegalArgumentException(CoreMessages.cannotFindBindingForMethod(method.getName()).toString());
        }

        MuleEvent currentEvent = RequestContext.getEvent();
        MuleEvent replyEvent = router.process(new DefaultMuleEvent(message,currentEvent));

        if (replyEvent != null && replyEvent.getMessage()!=null)
        {
            MuleMessage reply = replyEvent.getMessage();
            if (reply.getExceptionPayload() != null)
View Full Code Here


    }

    public Response invoke(InvocationContext ctx) throws Exception
    {
        InterfaceBinding router = routers.get(ctx.getMethod().toString());
        if (router == null)
        {
            throw new IllegalArgumentException(CoreMessages.cannotFindBindingForMethod(ctx.getMethod().getName()).toString());
        }
        router.getEndpoint().getProperties().putAll(ctx.getIBeanDefaultConfig().getPropertyParams());
        Request req = ctx.getRequest();
        MuleMessage message = ((MuleRequestMessage)req).getMessage();

        if (logger.isTraceEnabled())
        {
            try
            {
                logger.trace("Message Before invoking "
                        + ctx.getMethod()
                        + ": \n"
                        + StringMessageUtils.truncate(
                        StringMessageUtils.toString(message.getPayload()),
                        2000, false));
                logger.trace("Message Headers: \n"
                        + StringMessageUtils.headersToString(message));
            }
            catch (Exception e)
            {
                // ignore
            }
        }

//        MuleMessage message = new DefaultMuleMessage(req.getPayload(), muleContext);
//
//        message.addProperties(router.getEndpoint().getProperties(), PropertyScope.INVOCATION);
//        for (String s : req.getHeaderNames())
//        {
//            message.setOutboundProperty(s, req.getHeader(s));
//        }
//        for (String s : req.getAttachmentNames())
//        {
//            message.addAttachment(s, req.getAttachment(s));
//        }
      

        MuleEvent replyEvent = null;
        MuleMessage reply;
        MuleSession session = new DefaultMuleSession(flow, muleContext);

        try
        {
            replyEvent = router.process(new DefaultMuleEvent(message, router.getEndpoint()
                .getExchangePattern(), session));
       }
        catch (Throwable e)
        {
            //Make all exceptions go through the CallException handler
View Full Code Here

        return new MuleResponseMessage(replyEvent.getMessage());
    }

    public String getScheme(Method method)
    {
        InterfaceBinding router = routers.get(method.toString());
        if (router == null)
        {
            throw new IllegalArgumentException(CoreMessages.cannotFindBindingForMethod(method.getName()).toString());
        }
        return router.getEndpoint().getEndpointURI().getScheme();
    }
View Full Code Here

        return router.getEndpoint().getEndpointURI().getScheme();
    }

    ImmutableEndpoint getEndpointForMethod(Method method)
    {
        InterfaceBinding router = routers.get(method.toString());
        if (router != null)
        {
            return router.getEndpoint();
        }
        return null;
    }
View Full Code Here

        // Proxy
        if (bindings != null && bindings.size() > 0)
        {
            for (Iterator<?> it = bindings.iterator(); it.hasNext();)
            {
                InterfaceBinding interfaceBinding = (InterfaceBinding) it.next();
                String bindingName = ClassUtils.getSimpleName(interfaceBinding.getInterface());
                if (proxies.containsKey(bindingName))
                {
                    Object proxy = proxies.get(bindingName);
                    BindingInvocationHandler handler = (BindingInvocationHandler) Proxy.getInvocationHandler(proxy);
                    handler.addRouterForInterface(interfaceBinding);
                }
                else
                {
                    Object proxy = Proxy.newProxyInstance(getClass().getClassLoader(),
                        new Class[]{interfaceBinding.getInterface()},
                        new BindingInvocationHandler(interfaceBinding));
                    proxies.put(bindingName, proxy);
                }
            }
        }
View Full Code Here

                    for (Iterator iterator = c.iterator(); iterator.hasNext();)
                    {
                        EndpointAnnotationParser parser = (EndpointAnnotationParser) iterator.next();
                        if (parser.supports(metaData.getAnnotation(), metaData.getClazz(), metaData.getMember()))
                        {
                            InterfaceBinding binding;
                            Method method = (Method) metaData.getMember();
                            boolean callChannel = false;
                            Annotation ann;
                            //This is a little messy, but we need to detect whether we are doing a Mule 'send' or Mule 'request' call.
                            //Request calls get data from a resource such as DB, email inbox or message queue. These types of request will
                            //not have any payload or headers defined.
                            //The other way to handle this is to introduce a new annotation to explicitly handle this (See the Get annotation).
                            //The issue is it may be difficult for the user to understand the difference between @Call and @Get. Instead we figure it out
                            //here.
                            for (int x = 0; x < method.getParameterAnnotations().length; x++)
                            {
                                ann = method.getParameterAnnotations()[x][0];
                                if (ann.annotationType().equals(Body.class) ||
                                        ann.annotationType().equals(BodyParam.class) ||
                                        ann.annotationType().equals(HeaderParam.class))
                                {

                                    callChannel = true;

                                    break;
                                }
                            }
                            //TODO remove the HTTP hack above. Its required becuase HTTP request on the dispatcher
                            //don't honour authenitcation for some reason.  Also even though there may not be any headers
                            //defined we still need to attach some headers to the HTTP method. This is very difficult when
                            //using request
                            if (callChannel || http)
                            {
                                OutboundEndpoint endpoint = parser.parseOutboundEndpoint(metaData.getAnnotation(), metaInfo);
                                binding = new CallInterfaceBinding(this.flow);
                                binding.setEndpoint(endpoint);
                            }
                            else
                            {
                                InboundEndpoint endpoint = parser.parseInboundEndpoint(metaData.getAnnotation(), Collections.EMPTY_MAP);
                                binding = new DynamicRequestInterfaceBinding();
                                binding.setEndpoint(endpoint);
                            }

                            binding.setInterface(getInterface());
                            binding.setMethod(metaData.getMember().toString());
                            invoker.getCallHandler().addRouterForInterface(binding);

                        }
                    }
                }
View Full Code Here

        List<InterfaceBinding> bindings= ((JavaComponent) service.getComponent()).getInterfaceBindings();
        assertNotNull(bindings);

        assertEquals(2, bindings.size());
        // check first Router
        InterfaceBinding route1 = bindings.get(0);
        assertEquals(FruitCleaner.class, route1.getInterface());
        assertEquals("wash", route1.getMethod());
        assertNotNull(route1.getEndpoint());
        // check second Router
        InterfaceBinding route2 = bindings.get(1);
        assertEquals(FruitCleaner.class, route2.getInterface());
        assertEquals("polish", route2.getMethod());
        assertNotNull(route1.getEndpoint());
    }
View Full Code Here

    {
        //Test that the proxy object was created and set on the service object
        Service orange = muleContext.getRegistry().lookupService("orangeComponent");
        assertNotNull(orange);
        assertTrue(orange.getComponent() instanceof JavaComponent);
        InterfaceBinding r = ((JavaComponent) orange.getComponent()).getInterfaceBindings().get(0);
        assertNotNull(r);

        //TODO Grab an instance of the service object itself and test that the proxy has been injected
    }
View Full Code Here

        // Proxy
        if (bindings != null && bindings.size() > 0)
        {
            for (Iterator<?> it = bindings.iterator(); it.hasNext();)
            {
                InterfaceBinding interfaceBinding = (InterfaceBinding) it.next();
                String bindingName = ClassUtils.getSimpleName(interfaceBinding.getInterface());
                if (proxies.containsKey(bindingName))
                {
                    Object proxy = proxies.get(bindingName);
                    BindingInvocationHandler handler = (BindingInvocationHandler) Proxy.getInvocationHandler(proxy);
                    handler.addRouterForInterface(interfaceBinding);
                }
                else
                {
                    Object proxy = Proxy.newProxyInstance(muleContext.getExecutionClassLoader(),
                        new Class[]{interfaceBinding.getInterface()},
                        new BindingInvocationHandler(interfaceBinding));
                    proxies.put(bindingName, proxy);
                }
            }
        }
View Full Code Here

    {
        //Test that the proxy object was created and set on the service object
        Service orange = muleContext.getRegistry().lookupService("orangeComponent");
        assertNotNull(orange);
        assertTrue(orange.getComponent() instanceof JavaComponent);
        InterfaceBinding r = ((JavaComponent) orange.getComponent()).getInterfaceBindings().get(0);
        assertNotNull(r);

        //TODO Grab an instance of the service object itself and test that the proxy has been injected
    }
View Full Code Here

TOP

Related Classes of org.mule.api.component.InterfaceBinding

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.