Java cfx exampple
来源:互联网 发布:用ipad开淘宝店铺教程 编辑:程序博客网 时间:2024/06/03 17:21
cfx 是 java 平台下非常优秀的WebService框架,今天上手学习了一下,写了一个例子分享给大家。
cfx 官网:http://cxf.apache.org/
开发环境:
MyEclipse10+JDK7.0+cfx3.0.3+Win7
1.接口 - CalculatorService
package com.test.service;import javax.jws.WebService;import com.test.domain.*;@WebServicepublic interface CalculatorService {public int Add(int x,int y);public boolean Validate(User user);}
2.实现接口
package com.test.service.impl;import javax.jws.WebService;import com.test.domain.User;import com.test.service.*;@WebService(endpointInterface="com.test.service.CalculatorService",serviceName="calculator")public class CalculatorServiceImpl implements CalculatorService {public int Add(int x, int y) {// TODO Auto-generated method stubreturn x + y;}public boolean Validate(User user) {// TODO Auto-generated method stubreturn user.getId() > 0;}}
3.服务端
import javax.jws.WebService;import javax.xml.ws.Endpoint;import com.test.service.*;import com.test.service.impl.*;@WebServicepublic class Server {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubSystem.out.println("web service start");CalculatorService implementor = new CalculatorServiceImpl();String address = "http://localhost:8888/calculator"; //这是上面在注解中已经声明过的URL Endpoint.publish(address, implementor); System.out.println("web service started");}}
4.关于jar包
由于不清楚哪些包会用到,把apache-cxf-3.0.3\lib下面的jar包全部导入到项目中,如果有人清楚这方面的内容,欢迎留言。
5.发布服务
注意:运行前确认服务端口(这里是8888)没有被占用,可以通过如下方式查看并关闭端口。
服务器console输出
访问webservice
6.客户端
我们使用wdsl2java工具帮助生成客户端辅助类。
在E:\MyEclipseProject\software\apache-cxf-3.0.3\bin生成一个com包
把这个com包导入到工程中(红色方框内是com包里面的内容)
import com.test.service.CalculatorService;import com.test.service.User;import com.test.service.impl.Calculator;public class Client {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubCalculator calc = new Calculator(); CalculatorService service = calc.getCalculatorServiceImplPort(); int result = service.add(3, 7); System.out.println(result); /* User user = new User(); user.setId(100); user.setName("justin"); boolean r = service.validate(user); System.out.println("The user is "+ r); */}}
7.运行客户端
运行结果正确!
8.总结:
1)如何传递对象还没有实现,有待进一步研究...
2)目前不确定哪些cxf jar 包是需要的.
3)红色输出非错误,是日志信息.
4)cxf 通常与spring 结合使用,还有待研究...
5)cxf 之前的版本都没有通过注解的方式实现,需要配置xml文件,这种方式后来被注解的方式取代(spring3.0出现之后),注解很强大,和.NET 很类似。
0 0
- Java cfx exampple
- java webservice cfx
- CFX客户端
- cfx webservice
- cfx发布到weblogic
- webservice cfx学习
- WebService CFX 实现
- cfx使用https配置
- cfx webservice 入门步骤
- CFX生成客户端代码
- android webservice(cfx) 乱码
- cfx实现webService
- cfx发布webservice
- cfx webService 入门详细步骤
- cfx webservice入门详细步骤
- gradle, springboot,cfx-- Hello World
- Spring使用CFX发布Webservice
- 使用HttpClient调用CFX WebService
- Java调用GDAL 写入矢量文件编译环境搭建
- linux cp命令
- iOS开发网络篇—XML介绍
- 图文并茂设置eclipse汉字大小
- 【c++程序】结构体链表
- Java cfx exampple
- 黑客通过linux bash漏洞借助apache cgi向产品服务器植入木马病毒的实例分享!
- Brackets Sequence
- struts2安装调试(eclipse)
- Hibernate报错 No identifier specified for entity:
- 【win10】第一时间上手体验--不一样的windows
- 用户空间辅助程序---热插拔
- Hive-2-Hive的安装
- 【零起步开发Cocos2dx-3.x-王牌飞行员(二)】从程序的层次结构说起