001: /*
002: * Copyright 2001-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package samples.stock;
018:
019: import org.apache.axis.AxisFault;
020: import org.apache.axis.client.Call;
021: import org.apache.axis.client.Service;
022: import org.apache.axis.encoding.XMLType;
023: import org.apache.axis.utils.Options;
024:
025: import javax.xml.namespace.QName;
026: import javax.xml.rpc.ParameterMode;
027: import java.net.URL;
028:
029: /**
030: *
031: * @author Doug Davis (dug@us.ibm.com.com)
032: */
033: public class GetQuote {
034: public String symbol;
035:
036: // helper function; does all the real work
037: public float getQuote(String args[]) throws Exception {
038: Options opts = new Options(args);
039:
040: args = opts.getRemainingArgs();
041:
042: if (args == null) {
043: System.err.println("Usage: GetQuote <symbol>");
044: System.exit(1);
045: }
046:
047: symbol = args[0];
048:
049: // useful option for profiling - perhaps we should remove before
050: // shipping?
051: String countOption = opts.isValueSet('c');
052: int count = 1;
053: if (countOption != null) {
054: count = Integer.valueOf(countOption).intValue();
055: System.out.println("Iterating " + count + " times");
056: }
057:
058: URL url = new URL(opts.getURL());
059: String user = opts.getUser();
060: String passwd = opts.getPassword();
061:
062: Service service = new Service();
063:
064: Float res = new Float(0.0F);
065: for (int i = 0; i < count; i++) {
066: Call call = (Call) service.createCall();
067:
068: call.setTargetEndpointAddress(url);
069: call.setOperationName(new QName(
070: "urn:xmltoday-delayed-quotes", "getQuote"));
071: call.addParameter("symbol", XMLType.XSD_STRING,
072: ParameterMode.IN);
073: call.setReturnType(XMLType.XSD_FLOAT);
074:
075: // TESTING HACK BY ROBJ
076: if (symbol.equals("XXX_noaction")) {
077: symbol = "XXX";
078: }
079:
080: call.setUsername(user);
081: call.setPassword(passwd);
082:
083: Object ret = call.invoke(new Object[] { symbol });
084: if (ret instanceof String) {
085: System.out
086: .println("Received problem response from server: "
087: + ret);
088: throw new AxisFault("", (String) ret, null, null);
089: }
090: res = (Float) ret;
091: }
092:
093: return res.floatValue();
094: }
095:
096: public static void main(String args[]) {
097: try {
098: GetQuote gq = new GetQuote();
099: float val = gq.getQuote(args);
100: // args array gets side-effected
101: System.out.println(gq.symbol + ": " + val);
102: } catch (Exception e) {
103: e.printStackTrace();
104: }
105: }
106:
107: public GetQuote() {
108: };
109:
110: };
|