axis1.4 开发步骤

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 设置

 

 <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业务类

 

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

 

<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  发布

 

@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

 

@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 客户端测试

 

	public static void main(String[] args) throws RemoteException, Exception {
		
		HelloWSDDService  service=new HelloWSDDServiceLocator();
		HelloWSDD_PortType client=service.getHelloWSDD();
		String value=client.hello("hello,你好");
		System.out.println(value);
		
	}
 

 

 

你可能感兴趣的:(apache,tomcat,servlet,ant,ext)