xfire和ajax有哪些特征,XFire使用详解
最近一直使用XFire做WebServices方式使用,总结一些相关经验,本文以具体例子进行XFire开发过程分析
1、首先定义一个Interface,具体包含简单类型传值、返回自定义对象、返回集合三个接口方法
import java.util.List;
import com.gresoft.commons.core.exception.BusinessException;
import com.gresoft.sanitation.model.dictionary.Hospital;
public interface WebServicesInterface {
public String savePutXml(int i,String typecode) throws BusinessException;
public Hospital getList(int p);
public List getAll();
}
2、实现上述接口,实现业务逻辑
public class HospitalService extends HibernateEntityDao implements
WebServicesInterface {
private HospitalManager hospitalManager;
public void setHospitalManager(HospitalManager hospitalManager) {
this.hospitalManager = hospitalManager;
}
public String savePutXml(int o, String typecode) throws BusinessException {
// TODO Auto-generated method stub
Hospital h = new Hospital(o, typecode);
super.save(h);
System.out.println("ccccc");
return "gggg";
}
public Hospital getList(int p) {
// TODO Auto-generated method stub
Hospital h = hospitalManager.get(p);
System.out.println("name:" + h.getHospitalName());
return hospitalManager.get(p);
}
@SuppressWarnings("unchecked")
public List getAll() {
List list = hospitalManager.getAll();
System.out.println("size:" + list.size());
return hospitalManager.getAll();
}
}
定义自定义对象Hospital
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
/**
* @author wuxj:
* @version 创建时间:2007-10-15 上午11:31:39
*/
@Entity
@Table(name = "HOSPITAL", schema = "DB2ADMIN")
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class Hospital implements java.io.Serializable {
private int hospitalId;
private String hospitalName;
public Hospital() {
}
public Hospital(int hospitalId) {
this.hospitalId = hospitalId;
}
public Hospital(int hospitalId, String hospitalName) {
this.hospitalId = hospitalId;
this.hospitalName = hospitalName;
}
@Id
@Column(name = "HOSPITAL_ID", unique = true, nullable = false)
public int getHospitalId() {
return hospitalId;
}
public void setHospitalId(int hospitalId) {
this.hospitalId = hospitalId;
}
@Column(name = "HOSPITAL_NAME", nullable = false, length = 20)
public String getHospitalName() {
return hospitalName;
}
public void setHospitalName(String hospitalName) {
this.hospitalName = hospitalName;
}
}
3、编写XFire的描述文件
描述文件为WebServicesInterface.aegis.xml,一定要与Interface接口类在同一个目录,否则会出错误
只需要描述返回是集合的描述,getAll方法返回是List集合,需要对集合中的元素进行定义,在这里是Hospital对象
componentType="com.gresoft.sanitation.model.dictionary.Hospital" />
4、编写xfire-servlet.xml文件
xfire是跟spring结合一起使用的,所以用到了spring相关内容。
注意:位置一定要在WEB-INF目录下
key="/echo"中的echo为你在客户端访问的地址,具体看client内容
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
class="org.codehaus.xfire.spring.remoting.XFireExporter">
value="com.gresoft.sanitation.service.WebServicesInterface" />
5、编写客户端测试
import java.net.MalformedURLException;
import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
public class HospitalServiceClient {
public static void main(String args[]) {
Service srvcModel = new ObjectServiceFactory()
.create(WebServicesInterface.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
.newInstance().getXFire());
// XFireProxyFactory factory = new XFireProxyFactory(getXFire());
String helloWorldURL = "http://localhost:8080/sanitation/service/echo";
// String helloWorldURL ="xfire.local://echo";
try {
WebServicesInterface srvc = (WebServicesInterface) factory.create(
srvcModel, helloWorldURL);
Hospital h = new Hospital();
h.setHospitalId(11);
h.setHospitalName("测试");
// System.out.print(srvc.sayHello("wuxj")+"\n");
// RegisterApply apply = new RegisterApply();
// apply.setOperateDate("20071221");
// apply.setRegisterId("1000");
// srvc.savePutXml(apply);
System.out.println(srvc.savePutXml(11, "测试"));
srvc.getList(1);
srvc.getAll();
// System.out.print(((MsdpUser)srvc.getUser().get(0)).getUid());
} catch (MalformedURLException e) {
System.out.println("wrong");
e.printStackTrace();
}
}
}
6、定义web.xml的xfire
红色字体一定要加上,而且是固定格式,这是xfire需要加载的文件
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
contextConfigLocation
classpath*:spring/*.xml,classpath:org/codehaus/xfire/spring/xfire.xml
org.springframework.web.context.ContextLoaderListener
xfire
org.springframework.web.servlet.DispatcherServlet
xfire
/service/*
xfire和ajax有哪些特征,XFire使用详解相关推荐
- 尺度不变特征变换匹配算法详解
尺度不变特征变换匹配算法详解 Scale Invariant Feature Transform(SIFT) Just For Fun 对于初学者,从David G.Lowe的论文到实现,有许多鸿沟, ...
- 解决AJAX跨域WCF的问题详解
解决AJAX跨域WCF的问题详解 参考文章: (1)解决AJAX跨域WCF的问题详解 (2)https://www.cnblogs.com/jooucks/p/7159147.html 备忘一下.
- ajax 页面无刷新,Ajax的页面无刷新实现详解(附代码)
这次给大家带来Ajax的页面无刷新实现详解(附代码),Ajax页面无刷新实现的注意事项有哪些,下面就是实战案例,一起来看一下. ajax (ajax开发) AJAX即"Asynchronou ...
- java ajax同步请求,成都汇智动力-java ajax实现异步同步请求全面详解
原标题:成都汇智动力-java ajax实现异步同步请求全面详解 对象 var request=new () //兼容IE5 IE6 if (window.) {// code for IE7+, F ...
- 尺度不变特征变换匹配算法详解 Scale Invariant Feature Transform(SIFT)
1.SIFT综述 尺度不变特征转换(Scale-invariant feature transform或SIFT)是一种电脑视觉的算法用来侦测与描述影像中的局部性特征,它在空间尺度中寻找极值点,并提取 ...
- php 检测网络,PHP+Ajax 检测网络是否正常实例详解
本文实例讲述了PHP+Ajax实时自动检测是否联网的方法.分享给大家供大家参考.具体实现方法如下: html部分代码: /p> "http://www.w3.org/TR/xhtml1 ...
- ajax post 空格变加号,Ajax Post数据加号变空格详解
我在页面上得到BASE64编码想通过AJAX方式与后台交互,但是后台得到的数据所有的+号都变成了空格,查了一下. 采用Ajax传递数据时,通常会将数据整理为data="var1=abc&am ...
- AJAX请求和跨域请求详解(原生JS、Jquery)
一.概述 AJAX 是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术. AJAX = 异步 JavaScript 和 XML,是一种用于创建快速动态网页的技术.通过在后台与服务器进行少量数 ...
- 前端ajax数据提交到服务器_详解前端如何让服务器主动向浏览器推送数据
前言 前面我们已经聊了ajax,它的特点是浏览器必须先发起请求,服务器才能给出对应的响应,想一想能不能让服务器主动向浏览器推送数据呢?那么这篇文章我们来聊一聊服务器推送功能. 轮询 假设你现在需要去做 ...
最新文章
- 南京、苏州、杭州、上海你更喜欢哪座城市?
- android注册弹窗,Android开发之PopupWindow创建弹窗、对话框的方法详解
- 调试笔记--jlink 变量转实时波形小技巧
- 洛谷 P1955 [NOI2015]程序自动分析(沙雕题)
- pmbook 知识领域 第六版_PMP项目管理10大知识领域脑图
- maven项目打包时生成dependency-reduced-pom.xml
- C++ 内建函数对象
- 学python语言有前途吗-Python语言是什么?学Python语言有前途吗?
- 求求你了,不要再自己实现这些逻辑了,开源工具类不香吗?
- c lua mysql 扩展_lua安装及luarocks安装mysql扩展
- 中国传统色彩十六进制颜色码图片大全
- 多媒体技术计算机系统由组成,多媒体技术概述及多媒体计算机系统的组成
- 计算机专业考研2021,2021考研:计算机专业考研方向有哪些?
- 软件公司使用XPlanner进行敏捷项目计划和进度跟踪管理
- 小游戏——满天小星星
- 如何利用Photoshop进行快速切图
- TCL/TK 学习笔记 之 用C定义自己的TCL命令
- 群晖网络不通_群晖系统安装zerotier one进行内网穿透过程中常见问题及解决方法...
- 软硬件解耦太难!英伟达竟“越来越像Mobileye”
- 生产消费者模式实例(多线程实现价格监控)
热门文章
- Hough变换-理解篇
- 电网招聘考试其他工学类难吗?考什么?怎么备考?
- 智能表单设计器FreeForm常量定义及用途
- 【C++入门】类和对象(中)
- 微信小程序/uni-app生成海报功能@令狐张豪
- DateTime.ToString()用法详解
- C语言电脑睡眠,什么是计算机睡眠的意思概念介绍用法
- 淘淘商城第20讲——展示后台管理系统首页面
- linux文件系统基础--VFS中的file、dentry和inode--讲得非常透的一篇文章
- 图像检索之Neural Codes for Image Retrieval