1.0 XFire

XFire是codeHaus组织提供的一个开源框架,它构建了POJOSOA之间的桥梁,主要特性就是支持将POJO通过非常简单的方式发布成Web服务,这种处理方式不仅充分发挥了POJO的作用,简化了Java应用转化为Web服务的步骤和过程,也直接降低了SOA的实xfire现难度,为企业转向SOA架构提供了一种简单可行的方式。

目前,XFire虽然已经放弃维护了,并入了apache 的顶级项目CXF中,但是使用的人还是不少,所以留下笔录.供以后回忆.

下面是官方给出的一段话:
XFire is now CXF
Icon
User's looking to use XFire on a new project, should use CXF instead. CXF is a continuation of the XFire project and is considered XFire 2.0. It has many new features, a ton of bug fixes, and is now JAX-WS compliant! XFire will continue to be maintained through bug fix releases, but most development will occur on CXF now. For more information see the XFire/Celtix merge FAQ and the CXF website.

1.2 XFire的使用

1.2.1 XFire的使用,自底向上篇;

1.下载Xfire , 地址 http://xfire.codehaus.org/Download

2.导入jar包和所有依赖

3.编写接口

package cn.c.jorcen.service;

public interface CalculatorServicer {
public int add(int a, int b); public int del(int a, int b); public int get(int a, int b);
}

4.编写实现了

package cn.c.jorcen.service.impl;

import cn.c.jorcen.service.CalculatorServicer;

public class CalculatorServicerImpl implements CalculatorServicer {

    public int add(int a, int b) {

        return a + b;
} public int del(int a, int b) {
// TODO Auto-generated method stub
return a - b;
} public int get(int a, int b) {
return a - b;
} public static void main(String[] args) {
System.out.println(CalculatorServicerImpl.class); } }

5.编辑web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>XFireServlet</servlet-name>
<!-- <display-name>XFire Servlet</display-name>-->
<servlet-class>
org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
</servlet> <servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/servlet/XFireServlet/*</url-pattern>
</servlet-mapping> <servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>

6.编辑 META-INF/xfire/services.xml

<!-- START SNIPPET: services -->
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
<name>CalculatorService</name>
<serviceClass>cn.c.jorcen.service.CalculatorServicer</serviceClass>
<implementationClass>cn.c.jorcen.service.impl.CalculatorServicerImpl</implementationClass>
</service>
</beans>
<!-- END SNIPPET: services -->

7.启动服务器,我用的是Tomcat.测试结果;

http://localhost:8080/web/services

内容如下

8.自己编写测试类:

package cn.c.jorcen.service.test;

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; import cn.c.jorcen.service.CalculatorServicer; public class Client {
public static void main(String[] args) throws Throwable {
Service service = new ObjectServiceFactory()
.create(CalculatorServicer.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
.newInstance().getXFire());
String url = "http://localhost:8080/web/services/CalculatorService";
CalculatorServicer cs = (CalculatorServicer) factory.create(service,
url);
System.out.println(cs.getClass());
int add = cs.add(1, 3);
int del = cs.del(1, 4);
System.out.println(add);
System.out.println(del); }
}

结果如下:

class $Proxy0
4
-3

1.2.2 XFire的使用,自顶向下篇;

Xfire 使用Ant,来自动构建的.为了方便编写,我们把Xfire 的jar 包和 依赖包放在一起.并引入工程.

新建builder.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<!-- default 定义一个默认的任务-->
<project name="calculatorServicer" basedir="." default="gen-webservice">
<!-- 引入属性文件-->
<property file="buider.properties">
</property>
<!-- 定义 jar 文件 -->
<path id="project-classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</path> <!--定义一个任务 -->
<target name="gen-webservice">
<taskdef name="wsgen" classname="org.codehaus.xfire.gen.WsGenTask" classpathref="project-classpath" />
<!--outputDirectory 产生源码的位置, wsdl文件的位置,package 包名, overwrite 是否覆盖 -->
<wsgen outputDirectory="${src.dir}" wsdl="${wsdl.dir}" package="cn.c.ws.client" overwrite="true" /> </target> </project>

属性文件如下:

#引用ant里边的当前项目的src
src.dir=${basedir}/src
lib.dir=F:/bin/xfire-1.2.6/lib
wsdl.dir=http://localhost:8080/web/services/CalculatorService?wsdl

生产代码如下:

测试类如下:

public class Mail {
public static void main(String[] args) {
CalculatorServiceClient client = new CalculatorServiceClient();
CalculatorServicePortType pro = client.getCalculatorServiceHttpPort();
System.out.println(pro.add(1, 3));
System.out.println(pro.del(8, 9));
}
}

结果如下:

4
-1

2.使用maven来构建:

  废话不多说:

目录结构如下:

pom.xml 如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>webMaven</groupId>
<artifactId>webMaven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>webMaven</name>
<url>http://maven.apache.org</url> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <dependencies>
<dependency>
<groupId>org.codehaus.xfire</groupId>
<artifactId>xfire-generator</artifactId>
<version>1.2.6</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.3</version>
<scope>provided</scope>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<configuration>
<tasks>
<!-- START SNIPPET: client -->
<taskdef name="wsgen" classname="org.codehaus.xfire.gen.WsGenTask"
classpathref="maven.compile.classpath" /> <wsgen outputDirectory="${basedir}/src/main/java"
wsdl="${basedir}/src/wsdl/test.wsdl" package="cn.c.jorcen.test"
overwrite="true" />
<!-- END SNIPPET: client -->
</tasks>
<sourceRoot>${basedir}/src/main/java</sourceRoot>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
<sourceDirectory>src/main</sourceDirectory>
<testSourceDirectory>src/test</testSourceDirectory>
<resources>
<resource>
<directory>src/main</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.xsd</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
<include>**/*.wsdl</include>
</includes>
</testResource>
</testResources>
</build> <!-- needed for XmlSchema -->
<repositories>
<repository>
<id>codehaus</id>
<name>Codehaus maven repository</name>
<url>http://dist.codehaus.org/</url>
<layout>legacy</layout>
</repository>
</repositories> </project>

