<?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"
       xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.0"
       xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/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/stdio/2.0 http://www.mulesource.org/schema/mule/stdio/2.0/mule-stdio.xsd
               http://www.mulesource.org/schema/mule/vm/2.0 http://www.mulesource.org/schema/mule/vm/2.0/mule-vm.xsd
               http://www.mulesource.org/schema/mule/stdio/2.0 http://www.mulesource.org/schema/mule/stdio/2.0/mule-stdio.xsd">

    <description>
    This configuration is identical to the other Hello World example, except that instead of using the console 
    for I/O, other methods are used.  The example demonstrates how easy it is to swap out different transports 
    while never affecting the application.
    </description>
    <!--
    To invoke the Hello service over HTTP, hit the following URL in your browser:

        http://localhost:8888?name=Ross 

    To invoke the Hello service via a Servlet, submit a web form such as:

        <form method="POST" action="/mule-examples/rest?endpoint=greeter">
            <input type="text" name="payload"/>
            <input type="submit" value="POST" />
        </form>
    
    To invoke the Hello service programatically, use the MuleClient:
                    
        MuleClient client = new MuleClient();
        client.send("vm://greeter", "Ross", null);
        UMOMessage response = client.send("vm://greeter", "Ross", null);
        System.out.println("response = " + response.getPayload());
    -->
 
    <custom-transformer name="StringToNameString" class="org.mule.example.hello.StringToNameString"/>
    <custom-transformer name="NameStringToChatString" class="org.mule.example.hello.NameStringToChatString"/>
    <custom-transformer name="ChatStringToString" class="org.mule.example.hello.ChatStringToString"/>
    <custom-transformer name="HttpRequestToNameString" class="org.mule.example.hello.HttpRequestToNameString"/>
    <custom-transformer name="ExceptionToString" class="org.mule.example.hello.ExceptionToString"/>
    <custom-transformer name="HttpRequestToParameter" class="org.mule.transport.http.servlet.HttpRequestToParameter"/>

    <!-- workaround for http://mule.mulesource.org/jira/browse/MULE-1827 -->
    <message-properties-transformer name="PlainTextResponseTransformer">
        <add-message-property key="Content-Type" value="text/plain"/>
    </message-properties-transformer>
    
    <model name="helloSample">
        <!--
            This component receives input from 3 different endpoints (http, servlet, vm) and routes 
            them all to the same place.
        -->
        <service name="GreeterUMO">
            <inbound>
                <!-- Incoming HTTP requests -->
                <inbound-endpoint address="http://localhost:8888" transformer-refs="HttpRequestToNameString" synchronous="true">
                    <not-filter>
                        <wildcard-filter pattern="/favicon.ico"/>   
                    </not-filter>
                </inbound-endpoint>
                
                <!-- Incoming Servlet requests -->
                <inbound-endpoint address="servlet://rest" transformer-refs="HttpRequestToParameter StringToNameString" responseTransformer-refs="PlainTextResponseTransformer" synchronous="true"/>

                <!-- Incoming VM requests -->
                <vm:inbound-endpoint path="greeter" transformer-refs="StringToNameString" synchronous="true"/>
            </inbound>

            <component class="org.mule.example.hello.Greeter"/>
            
            <outbound>
                <filtering-router>
                    <vm:outbound-endpoint path="chitchatter"/>
                    <payload-type-filter expectedType="org.mule.example.hello.NameString"/>
                </filtering-router>
                
                <filtering-router>
                    <vm:outbound-endpoint path="userErrorHandler"/>
                    <payload-type-filter expectedType="java.lang.Exception"/>
                </filtering-router>
            </outbound>

            <!-- Route unexpected errors to separate error handler -->
            <default-service-exception-strategy>
                <vm:outbound-endpoint path="systemErrorHandler"/>
            </default-service-exception-strategy>
        </service>

        <!-- note the response transformer on this component. even though there is no outbound provider
        the transformer will transform the result event and pass it back as the http response -->
        <service name="ChitChatUMO">
            <inbound>
                <vm:inbound-endpoint path="chitchatter" transformer-refs="NameStringToChatString" responseTransformer-refs="ChatStringToString" synchronous="true"/>
            </inbound>
            <component class="org.mule.example.hello.ChitChatter"/>
        </service>

        <!-- This error handler returns user error messages to caller. Errors could also be routed elsewhere,
            e.g. into an error file, send via email to a list, stored in a database, etc. -->
        <service name="UserErrorHandler">
            <inbound>
                <vm:inbound-endpoint path="userErrorHandler" responseTransformer-refs="ExceptionToString" synchronous="true"/>
            </inbound>
        </service>
                
        <!-- Handle any unexpected errors. Errors could also be routed elsewhere,
            e.g. into an error file, send via email to a list, stored in a database, etc. -->
        <service name="SystemErrorHandler">
            <inbound>
                <vm:inbound-endpoint path="systemErrorHandler" synchronous="true"/>
            </inbound>
            
            <outbound>
                <outbound-pass-through-router>
                    <stdio:outbound-endpoint system="ERR"/>
                </outbound-pass-through-router>
            </outbound>
        </service>
                
    </model>

</mule>
