Overview This article describes a relatively simple-practical Java-based SOAP engine -Apache organization's installation, configuration, and application development methods, you want to help friends who are interested in Java-based Web Services applications.
AXIS Introduction AXIS is the SOAP engine introduced by Apache organization. The AXIS project is a successive project of Apache's famous SOAP project. The latest version is the 1.1 version of Java development, and the C version is under development. Axis v1.1 package can be downloaded from http://ws.apache.org/axis/dist/1_1/.
AXIS installation Application AXIS Development Web Services, you need to have a server engine that supports servlets, such as the wide-known Tomcat (Tomcat is also provided by the Apache organization, the current latest version is 4.1.24, the download address is http: // jakarta .apache.org / builds / jakarta-tomcat-4.0 / release / v4.1.24 /). Of course, you must already have a version of JDK1.3, and after the Tomcat is installed, you only need to add the downloaded AXIS software to compress it, the "Axis" directory under the "WebApps" directory will be copied. Under the "WebApps" directory in the Tomcat installation directory.
AXIS Configuration AXIS is based on Java development, which can be deployed in a variety of operating systems. You need to configure a series of system variables before use. It is assumed that you have installed Tomcat 4.0 or more, the system variables you need to configure are as follows Down:
Catalina_Homec: / Tomcat_4_1
(This should be the installation position of Tomcat, pay attention to the path name "Do not have spaces in the path name) AXIS_HOME% CATALINA_HOME% / WebAPPS / AXISAXIS_LIB% AXIS_HOSAXIS_LIB% AXIS_HOS_LIB% / AXIS.JAR;% AXIS_LIB% / Commons-Discovery.jar;% AXIS_LIB%;% AXIS_LIB% / jaxrpc.jar;% AXIS_LIB% / saaj.jar;% AXIS_LIB% / LOG4J-1.2.8.jar;% AXIS_LIB% / XML-APIS.jar;% AXIS_LIB% / xerceptimpl.jar
If you don't want to do so cumbersome path settings, you can directly add all the .jar files in the "lib" directory in the Axis package to the system environment variable ClassPath.
After the test installation configuration of Axis, it should be tested whether Axis can run correctly.
Start the Tomcat server, access http: // localhost: 8080 / axis / happyaxis.jsp in the browser, if the page is displayed, you need to look back if the relevant configuration is correct, if the browsing page can correctly display the system components, attributes When the parameter configuration information is displayed, the installation is successful, as shown below:
You can now develop your Web Services app.
The release of the service AXIS provides two service release methods, one is instant deployment, one is a custom publishing (Custom Deployment). Using instant publishing support for instant release is one of the features of AXIS, using instant release to enable users to provide the source code for the Java class providing service, you can quickly release it as a web service. Whenever the user calls this type of service, AXIS will automatically compile, even if the server is restarted, it is not necessary to do anything, it is very simple and fast. Using instant release first requires a Java source file that implements service functions, change its extension to .jws (Java Web Service Abbreviation), then place the file into the "... / WebApps / Axis" directory. Here, a service from the length unit conversion from miles to kilometers, its source code is as follows: Document.jws / ** * @Author Flying Eagle * / Public CLASS DISTANCE {Public Double ConvertMile2kilometre (double mile) {// Implement miles Distance to kilometers Return Mile * 1.609;} // communicationmile2kilometre ()} / * distance * / put it in the "... / WebApps / Axis" directory, by accessing http: // localhost: 8080 / axis / distance. JWS? WSDL can see the WSDL description file for this service, which means that the DISTANCE service is successfully released. As shown in the figure below: Using custom publishing instant release is an exciting technology, it makes the development of web services so simple; however, it is not always the best choice, such as some application system is a third party. We don't buy source code, only .class files, but we hope to release some of this application system into a web service, enabling it to generate a role in a larger range. At this time, it is not powerful. In addition, instant publishing techniques are not flexible, and more service configurations cannot be made, which makes it unable to meet the needs of some particular systems. Therefore, AXIS provides another service release method, which is custom release. Here, a service from gallon to rising volume unit conversion, its source code is as follows: File Capacity.javaPackage Samples.capacity; / ** * @Author Flying Eagle * / Public CAPACITY {public Double ConvertGallon2litre (double gallon) { // Realize the volume conversion of gallon to rise Return Gallon * 4.546;} // convertGallon2lit ()} / * Capacity * / compiles it into a .class file, place it to "... / WebApps / Axis / Samples / Capacity" directory It can be launched.
Customized release does not need to build .jws file, but must create a service release description file deploy.wsdd (Abbreviation for Web Service Deployment Descriptor), this file is responsible for describing the name, entrance and other information of the service, the content is as follows: File Deploy.wsdd
As shown below: Client Service Access Programming AXIS provides an API to implement SOAP, from http: // localhost: 8080 / axis / docs / apidocs / index.html, you can see Axis's API documentation. Among them, org.apache.axis.client.call and org.apache.axis.client.Service are two commonly used classes. When the general client program wants to access a web service, you must generate a client's service object and Call object, first set the corresponding parameters to the Call object, including the location of the service, the location, operand, inlet parameters, return value type, etc., and finally call the invoke method access service of the Call object.
The following is given a client access to the web service routine --Axistest.java: file axistest.javaPackage axisexercise; import org.apache.axis.client.call; import org.apache.axis.client.service; import Org. apache.axis.encoding.XMLType; import javax.xml.rpc.ParameterMode; / ** * @author Eagle * / public class AXISTest {public static void main (String [] args) throws Exception {Service service = new Service ( ); Call call = (call) service.createCall (); // Access to instant DISTANCE service // Settings Access Point Call.SetTargetendPointdaddress ("http: // localhost: 8080 / axis / distance.jws"); // Set the opera name call.setoperationname ("ConvertMile2kilometre"); // Set the entry parameter call.addParameter ("OP1", XmLType.xsd_double, parametermode.in); call.setRetRntype; double d1 = new double (190 ); // Call service system.out.println (D1 "mile equivalent to" call.invoke (new object [] {d1} "km!"); // Access custom release Capacity service call = Call) Service.createCall (); // Settings Access Point Call.SetTargetendPointAddress ("http: // localhost: 8080 / axis / service / capacity"); // Set the opera name Call.SetOperat Ionname ("ConvertGallon2litre"); // Sets the entry parameter call.addparameter ("OP1", XMLTYPE.XSD_DOUBLE, ParameterMode.in); call.setRetURNTYPE (XMLTYPE.XSD_DOUBLE); D1 = New Double (10.00); // Call service System.out.println (D1 "Gallon is equivalent to" call.invoke (new object [] {d1}) " ");} // main ()} / * Axistest * / Compile running running can see the following results: 190.0 miles equivalent to 305.71 km! 10.0 gallons equivalent to 45.46 liters! Note procedures to access instant Distance services and Different when customized Capacity services, the former's service access point address is http: // localhost: 8080 / axis / helloworld.jws, while the latter is http: // localhost: 8080 / axis / service / capacity.