<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:spring="http://www.springframework.org/schema/beans"
    xmlns:http="http://www.mulesource.org/schema/mule/http/2.0"
    xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://www.mulesource.org/schema/mule/core/2.0 http://www.mulesource.org/schema/mule/core/2.0/mule.xsd
              http://www.mulesource.org/schema/mule/http/2.0 http://www.mulesource.org/schema/mule/http/2.0/mule-http.xsd">

    <spring:bean id="doSpringWork"
        class="org.mule.module.spring.remoting.DoSomeWork" />

    <!--
        Transform a byte[] from an Http request into a Spring RemoteInvocation instance.
    -->
    <custom-transformer name="springInputXform"
        class="org.mule.module.spring.remoting.ObjectToRemoteInvocationTransformer" />
    <!--
        Convert an Object to a Spring RemoteInvocationResult and then into a byte[]
        for return to the caller via Http.
    -->
    <custom-transformer name="springOutputXform"
        class="org.mule.module.spring.remoting.ObjectToRemoteInvocationResultTransformer" />

    <model name="main">

        <!--
            SpringHttpInvokerComponent will receive a RemoteInvocation and execute
            the requested method on a POJO specified by "serviceClass".
        -->
        <service name="doSomeWorkViaSpring">

            <!--
                Listen on 8003 for Http requests.
                Use springInputXform to convert a byte[] from Http into a RemoteInvocation.
                Use springOutputXform to convert a Object from the Mule pipeline into a
                RemoteInvocationResult and then into a byte[].
            -->
            <inbound>
                <inbound-endpoint
                    address="http://localhost:8003/springService"
                    transformer-refs="springInputXform"
                    responseTransformer-refs="springOutputXform"
                    synchronous="true" />
            </inbound>

            <pooled-component>
                <prototype-object
                    class="org.mule.module.spring.remoting.SpringRemoteInvokerComponent">
                    <properties>

                        <!--
                            Instead of setting the class, provide SpringHttpInvokerComponent
                            with a Spring managed bean instead.
                            
                            (This doesn't work yet because I don't know how to teach
                            SpringHttpInvokerComponent to find Spring beans.)
                        -->
                        <spring:entry key="serviceBean"
                            value-ref="doSpringWork" />

                        <!--
                            Set the serviceInterface property of Spring's RemoteInvocationBasedExporter
                        -->
                        <spring:entry key="serviceInterface"
                            value="org.mule.module.spring.remoting.WorkInterface" />

                        <!--
                            Set other properties of Spring's RemoteInvocationBasedExporter
                            i.e. registerTraceInterceptor and remoteInvocationExecutor
                        -->
                    </properties>
                </prototype-object>
            </pooled-component>

        </service>
    </model>
</mule>
