📄 searchflightremoteclient.java
字号:
/*
* WebLogic Server Unleashed
*
*/
package com.wlsunleashed.ejb.session.stateless;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
/**
* This class represents A remote client that connects to the weblogic server
* and looks up a stateless session EJB, searches the flight information and
* prints it out.
*
* @version 1.0
*/
public class SearchFlightRemoteClient {
/**
* Constructor for SearchFlightRemoteClient.
*/
public SearchFlightRemoteClient() {
super();
}
/**
* The main method. invoked when the command line is invoked
*
* @param args The command line args: String[]
*/
public static final void main(String[] args) {
String origin;
String destination;
if (args.length != 2) {
System.out.println(
"Usage SearchFlightRemoteClient <origin> <destination>");
System.out.println("Using default origin = 'Los Angeles' and ");
System.out.println("destination = 'Amsterdam'");
origin = "Los Angeles";
destination = "Amsterdam";
} else {
origin = args[0];
destination = args[1];
}
SearchFlightRemoteClient test = new SearchFlightRemoteClient();
test.searchFlights(origin, destination);
}
/**
* Searches for flights between the two cities and prints out the flight
* numbers.
*
* @param origin : origin airport: String
* @param destination destination airport: String.
*/
private void searchFlights(String origin, String destination) {
try {
InitialContext ic = null;
Hashtable props = new Hashtable();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
props.put(Context.PROVIDER_URL, "t3://localhost:7001");
ic = new InitialContext(props);
Object o = ic.lookup("AirlineReservationBean");
AirlineReservationRemoteHome arrho = (AirlineReservationRemoteHome) PortableRemoteObject.narrow(o,
AirlineReservationRemoteHome.class);
AirlineReservationRemoteObject arro =
(AirlineReservationRemoteObject) arrho.create();
System.out.println("remote instance created");
int[] values = arro.getFlightNumbers(origin, destination);
System.out.println("Flight Numbers between " + origin + " and "
+ destination);
for (int i = 0; i < values.length; i++) {
System.out.println(" --> " + values[i]);
}
System.out.println("-- finished.");
ic.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -