1 51 52 package org.objectweb.jass.examples.travelagency.ws; 53 54 import java.rmi.RemoteException ; 55 56 import javax.xml.rpc.ServiceException ; 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 74 public class WSClient { 75 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 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 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 e) { 126 e.printStackTrace(); 127 } catch (RemoteException e) { 128 e.printStackTrace(); 129 } 130 System.exit(0); 131 } 132 } 133 | Popular Tags |