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