mule2.1.2 初步认识 发布cxf 和axis服务

最近公司需要写这样一个功能。也就是需要一个esb消息总线。初步的功能是提供webservice的消息管理以后还会增加很多的功能。。以前本来在soa esb上面的东西就是个空白。在Google上找了一天最后由我自己觉得用mule2.1.2。让后就疯狂的找些好的帖子。希望能够很快的入门。但发现不是那么一回事。找到的很多都是1.X的版本。2.1.2 的少得很。经过近半周的研究。。终于自己写了一个小的test。贴上来给新入门的朋友希望有帮助。深入的研究以后还会继续。
配置文件:mule_config.xml
<?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.imp.MuleServiceImp">
            </component>
        </service>
    </model>
    </mule>

一个简单的 接口 为了先跑同就这样把。
MuleService.java
 @WebService
public interface MuleService {
public String testMule(@WebParam(name="str")String str);
}

MuleServiceImp.java
@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;
	}
}

启动服务:
public class EagleMuleMain {
	public static void main(String[] args) throws ConfigurationException, InitialisationException {
		try {
			String configFile = "com/eagle/mule/test/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();
		}
	}
}

测试
package com.eagle.mule.test.clint;

import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;
import org.mule.api.MuleException;
import org.mule.api.MuleMessage;
import org.mule.module.client.MuleClient;

public class Client {
	public static void main(String[] args){
		MuleClient client = null; 
		try {
			client = new MuleClient();
			String url = "axis:http://localhost:8899/services/testMuleService?wsdl&method=testMule";

			MuleMessage message = client.send(url, "eagle", null);
			Object obj = message.getPayload();
			System.out.println("--------------obj---------"+obj.getClass().getName());
			if(obj instanceof String){
				System.out.println("---------str--------------"+obj);
			}
		} catch (MuleException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			client.dispose();
		}

	}
}
注意 这里需要把mule 下lib中 endorsed  mule  opt 文件夹中的jar都加进去。如果不发布cxf的服务 可以不用添加endorsed文件夹中的jar。 

你可能感兴趣的:(java,eclipse,tomcat,xml,webservice)