Show TOC Start of Content Area

Procedure documentation Looking Up Enterprise Beans  Locate the document in its SAP Library structure

Lookup from a J2EE Application

...

       1.      In the client’s additional deployment descriptor, declare an EJB reference to the bean that you want to look up:

¡        If your client is a Web component, declare the EJB reference in the web.xml. For more information, see Configuring Enterprise Bean References.

¡        If your client is another enterprise bean, declare the EJB reference in the ejb-jar.xml. For more information, see Declaring EJB References.

¡        If your client is a J2EE application client, declare the EJB reference in the application-client.xml. For more information, see Performing Lookup from Application Client.

       2.      Use the defined EJB reference name to look up the bean:

¡        Example client source code if you look up the remote home interface of a bean with reference name ejb/customer:

Syntax

javax.naming.Context ctx = new javax.naming.InitialContext();

CustomerHome customerHome = (CustomerHome) javax.rmi.PortableRemoteObject.narrow(ctx.lookup(“java:comp/env/ejb/customer”), CustomerHome.class);

 

¡        Example client source code if you look up the local home interface of a bean with reference name ejb/local_customer:

Syntax

javax.naming.Context ctx = new javax.naming.InitialContext();

CustomerLocalHome customerLocalHome = (CustomerLocalHome) ctx.lookup(“java:comp/env/ejb/local_customer”);

       3.      If the client and the bean belong to different J2EE applications, declare an application reference in the application-j2ee-engine.xml deployment descriptor of the client application. For more information, see Editing Application References.

Lookup from a Non-J2EE Java Application

Instead of declaring EJB references, use the bean’s JNDI name to look up the bean. By default, beans are registered in the JNDI namespace during application startup as <application provider>/<application name>/<EJB name>, where:

·        <application provider> is the name of the application provider as specified in the <provider-name> element in application-j2ee-engine.xml

·        <application name> is the name of the application as specified in the <display-name> element in application.xml

·        <EJB name> is the name of the bean as specified in the <ejb-name> element in ejb-jar.xml.

...

       1.      For how to look up the beans, see the example source code above. Replace the reference names with:

¡        If you look up the remote home interface of the bean – the bean’s default JNDI name.

¡        If you look up the local home interface of the bean – the localejbs/ prefix and the bean’s default JNDI name.

It is also possible (although not recommended) to declare an arbitrary JNDI name for your bean and to use that name instead of the default JNDI name of the bean. For more information, see Specifying Arbitrary JNDI Names for Your Beans.

       2.      Obtain the client JAR in order to be able to run the beans from within the client application. For more information, see Getting a Client JAR.

 

 

End of Content Area