Axis开发经验集(How to use Axis)

系统 1733 0
  • Axis是什么(What is Axis)

Axis is essentially a SOAP engine,The current version of Axis is written in Java, but a C++ implementation of the client side of Axis is being developed.

Axis本质上是一个SOAP引擎,目前的Axis是用java编写的,同时Axis还有一个C++版本(关于C++版本的Axis这里不做介绍,有兴趣的朋友可以自己去研究)。

for a detailed information about what axis is,please visit the official site of axis
http://ws.apache.org/axis/java/user-guide.html

如果需要了解更多的Axis信息,请访问Axis的官方网站
http://ws.apache.org/axis/java/user-guide.html

  • SOAP是什么(What is SOAP)



SOAP stands for Simple Object Access Protocol
SOAP is a communication protocol
SOAP is for communication between applications
SOAP is a format for sending messages
SOAP communicates via Internet
SOAP is platform independent
SOAP is language independent
SOAP is based on XML
SOAP is simple and extensible
SOAP allows you to get around firewalls
SOAP is a W3C recommendation


SOAP代表简单对象访问协议
SOAP是一种通信协议
SOAP用于在应用程序之间的通信
SOAP是一种用于发送消息的格式
SOAP 被设计用来通过因特网进行通信
SOAP 独立于平台
SOAP 独立于程序语言
SOAP 基于 XML
SOAP 很简单并可扩展
SOAP 允许您绕过防火墙
SOAP 将被作为 W3C 标准来发展


  • 如何安装Axis(How to install Axis in Web Application)


1.准备WEB服务器(Preparing an application server)

First of all,you should have an application server or servlet engine and be familiar with operating and deploying to it. and i prefered Jakarta Tomcat which is also Axis's official site( http://ws.apache.org/axis/java/ )'s recommendation


首先,你需要拥有一个WEB服务器或者Servlet引擎,而且熟悉它的操作和部署。我更喜欢Tomcat(感觉它是国内大多数Java开发者学习J2EE应用的入门级服务器,简单而实用)。


2.准备WEB应用程序(Preparing the webapp)


Here I assume that you have a web server up and running on the localhost at port 8080. If your server is on a different port,never mind.

这里我假设你已经有了一个已经启动的WEB服务器,端口号为8080。如果你的端口号不同也没关系。

Note:webapp refers to web application here.

备注:webapp在这里指的是web应用程序


my webapp is christened "myaxis" here which is alreay deployed in Tomcat.(the detail of how to deploy webapp in Tomcat will not be metioned here)

我将我的web应用程序命名为"myaxis",并且该web程序已经在Tomcat中部署。(关于如何在Tomcat中部署web应用程序,这里不会提及)


3、加入必须的jar文件(Setting up the required jar files)


there are a couple of jar files(listed below) needs to be added in your own webapp's lib folder(let's assume the lib folder of "myaxis" is "wwwroot\WEB-INF\lib")

如果想在你自己的应用程序中使用axis,必须要将下面列表中列出的jar文件加入到你的应用程序的lib目录下(假设"myaxis"的lib目录为"wwwroot\WEB-INF\lib")

AXIS必须的jar文件列表(AXIS REQUIRED JAR FILES LIST)
axis.jar
axis-ant.jar
commons-discovery*.jar
commons-logging*.jar
jaxrpc.jar
saaj.jar
wsdl4j*.jar

Note:lib folder refers to libararies folder here.
Note:* is a placeholader that substitutes the real version of jar file which depends on the version of axis.for example,Axis 1.4 uses commons-discovery-0.2.jar,commons-logging-1.0.4.jar.

备注:lib目录在这里指libararies目录。
备注:*代表占位符,代替该jar文件的真实版本号,因为axis的版本不同,它使用的jar文件就有可能不同。


4、设置web.xml(Setting up the web.xml)

(将以下内容加入你自己的web.xml)Add following text to your own web.xml

