WEB Services development with AXIS 1.1 for Java
All of the following is almost from the documentation of Axis1.1. But not completely from the document, I made some changes, these modifications are entirely from domestic readers.
What is soap?
SOAP is an XML-based transmission protocol for communication data encoding between applications. It was initially proposed by Microsoft and Userland Software. With the continuous improvement and improvement, SOAP quickly was widely used in the industry, and the fully released version was 1.1. During its development, W3C XML standard working group actively promotes SOAP to become a real open standard. When writing this document, the SOAP1.2 draft has been released, and 1.2 to the relatively confusing part of 1.1 is improved.
SOAP is widely used as a new generation of cross-platform, cross-language distribution calculation of Web Services.
Here is too beautiful, please refer to my finishing "step by step to learn soap".
What is AXIS?
AXIS is essentially a SOAP engine, providing a basic framework for creating server-side, client, and gateway SOAP operations. Axis current version is written for Java, but the version of C is under development.
But AXIS is not entirely a SOAP engine, which also includes:
Is it a separate SOAP server.
Is it a server embedded in a servlet engine (such as Tomcat).
• Support WSDL.
• Provide tools for transforming WSDL to Java classes.
• Provide an example program.
• Provide TCP / IP Packet Monitoring Tools.
AXIS is the third generation Apache SOAP. From 2000, the SOAP V2 development team begins to discuss how Axis is more flexible, configurable, and capable of processing SOAP and various XML standards from W3C. Axis currently has achieved the following results by continuous discussion and code.
• The speed is improved. AXIS processes the XML document by event-based SAX to improve the speed and efficiency.
? Flexibility is improved.
• Raise stability.
• Provide assemblies.
• Provide a simple transmission abstract frame. Its core engine is independent of the transmission mode. This makes it more flexible to choose from what protocol transmission.
• Support WSDL. Includes WSDL and customer agent generation, etc.
What is anything in the current release version 1.1?
? SOAP1.1 / 1.2 engine.
• Flexible configuration and deployment system.
• Support to automatically generate SOAP services (JWS) in time.
• Supports all basic data types to provide a type mapping system for custom serial operations.
JavaBean's automatic serial operation, including mapping the custom property type to the properties and elements of XML.
• RPC and message-based SOAP service providers.
• Automatically generate WSDL from deployed services.
• WSDL2JAVA tools can generate the corresponding customer and server-side SOAP operating framework from the WSDL description file.
• Preliminary security extensions can be integrated with servlet2.2 security.
• Provide session tracking through HTTP cookie and SOAP header information unrelated to the transfer.
• Precursively support SOAP messages with attachments.
• Provide access to the EJB as a Web service in EJB.
• Based on servlet's HTTP transmission.
- Based on JMS transmission.
• Independent server (but requires HTTP server and servlet container support).
• Provide a sample of the client, server-side related applications.
Axis runs requires the following components
? Axis.jar
? jaxrpc.jar
Saaj.jar
? commons-logging.jar
? Commons-discovery.jar
WSDL4J.JAR
• Comply with the XML processor of JAXP-1.1.
Step by step to use AXIS to perform web services
Here is a simple client code for calling the Web Services method (due to the original document to use the import package, beginners are not easy to understand that class in that package, so I do some simple changes, I hope I can learn Clear idea): public class testclient {
Public static void main (String [] args) {
Try {
String endpoint = "http:// localhost: 8080 / axis / sayhello.jws? WSDL"; // The URL address of the web service is called, here is an HTTP request, and the result is the result is the WSDL document.
Org.apache.axis.client.service service = new org.apache.axis.client.Service (); // Establish a request service framework instance.
/ *
* org.apache.axis.client.service Implement JAX-RPCS Javax.xml.rpc.Services interface
* This interface acts as an Org.Apache.Axis.Client.call instance that is mentioned below
* character of.
* /
Org.apache.axis.client.call call = (org.apache.axis.client.call) service.createCall (); // Generate an instance of a maintenance call from the frame.
/ *
* org.apache.axis.client.call implements the JAX-RPCS Javax.xml.rpc.call interface.
* /
Call.SettargetendPointdaddress (New Java.net.URL (Endpoint));
Call.SetoperationName (New javax.xml.namespace.qname ("http://www.edu-edu.com.cn/luopc/ws", "echostring")); // Set the function name that you need to call
String result = (string) Call.invoke (new object [] {"Hello!"});
System.out.println (Result);
} catch (exception e) {
System.err.println (e.tostring ());
}
}
}
The above code may be different from the original document, and in the namespace, the user will cause confusion to the user. But don't worry, I will add a lot of explanation of code at the same time, if I don't understand which purely can get help: luopc@edu-edu.com.cn, the mail topic must be the document name I provide.
Through the calling code above, finally generate the SOAP packet to the server, the specific XML content is as follows:
XML Version = "1.0" encoding = "UTF-8"?>
XMLns: soap-env = "http://schemas.xmlsoap.org/soap/envelop/" XMLns: xsi = "http://www.w3.org/2001/xmlschema-instance"> Soap-env: body> Soap-env: envelope> Here I am no longer, careful friends please find the corresponding corresponding information from the code to make your own logical understanding. As for the SOAP protocol, it will join in my later translation document. From the above code we entered the parameter new object [] {"Hello!"} When calling. The automatic serialization can then be seen from the generated SOAP request package Call.addparameter ("Testparam", Org.apache.axis.constants.xsd_string, Javax.xml.rpc.parametermode.in); Call.setReturntype (org.apache.axis.constants.xsd_string); Generate the following SOAP information after adding the above code: XML Version = "1.0" encoding = "UTF-8"?> XMLns: soap-env = "http://schemas.xmlsoap.org/soap/envelop/" XMLns: xsi = "http://www.w3.org/2001/xmlschema-instance"> ns1: echostring> Soap-env: body> Soap-env: envelope> It can make a simple contrast. Maybe you will puzzle what is the difference between setting a parameter name and does not set the parameter name. Simple explanation here: 1. Why do you want call.setreturntype (org.apache.axis.constants.xsd_string)? Above you can call or not call, but when the data type is not indicated in the return result, Axis does not know how to perform data type conversion. Of course, if you return the type, you are clear and return to the result of the response SOAP indicates that the corresponding data type can be called. 2. Why set the parameter name and type? Ok, look down on how to call Web Services, let's tell you how to write and publish web services. Release Web Services via AXIS Write here a simple class, then release it step by step. I hope that users can figure out some ideas. I have a general release method for Web Services in other articles about Web Services. Although Web Services involves a lot of complex knowledge, please don't feel these operations, maybe you have a lot of questions, don't matter, write down your questions, constantly try. Public class sayhello { Public string echostring (string hello) { Return hello; } } Haha, this class is not too simple. step by step. AXIS offers two ways to publish Java classes to Web Services, instantly quickly and automatically publish and publish through profiles. We first start with the easiest deployment. JWS ---- instant deployment Simply put, you can use the Java source files yourself by certain rules COPY to a specific directory. Specific steps are as follows: • Copy the SayHello.java written above to the AXIS directory. ? Renamed SayHello.jws. Note: There is no information on the specific package in the class you wrote, because this is not supported by AXIS instant deployment. Run the client to test the client to test, the result is Hello !. Do you have the following questions? How will the polymorphic functions in the class will handle? In fact, it is very simple, we know that the agent will directly request your URL before each time a call request, here is http: // localhost: 8080 / axis / sayhello.jws? WSDL, in fact, this request returned It is a WSDL description file that ultimately determines what request sent by the content of the specific description file and the type of parameters you entered. Interpretation of details requires the user to read the specific content of SOAP. I will also provide the corresponding authority as translation. Is the client of AXIS default to transfer through HTTP protocol? How to map your own defined type? Custom deployment via WSDD The above automatic deployment is quite simple, but when you need ? When maping your own type • Do not need exposure source code ? Time to manage your path and package management • When the user operates the Web Services event It is necessary to define deployments via WSDD. In the previous new features, AXIS is a very flexible configurable system, but you have to know the format and meaning of the AXIS Web Services to describe the document (WSDD) before configuration. Here is a simple example (deploy.wsdd): XMLns: java = "http://xml.apache.org/axis/wsdd/providers/java"> service> deployment> A short description will be customized to publish the specific class in the form of Web Services. Each Service item above will mean that a corresponding service that can be referenced by the WSDL file. Its internal description information will describe all core information requested from the request-processing request-answer. Here, the provider = "Java: RPC" corresponds to the corresponding service class as org.apache.axis.providers.java.rpcProvider. In fact, you can provide corresponding services in a variety of ways. These content will be explained in detail in architectural articles about AXIS. I don't explain the various parameters above, I think everyone will understand. Let's start a step-by-step configuration on the simple configuration above. Service survival range AXIS provides three optional range configurations for Session, Request, and Application. Specific configuration marked as: ... service> Once you finish the file above. You can write a script batch file to complete the deployment. The batch file is as follows: Java-ClassPath f: /resource/tools/axis-1_1/lib/axis.jar; f: /resource/tools/axis-1_1/lib/commons-discovery.jar; f: / resource / Tools / Axis-1_1 / Lib / jaxrpc.jar; f: /resource/tools/axis-1_1/lib/commons-logging.jar; f: /resource/tools/axis-1_1/lib/log4j-1.2.8.jar; f: / resource /Tools/axis-1_1/lib/wsdl4j.jar;f:/Resource/tools/axis-1_1/lib/j2ee.jar org.apache.axis.client.adminClient Sayllod.wsdd. Some of the JAR files above are the components that AXIS runs, so they must be added to the environment. The above directory is the directory in my machine, you can do it according to your own directory. If the deployment is successful, the But I have emphasized a few: ? You first put your compiled classes in Axis / Web-INF / CLASSES / below. • Call can be called via http: // localhost: 8080 / axis / service / selfhello2. ? You can find the concept of the package from my profile. • You can use the corresponding XML file to uninstall the deployed service. The unloading method is as follows: Write the following XML document undeployment> Change the SayHellod.wsdd in the above batch file to this file. Continue to pay attention to advanced deployment If you want to know how many times you are called, what should you do? AXIS provides a corresponding tracking mechanism. First, you should write a class handling class that meets a certain interface. • Add event processor information in the configuration file. Let's take a look at the information in the configuration file: XMLns: java = "http://xml.apache.org/axis/wsdd/providers/java"> handler> requestflow> service> deployment> The green part above is provided to the core configuration information. One will provide an event processing class, which is also from the original document, but in order to clearer, I also add a package name in front of all classes. Package luopc.ws; / ** * @Author Luopc * / Public class eventhandler extends org.apache.axis.handlers.basichandler { Public void invoke (org.apache.axis.MessageContext Mtxt) { String param = (string) GetOption ("parameter1"); System.out.println (Param); } Public static void main (String [] args) { } } In this way, we tracked the request.嘻嘻. Can manage remotely (not recommended) In the previous item, the service type is mentioned, there are four types of services in Axis, which are RPC, Document, Wrapped and Message.