Build web services with Globus Toolkit 4

Source: Internet
Author: User
Build web services with Globus Toolkit 4 (gt4)
Author: birali hakizumwami
Translator: xzzhouhu

Copyright Disclaimer: Any website authorized by matrix.Be sureThe original source and author information of the article and this statement are displayed as hyperlinks.
Author: birali hakizumwami; xzzhouhu
Address: http://www.onjava.com/pub/a/onjava/2005/10/19/constructing-web-services-with-globus-toolkit.html
Address: http://www.matrix.org.cn/resource/article/44/44032_Globus_Toolkit.html
Keywords: Globus Toolkit

Abstract:
This article describes how to build enterprise software by adjusting the concept of grid computing implemented by Globus Toolkit 4. Gt4 is an open resource that can be implemented through the Open Grid Service Architecture (OGSI. The main purpose of this implementation is to provide a basis for the grid service architecture, and also provide a reference for the implementation of other Grid Service architectures. This article describes Java core services in gt4 in detail. These services are capable of providing real-time runtime environments for managed grid services. Of course, these grid services are all written by Java. The real-time running environment coordinates the application and network bearer of the Grid Service and the transmission protocol engine.

1. Mesh Definition

Grid definition:
A grid provides all the available distributed computing resources on the network to end users or forms a huge computing system. Grid computing provides a completely new method for distributed computing, not only across regions but also across organizations, machine structures and software constraints, providing more resources to each user connected to the grid, collaboration and information access between computers. Distributed resources, such as computing cycles, storage, and information, can be accessed in any area of the grid, and these services can also be provided in the grid for access by other users. This requires the establishment of a dynamic virtual organization by securely coordinating resource sharing between each independent organization or resource.

Ii. Globus Toolkit version 4

In this article, we mainly discuss Java core services in gt4. (1 ), these servers are between the core services of J stool and the core services of T4., the Network bearer and transmission protocol engine play a coordinating role. Gt4 core services also provide functions supported by program development, including open development mode and implementation of accessing grid services, such as gram (Grid Resource Allocation Management, grid resource management ). The powerful reason for applying gt4 is that it is based on existing web service standards and technologies, such as soap and WSDL. The interfaces provided by the Grid Service are described through WSDL. Gt4 provides a software warehouse, such as security support, software exploration, software resource management, software calls, communication between software, exception handling, and data management.


(Figure 1)

Figure 1 describes the main component structure of gt4 on the server side. This is only part of the functions provided by gt4. We just think it is suitable for this article. The gt4 structure is composed of a grid container. The Grid container is mainly used to manage all deployed Web services throughout the running cycle of each web service. Gt4 uses Apache axis as its web service engine to handle all soap messages, JAX-RPC (Java API for XML-based RPC) processing and web service configuration.

Iii. Loan Repayment example:

Here is an example to show you how to use Globus Toolkit to integrate different types of operating systems in an enterprise. In an enterprise, some applications may be left behind by the original host, and the technology is relatively backward. Some applications have adopted modern technologies, such as J2EE. Even when we use the most advanced technology to share information among internal applications of an enterprise, we also face huge challenges. Figure 2 provides an example of interaction between loan repayment information processing and accounting department information processing in a mortgage agency,


(Figure 2)

The accounting department uses the loan processing service to apply for a loan.

To create and deploy a grid service, we need:
* Create a wsdl file to define the Service Interface
* Implemented in Java
* Create a WSDD file to define service deployment Parameters
* Use ant to compile the source code and generate the gar File
* Use gt4 distribution tool to deploy the gar File
We must use the top-down method to create a Grid Service (Figure 3)

This method begins with the provision of the WSDL file, which includes abstract definitions of Web Services, including service types, message types, and port types. A Java model is created from the WSDL document and based on the WSDL document, resulting in better interaction with other systems.

We use the tool that comes with gt4 toolkit to bind services and generate the root class required by the customer segment. The next step in this method is to provide interface implementation.

Definition of loan repayment service processing:
The interface type of the loan repayment service processing example is defined as loan. WSDL, which describes the operations (applying for loans, processing loans, and obtaining loans) provided by the loan repayment service ). First, describe the request and response of the loan repayment service:

<types>

  <xsd:element name="createLoan">
    <xsd:complexType>
      <xsd:sequence>
          <xsd:element name="loanNumber" type="xsd:int"/>
        <xsd:element name="amountUPB" type="xsd:double"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="createLoanResponse">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="returnValue" type="xsd:int"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

  <xsd:element name="processLoanPayment">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="loanNumber" type="xsd:int"/>
        <xsd:element name="amount" type="xsd:double"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="processLoanPaymentResponse">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="returnValue" type="xsd:int"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

  <xsd:element name="getLoan">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="loanNumber" type="xsd:int"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="getLoanResponse">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="returnValue" type="tns:LoanType"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

</types>

In the file loan. XSD. defines the loan data type, we use "Import <XSD: Import schemalocation =" loan. XSD "/>" can directly replace loan. XSD. the file is imported to the file loan. and use it as the type returned by the loan operation.

