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