FileDocCategorySizeDatePackage
PriceListClient.javaAPI DocExample2920Tue Oct 09 11:03:40 BST 2001com.ecerami.soap

PriceListClient

public class PriceListClient extends Object
A Sample SOAP Client Retrieves Price List for Specified SKUs usage: java PriceClient sku#1 sku#2 sku#N

Fields Summary
Constructors Summary
Methods Summary
public double[]getPriceList(java.lang.String[] skus)
getPriceList Method

    Parameter skuParam;

    //  Create SOAP RPC Call Object
    Call call = new Call ();

    // Set Encoding Style to standard SOAP encoding
    call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);

    // Set Object URI and Method Name
    call.setTargetObjectURI ("urn:examples:pricelistservice");
    call.setMethodName ("getPriceList");

    //  Set Method Parameters
    Vector paramList = new Vector ();
    Parameter param = new Parameter("sku", String[].class,
        skus, Constants.NS_URI_SOAP_ENC);
    paramList.addElement (param);
    call.setParams (paramList);

    //  Set the URL for the Web Service
    URL url = new URL ("http://localhost:8080/soap/servlet/rpcrouter");

    // Invoke the Service
    Response resp = call.invoke (url, null);

    // Check for Success
    if (!resp.generatedFault()) {
      // Extract Return value
      Parameter result = resp.getReturnValue ();
      double priceList[] = (double []) result.getValue();
      return priceList;
    }
    //  Check for Faults
    else {
      //  Extract Fault Code and String
      Fault f = resp.getFault();
      String faultCode = f.getFaultCode();
      String faultString = f.getFaultString();
      System.err.println("Fault Occurred (details follow):");
      System.err.println("Fault Code:  "+faultCode);
      System.err.println("Fault String:  "+faultString);
      return null;
    }
  
public static voidmain(java.lang.String[] args)
Static Main method

    System.out.println ("Price List Checker:  SOAP Client");
    String skus[] = new String [args.length];
    for (int i=0; i<args.length; i++)
      skus[i] = new String (args[i]);
    PriceListClient priceListClient = new PriceListClient();
    try {
      double price[] = priceListClient.getPriceList(skus);
      for (int i=0; i<price.length; i++) {
        System.out.print ("SKU:  "+skus[i]);
        System.out.println (" --> "+price[i]);
      }
    } catch (SOAPException e) {
      System.err.println (e);
    } catch (MalformedURLException e) {
      System.err.println (e);
    }