axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan O'Neill <>
Subject Re: web service for servlet
Date Tue, 08 Mar 2005 14:54:12 GMT
 * @author Daniel O'Neill 01330128
import java.util.Vector;
import java.util.Iterator;
import java.rmi.RemoteException;
import java.sql.*;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
//import org.apache.axis.utils.Options;

import javax.xml.rpc.ParameterMode;

public class BandBClient {
	public static void main(String args[]) throws Exception {
	    Vector hello = new Vector(20,5);
	  	Vector list = new Vector(20,5);
	  	BufferedReader in = new BufferedReader(new InputStreamReader(;
	    System.out.println("Welcome to something or other:\n\n");
	  	int charlie=0;
		    System.out.println("This is a list of the B&B's in that area:\n");
		    list = getList();
		    for(Iterator i = list.iterator();i.hasNext() ;){
		    	String one =(String);
		    	if (one!=null){
		    		System.out.println("There are no B&B's at this time. We
apologise for the inconvenience...");
		    int num = 0;
		    System.out.println("Please enter the number(i.e. 1 or 2) of the
B&B you wish you book:");
		    num = Integer.parseInt(in.readLine());
		    boolean beta = checknum(num);
		    if(beta ==true){
		    	System.out.println("Please enter a date:");
			    String dan = in.readLine();
			    System.out.println("These are the rooms available on that date
in this B&B");
			    String endpoint = getService(num);
			  	String method ="getRooms";
			  	Service  service = new Service();
			    Call     call    = (Call) service.createCall();
			    call.setTargetEndpointAddress( new );
			    call.setOperationName( method );
			    call.addParameter( "op1", XMLType.SOAP_VECTOR, ParameterMode.IN );
			    call.setReturnType( XMLType.SOAP_VECTOR );
			    try {
					hello = (Vector) call.invoke( new Object [] {dan});// This does
all the work!
				} catch (RemoteException e) {
					// This is used instead of the huge exception you get....
					// I only changed this after debugging
					System.out.println("Sorry this service is not available at the
moment... We're sorry for the inconvenience!");
			    for(Iterator i = hello.iterator();i.hasNext() ;){
			    	String hello2 =(String);
			    	if (hello2!=null){
			    		System.out.println("This B&B has no available rooms on those dates");
			    System.out.println("If you want to book one of these rooms on
this date please enter the number now. If you wish to go back to the
main menu please type \"c\" and hit return.");
			    String delta = in.readLine();
			    if (delta=="c"){
			    	charlie = 1;
			    else if (delta =="-1"){
			    	charlie = -1;
			    	System.out.println("Please enter your name:");
			    	String name = in.readLine();
			    	System.out.println("Please enter your address:");
			    	String address = in.readLine();
			    	System.out.println("And lastly please enter the number of
people(altogether) that are going to arrive(e.g. 1 or 2 or 3):");
			    	String numPeeps = in.readLine();
			    	String paid = "no";
			    	String endpoint2 = getService(num);
				  	String method2 ="bookRoom";
				  	Service  service2 = new Service();
				    Call     call2    = (Call) service2.createCall();
				    call2.setTargetEndpointAddress( new );
				    call2.setOperationName( method2 );
				    call2.addParameter( "op1", XMLType.SOAP_STRING, ParameterMode.IN );
				    call2.addParameter( "op2", XMLType.SOAP_STRING, ParameterMode.IN );
				    call2.addParameter( "op3", XMLType.SOAP_STRING, ParameterMode.IN );
				    call2.addParameter( "op4", XMLType.SOAP_STRING, ParameterMode.IN );
				    call2.addParameter( "op5", XMLType.SOAP_STRING, ParameterMode.IN );
				    call2.addParameter( "op6", XMLType.SOAP_STRING, ParameterMode.IN );
				    try {
						call2.invoke( new Object [] {delta,dan,name,address,numPeeps,paid});
					}catch (RemoteException e1) {
						// TODO Auto-generated catch block
						System.out.println("That did't work for some reason....");
					System.out.println("Do you want to see some of the other services
that are in the area?");
					BufferedReader st = new BufferedReader(new InputStreamReader(;
					String maybe = st.readLine();
					if (maybe.equals("yes") || maybe.equals("y")){
						Vector foxtrot = new Vector(20,5);
						foxtrot = getLocalServices();
						for(Iterator i = foxtrot.iterator();i.hasNext() ;){
					    	String hello2 =(String);
					    	if (hello2!=null){
					    		System.out.println("There are no local services... Go away now... ");
						System.out.println("Which one do you want to look at?(i.e. 1 or 2)");
						String geography = in.readLine();
					}else {
						System.out.println("Here is what you booked:");
						System.out.println("You booked "+getName(num)+" for the
"+delta+" for "+numPeeps+" people.");
						charlie = -1; 
		    	System.out.println("I'm sorry that number wasn't on the list....");
Sorry its so big buts its the first code example I came to? It might
not be right but it works. I've left a number of non-important(to this
question) methods out. If anyone wants to correct the code go ahead?


View raw message