run:

或者在工程根目录下: mvn clean generate-sources

控制台输出如下:

[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for webMaven:webMaven:jar:0.0.1-SNAPSHOT
[WARNING] 'repositories.repository.layout = legacy' is deprecated: codehaus @ webMaven:webMaven:0.0.1-SNAPSHOT, F:\Workspaces\MyEclipse8.6\workspace-webService\webMaven\pom.xml
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building webMaven 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-antrun-plugin:1.3:run (default) @ webMaven ---
[INFO] Executing tasks
2014-4-15 11:12:36 org.codehaus.xfire.gen.Wsdl11Generator generate
信息: Generating code for WSDL at file:/F:/Workspaces/MyEclipse8.6/workspace-webService/webMaven/src/wsdl/test.wsdl with a base URI of file:/F:/Workspaces/MyEclipse8.6/workspace-webService/webMaven/src/wsdl/test.wsdl
2014-4-15 11:12:38 org.codehaus.xfire.gen.jsr181.AbstractServiceGenerator generate
信息: Creating class cn.c.jorcen.test.CalculatorServicePortType
2014-4-15 11:12:38 org.codehaus.xfire.gen.jsr181.AbstractServiceGenerator generate
信息: Creating class cn.c.jorcen.test.CalculatorServiceImpl
cn\c\jorcen\service\Add.java
cn\c\jorcen\service\AddResponse.java
cn\c\jorcen\service\Del.java
cn\c\jorcen\service\DelResponse.java
cn\c\jorcen\service\Get.java
cn\c\jorcen\service\GetResponse.java
cn\c\jorcen\service\ObjectFactory.java
cn\c\jorcen\service\package-info.java
cn\c\jorcen\test\CalculatorServiceClient.java
cn\c\jorcen\test\CalculatorServiceImpl.java
cn\c\jorcen\test\CalculatorServicePortType.java
[INFO] Executed tasks
[INFO] Registering compile source root F:\Workspaces\MyEclipse8.6\workspace-webService\webMaven\src\main\java
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.436s
[INFO] Finished at: Tue Apr 15 11:12:38 CST 2014
[INFO] Final Memory: 2M/5M
[INFO] ------------------------------------------------------------------------

结果如下:

功成身退!

xfire for web-Service的更多相关文章

  1. XFire构建web service客户端的五种方式

    这里并未涉及到JSR 181 Annotations 的相关应用,具体的三种方式如下 ① 通过WSDL地址来创建动态客户端 ② 通过服务端提供的接口来创建客户端 ③ 使用Ant通过WSDL文件来生成客 ...

  2. SOAP: java+xfire(web service) + php客户端

    作者: 吴俊杰 web service这项技术暂不说它有多落伍,但是项目中用到了,没法逃避!    xml和json各有各的好处,但是JSON无疑是当今数据交互的主流了.客户soap服务器端用的是 j ...

  3. 使用XFire+Spring构建Web Service(一)——helloWorld篇

    转自:http://www.blogjava.net/amigoxie/archive/2007/09/26/148207.html原文出处:http://tech.it168.com/j/2007- ...

  4. 使用XFire+Spring构建Web Service

    XFire是与Axis 2并列的新一代Web Service框架,通过提供简单的API支持Web Service各项标准协议,帮助你方便快速地开发Web Service应用. 相 对于Axis来说,目 ...

  5. XFire+Spring构建Web Service经验总结

    使用工具 MyEclipse:6.5 ,tomcat6.x. 1.新建web项目,要导入用的包: 2程序结构: 3 web.xml配置文件 <?xml version="1.0&quo ...

  6. 采用web service传输超大数据

    因为以前也没有做过相关的web service开发,对于Xfire也只是知道有这么一个框架.当然现在它已经变成apache基金会旗下的一个开源项目CXF.不过,现在依旧有很多公司还在用Xfire作we ...

  7. MyEclipse XFire Web Service

    我们在做系统集成时,经常会需要调用webservice接口,本文将讲解在myeclipse中建立一个webservice项目,编写接口和实现类, 并且发布webservice,最后在myeclipse ...

  8. axis1,xfire,jUnit 测试案列+开Web Service开发指南+axis1.jar下载 代码

    axis1,xfire,jUnit 测试案列+Web Service开发指南(中).pdf+axis1.jar下载    代码 项目和资源文档+jar 下载:http://download.csdn. ...

  9. MyEclipse构建Web Service(Xfire框架)

    以下是本人原创,如若转载和使用请注明转载地址.本博客信息切勿用于商业,可以个人使用,若喜欢我的博客,请关注我,谢谢!博客地址 任务要求: 使用Xfire实现一个简单的CalculatorWebServ ...

  10. 《转》Web Service实践之——开始XFire

    Web Service实践之——开始XFire 一.Axis与XFire的比较XFire是与Axis2 并列的新一代WebService平台.之所以并称为新一代,因为它:1.支持一系列Web Serv ...

随机推荐

  1. 实用工具推荐(Live Writer)(2015年05月26日)

    1.写博客的实用工具 推荐软件:Live Writer 使用步骤: 1.安装 Live Essential 2011,下载地址:http://explore.live.com/windows-live ...

  2. 【Ionic】---AngularJS扩展基本布局

    目录: 标题栏 : ion-header-bar 页脚栏 : ion-footer-bar header/footer : 样式及内容 内容区 : ion-content 滚动框 : ion-scro ...

  3. MySql索引的优缺点

    优点 有了索引.对于记录数量很多的表,可以提高查询速度. 缺点 索引是占用空间的. 索引会影响update insert delete速度 ALERT!!! 1.索引要创建在where和join用到的 ...

  4. spring aop配置及用例说明(3)

    欢迎转载交流:http://www.cnblogs.com/shizhongtao/p/3476336.html 1.这里说一下aop的@Around标签,它提供了在方法开始和结束,都能添加用户业务逻 ...

  5. 为oracle中的表格增加列和删除列

    http://blog.csdn.net/rainharder/article/details/6663458 alter table 表名 drop column 列名eg:alter table ...

  6. PHP 魔术方法(所有的魔术方法)

    慢慢长寻夜,明月高空挂. 目前PHP所有的魔术方法有一下这些 __construct() __destruct() __call() __callStatic() __get() __set() __ ...

  7. 《APUE》第6章练习1

    问题:编写一个程序,它调用uname并输出utsname结构中的所有字段,并将输出与uname(1)命令的输出结构做比较. 我本来以为utsname结构也跟passwd结构一样,也有那三个函数来获取整 ...

  8. [DevExpress][TreeList]条件隐藏节点CheckBox

    关键代码: /// <summary> /// 隐藏CheckBox /// 说明 /// 在CustomDrawNodeCheckBox事件中使用 /// eg: /// TreeLis ...

  9. mysql中使用update select

    UPDATE t_user INNER JOIN t_shake ON t_shake.user_id = t_user.user_id SET t_user.shake_total_num = t_ ...

  10. php curl 伪造IP来源的代码分享

    php curl 可以模仿用户登录,还可以模仿用户IP地址.伪造IP来源. 1,curl发出请求的文件fake_ip.php: <?php $ch = curl_init(); $url = & ...