最近很闲只好学点知识,我们公司又用到soa,不过也是很少的部分,不过这块看来是趋势,就像EJB一样,只要有一些大商在哪顶着,什么技术都可以流行,在中国更是这样,领导一拍脑袋,方案就定下料。废话少说,来点实际的。
?
?
第一步:我们要去官方去下载2.1.2版本,不过现在的最新版本好像是2.2了,不过今天我的例子是2.1.2的,说真的mule在版本控制方面真够差劲,2.02的竟然跑不通1.3的例子,兼容性不好,(扯远了)下载地址http://www.mulesoft.org/display/MULE/Download
下载下来解压缩到D:/Downloads/java
第二步配置环境变量MULE_HOME=D:/Downloads/java/mule-2.1.2
???????????????????????????path = %MULE_HOME%/bin
?
第三步:就是写程序了
在eclipse里面新建一个工程mule,加入%MULE_HOME%/lib 下的opt和mule下的jar包 网上很多都是这样加的,不过在2.1.2环境下启动会报异常。因为这里少了endorsed下的jar
?第一个就是简单的接口类MuleService.java
??? package com.eagle.mule.test;
??? import javax.jws.WebParam;
??? import javax.jws.WebService;
??? @WebService
??? public interface MuleService {
?
??????? public String testMule(@WebParam(name="str")String str);
??? }
第二个就是实现类MuleServiceImpl.java
??? package com.eagle.mule.test.impl;
??? import javax.jws.WebService;
??? import com.eagle.mule.test.MuleService;
??? @WebService(serviceName="eagleMuleService",
??? endpointInterface="com.eagle.mule.test.MuleService")
??? public class MuleServiceImp implements MuleService {
???????? public String testMule(String str) {
?????????? ? System.out.println("----service---");
??????????? ?return "hello--"+str;
?????? ?}
?? }
第三步启动服务器:
import org.mule.api.MuleContext;
import org.mule.api.MuleException;
import org.mule.api.config.ConfigurationException;
import org.mule.api.context.MuleContextFactory;
import org.mule.api.lifecycle.InitialisationException;
import org.mule.config.spring.SpringXmlConfigurationBuilder;
import org.mule.context.DefaultMuleContextFactory;
public class EagleMuleMain {
?public static void main(String[] args) throws ConfigurationException,InitialisationException {
??try {
???String configFile = "mule_config.xml";
???String[] configFileArr = new String[] { configFile };
???MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
???MuleContext context = muleContextFactory
?????.createMuleContext(new SpringXmlConfigurationBuilder(
???????configFileArr));
???context.start();
??} catch (MuleException t) {
???t.printStackTrace();
??}
?}
}
?
第四步:配置mule_config.xml放在src下
<?xml version="1.0" encoding="UTF-8"?>??
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.1"?
????? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?
????? xmlns:spring="http://www.springframework.org/schema/beans"?
????? xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.1"?
????? xmlns:cxf="http://www.mulesource.org/schema/mule/cxf/2.1"?
????? xmlns:axis="http://www.mulesource.org/schema/mule/axis/2.1"?
????? xmlns:smtps="http://www.mulesource.org/schema/mule/smtps/2.1"?
????? xmlns:http="http://www.mulesource.org/schema/mule/http/2.1"?
????? xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.1"?
????? xmlns:soap="http://www.mulesource.org/schema/mule/soap/2.1"?
????? 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.1 http://www.mulesource.org/schema/mule/core/2.1/mule.xsd??
?????????????? http://www.mulesource.org/schema/mule/stdio/2.1 http://www.mulesource.org/schema/mule/stdio/2.1/mule-stdio.xsd??
?????????????? http://www.mulesource.org/schema/mule/vm/2.1 http://www.mulesource.org/schema/mule/vm/2.1/mule-vm.xsd??
?????????????? http://www.mulesource.org/schema/mule/cxf/2.1 http://www.mulesource.org/schema/mule/cxf/2.1/mule-cxf.xsd??
?????????????? http://www.mulesource.org/schema/mule/axis/2.1 http://www.mulesource.org/schema/mule/axis/2.1/mule-axis.xsd??
?????????????? http://www.mulesource.org/schema/mule/smtps/2.1 http://www.mulesource.org/schema/mule/smtps/2.1/mule-smtps.xsd??
?????????????? http://www.mulesource.org/schema/mule/soap/2.1 http://www.mulesource.org/schema/mule/soap/2.1/mule-soap.xsd??
?????????????? http://www.mulesource.org/schema/mule/http/2.1 http://www.mulesource.org/schema/mule/http/2.1/mule-http.xsd??
?????????????? ">??
???? <description>??
??????? eagleMule demo which shows how to publish web services over CXF.??
??? </description>??
??? <model name="eagleMule">??
???????? <service name="testMuleService">??
??????????? <inbound>??
??????????????? <axis:inbound-endpoint address="http://localhost:8899/services/testMuleService">??
??????????????????? <soap:http-to-soap-request-transformer />??
??????????????? </axis:inbound-endpoint>??
??????????????? <cxf:inbound-endpoint address="http://localhost:8898/services/testMuleService">??
??????????????????? <soap:http-to-soap-request-transformer />??
??????????????? </cxf:inbound-endpoint>??
??????????? </inbound>??
??????????? <component class="com.eagle.mule.test.impl.MuleServiceImp">??
??????????? </component>??
??????? </service>??
??? </model>??
??? </mule>?
就可以运行EagleMuleMain得到线面这个就说明运行成功了
**********************************************************************
* Mule ESB and Integration Platform????????????????????????????????? *
* Version: 2.1.2 Build: 13558??????????????????????????????????????? *
* MuleSource,Inc.?????????????????????????????????????????????????? *
* For more information go to http://mule.mulesource.org????????????? *
*??????????????????????????????????????????????????????????????????? *
* Server started: 09-11-23 下午2:10????????????????????????????????? *
* Server ID: d44c72f1-d7f6-11de-a19a-2989f1bc1464??????????????????? *
* JDK: 1.5.0_17 (mixed mode,sharing)??????????????????????????????? *
* Encoding: OS: GBK,Mule: UTF-8???????????????????????????????????? *
* OS: Windows XP - Service Pack 2 (5.1,x86)???????????????????????? *
* Host: USTC-XYIN (192.168.20.71)??????????????????????????????????? *
*??????????????????????????????????????????????????????????????????? *
* Agents Running: None?????????????????????????????????????????????? *
**********************************************************************
在浏览器里访问
http://localhost:8898/services/testMuleService?wsdl
如果出现xml文说明成功运行服务器。
?
ps:一定要加上endorsed下jar哦 这个很容易给忽略掉的,不知道别人怎么运行通过的额。
参考内容
http://speed847.javaeye.com/blog/458371
http://incan.javaeye.com/blog/308428