1 16 17 package samples.stock ; 18 19 import org.apache.axis.AxisFault; 20 import org.apache.axis.client.Call; 21 import org.apache.axis.client.Service; 22 import org.apache.axis.encoding.XMLType; 23 import org.apache.axis.utils.Options; 24 25 import javax.xml.namespace.QName ; 26 import javax.xml.rpc.ParameterMode ; 27 import java.net.URL ; 28 29 33 public class GetQuote { 34 public String symbol ; 35 36 public float getQuote (String args[]) throws Exception { 38 Options opts = new Options( args ); 39 40 args = opts.getRemainingArgs(); 41 42 if ( args == null ) { 43 System.err.println( "Usage: GetQuote <symbol>" ); 44 System.exit(1); 45 } 46 47 symbol = args[0] ; 48 49 String countOption = opts.isValueSet('c'); 52 int count=1; 53 if ( countOption != null) { 54 count=Integer.valueOf(countOption).intValue(); 55 System.out.println("Iterating " + count + " times"); 56 } 57 58 URL url = new URL (opts.getURL()); 59 String user = opts.getUser(); 60 String passwd = opts.getPassword(); 61 62 Service service = new Service(); 63 64 Float res = new Float (0.0F); 65 for (int i=0; i<count; i++) { 66 Call call = (Call) service.createCall(); 67 68 call.setTargetEndpointAddress( url ); 69 call.setOperationName( new QName ("urn:xmltoday-delayed-quotes", "getQuote") ); 70 call.addParameter( "symbol", XMLType.XSD_STRING, ParameterMode.IN ); 71 call.setReturnType( XMLType.XSD_FLOAT ); 72 73 if (symbol.equals("XXX_noaction")) { 75 symbol = "XXX"; 76 } 77 78 call.setUsername( user ); 79 call.setPassword( passwd ); 80 81 Object ret = call.invoke( new Object [] {symbol} ); 82 if (ret instanceof String ) { 83 System.out.println("Received problem response from server: "+ret); 84 throw new AxisFault("", (String )ret, null, null); 85 } 86 res = (Float ) ret; 87 } 88 89 return res.floatValue(); 90 } 91 92 public static void main(String args[]) { 93 try { 94 GetQuote gq = new GetQuote(); 95 float val = gq.getQuote(args); 96 System.out.println(gq.symbol + ": " + val); 98 } 99 catch( Exception e ) { 100 e.printStackTrace(); 101 } 102 } 103 104 public GetQuote () { 105 }; 106 107 }; 108 | Popular Tags |