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.userguide.example2;
18:
19: import org.apache.axis.client.Call;
20: import org.apache.axis.client.Service;
21: import org.apache.axis.encoding.XMLType;
22: import org.apache.axis.utils.Options;
23:
24: import javax.xml.rpc.ParameterMode;
25:
26: public class CalcClient {
27: public static void main(String[] args) throws Exception {
28: Options options = new Options(args);
29:
30: String endpoint = "http://localhost:" + options.getPort()
31: + "/axis/Calculator.jws";
32:
33: args = options.getRemainingArgs();
34:
35: if (args == null || args.length != 3) {
36: System.err
37: .println("Usage: CalcClient <add|subtract> arg1 arg2");
38: return;
39: }
40:
41: String method = args[0];
42: if (!(method.equals("add") || method.equals("subtract"))) {
43: System.err
44: .println("Usage: CalcClient <add|subtract> arg1 arg2");
45: return;
46: }
47:
48: Integer i1 = new Integer(args[1]);
49: Integer i2 = new Integer(args[2]);
50:
51: Service service = new Service();
52: Call call = (Call) service.createCall();
53:
54: call.setTargetEndpointAddress(new java.net.URL(endpoint));
55: call.setOperationName(method);
56: call.addParameter("op1", XMLType.XSD_INT, ParameterMode.IN);
57: call.addParameter("op2", XMLType.XSD_INT, ParameterMode.IN);
58: call.setReturnType(XMLType.XSD_INT);
59:
60: Integer ret = (Integer) call.invoke(new Object[] { i1, i2 });
61:
62: System.out.println("Got result : " + ret);
63: }
64: }
|