Using Enterprise JavaBeans

So far, we’ve seen the high-level details on implementing and deploying an EJB. Now let’s look at how you use an enterprise bean as a client.

It’s important to note that a “client” for a given EJB can be many things. In a fairly typical scenario, a client may be a Java servlet or JavaServer Page (JSP), running in the same or different J2EE server as the EJBs being used. A client can also be a standalone GUI client (in J2EE parlance, an “application client”) that directly connects to a local or remote EJB container and makes requests of beans. A client can also be another EJB, invoking an EJB on the same or different EJB server in order to satisfy a client request. Regardless of which of these scenarios is the case, the following details apply.

Local Versus Remote Clients

A local client (i.e., a client that resides in the same Java virtual machine as the EJB container) can interact with EJBs using either the local or remote interfaces for the EJB. If the EJB has a local home and client interface, then this provides an efficient way for the client to make requests, since their method calls don’t need to be marshalled into a remote method call and transmitted over an RMI or IIOP connection to the EJB container. If the EJB doesn’t have a local client and home interface, or if the local interfaces don’t expose the functionality that the client needs (remember that local and remote interfaces for the same EJB don’t need to be equivalent to each other), then ...

Get Java Enterprise in a Nutshell, 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.