<servlet>
    <servlet-name>AxisServlet</servlet-name>
    <display-name>Apache-Axis Servlet</display-name>
    <servlet-class>
        org.apache.axis.transport.http.AxisServlet
    </servlet-class>
  </servlet>

  <servlet>
    <servlet-name>AdminServlet</servlet-name>
    <display-name>Axis Admin Servlet</display-name>
    <servlet-class>
        org.apache.axis.transport.http.AdminServlet
    </servlet-class>
    <load-on-startup>100</load-on-startup>
  </servlet>

  <servlet>
    <servlet-name>SOAPMonitorService</servlet-name>
    <display-name>SOAPMonitorService</display-name>
    <servlet-class>
        org.apache.axis.monitor.SOAPMonitorService
    </servlet-class>
    <init-param>
      <param-name>SOAPMonitorPort</param-name>
      <param-value>5001</param-value>
    </init-param>
    <load-on-startup>100</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/servlet/AxisServlet</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>*.jws</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>SOAPMonitorService</servlet-name>
    <url-pattern>/SOAPMonitor</url-pattern>
  </servlet-mapping>

<!-- uncomment this if you want the admin servlet -->
<!--
  <servlet-mapping>
    <servlet-name>AdminServlet</servlet-name>
    <url-pattern>/servlet/AdminServlet</url-pattern>
  </servlet-mapping>
-->

    <session-config>
        <!-- Default to 5 minute session timeouts -->
        <session-timeout>5</session-timeout>
    </session-config>

    <!-- currently the W3C havent settled on a media type for WSDL;
    http://www.w3.org/TR/2003/WD-wsdl12-20030303/#ietf-draft
    for now we go with the basic 'it's XML' response -->
  <mime-mapping>
    <extension>wsdl</extension>
     <mime-type>text/xml</mime-type>
  </mime-mapping>
 

  <mime-mapping>
    <extension>xsd</extension>
    <mime-type>text/xml</mime-type>
  </mime-mapping>



4、启动WEB服务器(Starting the web server)


5、验证Axis部署是否成功(Validate the Installation)

Navigate to http://127.0.0.1:8080/myaxis/servlet/AxisServlet,
though of course the port and the address may differ.

访问地址http://127.0.0.1:8080/myaxis/servlet/AxisServlet,
当然你的web应用程序的端口或者地址可能不同。

You should now see an page as follows.
If you do not, then the webapp is not actually installed, or the appserver is not running.

你应该可以看到下面的页面。
如果你没有看到下面的这个页面,你的web应用程序可能还没部署,或者你的web服务器没有运行。




  • Axis在真实项目中的应用(Axis in real application)


服务发布方和服务调用方的定义
(The definition of the service publisher and the service invoker)

if the SOAP service(webservice also) which was being deployed in your webapp
(in real world,perhaps the project which your team developed)
by axis should be invoked by an external webapp
(in real world,perhaps the project which was already being published by another corp),
or probably by a couple of outer webapps.we call your webapp the service publisher,
consequently the external webapp is the service invoker.


如果你的WEB服务中(在现实中,指你开发的系统)
用axis部署的SOAP服务(或者称为WEBSERVICE服务)被外部的WEB服务
(在现实中,可能是别的厂家开发的系统)调用,
那么我们称你的WEB服务为服务发布方,相应地,外部WEB服务为服务调用方。


1、(作为服务发布方)The service publisher side

作为服务的发布方,首先需要做的是拥有一个SOAP服务,
下面将详细介绍如何用axis发布一个SOAP服务

(1)写一个Java类,在该类中写一个Java方法,我们的Java类名为:HalloAxis.java
public class HalloAxis {
     public int addition(int num1,int num2)
     {
    return num1 + num2;
     }
}

(2)写一个deploy.wsdd

(3)写一个windows批处理命令(假设你的操作系统是windows)
我们的批处理命令文件名为:deploy.bat
set axislib = 你的lib目录的路径(比如 D:/myaxis/wwwroot/WEB-INF/lib)
set classpath=.;%axislib%\axis.jar;%axislib%\axis-ant.jar;
                %axislib%\saaj.jar;%axislib%\commons-discovery*.jar;
                %axislib%\jaxrpc.jar;%axislib%\commons-logging*.jar;
java org.apache.axis.client.AdminClient -l http://localhost:8080/myaxis/servlet/AxisServlet 你的deploy.wsdd的路径
pause







Axis开发经验集(How to use Axis)


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论