axis开发步步为上

1 创建web工程,加入以下jar包;

    activation.jar

    ant.jar

    antlr.jar

    axis-ant.jar

    commons-discovery.jar

    commons-logging

    jaxrpc.jar

    log4j.jar

    mail.jar

    saaj.jar

    wsdl4j.jar

     xalan.jar

     xmlsec.jar

2 web.xml 设置

 

Java代码 复制代码  收藏代码
  1. <listener>   
  2.        <listener-class>org.apache.axis.transport.http.AxisHTTPSessionListener</listener-class>   
  3.    </listener>   
  4.       
  5.  <servlet>   
  6.    <servlet-name>AxisServlet</servlet-name>   
  7.    <display-name>Apache-Axis Servlet</display-name>   
  8.    <servlet-class>   
  9.        org.apache.axis.transport.http.AxisServlet   
  10.    </servlet-class>   
  11.  </servlet>   
  12.   
  13.  <servlet>   
  14.    <servlet-name>AdminServlet</servlet-name>   
  15.    <display-name>Axis Admin Servlet</display-name>   
  16.    <servlet-class>   
  17.        org.apache.axis.transport.http.AdminServlet   
  18.    </servlet-class>   
  19.    <load-on-startup>100</load-on-startup>   
  20.  </servlet>   
  21.   
  22.  <servlet>   
  23.    <servlet-name>SOAPMonitorService</servlet-name>   
  24.    <display-name>SOAPMonitorService</display-name>   
  25.    <servlet-class>   
  26.        org.apache.axis.monitor.SOAPMonitorService   
  27.    </servlet-class>   
  28.    <init-param>   
  29.      <param-name>SOAPMonitorPort</param-name>   
  30.      <param-value>5001</param-value>   
  31.    </init-param>   
  32.    <load-on-startup>100</load-on-startup>   
  33.  </servlet>   
  34.   
  35.  <servlet-mapping>   
  36.    <servlet-name>AxisServlet</servlet-name>   
  37.    <url-pattern>/servlet/AxisServlet</url-pattern>   
  38.  </servlet-mapping>   
  39.   
  40.  <servlet-mapping>   
  41.    <servlet-name>AxisServlet</servlet-name>   
  42.    <url-pattern>*.jws</url-pattern>   
  43.  </servlet-mapping>   
  44.   
  45.  <servlet-mapping>   
  46.    <servlet-name>AxisServlet</servlet-name>   
  47.    <url-pattern>/services/*</url-pattern>   
  48.  </servlet-mapping>   
  49.   
  50.  <servlet-mapping>   
  51.    <servlet-name>SOAPMonitorService</servlet-name>   
  52.    <url-pattern>/SOAPMonitor</url-pattern>   
  53.  </servlet-mapping>   
  54.   
  55. <!-- uncomment this if you want the admin servlet -->   
  56. <!--   
  57.  <servlet-mapping>   
  58.    <servlet-name>AdminServlet</servlet-name>   
  59.    <url-pattern>/servlet/AdminServlet</url-pattern>   
  60.  </servlet-mapping>   
  61. -->   
  62.   
  63.    <session-config>   
  64.        <!-- Default to 5 minute session timeouts -->   
  65.        <session-timeout>5</session-timeout>   
  66.    </session-config>   
  67.   
  68.    <!-- currently the W3C havent settled on a media type for WSDL;   
  69.    http://www.w3.org/TR/2003/WD-wsdl12-20030303/#ietf-draft   
  70.    for now we go with the basic 'it's XML' response -->   
  71.  <mime-mapping>   
  72.    <extension>wsdl</extension>   
  73.     <mime-type>text/xml</mime-type>   
  74.  </mime-mapping>   
  75.     
  76.   
  77.  <mime-mapping>   
  78.    <extension>xsd</extension>   
  79.    <mime-type>text/xml</mime-type>   
  80.  </mime-mapping>  
 <listener>
        <listener-class>org.apache.axis.transport.http.AxisHTTPSessionListener</listener-class>
    </listener>
    
  <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>

 3 开发服务器端java业务类

 

Java代码 复制代码  收藏代码
  1. public class HelloWSDD {   
  2.        
  3.     public int count=0;   
  4.        
  5.     public String hello(String name){   
  6.            
  7.         count++;   
  8.         System.out.println(count);   
  9.         System.out.println(name);   
  10.         return "hello---"+name;   
  11.     }   
  12.     public float add(float a,float b){   
  13.            
  14.         System.out.println(count);   
  15.         System.out.println(a+b);   
  16.         return a+b;   
  17.     }   
  18. }  
public class HelloWSDD {
	
	public int count=0;
	
	public String hello(String name){
		
		count++;
		System.out.println(count);
		System.out.println(name);
		return "hello---"+name;
	}
	public float add(float a,float b){
		
		System.out.println(count);
		System.out.println(a+b);
		return a+b;
	}
}

 4 发布方法--创建 deploy.wsdd

 

Java代码 复制代码  收藏代码
  1. <deployment xmlns="http://xml.apache.org/axis/wsdd/"  
  2. xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">   
  3.   
  4. <service name="HelloWSDD" provider="java:RPC">   
  5. <parameter name="className" value="com.axis.test.HelloWSDD"/>   
  6. <parameter name="allowedMethods" value="*"/>   
  7. <parameter name="scope" value="request"/>   
  8. </service>   
  9. </deployment>  
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

<service name="HelloWSDD" provider="java:RPC">
<parameter name="className" value="com.axis.test.HelloWSDD"/>
<parameter name="allowedMethods" value="*"/>
<parameter name="scope" value="request"/>
</service>
</deployment>

 5 执行deploy.bat  发布

 

Java代码 复制代码  收藏代码
  1. @echo off   
  2. set Axis_Lib=C:\apache-tomcat-6.0.18\webapps\axis141\WEB-INF\lib   
  3. set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib%   
  4. set Axis_Servlet=http://localhost:8080/axis141/servlet/AxisServlet    
  5. %Java_Cmd% org.apache.axis.client.AdminClient -l%Axis_Servlet% deploy.wsdd   
  6.   
  7. echo 完成!   
  8. echo. & pause   
@echo off
set Axis_Lib=C:\apache-tomcat-6.0.18\webapps\axis141\WEB-INF\lib
set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib%
set Axis_Servlet=http://localhost:8080/axis141/servlet/AxisServlet 
%Java_Cmd% org.apache.axis.client.AdminClient -l%Axis_Servlet% deploy.wsdd

echo 完成!
echo. & pause 

 6根据wsdd生产客户端代码 gener2java

 

Java代码 复制代码  收藏代码
  1. @echo off   
  2. set Axis_Lib=C:\apache-tomcat-6.0.18\webapps\axis141\WEB-INF\lib    
  3. set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib%     
  4. set Output_Path=D:\workweb\ttt\src     
  5. set Package=com.ws.testService     
  6. %Java_Cmd% org.apache.axis.wsdl.WSDL2Java -o%Output_Path% -p%Package% http://localhost:8080/axis141/services/HelloWSDD?wsdl   
  7.   
  8. echo 完成!   
  9. echo. & pause   
@echo off
set Axis_Lib=C:\apache-tomcat-6.0.18\webapps\axis141\WEB-INF\lib 
set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib%  
set Output_Path=D:\workweb\ttt\src  
set Package=com.ws.testService  
%Java_Cmd% org.apache.axis.wsdl.WSDL2Java -o%Output_Path% -p%Package% http://localhost:8080/axis141/services/HelloWSDD?wsdl

echo 完成!
echo. & pause 

 7 客户端测试

 

Java代码 复制代码  收藏代码
  1. public static void main(String[] args) throws RemoteException, Exception {   
  2.        
  3.     HelloWSDDService  service=new HelloWSDDServiceLocator();   
  4.     HelloWSDD_PortType client=service.getHelloWSDD();   
  5.     String value=client.hello("hello,你好");   
  6.     System.out.println(value);   
  7.        
  8. }  

你可能感兴趣的:(axis)