KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > samples > userguide > example5 > Client


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.example5;
18
19 import org.apache.axis.AxisFault;
20 import org.apache.axis.client.Call;
21 import org.apache.axis.client.Service;
22 import org.apache.axis.utils.Options;
23
24 import javax.xml.namespace.QName JavaDoc;
25 import javax.xml.rpc.ParameterMode JavaDoc;
26                                            
27 public class Client
28 {
29     public static void main(String JavaDoc [] args) throws Exception JavaDoc
30     {
31         Options options = new Options(args);
32         
33         Order order = new Order();
34         order.setCustomerName("Glen Daniels");
35         order.setShippingAddress("275 Grove Street, Newton, MA");
36         
37         String JavaDoc [] items = new String JavaDoc[] { "mp3jukebox", "1600mahBattery" };
38         int [] quantities = new int [] { 1, 4 };
39         
40         order.setItemCodes(items);
41         order.setQuantities(quantities);
42         
43         Service service = new Service();
44         Call call = (Call) service.createCall();
45         QName JavaDoc qn = new QName JavaDoc( "urn:BeanService", "Order" );
46
47         call.registerTypeMapping(Order.class, qn,
48                       new org.apache.axis.encoding.ser.BeanSerializerFactory(Order.class, qn),
49                       new org.apache.axis.encoding.ser.BeanDeserializerFactory(Order.class, qn));
50         String JavaDoc result;
51         try {
52             call.setTargetEndpointAddress( new java.net.URL JavaDoc(options.getURL()) );
53             call.setOperationName( new QName JavaDoc("OrderProcessor", "processOrder") );
54             call.addParameter( "arg1", qn, ParameterMode.IN );
55             call.setReturnType( org.apache.axis.encoding.XMLType.XSD_STRING );
56
57             result = (String JavaDoc) call.invoke( new Object JavaDoc[] { order } );
58         } catch (AxisFault fault) {
59             result = "Error : " + fault.toString();
60         }
61         
62         System.out.println(result);
63     }
64 }
65
Popular Tags