Interfacing Struts to EJB

It’s now time to turn our attention back to the client side of our session façade. In this section, we’ll first cover how to satisfy the requirements of our service interface with our session-bean implementation. We’ll then look at how to better manage the JNDI lookups and home and remote interface management inherent in being a remote client to an EJB.

Using a Business Delegate

As you saw when we defined the business interface for the Storefront session bean, we still have some work to do to match it up to the Storefront service interface. Our business interface doesn’t include all the methods of IStorefrontService, and the methods that are declared include RemoteException in their throws clauses. We’ll address these differences by going back to the Business Delegate pattern introduced in Chapter 6. Recall that the purpose of this pattern is to hide the business-service implementation from the client application.

We’ll start out with a fairly straightforward Business Delegate implementation and then cover some specific ways to improve it. An initial implementation is shown in Example 13-7.

Example 13-7. A business delegate for the Storefront session bean

package com.oreilly.struts.storefront.service; import java.rmi.RemoteException; import java.util.Hashtable; import java.util.List; import javax.ejb.CreateException; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.rmi.PortableRemoteObject; ...

Get Programming Jakarta Struts, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.