<complexType name="LoanType">
    <sequence>
        <element name="loanNumber" type="int"/>
        <element name="UPB" type="double"/>
        <element name="status" type="string"/>
        <element name="createDate" type="string"/>
    </sequence>
</complexType>

Next, we need to define all the message services. A message element may consist of one or more parts. Each part of the message element corresponds to a parameter and has a type attribute. A message can be either a request message (input message) or a Response Message (output message ).

<message name="CreateLoanInputMessage">
  <part name="parameters" element="tns:createLoan"/>
</message>
<message name="CreateLoanOutputMessage">
  <part name="parameters" element="tns:createLoanResponse"/>
</message>

<message name="ProcessLoanPaymentInputMessage">
  <part name="parameters" element="tns:processLoanPayment"/>
</message>
<message name="ProcessLoanPaymentOutputMessage">
  <part name="parameters"
    element="tns:processLoanPaymentResponse"/>
</message>

<message name="GetLoanInputMessage">
  <part name="parameters" element="tns:getLoan"/>
</message>
<message name="GetLoanOutputMessage">
  <part name="parameters" element="tns:getLoanResponse"/>
</message>

Finally, we define all port types. Each interface type defines one or more operations to use the current operation element, each independent operation element defines the input and output of an operation and a message associated with the operation. The operation element in a port type defines the syntax of all call methods in the port type.

<portType name="LoanPortType">
  <operation name="createLoan">
    <input message="tns:CreateLoanInputMessage"/>
    <output message="tns:CreateLoanOutputMessage"/>
    <fault name="Fault" message="ogsi:FaultMessage"/>
  </operation>
  <operation name="processLoanPayment">
    <input message="tns:ProcessLoanPaymentInputMessage"/>
    <output message="tns:ProcessLoanPaymentOutputMessage"/>
    <fault name="Fault" message="ogsi:FaultMessage"/>
  </operation>
  <operation name="getLoan">
    <input message="tns:GetLoanInputMessage"/>
    <output message="tns:GetLoanOutputMessage"/>
    <fault name="Fault" message="ogsi:FaultMessage"/>
  </operation>
</portType>

Service implementation:
In the previous step, an interface of the terminal loan port type has been generated. When defining interfaces of these port types, all remote operations must be set to public and Java is thrown. RMI. remoteException. This article provides the loanserviceimpl class, which mainly implements the interface of the loan port type. These implementations use the root class generated by the loan. WSDL file mentioned earlier.

public class LoanServiceImpl implements LoanPortType

The loanserviceimpl method is defined in the loanporttype interface. The createloan method obtains a loan number as its parameter in the constructor that generates a createloan object.

public CreateLoanResponse createLoan(CreateLoan cl)
throws java.rmi.RemoteException
public ProcessLoanPaymentResponse processLoanPayment(ProcessLoanPayment plp)
throws java.rmi.RemoteException
public GetLoanResponse getLoan(GetLoan gl) throws java.rmi.RemoteException

See the complete code to describe the implementation of the method.

Compile and create a Web Service for loan/repayment processing:
The following describes how to create a gt4 packaging document that is easy to deploy through the following steps. The build. xml generated by ANT when compiling the files provided in this article contains steps for ant to execute tasks. The ant execution task in build. xml calls the ant task in gt4. These tasks can be found in the compilation file along with the release of gt4.

%GLOBUS_LOCATION%/share/globus_wsrf_common/build-packages.xml
%GLOBUS_LOCATION%/share/globus_wsrf_tools/build-stubs.xml
%GLOBUS_LOCATION%/share/schema

Compile the easy-to-deploy Gar file in gt4
To create a deploy grid package file, loan. Gar follows these steps: (these steps are consistent with ant tasks in builder. XML ):
· Binding to the WSDL File
· Generate a root class using the WSDL file. During installation, a special file is provided to map different namespaces and packages. These packages are consistent with the directory structure in the table.
· Compile the root class
· Compile interface class
· Use the jar compression interface class, which is the same as the root class (loan. jar and loan_stubs.jar ).
· Create a deployment description file deploy-server.wsdd. Generate the easy-to-deploy Gar file, loan. Gar
Refer to the complete build. xml file in the source code and use the above steps to implement a series of ant compilation tasks. Gt4 describes our web service file deploy-server.wsdd to think like this:

<service name="loan/impl/LoanService" provider="Handler"
use="literal" style="document">
    <parameter name="className" value="loan.impl.LoanServiceImpl"/>
    <wsdlFile>share/schema/loan/Loan_service.wsdl</wsdlFile>
    <parameter name="allowedMethods" value="*"/>
    <parameter name="handlerClass"
    value="org.globus.axis.providers.RPCProvider"/>
    <parameter name="scope" value="Application"/>
    <parameter name="providers" value="GetRPProvider"/>
    <parameter name="loadOnStartup" value="true"/>
</service>

Let's take a look at some parameters in the deploy-server.wsdd:
Service name: Specifies the path of the web service we provide. We can combine it with the address of the web service container to obtain the complete URL of the web service. To facilitate testing, use an independent gt4 container. The URL is like this:

