<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
       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.2"
       xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2"
       xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.2"
       xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
            http://www.mulesource.org/schema/mule/http/2.2 http://www.mulesource.org/schema/mule/http/2.2/mule-http.xsd
            http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd
            http://www.mulesource.org/schema/mule/stdio/2.2 http://www.mulesource.org/schema/mule/stdio/2.2/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.servlet.transformers.HttpRequestToParameter"/>
    <custom-transformer name="ObjectToString" class="org.mule.transformer.simple.ObjectToString"/>

    <!-- 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 service receives input from 3 different endpoints (http, servlet, vm) and routes 
            them all to the same place.
        -->
        <service name="GreeterUMO">
            <inbound>
                <!-- 
                  Incoming HTTP requests
                  
                  Note: the REST endpoint currently only works on the servlet transport only
                  since the HttpRequestToParameter transformer only supports servlets.
                 -->
                <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://name" transformer-refs="HttpRequestToNameString" synchronous="true">
                    <not-filter>
                        <wildcard-filter pattern="/favicon.ico"/>   
                    </not-filter>
                </inbound-endpoint>
                <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" synchronous="true"/>
                    <payload-type-filter expectedType="org.mule.example.hello.NameString"/>
                </filtering-router>

                <filtering-router>
                    <vm:outbound-endpoint path="userErrorHandler" synchronous="true"/>
                    <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>
                <pass-through-router>
                    <stdio:outbound-endpoint system="ERR"/>
                </pass-through-router>
            </outbound>
        </service>

    </model>

</mule>
