Develop JAX-RPC-based Web services (1) with AXIS and SOAP

zhaozj2021-02-16  58

Web services are software programs based on a series of industrial standards, which can be shared, can be used as a distributed web-based application. The web service can be identified by a URI, and their common interfaces can be described and discovered with XML.

As interoperability and application integration demand, Web services are considered to be the most ideal business solution because they are standard-based Internet protocols. The Web service uses a common transmission protocol (eg, HTTP and SMTP), allowing the application to handle requests from remote, different systems using public transport protocols such as HTTP and SMTP.

This article focuses on the use of AXIS to build a cheap web service to solve the problems mentioned above. AXIS is an open source SOAP implementation provided by Apache. For impartiality, the web service construction of this article will be based on JAX-RPC, follow-up articles will introduce other methods.

XML-based remote procedure calling Java API (JAX-RPC) simplifies the creation process of web services (Web service itself combines XML-based PRC). It defines mappings between Java types and XML types to hide the details of XML, provide a familiar way to call examples. This article explains how developers use JAX-RPC to implement and call SOAP-based Web services, which use the web service described by Web Service Description Language (WSDL) using an open source tool provided by Apache - for deploying services Apache Tomcat and SOAP implementation apache axis.

Web services based on JAX-RPC

JAX-RPC is fully included with the isomer of the web service. It allows a JAX-RPC client to talk to another WEB service written in different platforms in different platforms. JAX-RPC provides a range of specifications, including call modes, client generation, parameter mode, Java to WSDL and WSDL to Java type mapping, and client APIs that call Web services.

2. Call mode and client

JAX-RPC supports three web service call modes:

A. Synchronous request - Synchronous request-response: The client calls a remote method on the web service, calling the thread blocking during the Web service processing until a return value or exception is received.

B. One-Way): One-Way RPC Mode: The client calls a remote method on the web service in one-way mode, and the thread does not block and continue to execute. The client does not receive any return values.

C. Non-blocking RPC Mode: The client calls a remote method on the web service, which continues to process. Take later, the client handles remote methods by performing a receiving module or polling return value.

With the call mode described herein, let's see how to use the synchronous request on the Tomcat-Axis combination, write or generate the Java client.

3. Parameter Modes

The web service call based on JAX-RPC is used is the parameter transmission method of copying value. It does not support the parameter transfer method of reference transmittance.

JAX-RPC supports the following parameter mode:

A. IN Mode: Parameters of an in type are passed a copy. The value of the IN type parameter is copied before the web service call. The return value is also created as a copy and then returns the client to the web service.

B. OUT mode: The parameter of the OUT type is passed to the Web service method as a copy without any input values. The Web service method fills the OUT parameter and then returns it to the client.

C. INOUT mode: The inout parameter is passed as a copy with a input value to a web service method. Web service method uses this input value, processing it, populates the inout parameter with a new value, and then returns to the client. The parameter transmission mode of the OUT and INOUT parameters is used using the Holder class. Use the Holder class to keep mapping to maintain the expected WSDL signature semantics. The JAX-RPC specification includes the "Holder class" of the simple XML type to the Java data type. The Holder class of the atomic data type (for example, int, float, etc.) can be obtained in the javax.xml.rpc.Holders package implemented in JAX-RPC. For complex XML data types, the name of the HOLDER class is configured by attaching "Holder" after the corresponding Java class. These generated HOLDER classes are wrapped in WSDL to Java as part of the generator class Holders.

Each Holder class provides the following methods and properties:

A. A public property "value", "value" type is the mapped Java type.

B. A default constructor used to initialize the "value" property as a default value.

C. Set the value of the "value" attribute to the constructor of the incoming parameter.

4. Web service call

Apache Tomcat-Axis combination provides a JAX-RPC 1.0 compatible runtime engine, which has clients and server logs and deployment tools. Figure 1 details the standard synchronization request - the Web service call framework for the response mode. Application1 encapsulated the web service client Using the JAX-RPC runtime environment Perform a remote procedure call request encapsulates the public method of Application 2 of the web service server. The client uses the runtime library to sequence the Java object into a SOAP message, and then send the message to the web service endpoint via the HTTP protocol. When the WEB service deployed on the Apache Tomcat receives this request, the server-side JAX-RPC runtime library puts the SOAP message to the Java type and calls the method on the Web service, followed by the Application 2. After processing the request, the web service sent the response back to the client in a similar manner.

Figure 1 Web Service Call Framework

At this point, we have understood a Web service call based on JAX-RPC. The next part of this article will develop an example web service in the Apache Tomcat-Axis combination, a dynamic client.

转载请注明原文地址:https://www.9cbs.com/read-24734.html

New Post(0)