看了下XFire,记录相关资料。
一.概述
官网
http://xfire.codehaus.org/
XFire 是 codeHaus 组织提供的一个开源框架,它构建了 POJO 和 SOA 之间的桥梁,主要特性就是支持将 POJO 通过非常简单的方式发布成 Web 服务,这种处理方式不仅充分发挥了 POJO 的作用,简化了 Java 应用转化为 Web 服务的步骤和过程,也直接降低了 SOA 的实现难度,为企业转向 SOA 架构提供了一种简单可行的方式。
二.技术架构
XFire框架是一种基于Servlet技术的SOA应用开发框架,要正常运行基于XFire应用框架开发的企业应用,除了XFire框架本身之外,还需要JDK和Servlet容器的支持(XFire 支持在多种 Servlet 容器中运行,包括 Websphere、Weblogic、TOMCAT 等)
三.XFire的使用
详细讲解
http://www.ibm.com/developerworks/cn/java/j-lo-xfire/#h1
四.Spring集成XFire
XFire可以很好的集成到Spring中,Spring的代码已经做了这方面的集成。
将 POJO 发布成 Web 服务的基本步骤如下
1.创建 Web 服务接口
声明和实现该 Web 服务对外暴露的接口;
接口Echo.java:
Echo.java
package org.codehaus.xfire.spring.example;
public interface Echo{
String echo(String in);
}
实现EchoImpl.java
package org.codehaus.xfire.spring.example;
public class EchoImpl implements Echo{
public String echo(String in){
return in;
}
}
META-INF/xfire/service.xml文件可以省略了,因为web服务的定义在xfire-servlet.xml中可以找到。
2.配置普通bean
下面要做的工作就是配置了,在WEB-INF文件夹下创建applicationContext.xml文件,这是Spring的配置文件,如果你使用其他的Spring配置文件,可以将下面的bean添加到那个配置文件中:
<?xml version=1.0 encoding=UTF-8?>
<beans>
<bean id=echoBean class=org.codehaus.xfire.spring.example.EchoImpl/>
</beans>
定义了echoBean,这个Bean就是我们的实现类,当然你也可以在这个文件中定义其他的需要Spring管理的bean。
3.创建xfire-servlet.xml文件
在WEB-INF文件夹下创建xfire-servlet.xml文件,根据Spring规范,这个文件名起做xfire-servlet.xml,其中xfire是web.xml配置的DispatcherServlet的名称,这个文件的配置是关键:
xfire-servlet.xml
<?xml version=1.0 encoding=UTF-8?>
<beans>
<bean class=org.springframework.web.servlet.handler.SimpleUrlHandlerMapping>
<property name=urlMap>
<map>
<!--这个文件的上半部分将EchoService这个URL和echo这个bean联系在一起-->
<entry key=/EchoService><ref bean=echo></entry>
</map>
</property>
</bean>
<!--echo定义了Web服务的bean和服务接口,其中echoBean是我们在applicationContext.xml中配置的那个Bean-->
<bean id=echo class=org.codehaus.xfire.spring.remoting.XFireExporter>
<!--固定内容-->
<property name=serviceFactory><ref bean=xfire.serviceFactory</property>
<property name=xfire><ref bean=xfire</property>
<!--serviceBean是实现的类-->
<property name=serviceBean><ref bean=echoBean</property>
<!--serviceClass是接口-->
<property name=serviceClass>
<value>org.codehaus.xfire.spring.example.Echo</value>
</property>
</bean>
</beans>
4.修改web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml
classpath:org/codehaus/xfire/spring/xfire.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>xfire</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>xfire</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
………
</web-app>
需要注意这个文件的三个部分:
1.在定义contextConfigLocation参数时一定要加上
classpath:org/codehaus/xfire/spring/xfire.xml[/url]
[color=red]2[/color].定义listener:org.springframework.web.context.ContextLoaderListener
[color=red]3[/color].定义DispatcherServlet:xfire
调用这个Web服务 [url]http://localhost:8080/xfire/EchoService[/url]
查看wsdl文档 [url]http://localhost:8080/xfire/EchoService?wsdl[/url]
以上即为一个在spring中集成XFire的例子。
分享到:
相关推荐
WebService xfire学习报告WebService xfire学习报告xfire学习报告WebService xfire学习报告
webservice xfire 学习资料,里面还有xfire的官网jar包。
WebService教程-xfire学习手册
xfire学习文档
WebService教程-xfire的方式,pdf格式,共46页。
这是我总结xfire学习笔记,里面包括了xfire的配置和一些异常情况的处理
webservice 学习手册 webservice 开发步骤-spring集成-传输文件
一个简单的xfire入门例子 包含字符对象和list的调用传递 部署后引xfire类库可运行
如何利用xire来写WebService,非常实用的教程,跟着里面的教程去做就行了。
xfire 新手快速入门!根据Web_Service学习手册(Xfire)学习,加上源代码很很快入门
Myeclipse10 利用 Xfire构建 webservice。可以学习,学习。
xfire-spring,学习WebService,Xfire和Spring集成的好资料。
基于webservice的短信接口学习,XFIRE
xfire的一个完整实例,不过我建议大家,学习完理论知识后,根据自己学得知识,手动练习一下,遇到异常就百度,一下,这样比较好!
这是我自己经过琢磨在工作中使用了一段时间Web Service后,自己学习Xfire的Web Service后编写的,随后发现Web Service其实就是这样简单。包中油服务器端代码,也有客户端代码,也有一个使用说明。要是你也想学习接触...
webservice学习资料和样例webservice学习资料和样例webservice学习资料和样例webservice学习资料和样例webservice学习资料和样例webservice学习资料和样例
web service xfire 很实用的东西,希望能帮助大家。我也正在学习web service大家可以一起研究
我整理了一下使用XFire1.2.6进行Web Service开发的思路,尝试完成了一个入门实例(完整的MyEclipse项目)。如果你正在学习Web Service或者对这个有兴趣,你可以下载该附件,导入MyEclipse中运行以查看示例效果。希望...
基于XFire实施WS-Security,学习web service的材料
Xfire的小例子,方便学习,快速部署,很好很强大