您的位置:首页 > 其它

以一个实例看Mule3.0中的Flow

2012-07-13 14:26 141 查看
flow是mule3.0中新增的一个处理消息的形式,它是区别与之前版本的service的,但又可以以不同的方式来处理service中能够处理的消息。下面以Mule3.0中的Echo Example来学习一下关于flow的知识,flow里面可以配置入站,出站,可以放component等等的东西,另外flow是不知道如何处理Web服务调用的,所以我们一般需要一个像CXF这样的过滤器,因为CXF中有内置的支持去理解GET请求,CXF使用如下的语法:
http://主机/服务/方法/参数名/参数值 如下面的这个例子使用的是:
http://localhost:65082/services/EchoUMO/echo/text/hello
另外在Flow中配置的CXF必须要指定他的serviceClass,在service中配置是不需要的是因为service中可以自动的发现component,但是flow目前还不支持所以必须要配上之后才可以找到component。
还有一个地方就是入站中设置的入口时一个WS的url地址,如果使用了exchange-pattern =“request-response”,则它将返回给我们这个URL。
mule的配置文件如下:
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns="http://www.mulesoft.org/schema/mule/core"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:spring="http://www.springframework.org/schema/beans"

xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf"

xsi:schemaLocation="

http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/3.0/mule.xsd

http://www.mulesoft.org/schema/mule/cxf
http://www.mulesoft.org/schema/mule/cxf/3.0/mule-cxf.xsd">
<description>

This config builds a JAX-WS service with CXF.

We use a "serviceClass" which is a JAX-WS interface we've defined. It allows us

to ensure that the WSDL is only generated for the "echo" method (as opposed

to all the other methods on the EchoComponent). This keeps our WSDL nice

in clean - but it is not required.
To invoke the EchoUMO hit the following URL -

http://localhost:65082/services/EchoUMO/echo/text/hello

To view the WSDL for the EchoUMO service go to -

http://localhost:65082/services/EchoUMO?wsdl

</description>
<flow name="EchoFlow">

<inbound-endpoint address="http://localhost:65082/services/EchoUMO" exchange-pattern="request-response"/>

<cxf:jaxws-service serviceClass="org.mule.example.echo.Echo"/><!--这里是必须要配置的然后才能找到下面的component-->

<component>

<singleton-object class="org.mule.example.echo.Echo" />

</component>

</flow>

</mule>

Echo类是要根据CXF的语法规则发布成WS的,其实现形式如下:
/*

* $Id: Echo.java 19191 2010-08-25 21:05:23Z tcarlson $

* --------------------------------------------------------------------------------------

* Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
*

* The software in this package is published under the terms of the CPAL v1.0

* license, a copy of which has been included with this distribution in the

* LICENSE.txt file.

*/
package org.mule.example.echo;
import javax.jws.WebParam;

import javax.jws.WebResult;

import javax.jws.WebService;
@WebService

public class Echo

{

@WebResult(name="text")

public String echo(@WebParam(name="text") String string)

{

return string;

}

}

以上类的形式是说明该类被发布成了WebService的形式。
本文就想以最简单的形式来说明一下mule3.0中的flow的用法。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: