Home

 

Creating an EJB reference and binding

An EJB 3.0 session bean has a short binding and a long binding that can be used to inject the EJB reference. For the EJBBankBean session bean, the short and long bindings for the remote interface are:

itso.bank.service.EJBBankRemote
ejb/RAD75EJBEAR/RAD75EJB.jar/EJBBankBean#itso.bank.service.EJBBankRemote

For this example, we use the long binding to invoke EJBBankRemote interface. We have to define an EJB reference in deployment descriptor. Follow these steps to add this EJB reference with the long binding.

Expand RAD75AppClient and open (double-click) the RAD75AppClient deployment descriptor. (Alternatively, right-click application-client.xml in appClientModule/META-INF and select Open With Æ Application Client Deployment Editor).

In the Design tab, click Add to add a new EJB reference. Select EJB Reference and click OK. Type ejb/bank as EJB Reference Name, Session as EJB Reference Type, and itso.bank.service.EJBBankRemote as Remote Interface (Figure | 7-9).

Figure 17-9 Create an EJB reference

The Source tab shows the XML source of the EJB reference:

<ejb-ref>

<ejb-ref-name>ejb/bank</ejb-ref-name>

<ejb-ref-type>Session</ejb-ref-type>

<remote>itso.bank.service.EJBBankRemote</remote>

</ejb-ref>

Save and close the application-client.xml file.

Right-click RAD75AppClient and select Java EE Æ Generate WebSphere Bindings Deployment Descriptor to create a stub of the ibm-application-client-bnd.xml file.

In the Design tab, click Add to add a new EJB reference. Select EJB Reference and click OK. Type ejb/bank as Name and ejb/RAD75EJBEAR /RAD75EJB.jar/EJBBankBean#itso.bank.service.EJBBankRemote as Binding Name (Figure | 7-10).

Figure 17-10 Create an EJB binding

The Source tab shows the XML source of the EJB binding:

<ejb-ref name="ejb/bank" binding-name="ejb/RAD75EJBEAR/RAD75EJB.jar

/EJBBankBean#itso.bank.service.EJBBankRemote" />

Save and close the ibm-application-client-bnd.xml file.

The code and configuration for the ITSO Bank Java EE application client is now complete. Now we just need to register the BankDesktopController class as the main class for the application client.

ibm.com/redbooks