CONTENTS | PREV | NEXT | INDEX J2EE BluePrints



3.4 EJB Clients

EJB clients are application clients that interact with the J2EE EJB tier. EJB clients are GUI programs that typically execute on a desktop computer; they manage their own GUI and offer a user experience similar to that of native applications. Here we discuss how to develop and deploy EJB clients.


3.4.1 Protocols and Facilities

EJB clients interact with the J2EE EJB tier using the RMI-IIOP protocol. A variety of middle-tier services are available to an application client:1 JNDI for directory lookups, JMS for messaging, and JDBC for relational database access.

An EJB client depends on a client container to provide some system services. Such a container is typically very lightweight compared to other J2EE containers and usually provides security and deployment services.

3.4.1.1 The Client Container

A client container is usually a library that is distributed along with the client. It is specific to the J2EE EJB container,2 and is often provided by the same vendor. The container manages details of RMI-IIOP communication. It also handles security, transaction, and deployment issues. The following discussion assumes a Java client container. The J2EE specification doesn't define service requirements for applications implemented in other languages. However, a similar set of services should be provided by containers for such clients.

3.4.1.2 Deployment

EJB application clients are packaged in JAR files that include a deployment descriptor similar to other J2EE application components. The deployment descriptor describes the enterprise beans and external resources referenced by the application. As with other J2EE application components, access to resources is configured at deployment time, names are assigned for enterprise beans and resources, and so on.

The J2EE platform does not specify tools to deploy an application client, or mechanisms to install it. Very sophisticated J2EE products might allow the application client to be deployed on a J2EE server and automatically made available to some set of (usually intranet) clients. Other J2EE products might require the J2EE application bundle containing the application client to be manually deployed and installed on each client machine. Another approach would be for the deployment tool on the J2EE server to produce an installation package that could be taken to each host to install the application client.

3.4.1.3 Transactions

Since client containers aren't required to provide direct access to transaction facilities, EJB clients should use enterprise beans to start transactions. They can also use transaction facilities of JDBC. However, doing so may be risky since the J2EE platform doesn't define a mechanism for propagating the transaction context to the EJB server.

3.4.1.4 Security

The client application must be authenticated to access the J2EE middle tier. Techniques for authentication are provided by the client container, and are not under the control of the application client. The container can integrate with the platform's authentication system, authenticate when the application is started, or use some other lazy authentication policy. The container takes responsibility for gathering authentication data from the user, by presenting a login window to the user.

EJB clients in the Java programming language execute in an environment with a security manager installed. They have similar security permission requirements as servlets.


3.4.2 Strengths and Weaknesses

EJB clients have a number of strengths, including:

The disadvantages of EJB clients are that they:


3.4.3 Types of EJB Clients

EJB clients can be implemented using either the Java programming language, or languages such as Visual Basic or C++. When a language other than Java is used, depending on the implementation on the client container, some of the facilities of the J2EE platform may not be available.

3.4.3.1 Java Technology Clients

Java clients execute in their own Java virtual machine. Following the model for Java applications, they are invoked at their main method and run until the virtual machine is terminated. Security and deployment services are provided through the use of a client container.

The Java programming language should be used for implementation of EJB clients. Since the EJB server communicates using RMI-IIOP, the client needs to support RMI-IIOP. This is most naturally done using services provided by the standard Java platform.

Some facilities cannot be easily implemented in other languages as a result, client containers for these languages may not provide the full set of features.


Multitier Clients

Java technology clients are usually stand-alone Java applications. However, when appropriately signed and trusted, Java applets can also be used as EJB clients. Applets and applications have essentially the same set of platform service available to them. Additionally, a Java applet can communicate with the Web tier as well as the application tier to get its job done. In this sense it is a multitier client.

3.4.3.2 Non-Java Clients

EJB clients can be implemented in programming languages other than Java. Since the EJB server uses RMI-IIOP, this requires some form of RMI-IIOP support available to the client.


Accessing Enterprise Beans as COM Objects

Scripting COM objects together into an application is a common client implementation approach. It is possible for a client container to make enterprise beans appear as COM objects on the client machine.

When enterprise beans are exposed as COM objects, any scripting languages supported by the Active Scripting Engine can be used to automate the components to develop the application client. While Visual Basic is most often used for this purpose, languages such as JavaScript or Perl can also be used.

The specific approach to developing such clients will be largely dependent on the J2EE product used and the platform. Client containers will be provided by the J2EE server.

Here's an example of how such clients might work:


Limitations

Translating between one distributed computing architecture and another is not straightforward. There are some limitations when using Visual Basic clients that access the EJB tier:


When to Use COM Clients

The decision to use Visual Basic clients is largely non-technical. It depends on the expertise available, as well as the desire to integrate with existing EJB clients. When legacy issues are not a concern, EJB clients should be developed using Java technology.


Active Server Pages

There is one interesting case where a COM-based scripting client might interact with an EJB server. This is the scripting present in Microsoft IIS Active Server Pages (ASP). ASPs are server-side scripting components that use Visual Basic script to produce dynamic content. An ASP developer that wishes to use the J2EE platform for its middle tier needs, can do so using the techniques outlined above.


1
These services are only available if the application client is implemented using Java.

2
The IIOP protocol does not completely specify details of the security and transaction contexts, thus different implementations of the protocol may not be compatible.



CONTENTS | PREV | NEXT | INDEX
Copyright © 2001 Sun Microsystems, Inc. All Rights Reserved.