View RSS Feed

JNDI

Locating EJB Home Interface

Rate this Entry
by , 01-02-2012 at 07:21 PM (1078 Views)
Home interface of EJB can be located by an EJB client via standard JNDI API. To make available the home interfaces of its deployed beans EJB is considered responsible, using JNDI. JNDI namespace of a client can be configured to consider the EJBs home interfaces which are installed on other hosts or containers.

Java Code: This is the code to locate EJB Home Interface
import java.util.Collection;
import java.util.Iterator;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class CartClient {
    public static void main(String [] args) throws NamingException {       
        try {
            final Context context = getInitialContext();
            Cart cart = (Cart)context.lookup("CartBean");            
            cart.addItem("Pizza");
            cart.addItem("Pasta");
            cart.addItem("Noodles");
            cart.addItem("Bread");
            cart.addItem("Butter");
            Collection items = cart.getItems();
            for (Iterator i = items.iterator(); i.hasNext();) {
            String item = (String) i.next();
            System.out.println("  " + item);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    private static Context getInitialContext() throws NamingException {
        return new InitialContext();
    }
}

Submit "Locating EJB Home Interface" to Facebook Submit "Locating EJB Home Interface" to Digg Submit "Locating EJB Home Interface" to del.icio.us Submit "Locating EJB Home Interface" to StumbleUpon Submit "Locating EJB Home Interface" to Google

Updated 01-14-2012 at 07:20 PM by JNDI

Categories
Tutorial

Comments