加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Mule发布webservice--cxf

发布时间:2020-12-17 00:06:45 所属栏目:安全 来源:网络整理
导读:package mule.webservice.service;? import javax.jws.WebParam;? import javax.jws.WebResult;? import javax.jws.WebService;? @WebService ? public interface HelloCXF {? ??? @WebResult (name= "text" )? ??? public String sayHello( @WebParam (name
  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. ?????
  10. }?

[java] view plain copy print ?
  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. ??? }?
  11. }?

配置文件

[xhtml] view plain copy print ?
  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>?

测试类

[java] view plain copy print ?
  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. ??? }?
  32. }?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读