KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > samples > jaxrpc > GetInfo


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.jaxrpc;
18
19 import org.apache.axis.encoding.XMLType;
20 import org.apache.axis.utils.Options;
21
22 import javax.xml.namespace.QName JavaDoc;
23 import javax.xml.rpc.Call JavaDoc;
24 import javax.xml.rpc.ParameterMode JavaDoc;
25 import javax.xml.rpc.Service JavaDoc;
26 import javax.xml.rpc.ServiceFactory JavaDoc;
27
28 /**
29  * This version of GetInfo is a near-duplicate of the GetInfo class in
30  * samples/stock. This version is strictly JAX-RPC compliant. It uses
31  * no AXIS enhancements.
32  *
33  * @author Russell Butek (butek@us.ibm.com)
34  */

35 public class GetInfo {
36
37     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
38         Options opts = new Options(args);
39
40         args = opts.getRemainingArgs();
41
42         if (args == null || args.length % 2 != 0) {
43             System.err.println("Usage: GetInfo <symbol> <datatype>");
44             System.exit(1);
45         }
46
47         String JavaDoc symbol = args[0];
48         Service JavaDoc service = ServiceFactory.newInstance().createService(null);
49         Call JavaDoc call = service.createCall();
50
51         call.setTargetEndpointAddress(opts.getURL());
52         call.setOperationName(new QName JavaDoc("urn:cominfo", "getInfo"));
53         call.addParameter("symbol", XMLType.XSD_STRING, ParameterMode.IN);
54         call.addParameter("info", XMLType.XSD_STRING, ParameterMode.IN);
55         call.setReturnType(XMLType.XSD_STRING);
56         if(opts.getUser()!=null)
57             call.setProperty(Call.USERNAME_PROPERTY, opts.getUser());
58         if(opts.getPassword()!=null)
59             call.setProperty(Call.PASSWORD_PROPERTY, opts.getPassword());
60
61         String JavaDoc res = (String JavaDoc) call.invoke(new Object JavaDoc[] {args[0], args[1]});
62
63         System.out.println(symbol + ": " + res);
64     } // main
65
}
66
67
Popular Tags