Debian Codegraph @

samples/stock/GetQuote2.java

raw
1 /*
2 * Copyright 2001-2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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","GetQuoteService");
46 QName portQN = new QName("urn:xmltoday-delayed-quotes","GetQuoteJava");
47
48 /* Now use those QNames as pointers into the WSDL doc */
49 /******************************************************/
50 Service service = new Service( new URL("file:GetQuote.wsdl"), servQN );
51 Call call = (Call) service.createCall( portQN, "getQuote" );
52
53 /* Strange - but allows the user to change just certain portions of */
54 /* the URL we're gonna use to invoke the service. Useful when you */
55 /* want to run it thru tcpmon (ie. put -p81 on the cmd line). */
56 /********************************************************************/
57 opts.setDefaultURL( call.getTargetEndpointAddress() );
58 call.setTargetEndpointAddress( new URL(opts.getURL()) );
59
60 /* Get symbol and invoke the service */
61 /*************************************/
62 Object result = call.invoke( new Object[] { symbol = args[0] } );
63
64 return( ((Float) result).floatValue() );
65 }
66
67 public static void main(String args[]) {
68 try {
69 String save_args[] = new String[args.length];
70 float val ;
71 GetQuote2 gq = new GetQuote2();
72
73 /* Call the getQuote() that uses the WDSL */
74 /******************************************/
75 System.out.println("Using Java binding in WSDL");
76 System.arraycopy( args, 0, save_args, 0, args.length );
77 val = gq.getQuote( args );
78 System.out.println( gq.symbol + ": " + val );
79 }
80 catch( Exception e ) {
81 e.printStackTrace();
82 }
83 }
84 };