关键字: Mule XFire ESB WebService
下载和安装XFire和Mule
参考http://hideto.iteye.com/blog/59750和http://hideto.iteye.com/blog/64742对XFire和Mule的介绍
本文例子也以上述两篇文章的例子为背景。
利用XFire发布一个Web服务BookService
在Eclipse里新建项目webservice,目录结构如下:
代码
- webservice
- src-service
- cn.hidetoishandsome.xfire.model
- Book.java
- cn.hidetoishandsome.xfire.service
- IBookService.java
- cn.hidetoishandsome.xfire.service.impl
- BookService.java
- src-conf
- META-INF
- xfire
- services.xml
- web
- WEB-INF
- lib
- web.xml
<script>render_code();</script>
其中web.xml:
代码
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
-
- <servlet>
- <servlet-name>xfire</servlet-name>
- <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
- </servlet>
-
- <servlet-mapping>
- <servlet-name>xfire</servlet-name>
- <url-pattern>/services/*</url-pattern>
- </servlet-mapping>
-
- </web-app>
<script>render_code();</script>
以及services.xml:
代码
- <beans xmlns="http://xfire.codehaus.org/config/1.0">
- <service>
- <name>BookService</name>
- <namespace>http://localhost:9090/webservice/services/BookService</namespace>
- <serviceClass>cn.hidetoishandsome.xfire.service.IBookService</serviceClass>
- <implementationClass>cn.hidetoishandsome.xfire.service.impl.BookService</implementationClass>
- </service>
- </beans>
<script>render_code();</script>
我们发布BookService类的findBookByISBN方法,通过传入book的isbn返回查询到的book的title
注意services.xml中我们把BookService的namespace设置为http://localhost:9090/webservice/services/BookService,这是为了在同一机器上同时
启动两个Tomcat实例来测试我们的demo,我们将启动一个Tomcat来host我们发布的BookService,并且port设置为9090,而启动的第二个Tomcat用来
host我们的Mule ESB,以及前台页面调用测试。
好了,现在我们已经可以启动第一个Tomcat实例来发布BookService了,访问http://localhost:9090/webservice/services/BookService?wsdl可以看
到XFire自动生成的WSDL文档。
利用Mule构建我们的ESB中心
在Eclipse里创建新项目esb,目录结构如下:
代码
- esb
- web
- WEB-INF
- lib
- mule-services-config.xml
- web.xml
- index.jsp
<script>render_code();</script>
其中web.xml:
代码
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
- <web-app>
- <display-name>Mule</display-name>
- <description>Mule Demo</description>
-
- <context-param>
- <param-name>org.mule.config</param-name>
- <param-value>/WEB-INF/mule-services-config.xml,</param-value>
- </context-param>
-
- <listener>
- <listener-class>org.mule.config.builders.MuleXmlBuilderContextListener</listener-class>
- </listener>
-
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- </web-app>
<script>render_code();</script>
以及mule-services-config.xml:
代码
- <?xml version="1.0" encoding="UTF-8"?>
-
- <!DOCTYPE mule-configuration PUBLIC "-//MuleSource //DTD mule-configuration XML V1.0//EN"
- "http://mule.mulesource.org/dtds/mule-configuration.dtd">
-
- <mule-configuration id="Mule_Demo" version="1.0">
-
- <mule-descriptor name="BookService" inboundEndpoint="vm://bookservice" implementation="org.mule.components.simple.BridgeComponent">
-
- <outbound-router>
- <router className="org.mule.routing.outbound.OutboundPassThroughRouter">
- <endpoint address="wsdl-xfire:http://localhost:9090/webservice/services/BookService?wsdl&method=findBookByISBN"/>
- </router>
- </outbound-router>
-
- </mule-descriptor>
-
- </mule-configuration>
<script>render_code();</script>
这里我们配置了我们要调用的BookService的outbound router endpoint的address为:
wsdl-xfire:http://localhost:9090/webservice/services/BookService?wsdl&method=findBookByISBN
好了,我们的Mule ESB已经构建好了,并且我们在自己的ESB中注入了一个Web服务BookService,我们不用担心底层的实现,我们只需按照接口简单调用即可。
下面我们写前端调用代码index.jsp:
代码
- <%@ page import="org.mule.extras.client.MuleClient, org.mule.umo.UMOMessage"%>
- <%@ page language="java" contentType="text/html; charset=UTF-8" %>
-
- <html>
- <head>
- <title>Mule Echo Example</title>
- </head>
- <body>
- <%
- String s = request.getParameter("isbn");
- if(s!=null) {
- MuleClient client = new MuleClient();
- UMOMessage message = client.send("vm://bookservice", s, null);
- %>
- <h3>The book with isbn "<%=s%>" is : <<<%=message.getPayload()%>>></h3>
- <%}%>
- Please enter the isbn of book:
- <form method="POST" name="submitISBM" action="">
- <table>
- <tr><td>
- <input type="text" name="isbn"/></td><td><input type="submit" name="Go" value=" Go " />
- </td></tr>
- </table>
- </form>
- <p/>
- </body>
- </html>
<script>render_code();</script>
现在让我们启动第二个Tomcat实例,然后访问http://localhost:8080/esb,输入isbn号码“123456”,提交来查看返回的Book的Title。
源代码
将源代码打包提供如下,WEB-INF/lib下面的jar包都删除了,请参考http://hideto.iteye.com/blog/59750和http://hideto.iteye.com/blog/64742来
添加jar包。
|
mule-xfire.rar |
描述: |
|
下载 |
文件名: |
mule-xfire.rar |
文件大小: |
4 KB |
下载过的: |
文件被下载或查看 106 次 |
可否提供一个可以跑起来的例子,MULE的XML配置文件参数文档有吗?谢谢!!
|
以上的例子部署不能运行,请楼主再仔细看看。最好能把使用的包的小version列出来。
|
引用
参考http://hideto.iteye.com/blog/59750和http://hideto.iteye.com/blog/64742对XFire和Mule的介绍
上面链接里描述了使用哪些jar包
|
请问使用的Mule是哪个版本的?我使用1.4的。
1、发现mule的配置文件缺少<model>标签,加上后可以使用;
2、使用xfire方式发布 BrigeComponent 报异常,大致意思是UMOSecurityManager 有 java.util.List 参数,没有配置;不知hideto是否遇到过。
|
分享到:
相关推荐
博文链接:https://hideto.iteye.com/blog/65822
利用mule 服务总线代理 cxf发布的服务。其中详细的描述了cxf服务的发布的访问,以及如何使用mule的代理模式代理cxf的服务。步骤详细,有图有真相.
[Manning Publications] Mule 实战 第2版 (英文版) [Manning Publications] Mule in Action 2nd Edition (E-Book) ☆ 图书概要:☆ Mule in Action, Second Edition is a totally revised guide covering Mule 3 ...
Mule ESB 是一个轻量级的基于java的企业服务总线和集成平台, 使得开发人员可以快速,简单的连接多个应用, 使得它们可以交换数据。 Mule ESB 容易集成现有异构系统,包括:JMS, Web Services, JDBC, HTTP, 等. ESB...
使用MuleEsb同时掉多个webservice,并返回到调用方。开发环境为AnyPoint3.7,将例子中的webservice接口修改成自己的即可运行。
利用mule服务总线代理cxf服务源码。
mule in aciton:mule 实战,主要是社区成熟,文档丰富。开源esb
MuleESB Docker映像 此存储库包含。 您需要通过以下命令从Docker注册表中提取Mule docker映像: docker pull eddumelendez/mule 之后,您应该可以通过以下方式运行Mule docker映像: docker run -ti ...
NULL 博文链接:https://lgcjava.iteye.com/blog/2152331
vim-mule:用于VIM的Django生产力插件
您可以使用Mule来智能地管理节点之间的消息路由,数据映射,编排,可靠性,安全性和可伸缩性,而不是在系统,服务,API和设备之间创建点对点集成。 将其他系统和应用程序插入Mule,并使其处理系统之间的所有通信,...
使用Mule发布web service
Expert advice to using filters connecting with cloud integrating with web services and much more ☆ 出版信息:☆ [作者信息] Dr Zakir Laliwala Abdul Samad Azaz Desai Uchit Vyas [出版机构] Packt ...
mule的最新版本mule-standalone-3.1.1
关于在tomcat上进行mule多线程数量参数配置