?? railclient.java
字號:
import java.io.*;
import java.net.*;
import java.util.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
import java.rmi.*;
import java.sql.*;
import java.io.*;
import java.lang.*;
public class RailClient {
public static void main(String[] args) throws Exception {
int n=0;
URL url = new URL ("http://localhost:8080/soap/servlet/rpcrouter");
do
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(" \n");
System.out.println("******************************************************");
System.out.println(" RAILWAY RESERVATION SYSTEM");
System.out.println("******************************************************");
System.out.println(" \n");
System.out.println(" 1.Train Details");
System.out.println(" 2.Check Availability");
System.out.println(" 3.Reservation");
System.out.println(" 4.PNR STATUS");
System.out.println(" 5.EXIT");
System.out.println("Enter ur choice: ");
try{
n = Integer.parseInt(br.readLine());
String str1,str2,str3,str4,str5,str6,str7;
switch(n)
{
case 3:
System.out.println("Enter the name,source,destination,Address,date of journey,train number,berth-class");
str1 = br.readLine();
str2 = br.readLine();
str3 = br.readLine();
str4=br.readLine();
str5=br.readLine();
str6=br.readLine();
int x=Integer.parseInt(str6);
str7=br.readLine();
// Build the call.
Call call = new Call();
call.setTargetObjectURI("urn:mahendra");
call.setMethodName("insertion");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
Vector params = new Vector();
params.addElement(new Parameter("name1", String.class, str1, null));
params.addElement(new Parameter("source", String.class, str2, null));
params.addElement(new Parameter("destination", String.class, str3, null));
params.addElement(new Parameter("city", String.class, str4, null));
params.addElement(new Parameter("jrdate", String.class, str5, null));
params.addElement(new Parameter("tno", Integer.class, x, null));
params.addElement(new Parameter("cla", String.class, str7, null));
call.setParams (params);
// make the call: note that the action URI is empty because the
// XML-SOAP rpc router does not need this. This may change in the
// future.
Response resp = call.invoke(url, "" );
// Check the response.
if ( resp.generatedFault() ) {
Fault fault = resp.getFault ();
System.out.println("The call failed: ");
System.out.println("Fault Code = " + fault.getFaultCode());
System.out.println("Fault String = " + fault.getFaultString());
}
else {
Parameter result = resp.getReturnValue();
System.out.println(result.getValue());
break;
}
case 1:
String s1,s2;
System.out.println("Enter Source from the following");
String sr=" Chennai Pondicherry Vellore";
System.out.println(sr);
s1=br.readLine();
System.out.println("Source " + s1);
System.out.println("Enter Destination from the following");
System.out.println(" Chidambaram Hyderabad Delhi ");
s2=br.readLine();
System.out.println("destination is " + s2);
if((s1.equals("chennai") || s1.equals("pondicherry") || s1.equals("vellore")) && (s2.equals("chidambaram") || s2.equals("hyderabad") || s2.equals("delhi")))
{
// Build the call.
Call call1 = new Call();
call1.setTargetObjectURI("urn:mahendra");
call1.setMethodName("retrieve");
call1.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
Vector params1 = new Vector();
params1.addElement(new Parameter("d1", String.class, s1, null));
params1.addElement(new Parameter("d2", String.class, s2, null));
call1.setParams (params1);
// make the call: note that the action URI is empty because the
// XML-SOAP rpc router does not need this. This may change in the
// future.
Response resp1 = call1.invoke(url, "" );
// Check the response.
if ( resp1.generatedFault() )
{
Fault fault = resp1.getFault ();
System.out.println("The call failed: ");
System.out.println("Fault Code = " + fault.getFaultCode());
System.out.println("Fault String = " + fault.getFaultString());
}
else
{
Parameter result = resp1.getReturnValue();
System.out.println("TRAINNO TRAINNAME Source DESTINATION");
System.out.println(result.getValue());
break;
}
}
else
{
System.out.println("Train is not available");
break;
}
case 2:
String d1;
int xz;
System.out.println("Enter date of journey required");
d1=br.readLine();
System.out.println("Enter train number");
xz=Integer.parseInt(br.readLine());
Call call2 = new Call();
call2.setTargetObjectURI("urn:mahendra");
call2.setMethodName("avail");
call2.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
Vector params2 = new Vector();
params2.addElement(new Parameter("jdate", String.class, d1, null));
params2.addElement(new Parameter("tno", Integer.class, xz, null));
call2.setParams (params2);
// make the call: note that the action URI is empty because the
// XML-SOAP rpc router does not need this. This may change in the
// future.
Response resp2 = call2.invoke(url, "" );
// Check the response.
if ( resp2.generatedFault() )
{
Fault fault = resp2.getFault ();
System.out.println("The call failed: ");
System.out.println("Fault Code = " + fault.getFaultCode());
System.out.println("Fault String = " + fault.getFaultString());
}
else
{
Parameter result = resp2.getReturnValue();
System.out.println("DATE TRAINNO Istclass IIndclass");
System.out.println(result.getValue());
break;
}
case 4:
int p;
System.out.println("Enter PNR");
p=Integer.parseInt(br.readLine());
Call call3 = new Call();
call3.setTargetObjectURI("urn:mahendra");
call3.setMethodName("status");
call3.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
Vector params3 = new Vector();
params3.addElement(new Parameter("x", Integer.class, p, null));
call3.setParams (params3);
// make the call: note that the action URI is empty because the
// XML-SOAP rpc router does not need this. This may change in the
// future.
Response resp3 = call3.invoke(url, "" );
// Check the response.
if ( resp3.generatedFault() )
{
Fault fault = resp3.getFault ();
System.out.println("The call failed: ");
System.out.println("Fault Code = " + fault.getFaultCode());
System.out.println("Fault String = " + fault.getFaultString());
}
else
{
Parameter result = resp3.getReturnValue();
System.out.println(" NAME SOURCE DESTINATION ADDRESS PNR DATE OF JOURNEY TRAIN NUMBER CLASS");
System.out.println(result.getValue());
break;
}
case 5:
System.exit(0);
}
}
catch(Exception e)
{
System.out.println(e);
}
}while(n<=5);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -