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

发布webservice--axis

发布时间:2020-12-17 00:06:51 所属栏目:安全 来源:网络整理
导读:[java] view plain copy print ? package mule.webservice.service;? import javax.jws.WebParam;? import javax.jws.WebResult;? import javax.jws.WebService;? @WebService ? public interface Hello {? ????? ??? @WebResult (name= "text" )? ??? publi
[java] view plain copy print ?
  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 Hello {?
  7. ?????
  8. ??? @WebResult(name="text")?
  9. ??? public String sayHello(@WebParam(name="text")String name);?
  10. ?????
  11. }?

[java] view plain copy print ?
  1. package mule.webservice.service.impl;?
  2. import mule.webservice.service.Hello;?
  3. public class HelloImpl implements Hello {?
  4. ??? @Override?
  5. ??? public String sayHello(String name) {?
  6. ??????? System.out.println("Hello," + name);?
  7. ??????? return "Hello," + name;?
  8. ??? }?
  9. }?

配置config文件

[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"?
  3. ??? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?
  4. ??? xmlns:soap="http://www.mulesource.org/schema/mule/soap/2.2"?
  5. ??? xmlns:axis="http://www.mulesource.org/schema/mule/axis/2.2"?
  6. ??? xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2"?
  7. ??? xsi:schemaLocation="?
  8. ??? http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd?
  9. ??? http://www.mulesource.org/schema/mule/soap/2.2 http://www.mulesource.org/schema/mule/soap/2.2/mule-soap.xsd?
  10. ??? http://www.mulesource.org/schema/mule/axis/2.2 http://www.mulesource.org/schema/mule/axis/2.2/mule-axis.xsd?
  11. ??? http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd?
  12. ??? ">????
  13. ?????
  14. ??? <model name="echoSample">?
  15. ?????????
  16. ??????? <service name="testService">?
  17. ??????????? <inbound>?
  18. ??????????????? <axis:inbound-endpoint address="http://localhost:65088/services"/>?
  19. ??????????? </inbound>?
  20. ??????????? <component class="mule.webservice.service.impl.HelloImpl"></component>?
  21. ??????? </service>?
  22. ??? </model>?
  23. </mule>?

测试类

[java] view plain copy print ?
  1. package mule.webservice.client;?
  2. import org.mule.api.MuleContext;?
  3. import org.mule.api.MuleException;?
  4. import org.mule.api.MuleMessage;?
  5. import org.mule.api.config.ConfigurationException;?
  6. import org.mule.api.lifecycle.InitialisationException;?
  7. import org.mule.context.DefaultMuleContextFactory;?
  8. import org.mule.module.client.MuleClient;?
  9. public class Client1 {?
  10. ??? public static void startMule(String config) {?
  11. ??????? try {?
  12. ??????????? MuleContext muleContext;???
  13. ??????????? muleContext = new DefaultMuleContextFactory().createMuleContext(config);???
  14. ??????????? muleContext.start();?
  15. ??????? } catch (InitialisationException e) {?
  16. ??????????? e.printStackTrace();?
  17. ??????? } catch (ConfigurationException e) {?
  18. ??????????? e.printStackTrace();?
  19. ??????? } catch (MuleException e) {?
  20. ??????????? e.printStackTrace();?
  21. ??????? }?
  22. ??? }?
  23. ?????
  24. ??? public static void main(String[] args) {?
  25. ??????? startMule("ws-config-1.xml");?
  26. ?????????
  27. ??????? MuleClient client = null;?
  28. ??????? try {?
  29. ??????????? client = new MuleClient();?
  30. ??????????? String url = "axis:http://localhost:65088/services/testService?method=sayHello";?
  31. ??????????? MuleMessage message = client.send(url, "zhuyoufeng",null);?
  32. ??????????? Object obj = message.getPayload();?
  33. ??????????? System.out.println(obj.getClass().getName());?
  34. ??????????? if (obj instanceof String) {?
  35. ??????????????? System.out.println(obj);?
  36. ??????????? }?
  37. ??????? } catch (MuleException e) {?
  38. ??????????? e.printStackTrace();?
  39. ??????? } finally {?
  40. ??????????? client.dispose();?
  41. ??????? }?
  42. ??? }?
  43. }?

(编辑:李大同)

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

    推荐文章
      热点阅读