A Quick Setup Note:
The code for the document can be found in the extracted Standard Binary Distribution , more specifically at Axis2_HOME/samples/ inside the directories- quickstart, quickstartadb, quickstartaxiom, quickstartjibx and quickstartxmlbeans. (Consider getting it now as it will help you to follow along.) It includes Ant buildfiles (build.xml) that we'll refer to throughout the examples to make compilation easier.
可以从标准Binary版本中找到这篇文档的所有代码,特别是在Axis2_HOME/samples/里的
quickstart, quickstartadb, quickstartaxiom, quickstartjibx and quickstartxmlbeans这几个目录下(可以考虑现在下载它,因为下面都要用到它)它包括Ant 文件(build.xml),这个文件是在使用例子的过程中我们都要用到的,Ant文件使例子的编译更加简单
Let's start with the service itself. We'll make it simple so you can see what is going on when we build and deploy the services. A StockQuoteService example seems to be mandatory in instances like this one, so let's use the following (see Code Listing 1).
我们现在就从它自身的例子开始讲起。我们将尽量简单,以使你能够明白在我们build和deploy服务时,究竟发生了什么。StockQuoteService看起来就是一个这样的例子,所以,让我们从它开始,先看下面的code Listing 1.
Code Listing 1: The StockQuoteService class
package samples.quickstart.service.pojo;
import java.util.HashMap;
public class StockQuoteService {
private HashMap map = new HashMap();
public double getPrice(String symbol) {
Double price = (Double) map.get(symbol);
if(price != null){
return price.doubleValue();
}
return 42.00;
}
public void update(String symbol, double price) {
map.put(symbol, new Double(price));
}
}
It will be a simple service with two possible calls. One of which is an in/out message, and the other is an in-only service. Ultimately, we'll package the service and deploy it in four different ways.
这是一个有两个调用的简单例子。一个是in/out形式,一个只有进的消息。我们最终将打包这个服务,并且用4种不同的方式部署它
First, let's look at how this simple Java class corresponds to a service.
首先,让我们来看看java class文件怎么关联这个服务的
Getting Ready
Before we build anything using Axis2, we have to take care of a little housekeeping. First off, you'll need to get your environment ready for working with Axis2. Fortunately, it involves just a few simple steps:
在构建任何与Axis2相关的业务时,我们先要设置一下自己的电脑。你必须搭建好与Axis2一起工作的环境。幸运的是,这只包含几个简单的步骤
Download and install Java (Minimum version is JDK1.4). Set the JAVA_HOME environment variable to the pathname of the directory into which you installed the JDK release.
Download Axis2 and extract it to a target directory.
Copy the axis2.war file to the webapps directory of your servlet engine.
Set the AXIS2_HOME environment variable to point to the target directory in step. Note that all of the scripts and build files Axis2 generates depend on this value, so don't skip this step! Linux users can alternatively run the setenv.sh file in the AXIS2_HOME/bin directory to set the AXIS2_HOME environment variable to the pathname of the extracted directory of Axis2.
In most cases, we're also going to need a WSDL file for our service. Axis2's Java2WSDL can be used to bootstrap a WSDL. To generate a WSDL file from a Java class, perform the following steps:
1.下载并安装java(至少是jdk1.4),设置好java_home环境变量,值就是你安装JDK版本的目录
2.设置AXIS2_HOME变量,让它指向你的安装目录。注意所有的脚本和Axis2产生的构建文件都信赖这个值。千万不能省略这一步。
Create and compile the Java class.
(Windows)
%AXIS2_HOME%\bin\java2wsdl -cp . -cn samples.quickstart.service.pojo.StockQuoteService -of StockQuoteService.wsdl
(Linux)
$AXIS2_HOME/bin/java2wsdl -cp . -cn samples.quickstart.service.pojo.StockQuoteService -of StockQuoteService.wsdl
Generate the WSDL using the command:
Once you've generated the WSDL file, you can make the changes you need. For example, you might add custom faults or change the name of the generated elements. For example, this StockQuoteService.wsdl is in AXIS2_HOME/samples/quickstartadb/resources/META-INF folder, which we'll be using throughout the rest of this guide, replaces the generic parameters created by the generation process.