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

Java代码 复制代码
  1. <?xml version="1.0" encoding="UTF-8"?>   
  2. <mule xmlns="http://www.mulesource.org/schema/mule/core/2.1"  
  3.       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.       xmlns:spring="http://www.springframework.org/schema/beans"  
  5.       xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.1"  
  6.       xmlns:cxf="http://www.mulesource.org/schema/mule/cxf/2.1"  
  7.       xmlns:axis="http://www.mulesource.org/schema/mule/axis/2.1"  
  8.       xmlns:smtps="http://www.mulesource.org/schema/mule/smtps/2.1"  
  9.       xmlns:http="http://www.mulesource.org/schema/mule/http/2.1"  
  10.       xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.1"  
  11.       xmlns:soap="http://www.mulesource.org/schema/mule/soap/2.1"  
  12.       xsi:schemaLocation="   
  13.                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd   
  14.                http://www.mulesource.org/schema/mule/core/2.1 http://www.mulesource.org/schema/mule/core/2.1/mule.xsd   
  15.                http://www.mulesource.org/schema/mule/stdio/2.1 http://www.mulesource.org/schema/mule/stdio/2.1/mule-stdio.xsd   
  16.                http://www.mulesource.org/schema/mule/vm/2.1 http://www.mulesource.org/schema/mule/vm/2.1/mule-vm.xsd   
  17.                http://www.mulesource.org/schema/mule/cxf/2.1 http://www.mulesource.org/schema/mule/cxf/2.1/mule-cxf.xsd   
  18.                http://www.mulesource.org/schema/mule/axis/2.1 http://www.mulesource.org/schema/mule/axis/2.1/mule-axis.xsd   
  19.                http://www.mulesource.org/schema/mule/smtps/2.1 http://www.mulesource.org/schema/mule/smtps/2.1/mule-smtps.xsd   
  20.                http://www.mulesource.org/schema/mule/soap/2.1 http://www.mulesource.org/schema/mule/soap/2.1/mule-soap.xsd   
  21.                http://www.mulesource.org/schema/mule/http/2.1 http://www.mulesource.org/schema/mule/http/2.1/mule-http.xsd   
  22.                ">   
  23.      <description>   
  24.         eagleMule demo which shows how to publish web services over CXF.   
  25.     </description>   
  26.     <model name="eagleMule">   
  27.          <service name="testMuleService">   
  28.             <inbound>   
  29.                 <axis:inbound-endpoint address="http://localhost:8899/services/testMuleService">   
  30.                     <soap:http-to-soap-request-transformer />   
  31.                 </axis:inbound-endpoint>   
  32.                 <cxf:inbound-endpoint address="http://localhost:8898/services/testMuleService">   
  33.                     <soap:http-to-soap-request-transformer />   
  34.                 </cxf:inbound-endpoint>   
  35.             </inbound>   
  36.             <component class="com.eagle.mule.test.imp.MuleServiceImp">   
  37.             </component>   
  38.         </service>   
  39.     </model>   
  40.     </mule>  
<?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

Java代码 复制代码
  1.  @WebService  
  2. public interface MuleService {   
  3. public String testMule(@WebParam(name="str")String str);   
  4. }  
 @WebService
public interface MuleService {
public String testMule(@WebParam(name="str")String str);
}


MuleServiceImp.java

Java代码 复制代码
  1. @WebService(serviceName="eagleMuleService",   
  2.           endpointInterface="com.eagle.mule.test.MuleService")   
  3. public class MuleServiceImp implements MuleService {   
  4.   
  5.     public String testMule(String str) {   
  6.         System.out.println("----service---");   
  7.         return "hello--"+str;   
  8.     }   
  9. }  
@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;
	}
}


启动服务:

Java代码 复制代码
  1. public class EagleMuleMain {   
  2.     public static void main(String[] args) throws ConfigurationException, InitialisationException {   
  3.         try {   
  4.             String configFile = "com/eagle/mule/test/mule_config.xml";   
  5.             String[] configFileArr = new String[] { configFile };   
  6.             MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();   
  7.             MuleContext context = muleContextFactory   
  8.                     .createMuleContext(new SpringXmlConfigurationBuilder(   
  9.                             configFileArr));   
  10.             context.start();   
  11.         } catch (MuleException t) {   
  12.             t.printStackTrace();   
  13.         }   
  14.     }   
  15. }  
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();
		}
	}
}


测试

Java代码 复制代码
  1. package com.eagle.mule.test.clint;   
  2.   
  3. import java.io.IOException;   
  4. import java.io.InputStream;   
  5.   
  6. import org.apache.commons.io.IOUtils;   
  7. import org.mule.api.MuleException;   
  8. import org.mule.api.MuleMessage;   
  9. import org.mule.module.client.MuleClient;   
  10.   
  11. public class Client {   
  12.     public static void main(String[] args){   
  13.         MuleClient client = null;    
  14.         try {   
  15.             client = new MuleClient();   
  16.             String url = "axis:http://localhost:8899/services/testMuleService?wsdl&method=testMule";   
  17.   
  18.             MuleMessage message = client.send(url, "eagle"null);   
  19.             Object obj = message.getPayload();   
  20.             System.out.println("--------------obj---------"+obj.getClass().getName());   
  21.             if(obj instanceof String){   
  22.                 System.out.println("---------str--------------"+obj);   
  23.             }   
  24.         } catch (MuleException e) {   
  25.             // TODO Auto-generated catch block   
  26.             e.printStackTrace();   
  27.         }finally{   
  28.             client.dispose();   
  29.         }   
  30.   
  31.     }   
  32. }   
  33. 注意 这里需要把mule 下lib中 endorsed  mule  opt 文件夹中的jar都加进去。如果不发布cxf的服务 可以不用添加endorsed文件夹中的jar。   

你可能感兴趣的:(spring,xml,Web,webservice,SOAP)