1 16 17 package samples.stock ; 18 19 import org.apache.axis.client.Call; 20 import org.apache.axis.client.Service; 21 import org.apache.axis.encoding.XMLType; 22 import org.apache.axis.utils.Options; 23 24 import javax.xml.namespace.QName ; 25 import javax.xml.rpc.ParameterMode ; 26 import java.net.URL ; 27 28 40 public class GetQuote1 { 41 public String symbol ; 42 43 47 public float getQuote1(String args[]) throws Exception { 48 Options opts = new Options( args ); 49 50 args = opts.getRemainingArgs(); 51 52 if ( args == null ) { 53 System.err.println( "Usage: GetQuote <symbol>" ); 54 System.exit(1); 55 } 56 57 58 59 QName servQN = new QName ("urn:xmltoday-delayed-quotes","GetQuoteService"); 60 QName portQN = new QName ("urn:xmltoday-delayed-quotes","GetQuote"); 61 62 63 64 Service service = new Service( new URL ("file:GetQuote.wsdl"), servQN ); 65 Call call = (Call) service.createCall( portQN, "getQuote" ); 66 67 68 69 70 71 opts.setDefaultURL( call.getTargetEndpointAddress() ); 72 call.setTargetEndpointAddress( new URL (opts.getURL()) ); 73 74 75 76 call.setUsername( opts.getUser() ); 77 call.setPassword( opts.getPassword() ); 78 79 80 81 Object result = call.invoke( new Object [] { symbol = args[0] } ); 82 83 return( ((Float ) result).floatValue() ); 84 } 85 86 89 public float getQuote2(String args[]) throws Exception { 90 Options opts = new Options( args ); 91 92 args = opts.getRemainingArgs(); 93 94 if ( args == null ) { 95 System.err.println( "Usage: GetQuote <symbol>" ); 96 System.exit(1); 97 } 98 99 100 101 Service service = new Service(); 102 Call call = (Call) service.createCall(); 103 104 105 106 107 108 opts.setDefaultURL( "http://localhost:8080/axis/servlet/AxisServlet" ); 109 110 111 112 call.setTargetEndpointAddress( new URL (opts.getURL()) ); 113 call.setUseSOAPAction( true ); 114 call.setSOAPActionURI( "getQuote" ); 115 call.setEncodingStyle( "http://schemas.xmlsoap.org/soap/encoding/" ); 116 call.setOperationName( new QName ("urn:xmltoday-delayed-quotes", "getQuote") ); 117 call.addParameter( "symbol", XMLType.XSD_STRING, ParameterMode.IN ); 118 call.setReturnType( XMLType.XSD_FLOAT ); 119 120 121 122 call.setUsername( opts.getUser() ); 123 call.setPassword( opts.getPassword() ); 124 125 126 127 Object result = call.invoke( new Object [] { symbol = args[0] } ); 128 129 return( ((Float ) result).floatValue() ); 130 } 131 132 136 public float getQuote3(String args[]) throws Exception { 137 Options opts = new Options( args ); 138 139 args = opts.getRemainingArgs(); 140 141 if ( args == null ) { 142 System.err.println( "Usage: GetQuote <symbol>" ); 143 System.exit(1); 144 } 145 146 147 148 QName servQN = new QName ("urn:xmltoday-delayed-quotes","GetQuoteService"); 149 QName portQN = new QName ("urn:xmltoday-delayed-quotes","GetQuote"); 150 151 152 153 Service service = new Service( new URL ("file:GetQuote.wsdl"), servQN ); 154 Call call = (Call) service.createCall( portQN, "getQuote" ); 155 156 157 158 159 160 opts.setDefaultURL( call.getTargetEndpointAddress() ); 161 call.setTargetEndpointAddress( new URL (opts.getURL()) ); 162 163 164 165 call.setUsername( opts.getUser() ); 166 call.setPassword( opts.getPassword() ); 167 168 169 170 Object result = call.invoke( new Object [] { symbol = args[0] } ); 171 result = call.invoke( new Object [] { symbol = args[0] } ); 172 173 174 175 call.setOperation( portQN, "test" ); 176 call.setReturnType( XMLType.XSD_STRING ); 177 178 System.out.println( call.invoke(new Object []{}) ); 179 180 return( ((Float ) result).floatValue() ); 181 } 182 183 public static void main(String args[]) { 184 try { 185 String save_args[] = new String [args.length]; 186 float val ; 187 GetQuote1 gq = new GetQuote1(); 188 189 190 191 System.out.println("Using WSDL"); 192 System.arraycopy( args, 0, save_args, 0, args.length ); 193 val = gq.getQuote1( args ); 194 System.out.println( gq.symbol + ": " + val ); 195 196 197 198 System.out.println("Manually"); 199 System.arraycopy( save_args, 0, args, 0, args.length ); 200 val = gq.getQuote2( args ); 201 System.out.println( gq.symbol + ": " + val ); 202 203 204 205 System.out.println("WSDL + Reuse Call"); 206 System.arraycopy( save_args, 0, args, 0, args.length ); 207 val = gq.getQuote3( args ); 208 System.out.println( gq.symbol + ": " + val ); 209 } 210 catch( Exception e ) { 211 e.printStackTrace(); 212 } 213 } 214 }; 215 | Popular Tags |