Sunday, May 4, 2014

Implement a client to invoke the service deployed in Axis2

In this blog, I’m going to implement a client to invoke the OrderProcessingService deployed in Axis2 

Step 1: Generate the client stubs using wsdl2java tool

Go to AXIS2_HOME/bin and execute the following command.
>> ./wsdl2java.sh -uri http://localhost:8080/axis2/services/OrderProcessingService?wsdl -o /path/to/OrderProcessingClient -p com.wso2.orderprocessing.client




com.wso2.orderprocessing.client.OrderProcessingServiceStub will invoke the operations of the service.

Step 2: Implement a client to invoke the OrderProcessingServiceStub

package com.wso2.orderprocessing.client;

import java.rmi.RemoteException;
import com.wso2.orderprocessing.client.OrderProcessingServiceStub.GetPrice;
import com.wso2.orderprocessing.client.OrderProcessingServiceStub.Update;

public class OrderProcessingClient {
   public static void main(String[] args) {

      OrderProcessingServiceStub stub = null;
      try {
          stub = new OrderProcessingServiceStub();
          Update update = new Update();
          update.setArgs0("IBM");
          update.setArgs1(80.0);
          stub.update(update);
      } catch (RemoteException e) {
          System.err.println("price updated");
      }

      try {
          GetPrice getPrice = new GetPrice();
          getPrice.setArgs0("IBM");
          System.err.println("Price : " + stub.getPrice(getPrice).get_return());
      } catch (RemoteException e) {
      }
   }
}

Run the client

Output:
Price updated
Price : 80.0


References:
1. http://axis.apache.org/axis2/java/core/docs/quickstartguide.html

No comments: