⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searchflightremoteclient.java

📁 BEA WebLogic Server 8.1大全 = BEA webLogic server 8.1 unleashed (美) Mark Artiges等著 袁毅 ... [等] 译 eng
💻 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 + -