KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jass > examples > travelagency > ws > WSClient


1 /**
2  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3  -
4  - JASS: Java Advanced tranSaction Support
5  -
6  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7  -
8  - This module was originally developed by
9  -
10  - LSD (Distributed Systems Lab, http://lsd.ls.fi.upm.es/lsd/lsd.htm)
11  - at Universidad Politecnica de Madrid (UPM) as an ObjectWeb Consortium
12  - (http://www.objectweb.org) project.
13  -
14  - This project has been partially funded by the European Commission under
15  - the IST programme of V FP grant IST-2001-37126 and by the Spanish
16  - Ministry of Science & Technology (MCyT) grants TIC2002-10376-E and
17  - TIC2001-1586-C03-02
18  -
19  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20  - The original code and portions created by LSD are
21  - Copyright (c) 2004 LSD (UPM)
22  - All rights reserved.
23  -
24  - Redistribution and use in source and binary forms, with or without
25  - modification, are permitted provided that the following conditions are met:
26  -
27  - -Redistributions of source code must retain the above copyright notice, this
28  - list of conditions and the following disclaimer.
29  -
30  - -Redistributions in binary form must reproduce the above copyright notice,
31  - this list of conditions and the following disclaimer in the documentation
32  - and/or other materials provided with the distribution.
33  -
34  - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
35  - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36  - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37  - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
38  - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
39  - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
40  - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
41  - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
42  - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
43  - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44  - POSSIBILITY OF SUCH DAMAGE.
45  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
46  -
47  - Author: Francisco Perez Sorrosal (frperezs)
48  -
49  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50 */

51
52 package org.objectweb.jass.examples.travelagency.ws;
53
54 import java.rmi.RemoteException JavaDoc;
55
56 import javax.xml.rpc.ServiceException JavaDoc;
57
58 import org.apache.axis.EngineConfiguration;
59 import org.apache.axis.Handler;
60 import org.apache.axis.SimpleChain;
61 import org.apache.axis.SimpleTargetedChain;
62 import org.apache.axis.client.AxisClient;
63 import org.apache.axis.configuration.SimpleProvider;
64 import org.apache.axis.handlers.SimpleSessionHandler;
65 import org.apache.axis.transport.http.HTTPSender;
66 import org.apache.axis.transport.http.HTTPTransport;
67
68 /**
69  * This is the client for the travel agency WS example.
70  * @author fran
71  * Date: Feb 26, 2004
72  * org.objectweb.jass.examples.travelagency.wsWSClient.java
73  */

74 public class WSClient {
75     /**
76      * Configures the AXIS engine on the client side.
77      * @return the engine configuration.
78      */

79     private static EngineConfiguration getClientConfig() {
80         SimpleProvider clientConfig = new SimpleProvider();
81         Handler sessionHandler = (Handler) new SimpleSessionHandler();
82         SimpleChain reqHandler = new SimpleChain();
83         SimpleChain respHandler = new SimpleChain();
84         reqHandler.addHandler(sessionHandler);
85         respHandler.addHandler(sessionHandler);
86         Handler pivot = (Handler) new HTTPSender();
87         Handler transport =
88             new SimpleTargetedChain(reqHandler, pivot, respHandler);
89         clientConfig.deployTransport(
90             HTTPTransport.DEFAULT_TRANSPORT_NAME,
91             transport);
92
93         return clientConfig;
94     }
95
96     public static void main(String JavaDoc args[]) {
97         
98         if (args.length != 3) {
99             System.out.println("Usage: WSClient reservation_name number_of_seats number_of_rooms");
100             System.exit(1);
101         }
102         
103         String JavaDoc rName = args[0];
104         int nSeats = Integer.parseInt(args[1]);
105         int nRooms = Integer.parseInt(args[2]);
106         
107         try {
108             EngineConfiguration clientConfig = getClientConfig();
109             TravelAgencyService service = new TravelAgencyServiceLocator();
110             ((org.apache.axis.client.Service) service).setEngineConfiguration(clientConfig);
111             ((org.apache.axis.client.Service) service).setEngine(new AxisClient(clientConfig));
112             ((org.apache.axis.client.Service) service).setMaintainSession(true);
113             
114             TravelAgency port = service.getTravelAgency();
115             nSeats = port.reserveSeats(nSeats);
116             nRooms = port.reserveRooms(nRooms);
117             System.out.println("Reservation made succesfully !!!");
118             System.out.println(rName + " has reserved " + nSeats + " seats and " + nRooms + " rooms.");
119         } catch (NotEnoughSeatsException e) {
120             System.out.println("Not enough seats!!!");
121         } catch (NotEnoughRoomsException e) {
122             System.out.println("Not enough rooms!!!");
123         } catch (DBException e) {
124             System.out.println("DB Error!!!");
125         } catch (ServiceException JavaDoc e) {
126             e.printStackTrace();
127         } catch (RemoteException JavaDoc e) {
128             e.printStackTrace();
129         }
130         System.exit(0);
131     }
132 }
133
Popular Tags