home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
wsgatsam.zip
/
GetQuote.java
< prev
next >
Wrap
Text File
|
2003-02-24
|
2KB
|
74 lines
/**
* %wsgw_sample_start%
* Licensed Materials - Property of IBM
*
* (c) Copyright IBM Corp. 2001, 2002 All Rights Reserved.
*
* US Government Users Restricted Rights - Use, duplication or
* disclosure restricted by GSA ADP Schedule Contract with
* IBM Corp.
* %wsgw_sample_end%
*/
package services.stockquote;
import java.io.*;
import java.net.*;
import java.util.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
import org.apache.soap.transport.*;
import org.apache.soap.transport.http.*;
/**
* See README for info.
*
* @author Sanjiva Weerawarana (sanjiva@watson.ibm.com)
*/
public class GetQuote {
public static void main (String[] args) throws Exception {
if ((args.length != 4) && (args.length != 6)) {
System.err.println ("Usage: java " + GetQuote.class.getName () +
" SOAP-router-URL method-namespace-uri" +
" action-uri symbol [username password]");
System.exit (1);
}
URL url = new URL (args[0]);
String id = args[1];
String actionURI = args[2];
String symbol = args[3];
String userName = null;
String password = null;
if (args.length == 6) {
userName = args[4];
password = args[5];
}
// Build the call.
Call call = new Call ();
call.setTargetObjectURI (id);
call.setMethodName ("getQuote");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
Vector params = new Vector ();
params.addElement (new Parameter("symbol", String.class, symbol, null));
call.setParams (params);
if (userName != null) {
SOAPHTTPConnection shc = new SOAPHTTPConnection ();
shc.setUserName (userName);
shc.setPassword (password);
call.setSOAPTransport (shc);
}
Response resp = call.invoke (url, actionURI);
// Check the response.
if (resp.generatedFault ()) {
Fault fault = resp.getFault ();
System.out.println ("Ouch, the call failed: " + fault);
} else {
Parameter result = resp.getReturnValue ();
System.out.println (result.getValue ());
}
}
}