文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>ant axis2 and tomcat 5.5

ant axis2 and tomcat 5.5

时间:2009-04-13  来源:luohuan123

Uzip tomcat5.5 and ant and axis2 to the directory.

Set environment variables :

CATALINA_HOME, ANT_HOME, AXIS2_HOME

then

1.C:\>CD %AXIS2_HOME%

2.C:\axis2-1.4.1>CD WEBAPP

3.C:\axis2-1.4.1\webapp>ant create.war

  Buildfile: build.xml

4.copy the file dist/axis2.war to the tomcat webapp direcory

5.enter tomcat direcory and input command : startup

you will see some info. about tomcat deployed the axis2.war

6. browser the http://localhost:8080/axis2/services/listServices you will see the service API format in XML you can use.

;-------------------------------------------------------------------------------------------

//let's have a real example

Open Eclipse and establish a project :

the code as follows:

// Product.java

package gmit;

public class Product
{
 private String partNumber ;
 private String partName ;
 private double price  ;
 
 public Product(String partNumber, String partName, double price) {
  super();
  this.partNumber = partNumber;
  this.partName = partName;
  this.price = price;
 }
 public String getPartNumber() {
  return partNumber;
 }
 public void setPartNumber(String partNumber) {
  this.partNumber = partNumber;
 }
 public String getPartName() {
  return partName;
 }
 public void setPartName(String partName) {
  this.partName = partName;
 }
 public double getPrice() {
  return price;
 }
 public void setPrice(double price) {
  this.price = price;
 }
}//

//ProductManager.java

package gmit;

import java.util.*;


public class ProductManager
{
 private Map<String, Product> products = new HashMap<String, Product>() ;
 
 public double getPrice(String number) throws Exception
 {
  if(products.containsKey(number))
  {
   return products.get(number).getPrice();
  }
  else
  {
   throw new Exception("no match number!") ;
  }
 }
 
 public void addPart(String number, String name , double price )
 {
  products.put(number, new Product(number,name ,price)) ;
 }
 
 public ProductManager()
 {
  Product p1 = new Product("AB-101", "T-shirt", 10.99) ;
  Product p2 = new Product("AB-102", "Jumper", 10.99) ;
  
  products.put(p1.getPartName(), p1);
  products.put(p2.getPartName(), p2);
 }
}
;--------------------------------------------------------------------------------

//publish the interface to the Internet:

 First, let's have the example in AXIS2.

-----><AXIS2_HOME>/samples/quickstart

5种部署方式:

1. POJOs(Plain Old Java Objects)Deploy the services:

D:\Java\axis2-1.4.1\samples\quickstart>ant generate.wsdl  -->generate StockQuoteService.wsdl

D:\Java\axis2-1.4.1\samples\quickstart>ant generate.service -->generate StockQuoteService.aar

copy the aar file to the Tomcat home webapp folder, you can access the  public API.

Check:

http://localhost:8080/axis2/services/ListServices

http://localhost:8080/axis2/services/StockQuoteService?wsdl

http://localhost:8080/axis2/services/StockQuoteService?xsd

 

2.使用AXIOM从零开始构建服务

/samples/quickstartaxiom的目录结构: 与之前的有所不同:

Axis2使用AXIOM,或者AXIs Object Model,一个基于StAX API(Streaming API for XML)的DOM(Document Object Model)类似的结构

作为服务的方法必须使用OMElement作为它们的参数,OMElement表示一个XML元素,在这里它则为进来的SOAP消息的有效载荷。这里,
你提取有效载荷元素的第一个孩子,添加文本给它,并使用它作为返回的OMElement的内容。除非这是一个"只有in"的服务,这些方法
必须返回一个OMElement,因为它成为返回的SOAP消息的有效载荷。

D:\Java\axis2-1.4.1\samples\quickstartaxiom>ant generate.service

 

3.使用ADB生成服务

执行以下步骤来使用Axis2 Databinding Framework(ADB)生成和部署服务。
通过在Axis2_HOME/samples/quickstartadb目录键入以下内容来使用WSDL2Java工具生成骨架:

D:\Java\axis2-1.4.1\samples\quickstartadb>WSDL2java -uri resources/META-INF/StockQuoteService.wsdl -p samples.quickstart.adb -d adb -s -ss -sd -o build/service

或 ant generate.service

 

选项-d adb指定了Axis Data Binding(ADB)。-s转换指定同步或者只模块化调用。-ss转换创建服务器端代码(骨架和相关文件)。-sd
转换创建一个服务描述符(services.xml文件)。-ssi转换为服务骨架创建一个接口。服务文件现在应该定位于build/service。
如果你通过使用WSDL2Java直接生成代码,下一步你需要修改生成的骨架来实现服务(如果你使用"ant generate.service",一个完全的骨架会自动复制并覆盖生成的那个)。
打开build/service/src/samples/quickstart/adb/service/StockQuoteServiceSkeleton.java文件并修改它来添加你的服务的功能性到生成的方法

build/service目录键入命令ant jar.server --> generate aar file

D:\Java\axis2-1.4.1\samples\quickstartadb\build\service>ant jar.service

 

