01: /*
02: * Copyright 2001-2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
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.utils.Options;
22:
23: import javax.xml.namespace.QName;
24: import java.net.URL;
25:
26: public class GetQuote2 {
27: public String symbol;
28:
29: /**
30: * This will use the WSDL to prefill all of the info needed to make
31: * the call. All that's left is filling in the args to invoke().
32: */
33: public float getQuote(String args[]) throws Exception {
34: Options opts = new Options(args);
35:
36: args = opts.getRemainingArgs();
37:
38: if (args == null) {
39: System.err.println("Usage: GetQuote <symbol>");
40: System.exit(1);
41: }
42:
43: /* Define the service QName and port QName */
44: /*******************************************/
45: QName servQN = new QName("urn:xmltoday-delayed-quotes",
46: "GetQuoteService");
47: QName portQN = new QName("urn:xmltoday-delayed-quotes",
48: "GetQuoteJava");
49:
50: /* Now use those QNames as pointers into the WSDL doc */
51: /******************************************************/
52: Service service = new Service(new URL("file:GetQuote.wsdl"),
53: servQN);
54: Call call = (Call) service.createCall(portQN, "getQuote");
55:
56: /* Strange - but allows the user to change just certain portions of */
57: /* the URL we're gonna use to invoke the service. Useful when you */
58: /* want to run it thru tcpmon (ie. put -p81 on the cmd line). */
59: /********************************************************************/
60: opts.setDefaultURL(call.getTargetEndpointAddress());
61: call.setTargetEndpointAddress(new URL(opts.getURL()));
62:
63: /* Get symbol and invoke the service */
64: /*************************************/
65: Object result = call.invoke(new Object[] { symbol = args[0] });
66:
67: return (((Float) result).floatValue());
68: }
69:
70: public static void main(String args[]) {
71: try {
72: String save_args[] = new String[args.length];
73: float val;
74: GetQuote2 gq = new GetQuote2();
75:
76: /* Call the getQuote() that uses the WDSL */
77: /******************************************/
78: System.out.println("Using Java binding in WSDL");
79: System.arraycopy(args, 0, save_args, 0, args.length);
80: val = gq.getQuote(args);
81: System.out.println(gq.symbol + ": " + val);
82: } catch (Exception e) {
83: e.printStackTrace();
84: }
85: }
86: };
|