ImageVerifierCode 换一换
格式:DOCX , 页数:67 ,大小:37.32KB ,
资源ID:2833668      下载积分:1 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-2833668.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Apache CXF实战.docx)为本站会员(b****1)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

Apache CXF实战.docx

1、Apache CXF实战Apache CXF实战Apache的CXF现在几乎成了Java领域构建Web Service的首选类库,并且它也确实简单易用,下面就通过几篇系列文章做一下简单介绍。当然首先想到的当然还是那个Hello World示例。这个系列文章中用到的例子都是基于Maven构建的工程,下面是我的pom.xml文件内容1. 3. 4.0.0 4. com.googlecode.garbagecan.cxfstudy 5. cxfstudy 6. war 7. 1.0-SNAPSHOT 8. cxfstudyMavenWebapp 9. http:/maven.apache.org 1

2、0. 11. 12. 2.2.7 13. 14. 15. 16. 17. org.apache.cxf 18. cxf-rt-frontend-jaxws 19. $cxf.version 20. 21. 22. org.apache.cxf 23. cxf-rt-transports-http 24. $cxf.version 25. 26. 27. org.apache.cxf 28. cxf-rt-transports-http-jetty 29. $cxf.version 30. 31. 32. org.apache.cxf 33. cxf-rt-ws-security 34. $cx

3、f.version 35. 36. 37. org.apache.cxf 38. cxf-rt-ws-policy 39. $cxf.version 40. 41. 42. org.apache.cxf 43. cxf-bundle-jaxrs 44. $cxf.version 45. 46. 47. javax.ws.rs 48. jsr311-api 49. 1.1.1 50. 51. 52. org.slf4j 53. slf4j-api 54. 1.5.8 55. 56. 57. org.slf4j 58. slf4j-jdk14 59. 1.5.8 60. 61. 62. commo

4、ns-httpclient 63. commons-httpclient 64. 3.0 65. 66. 67. commons-io 68. commons-io 69. 2.3 70. 71. 72. junit 73. junit 74. 4.8.1 75. test 76. 77. 78. 79. 80. cxfstudy 81. 82. 83. src/main/resources 84. 85. 86. src/main/java 87. 88. * 89. 90. 91. */*.java 92. 93. 94. 95. 96. 97. org.mortbay.jetty 98.

5、 maven-jetty-plugin 99. 100. / 101. 102. 103. 9000 104. 105. 106. 107. 108. 109. org.apache.maven.plugins 110. maven-compiler-plugin 111. 112. 1.5 113. 1.5 114. 115. 116. 117. 118. 119. 下面来看看HelloWorld的具体例子。 1.创建HelloWorld 接口类1. packagecom.googlecode.garbagecan.cxfstudy.helloworld; 2. 3. importjavax

6、.jws.WebMethod; 4. importjavax.jws.WebParam; 5. importjavax.jws.WebResult; 6. importjavax.jws.WebService; 7. 8. WebService 9. publicinterfaceHelloWorld 10. WebMethod 11. WebResultStringsayHi(WebParamStringtext); 12. 2.创建HelloWorld实现类 1. packagecom.googlecode.garbagecan.cxfstudy.helloworld; 2. 3. pub

7、licclassHelloWorldImplimplementsHelloWorld 4. 5. publicStringsayHi(Stringname) 6. Stringmsg=Hello+name+!; 7. returnmsg; 8. 9. 3.创建Server端测试类 1. packagecom.googlecode.garbagecan.cxfstudy.helloworld; 2. 3. importorg.apache.cxf.jaxws.JaxWsServerFactoryBean; 4. 5. /http:/localhost:9000/HelloWorld?wsdl 6

8、. publicclassServer 7. publicstaticvoidmain(Stringargs)throwsException 8. JaxWsServerFactoryBeanfactory=newJaxWsServerFactoryBean(); 9. factory.setServiceClass(HelloWorldImpl.class); 10. 11. factory.setAddress(http:/localhost:9000/ws/HelloWorld); 12. factory.create(); 13. 14. System.out.println(Serv

9、erstart.); 15. Thread.sleep(60*1000); 16. System.out.println(Serverexit.); 17. System.exit(0); 18. 19. 4.创建Client端测试类 1. packagecom.googlecode.garbagecan.cxfstudy.helloworld; 2. 3. importorg.apache.cxf.jaxws.JaxWsProxyFactoryBean; 4. 5. publicclassClient 6. publicstaticvoidmain(Stringargs) 7. JaxWsP

10、roxyFactoryBeanfactory=newJaxWsProxyFactoryBean(); 8. factory.setServiceClass(HelloWorld.class); 9. factory.setAddress(http:/localhost:9000/ws/HelloWorld); 10. HelloWorldhelloworld=(HelloWorld)factory.create(); 11. System.out.println(helloworld.sayHi(kongxx); 12. System.exit(0); 13. 14. 5.测试 首先运行Ser

11、ver类来启动Web Service服务,然后访问http:/localhost:9000/ws/HelloWorld?wsdl地址来确定web service启动正确。运行Client测试类,会在命令行输出Hello kongxx!的message。书接上文,下面看看CXF怎样和spring集成。1.创建HelloWorld 接口类1. packagecom.googlecode.garbagecan.cxfstudy.helloworld;2. 3. importjavax.jws.WebMethod;4. importjavax.jws.WebParam;5. importjavax.j

12、ws.WebResult;6. importjavax.jws.WebService;7. 8. WebService9. publicinterfaceHelloWorld10. WebMethod11. WebResultStringsayHi(WebParamStringtext);12. 2.创建HelloWorld实现类 1. packagecom.googlecode.garbagecan.cxfstudy.helloworld;2. 3. publicclassHelloWorldImplimplementsHelloWorld4. 5. publicStringsayHi(St

13、ringname)6. Stringmsg=Hello+name+!;7. returnmsg;8. 9. 3.修改web.xml文件 1. 4. 5. 6. 7. cxfstudy8. 9. 10. cxf11. org.apache.cxf.transport.servlet.CXFServlet12. 113. 14. 15. 16. cxf17. /ws/*18. 19. 20. 21. org.springframework.web.context.ContextLoaderListener22. 23. 24. 25. contextConfigLocation26. classpath*:*/spring.xml27. 28. 29. 4.创建spring配置文件并放在classpath路径下 1. 2. 6. 7. 8. importresource=classpath:META-INF/cxf/cxf

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2