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.     } 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值