ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Constructing Web Services with the Globus Toolkit Version 4
Pages: 1, 2, 3, 4, 5

Testing the Loan Payment Processing Example

Client Implementation

Figure 1 described how the loan origination subsystem and the loan accounting subsystem can act as clients to the loan payment processing web services. Now that we have build and deploy our web service in the GT4 grid container, we need to test the services with a client program. Test cases simulate a loan creation event, a loan monthly payment activity event, and a loan pay-off event. The client expects the service URI as one of its arguments from the command line. The client program is compiled separately. Following are a description of the main steps to implement the client to call our web services:

  • Create an EndpointReferenceType object representing the endpoint reference of the loan service. Our endpoint reference only needs the service's URI.

    EndpointReferenceType endpoint = new EndpointReferenceType();
    endpoint.setAddress(new Address(serviceURI));

  • Next, we obtain a reference to the service's portType. This is done with a stub class called LoanServiceAddressingLocator, which takes care of contacting the service (given its endpoint) and getting a reference to the loan portType.

    LoanServiceAddressingLocator locator = new LoanServiceAddressingLocator();
    LoanPortType loanPT = locator.getLoanPortTypePort(endpoint);

  • Once we have that reference, we can work with the web service as if it were a local object. For example, to invoke the remote create operation, we simply have to use the create method in the LoanPortType object.

    CreateLoanResponse clr = loanPT.createLoan(new CreateLoan(amount, loanNumber));

Please see the full code listing in the attached source code for the client. Before compiling the client, make sure you run the following script that comes with the GT4 distribution:

%GLOBUS_LOCATION%/etc/globus-devel-env.bat

The globus-devel-env.bat script takes care of putting all of the Globus libraries into the CLASSPATH, because the client is being compiled as a standalone application. Also, make sure that the CLASSPATH used to compile the client contains the directory where all of the compiled stub classes are placed, so our client can access generated stub classes such as LoanServiceAddressingLocator.

Starting the Grid Container

Use the following GT4 command to start the grid container:

%GLOBUS_LOCATION%/bin/globus-start-container -nosec

The -nosec option disable the security configuration to simplify testing. If the container is started successfully, you'll see a list with the URIs of all the deployed services. If our LoanService is correctly deployed, the following line appears in the list of deployed services (assuming a default GT4 installation):

[13]: http://localhost:8080/wsrf/services/loan/impl/LoanService

Testing the Loan Payment Processing Web Services

To test the service using the client, we consider the following scenarios: creating a loan, making payments, and paying off the loan.

  • Create an initial loan with loan number 100 and a UPB (Unpaid Principal Balance) of $120,000:

    java Client http://172.24.15.29:8080/wsrf/services/loan/impl/LoanService createLoan 100 120000
    Loan 100 created successfully.

  • Assume two monthly payments of $1,100. (No interest calculations are considered in this example for the sake of simplicity and clarity.)

    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 status of the loan:

    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 remainder of the loan ($117,800) on the third month:

    java Client http://172.24.15.29:8080/wsrf/services/loan/impl/LoanService processLoanPayment 100 117800
    Loan 100 processed successfully.

  • View the status of the loan:

    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 PAIDOFF

Conclusion

This article described how the GT4 grid infrastructure can be leveraged to create application grid services based on existing web services standards. Although GT4 has been primarily used to solve large scientific computational problems, it can be used as a way to implement a service-oriented architecture within an enterprise. This article shows through a simple example how to create and deploy a grid service using the GT4 Core Java Services. It does not cover the more advanced concepts on how to use other grid services, such as the Grid Resource Allocation and Management (GRAM), Reliable File Transfer (RFT), notification, or security.

Resources

Birali Hakizumwami is currently working as an application architect.


Return to ONJava.com.