4.使用JiBX生成服务
执行以下步骤来使用JiBX数据绑定生成和部署服务。
通过在Axis2_HOME/samples/quickstartjibx目录的控制台键入以下内容来使用WSDL2Java工具生成骨架:
%AXIS2_HOME%/bin/wsdl2java -uri resources/META-INF/StockQuoteService.wsdl -p samples.quickstart.service.jibx -d jibx
-s -ss -sd -ssi -uw -o build/service
或者在Axis2_HOME/samples/quickstartjibx目录简单的键入"ant generate.service"
选项-d jibx指定了JiBX数据绑定。-s转换指定同步或者只是模块化调用。-ss转换创建服务器端代码(骨架和相关文件)。-sd转换创建
一个服务描述符(services.xml文件)。-ssi转换创建服务骨架的接口。-uw转换解开传递给服务操作和从服务操作传递出去的参数,来
创建一个更自然的编程接口。
在运行WSDL2Java后,服务文件应该位于build/service。如果你通过使用WSDL2Java直接生成代码,下一步你需要修改生成的骨架来
实现服务(如果你使用"ant generate.service"则一个完全的骨架将自动被复制并覆盖生成的那个)。打开build/service/src/samples
/quickstart/service/jibx/StockQuoteServiceSkeleton.java文件并修改它来添加你的服务的功能性到生成的方法

现在你可以通过在build/service目录键入命令ant jar.server构建工程 

5.使用XMLBeans生成服务
执行以下步骤来使用XMLBeans生成服务。
通过在Axis2_HOME/samples/quickstartxmlbeans目录键入以下命令来使用WSDL2Java工具生成骨架:
%AXIS2_HOME%/bin/WSDL2Java -uri resources/META-INF/StockQuoteService.wsdl -p samples.quickstart.service.xmlbeans
-d xmlbeans -s -ss -sd -ssi -o build/service
或者在Axis2_HOME/sampels/quickstartxmlbeans目录简单的键入ant generate.service
选项-d xmlbeans指定XMLBeans数据绑定。-s转换指定同步或者只是模块化调用。-ss转换创建服务器端代码(骨架和相关文件)。-sd 转换创建一个服务描述符(services.xml文件)。-ssi转换创建一个服务骨架的接口。现在服务文件应该位于build/service。
如果你通过使用WSDL2Java直接生成代码,下一步你需要修改生成的骨架来实现服务(如果你使用"ant generate.service",一个完全 的骨架将被自动复制并覆盖生成的那个)。
下一步打开build/service/src/samples/quickstart/service/xmlbeans/StockQuoteServiceSkeleton.java文件并修改它来添加你的服务的功能性到生成的方法

现在你可以通过在build/service目录键入命令ant jar.server构建工程 

部署自己的工程:

目录tree :

-ProductManger

  -resources

         -META-INF

               -services.xml

  -src

         -gmit

               -Product.java

               -ProductManager.java

  - build.xml

//build.xml

<project name="ProductManger" basedir="." default="generate.service">

    <property environment="env"/>
    <property name="AXIS2_HOME" value="D:\Java\axis2-1.4.1"/>


    <property name="build.dir" value="build"/>

    <path id="axis2.classpath">
        <fileset dir="${AXIS2_HOME}/lib">
            <include name="*.jar"/>
        </fileset>
    </path>

    <target name="compile.service">
        <mkdir dir="${build.dir}"/>
        <mkdir dir="${build.dir}/classes"/>

        <!--First let's compile the classes-->
        <javac debug="on"
               fork="true"
               destdir="${build.dir}/classes"
               srcdir="${basedir}/src"
               classpathref="axis2.classpath">
        </javac>
    </target>

    <target name="generate.wsdl" depends="compile.service">
        <taskdef name="java2wsdl"
                 classname="org.apache.ws.java2wsdl.Java2WSDLTask"
                 classpathref="axis2.classpath"/>
        <java2wsdl className="gmit.ProductManager"   <--- important
                   outputLocation="${build.dir}"
                   targetNamespace="http://www.gmit.ie/ProductManager/"
                   schemaTargetNamespace="http://www.gmit.ie/ProductManager/xsd">
            <classpath>
                <pathelement path="${axis2.classpath}"/>
                <pathelement location="${build.dir}/classes"/>
            </classpath>
        </java2wsdl>
    </target>

    <target name="generate.service" depends="compile.service">
        <!--aar them up -->
        <copy toDir="${build.dir}/classes" failonerror="false">
            <fileset dir="${basedir}/resources">
                <include name="**Test.class" dir="${build.dir}/classes"/>
        </jar>
    </target>

    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>
</project>
//services.xml
<service name="ProductManager" scope="application" targetNamespace="http://www.gmit.ie/ProductManager/">
    <description>
        Product Manager
    </description>
    <messageReceivers>
        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
                         class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>
        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
                         class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
    </messageReceivers>
    <schema schemaNamespace="http://www.gmit.ie/ProductManager"/>
    <parameter name="ServiceClass">gmit.ProductManager</parameter>  <--- important
</service>
//----------------------------------------------------------------------

copy the aar file to %CATALINA_HOME%\webapps\axis2\WEB-INF\services

then you can see the service ...

//----------------------------------------------------------------------

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载