微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Mule发布webservice--cxf

  1. package mule.webservice.service; 
  2. import javax.jws.WebParam; 
  3. import javax.jws.WebResult; 
  4. import javax.jws.WebService; 
  5. @WebService 
  6. public interface HelloCXF { 
  7.     @WebResult(name="text"
  8.     public String sayHello(@WebParam(name="text")String name); 
  9.      

  1. package mule.webservice.service.impl; 
  2. import javax.jws.WebService; 
  3. import mule.webservice.service.HelloCXF; 
  4. @WebService(endpointInterface = "mule.webservice.service.HelloCXF"
  5.         serviceName = "HelloCXF"
  6. public class HelloCXFImpl implements HelloCXF { 
  7.     @Override 
  8.     public String sayHello(String name) { 
  9.         return "Hello," + name + "! by cxf."
  10.     } 

配置文件

  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <mule xmlns="http://www.mulesource.org/schema/mule/core/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  3.     xmlns:spring="http://www.springframework.org/schema/beans"  
  4.     xmlns:cxf="http://www.mulesource.org/schema/mule/cxf/2.2"  
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans  
  6.     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
  7.     http://www.mulesource.org/schema/mule/core/2.2  
  8.     http://www.mulesource.org/schema/mule/core/2.2/mule.xsd  
  9.     http://www.mulesource.org/schema/mule/cxf/2.2 
  10.     http://www.mulesource.org/schema/mule/cxf/2.2/mule-cxf.xsd"> 
  11.     <model name="helloCXF"> 
  12.         <service name="helloService"> 
  13.             <inbound> 
  14.                 <inbound-endpoint address="cxf:http://localhost:63081/hello" />  
  15.             </inbound> 
  16.             <component class="mule.webservice.service.impl.HelloCXFImpl" />  
  17.         </service> 
  18.     </model> 
  19. </mule> 

测试类

  1. package mule.webservice.client; 
  2. import mule.webservice.service.HelloCXF; 
  3. import org.apache.cxf.jaxws.JaxWsProxyfactorybean
  4. import org.mule.api.MuleContext; 
  5. import org.mule.api.MuleException; 
  6. import org.mule.api.config.ConfigurationException; 
  7. import org.mule.api.lifecycle.InitialisationException; 
  8. import org.mule.context.DefaultMuleContextFactory; 
  9. public class Client3 { 
  10.     public static void startMule(String config) { 
  11.         try
  12.             MuleContext muleContext; 
  13.             muleContext = new DefaultMuleContextFactory() 
  14.                     .createMuleContext(config); 
  15.             muleContext.start(); 
  16.         } catch (InitialisationException e) { 
  17.             e.printstacktrace(); 
  18.         } catch (ConfigurationException e) { 
  19.             e.printstacktrace(); 
  20.         } catch (MuleException e) { 
  21.             e.printstacktrace(); 
  22.         } 
  23.     } 
  24.     public static void main(String[] args) { 
  25.         startMule("ws-config-cxf.xml"); 
  26.         JaxWsProxyfactorybean factory = new JaxWsProxyfactorybean(); 
  27.         factory.setAddress("http://localhost:63081/hello"); 
  28.         factory.setServiceClass(HelloCXF.class); 
  29.         HelloCXF helloworld = (HelloCXF) factory.create(); 
  30.         System.out.println(helloworld.sayHello("abc")); 
  31.     } 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