home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wsgatsam.zip / GetQuote.java < prev    next >
Text File  |  2003-02-24  |  2KB  |  74 lines

  1. /**
  2.  * %wsgw_sample_start%
  3.  * Licensed Materials - Property of IBM  
  4.  *    
  5.  * (c) Copyright IBM Corp. 2001, 2002 All Rights Reserved.  
  6.  *    
  7.  * US Government Users Restricted Rights - Use, duplication or   
  8.  * disclosure restricted by GSA ADP Schedule Contract with   
  9.  * IBM Corp.  
  10.  * %wsgw_sample_end%
  11.  */
  12. package services.stockquote;
  13.  
  14. import java.io.*;
  15. import java.net.*;
  16. import java.util.*;
  17. import org.apache.soap.*;
  18. import org.apache.soap.rpc.*;
  19. import org.apache.soap.transport.*;
  20. import org.apache.soap.transport.http.*;
  21.  
  22. /**
  23.  * See README for info.
  24.  *
  25.  * @author Sanjiva Weerawarana (sanjiva@watson.ibm.com)
  26.  */
  27. public class GetQuote {
  28.   public static void main (String[] args) throws Exception {
  29.     if ((args.length != 4) && (args.length != 6)) {
  30.       System.err.println ("Usage: java " + GetQuote.class.getName () +
  31.                           " SOAP-router-URL method-namespace-uri" +
  32.                           " action-uri symbol [username password]");
  33.       System.exit (1);
  34.     }
  35.  
  36.     URL url = new URL (args[0]);
  37.     String id = args[1];
  38.     String actionURI = args[2];
  39.     String symbol = args[3];
  40.     String userName = null;
  41.     String password = null;
  42.     if (args.length == 6) {
  43.       userName = args[4];
  44.       password = args[5];
  45.     }
  46.  
  47.     // Build the call.
  48.     Call call = new Call ();
  49.     call.setTargetObjectURI (id);
  50.     call.setMethodName ("getQuote");
  51.     call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
  52.     Vector params = new Vector ();
  53.     params.addElement (new Parameter("symbol", String.class, symbol, null));
  54.     call.setParams (params);
  55.     if (userName != null) {
  56.       SOAPHTTPConnection shc = new SOAPHTTPConnection ();
  57.       shc.setUserName (userName);
  58.       shc.setPassword (password);
  59.       call.setSOAPTransport (shc);
  60.     }
  61.  
  62.     Response resp = call.invoke (url, actionURI);
  63.  
  64.     // Check the response.
  65.     if (resp.generatedFault ()) {
  66.       Fault fault = resp.getFault ();
  67.       System.out.println ("Ouch, the call failed: " + fault);
  68.     } else {
  69.       Parameter result = resp.getReturnValue ();
  70.       System.out.println (result.getValue ());
  71.     }
  72.   }
  73. }
  74.