What is ejb remote interface
We'll discuss them in detail a bit later, when we talk about entity beans. You usually start putting together an EJB by defining its remote interface. This interface contains declarations of the methods that are available to remote clients, so it really points to the heart of the EJB object.
The remote interface for our ProfileServer is shown in Example A remote EJB interface must extend the javax. EJBObject interface. EJBObject in turn extends the java.
The ProfileServer interface defines a single remote method, getProfile , that accepts a username as its only argument. It returns a Profile object, containing the profile information for the person named.
If the person's profile cannot be found on the server, a NoSuchPersonException is thrown. This is an application-specific exception whose implementation isn't shown here. The remote interface for Profile is shown in Example The interface has only two remote methods, one to set profile entry values and one to get those values. Note: the implementation of the Profile remote interface isn't shown in this chapter.
When you deploy your EJB object, you can specify who is allowed to call each method on your bean through the remote interface. In this case, we might want only certain clients to be able to query for user profiles, so we might want to limit access to the getProfile method on our ProfileServer bean.
We discuss the access control features of bean deployment descriptors later in the chapter. Now that we have a home interface that lets clients create EJB references and a remote interface that describes the EJB methods, we need to actually implement the EJB object itself. Our ProfileServerBean is shown in Example These extra methods are the hooks the EJB container uses to manage the bean as a component. At the end of the class is the implementation of the getProfile method from the remote interface.
The ejbCreate method is also included here, to match the create method on the home interface. The class for an EJB object must implement the javax.
EnterpriseBean interface. This is usually done indirectly, through either the javax. SessionBean interface or the javax. EntityBean interface. This client code demonstrates how a client:.
To get a remote object reference you have to know:. JNDI is an interface to a naming and directory service. For example, JNDI can be used as an interface to a file system, that you can use to look up directories and the files that they contain. This section presents a short description of JNDI. JNDI is supplied by Sun in the packages in javax. In fact, to start off all you really need to know is how to use the JNDI methods that are used to get access to permanently-stored home interface objects, and how to set up the environment for the JNDI Context object.
The remainder of this JNDI section describes the data structures and methods of the javax. The first Context object that you get is bound to the root naming context of the Oracle8i publishing context. EJB home interfaces are published in the database, arranged in a file system-like hierarchy. See "publish" for more details about publishing EJB home interfaces, and about the Oracle8i published object directory structure. The environment parameter is a Java hashtable.
There are six properties that you can set in the hashtable, that are passed to the javax. The properties are shown in Table Property Purpose javax. You must use the value "oracle. The three possible values are: oracle. Once you have the "initial references" context, you can invoke its methods to get a reference to an EJB home interface. To do this, you must know the published full pathname of the object, the host system where the object is located, the IIOP port for the listener on that system, and the database system identifier SID.
The listener port for IIOP requests is configured in the listener. The default for Oracle8i is You get the home interface using the lookup method on the initial context, passing the URL as the parameter. Once you have the home interface for the bean, you can invoke one of the bean's create methods to instantiate a bean.
For example:. A First EJB Application This section demonstrates a complete example application, including: home and remote interface code the bean implementation code the deployment descriptor client-side code This example has a single EJB, which queries an Oracle8i database to get name and salary information about an employee. The Interfaces The first task of the bean provider is to design and code the home and remote interfaces.
Home Interface As required by the EJB specification, you must declare that any home interface create method throws the javax. EJBObject; import java. Here is the code for the remote interface for this example EJB: package employee; import employee.
EmpRecord; import javax. RemoteException; import javax. SessionBean interface: ejbActivate Implement this as a null method, as it is never called in this release of the EJB server. Clear the disabled cache after the connection is disconnected.
For details on the procedure, see 2. This subsection describes the precautions concerning invocation of the EJB remote interface. Organization of this subsection 1 Precautions when applying optimization of local invocation 2 Precautions when setting up the operation during the occurrence of a communication failure in the EJB remote interface 3 Precautions when executing multiple threads 4 Precautions when the caching functionality has been enabled in the naming management functionality.
When applying optimization of local invocation of the EJB remote interface in the processing within the same application when specifying ejbserver. Furthermore, even when the same host is specified but the string specified in the host name is different, the local invocation will not be optimized.
For example, if there is a difference in upper case and lower case characters or a different IP address and host name is specified, the local invocation will not be optimized.
0コメント