mule2.2.x架构(三)示例学习hello

mule2.2.x架构(三)示例学习hello

所有的示例文档
http://www.mulesoft.org/display/MULE2INTRO/Examples

本例参考示例地址
http://www.mulesoft.org/display/MULE2INTRO/Hello+World+Example

2.简单示例hello
2.1.接受标准输入驱动
主要分析了配置文件hello-config.xml
<!-- 提示语言,从hello-messages_zh_CN.properties中提取第三个元素 -->
    <stdio:connector name="SystemStreamConnector"
        promptMessageCode="3"
        resourceBundle="messages.hello-messages"
        messageDelayTime="1000"/>
<!-- 装换的工具类 -->
    <custom-transformer name="StdinToNameString" class="com.sillycat.easymule.hello.transformer.StdinToNameString"/>
    <custom-transformer name="NameStringToChatString" class="com.sillycat.easymule.hello.transformer.NameStringToChatString"/>
    <custom-transformer name="ChatStringToString" class="com.sillycat.easymule.hello.transformer.ChatStringToString"/>
    <custom-transformer name="ExceptionToString" class="com.sillycat.easymule.hello.transformer.ExceptionToString"/>

    <model name="helloSample">
        <service name="GreeterUMO">
            <!-- 接受系统标准输入 -->
   <inbound>
                <stdio:inbound-endpoint system="IN" transformer-refs="StdinToNameString"/>
            </inbound>
            <component class="com.sillycat.easymule.hello.service.Greeter"/>
            <outbound>
         <!-- 根据类型,返回到不同的vm,vm貌似是mule的一个memory queen -->
                <filtering-router>
                    <vm:outbound-endpoint path="chitchatter"/>
                    <payload-type-filter expectedType="com.sillycat.easymule.hello.model.NameString"/>
                </filtering-router>
                <filtering-router>
                    <vm:outbound-endpoint path="userErrorHandler"/>
                    <payload-type-filter expectedType="java.lang.Exception"/>
                </filtering-router>
            </outbound>
            <default-service-exception-strategy>
                <vm:outbound-endpoint path="systemErrorHandler"/>
            </default-service-exception-strategy>
        </service>
        <!-- 正常的接受chitchatter的vm分支 -->
        <service name="ChitChatUMO">
            <inbound>
                <vm:inbound-endpoint path="chitchatter" transformer-refs="NameStringToChatString"/>
            </inbound>
            <component class="com.sillycat.easymule.hello.service.ChitChatter"/>
            <!-- 输出到控制台 -->
   <outbound>
                <pass-through-router>
                    <stdio:outbound-endpoint system="OUT" transformer-refs="ChatStringToString" />
                </pass-through-router>
            </outbound>
        </service>
    <!-- handler一些出错信息 -->
        <service name="UserErrorHandler">
            <inbound>
                <vm:inbound-endpoint path="userErrorHandler" transformer-refs="ExceptionToString"/>
            </inbound>
            <outbound>
                <pass-through-router>
                    <stdio:outbound-endpoint system="OUT"/>
                </pass-through-router>
            </outbound>
        </service>
        <service name="SystemErrorHandler">
            <inbound>
                <vm:inbound-endpoint path="systemErrorHandler"/>
            </inbound>
            <outbound>
                <pass-through-router>
                    <stdio:outbound-endpoint system="ERR"/>
                </pass-through-router>
            </outbound>
        </service>       
    </model>
2.2接受http请求驱动
主要分析了配置文件hello-http-config.xml,没有什么大的区别,主要是区分了第一个inbound,另外新增了transformer
<inbound>
<inbound-endpoint address="http://localhost:8888"
    transformer-refs="HttpRequestToNameString" synchronous="true">
   <not-filter>
    <wildcard-filter pattern="/favicon.ico" />
   </not-filter>
</inbound-endpoint>
</inbound>
以上是接受http请求的inbound,接受请求
http://localhost:8888?name=Ross
为啥是name=Ross
com.sillycat.easymule.hello.transformer.HttpRequestToNameString里面的NAME_REQUEST_PARAMETER就写死了再url里面去寻找
新增的transformer
<custom-transformer name="NameStringToChatString"
   class="com.sillycat.easymule.hello.transformer.NameStringToChatString" />
<custom-transformer name="ChatStringToString"
   class="com.sillycat.easymule.hello.transformer.ChatStringToString" />
<custom-transformer name="HttpRequestToNameString"
   class="com.sillycat.easymule.hello.transformer.HttpRequestToNameString" />
<custom-transformer name="ExceptionToString"
   class="com.sillycat.easymule.hello.transformer.ExceptionToString" />
<message-properties-transformer name="PlainTextResponseTransformer">
<add-message-property key="Content-Type" value="text/plain" />
</message-properties-transformer>

简单的测试完毕,基本上是按照英文文档上拷贝了一次。等学习完所有的example,再考虑如何和自己的系统结合。

你可能感兴趣的:(xml)