Java client

The Java client example uses a batch file that runs the WSDL2Java utility to generate classes from the WSDL document. The generated classes are then called from the Test.java client to invoke the Web Services.

Java client examples are located in the <MVS.install.dir>\samples\mv-ws-java\ folder of your installation.

Note:
  • You must have the Java 1.5 SDK or above installed.

  • For Windows, you must set your path environment variable to the path for the Java SDK. For example, C:\Program Files\Java\jdk<version>

Here is the Test.java code calling the mvs Web Service:

import com.rocketsoftware.www.namespaces.ws.mvs.*;
import mvs.mv.localserver.data_sources.*;
import javax.xml.rpc.ServiceException;
import javax.xml.rpc.holders.StringHolder;
import java.rmi.RemoteException;
/**
* Demonstrates using MV web services.
*
*/
public class Test
{
   public static void main(String [] args)
   {
      MvsServiceLocator mvsServiceLocator = new MvsServiceLocator();
      try
      {
         MvsPortType mvsPortType = mvsServiceLocator.getmvsPort();
         // ------------------------------------------------------------------
         // search-inventory
         // ------------------------------------------------------------------
         System.out.println("\nsearch-inventory");
         MvsSearchInventoryRow[] searchInventoryRows = 
            mvsPortType.searchInventory("[OFFICE]");
         for (int i=0;i<searchInventoryRows.length;i++)
         {
            MvsSearchInventoryRow row = searchInventoryRows[i];
               System.out.printf("%s %s %s %s %s\n", row.getID()[0][0],
                  row.getDESCRIPTION()[0][0], row.getRETAILPRICE()[0][0],
                  row.getPROMOPRICE()[0][0], row.getQTYONHAND()[0][0]);
         }
         // ------------------------------------------------------------------
         // check-inventory
         // ------------------------------------------------------------------
         System.out.println("\ncheck-inventory");
         String id = "DVD-201";
         String result = mvsPortType.checkInventory(id);
         System.out.printf("%s %s\n\n", id, result);
         // ------------------------------------------------------------------
         // check-inventory-by-location
         // ------------------------------------------------------------------
         // Set the locations to search.
         // ----------------------------
         Locations[] locations = new Locations[2];
         locations[0] = new Locations("IRVINE");
         locations[1] = new Locations("SAN JOSE");
         // Set the items to search for.
         // ----------------------------
         mvs.mv.localserver.data_sources.Items[]
         requestItems = new mvs.mv.localserver.data_sources.Items[2];
         requestItems[0] = new mvs.mv.localserver.data_sources.Items();
         requestItems[0].setItemId("DVD-200");
         requestItems[0].setLocations(locations);
         requestItems[1] = new mvs.mv.localserver.data_sources.Items();
         requestItems[1].setItemId("DVD-201");
         requestItems[1].setLocations(locations);
         // Generate and send the request.
         // ------------------------------
         InventoryRequest request = new InventoryRequest();
         request.setCustomerId("123");
         request.setItems(requestItems);
         InventoryResponse response = mvsPortType.checkInventoryByLocation(request);
         // Process the response.
         // ---------------------
         System.out.println("\ncheck-inventory-by-location");
         System.out.println(response.getCustomerId());
         com.rocketsoftware.www.namespaces.ws.mvs.Items[] items = 
            response.getItems();
         for (int i=0;i<items.length;i++)
         {
            com.rocketsoftware.www.namespaces.ws.mvs.Items item = items[i];
            System.out.println("item");
            System.out.printf("%s %s %s %s\n", item.getItemId(), 
               item.getDescription(), item.getListPrice(), item.getSalePrice());
            System.out.println("\tinventory");
            Inventory[] inventory = item.getInventory();
            for (int j=0;j<inventory.length;j++)
            {
               Inventory itemInventory = inventory[j];
                  System.out.printf("\t%s %s %s\n", itemInventory.getLocationId(),
                  itemInventory.getLocationName(), itemInventory.getQtyOnHand());
            }
         }
         // --------------------------------------------------------------------
         // list-customers
         // --------------------------------------------------------------------
         System.out.println("\nlist-custommers");
         MvsListCustomersRow[] listCustomersRows = 
            mvsPortType.listCustomers("California");
         for (int i=0;i<listCustomersRows.length;i++)
         {
            MvsListCustomersRow row = listCustomersRows[i];
            System.out.printf("%s %s %s %s\n", row.getCUSTOMERID()[0][0],
               row.getORGANIZATIONNAME()[0][0], row.getCITY()[0][0], 
               row.getPHONENUMBER()[0][0]);
         }
         // --------------------------------------------------------------------
         // quote
         // --------------------------------------------------------------------
         System.out.println("\nquote");
         String symbol = "MSFT";
         StringHolder name = new StringHolder();
         StringHolder price = new StringHolder();
         StringHolder lastTrade = new StringHolder();
         StringHolder volume = new StringHolder();
         StringHolder avgVolume = new StringHolder();
         StringHolder changeAmt = new StringHolder();
         mvsPortType.quote(symbol, name, price, lastTrade, volume, avgVolume, 
            changeAmt);
         System.out.printf("%s %s %s %s %s %s %s\n", symbol, name.value, 
            price.value, lastTrade.value, volume.value, avgVolume.value, 
            changeAmt.value);
      }
      catch (ServiceException e)
      {
         e.printStackTrace();
      }
      catch (RemoteException e)
      {
         e.printStackTrace();
      }
   }
}