Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Banking command line client

The bank command line client does a JNDI lookup to the remote interface. Later, the list of ExchangeRate is obtained and printed out on the screen.

Code Block
xml
xml
borderStylesolid
titleBankClient.java

package org.apache.geronimo.samples.bank.client;

import java.util.List;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;

import org.apache.geronimo.samples.bank.ejb.BankManagerFacadeRemote;
import org.apache.geronimo.samples.bank.ejb.ExchangeRate;

public class BankClient {
    public static void main(String[] args) {


        Properties p = new Properties();
        p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
        p.setProperty(Context.PROVIDER_URL, "ejbd://localhost:4201");
        try {
            Context ic = new InitialContext(p);
            BankManagerFacadeRemote bmr = (BankManagerFacadeRemote) ic.lookup("BankManagerFacadeBeanRemote");
            List<ExchangeRate> rates = bmr.getExchangeRates();
            System.out.println("Exchange Rates");
            for (int i = 0; i < (int) rates.size(); i++) {
                ExchangeRate rate = rates.get(i);
                System.out.println("Currency: " + rate.getCurrency());
                System.out.println("Rate: " + rate.getRate());
                System.out.println();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Note

Please note that "BankManagerFacadeBeanRemote" is used here as the look up name instead of "BankManagerFacadeRemote". Otherwise, you'll get an error like this -

javax.naming.NameNotFoundException: /BankManagerFacadeRemote does not exist in the system. Check that the app was successfully deployed.

To test the command line client first determine a useable (although excessive classpath) by running

...