Debian Codegraph @

samples/userguide/example2/CalcClient.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.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 {
28 public static void main(String [] args) throws Exception {
29 Options options = new Options(args);
30
31 String endpoint = "http://localhost:" + options.getPort() +
32 "/axis/Calculator.jws";
33
34 args = options.getRemainingArgs();
35
36 if (args == null || args.length != 3) {
37 System.err.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.println("Usage: CalcClient <add|subtract> arg1 arg2");
44 return;
45 }
46
47 Integer i1 = new Integer(args[1]);
48 Integer i2 = new Integer(args[2]);
49
50 Service service = new Service();
51 Call call = (Call) service.createCall();
52
53 call.setTargetEndpointAddress( new java.net.URL(endpoint) );
54 call.setOperationName( method );
55 call.addParameter( "op1", XMLType.XSD_INT, ParameterMode.IN );
56 call.addParameter( "op2", XMLType.XSD_INT, ParameterMode.IN );
57 call.setReturnType( XMLType.XSD_INT );
58
59 Integer ret = (Integer) call.invoke( new Object [] { i1, i2 });
60
61 System.out.println("Got result : " + ret);
62 }
63 }