O'Reilly logo

Programming Jakarta Struts, Second Edition by Chuck Cavaness

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required