Http: // localhost: 8080/WSRF/services/loan/impl/loanservice

Class Name: refers to the class that implements the Service Interface (loanserviceimpl ).
WSDL file: tells the Web Service container in gt4 where the WSDL file of the current web service can be found. The WSDL file loan_service.wsdl is automatically generated when gt4 performs ant from loan. WSDL.
Start fashion load: if we need to load the service when the web service container starts, we can control the load of the service.

Deploy the gar file:
The gar file loan. Gar contains all the files and deployment information required by the Web server. We use the gt4 deployment tool:

% Globus_location %/bin/Globus-deploy-gar $ project_home/loan. Gar

Copy the document file (loan. WSDL, compiled root class, compiled interface implementation, loan. WSDD) to the appropriate location in the gt4 container directory.

Test the loan processing instance

Figure 1 describes how to use the sub-system of the lender and the sub-system of the loan settlement as the client of the loan web service. Now we create and deploy the Web service in the gt4 Grid Service container, we need to use a client for testing. The test case simulates a loan event, a loan monthly repayment event, and a loan repayment event. As clients, they want the Web Service uri (Uniform Resource Identifier) to serve as the basis for the client to access the Web service. The client program must be compiled independently. The following describes the main steps for the client to access web services:

Create a terminal reference type object to represent the loan service referenced by the terminal. Our terminal references only the service URI:
Endpointreferencetype endpoint = new endpointreferencetype ();
Endpoint. setaddress (new address (serviceuri ));

Next, we need to obtain the port type of the referenced service. This requires a root class to call loanserviceaddressinglocator. loanserviceaddressinglocator is mainly used to maintain the communication between the client and the web service and to obtain the type of the referenced loan port.
Loanserviceaddressinglocator locator = new loanserviceaddressinglocator ();
Loanporttype loanpt = locator. getloanporttypeport (endpoint );

Once we obtain this reference, we can operate the Web service as a local object. For example, to call a remote creation operation, we only need to use the creation method in the loan port type.
Createloanresponse CLR = loanpt. createloan (New createloan (amount, loannumber ));

See the complete client code in the attachment. Before compiling the client, make sure to run the following script to facilitate the release of gt4:
% Globus_location %/etc/globus-devel-env.bat

The globus-devel-env.bat file is mainly to register the globus class library to the classpath of the system, because the client is compiled as an independent application, similarly, ensure that the compiled root classes placed in the directory of the compiling client can be found through classpath. Therefore, our client can access the root classes of the server, such as loanserviceaddressinglocator.

Start the Grid container
Run the following command to start the Grid container:

% Globus_location %/bin/Globus-start-container-nosec

-The nosec parameter is used to simplify the test and omit the security settings. If the Grid container is successfully started, you will see the list of deployed service Uris. If loanservice is correctly deployed, the following line is displayed in the list of deployed services:

[13]: http: // localhost: 8080/WSRF/services/loan/impl/loanservice

Test the Web Service for loan processing
The client is used for testing. We assume that you have the following operations: apply for a loan, repay the loan, and pay off the loan.

· Create an initial loan number of 100 and 12000 has not yet been returned
Java client http: // 172.24.15.29: 8080/WSRF/services/loan/impl/loanservice createloan 100 120000
Loan 100 created successfully.

· Assume that the service is paid in two months and $1100 is returned each month (in this example, the interest is not calculated)
Java client http: // 172.24.15.29: 8080/WSRF/services/loan/impl/loanservice processloanpayment 100 1100
Loan 100 processed successfully.
Java client http: // 172.24.15.29: 8080/WSRF/services/loan/impl/loanservice processloanpayment 100 1100
Loan 100 processed successfully.

· View the loan status
Java client http: // 172.24.15.29: 8080/WSRF/services/loan/impl/loanservice getloandata 100
Loan Data
Create date mon Jun 06 16:41:06 EDT 2005
Unpaid principal balance 117800.0
Status active

· Pay off the remaining amount in the third month ($117,800)
Java client http: // 172.24.15.29: 8080/WSRF/services/loan/impl/loanservice processloanpayment 100 117800
Loan 100 processed successfully

· View loan status
Java client http: // 172.24.15.29: 8080/WSRF/services/loan/impl/loanservice getloandata 100
Loan Data
Create date mon Jun 06 16:41:06 EDT 2005
Unpaid principal balance 0.0
Status wait doff

Conclusion:

This article describes how to adjust the gt4 mesh structure to create a grid service application based on the existing web service standards. Although gt4 has been mainly applied to large-scale scientific computing problems, it can be used as a method to implement SOA within an enterprise. This article describes how to use the Java core service in gt4 to create and deploy a grid service through a simple example, however, it does not cover more advanced concepts about how to use the Grid Service, how to allocate and manage the Grid Service, the reliability of file transmission, and grid exceptions and security.

Resources
· Sample code in this article
· Matrix-Java developer community: http://www.matrix.org.cn
· Onjava. com: onjava.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.