Professional Documents
Culture Documents
J2ee Multitier Architecture431 PDF
J2ee Multitier Architecture431 PDF
Chapter 2
J2EE Multi-Tier
Architecture
23
P:\010Comp\CompRef8\472-x\ch02.vp
Thursday, August 15, 2002 2:32:14 PM
24
he expectation for instant gratification was ratcheted up a notch with the growth of
the Internet and the maturity of corporate infrastructure. Executives and customers
alike demand instant access to information any time, any place24 hours a day, 7
days a week. Whether its accessing the corporation online catalog, placing an online
order, retrieving account information, or sending and receiving email, they want an
immediate response.
Information technology departments of corporations had to devise a scheme to
revamp their networks and systems to accommodate thousands of people who
wanted to simultaneously access corporate resources. To meet these expectations,
technologists rethought the way in which information is stored, accessed by, and
delivered to clients.
Focus was directed at the technology architecture model used to provide services
to desktop and remote computers. Many IT departments used a two-tier, client/server
architecture model where desktop software called clients request information over
the corporate network infrastructure to servers running software that fulfilled a clients
request.
However, this two-tier architecture depends heavily on keeping client software
updated, which is both difficult to maintain and costly to deploy in a large corporation
that has several intranets and a workforce that consists of field representatives and
other remote users. Web-based, multi-tier systems dont require client software to be
upgraded whenever presentation and functionality of an application are changed.
The infrastructure had to be revamped. The two-tier, client/server architecture
had to be abandoned and a new, multi-tier architecture had to be built in its place. The
Java development team at Sun Microsystems, Inc. with the collaboration of the Java
Community Program (JCP) developed the Java programming language to be used to
build software for this new multi-tier architecture.
In this chapter youll learn about multi-tier architecture and the role each Java 2
Enterprise Edition component plays in the redevelopment of corporate Americas
infrastructureand how Java 2 Enterprise Edition is becoming a key component in
web services technology.
Distributive Systems
The concept of multi-tier architecture has evolved over decades, following a similar
evolutionary course as programming languages. The key objective of multi-tier
architecture is to share resources amongst clients, which is the fundamental design
philosophy used to develop programs.
As you learned in the previous chapter, programmers originally used assembly
language to create programs. These programs employed the concept of software
services that were shared with the program running on the machine.
Software services consist of subroutines written in assembly language that
communicate with each other using machine registers, which are memory spaces
P:\010Comp\CompRef8\472-x\ch02.vp
Thursday, August 15, 2002 2:32:14 PM
Chapter 2:
J 2 E E M u l t i - Ti e r A r c h i t e c t u r e
Real-Time Transmission
Real-time transmission came about with the introduction of the UNIX operating system.
The UNIX operating system contains support for Transmission Control Protocol/Internet
Protocol (TCP/IP), which is a standard that specifies how to create, translate, and control
transmissions between machines over a computer network.
It was also around the same time when technologists developed the Remote
Procedure Call (RPC). RPC defined a way to share functions written in any procedural
language such as FORTRAN, COBOL, and the C programming language. This meant
that software services were no longer limited to a machine. Furthermore, a programmer
could now call a function that was created by a different program using a different
procedural language that resided on an entirely different machine as long as that
machine was connected to the same network.
Another important development in the evolution of distributive systems came with
the development of eXternal Data Representation (XDR). While RPC enabled programmers
to call preprogrammed functions that were available on the network using TCP/IP, there
remained a need to exchange complex data structures between programs and functions
and between functions.
P:\010Comp\CompRef8\472-x\ch02.vp
Thursday, August 15, 2002 2:32:15 PM
J2EE BASICS
25
26
The solution came with the introduction of XDR. XDR specified how complex data
structures could be exchanged among programs and software services. This became the
linchpin that changed the way programmers and system designers conceived
applications. Instead of limiting an application to one machine, an application became
a collaborative development effort that utilized software services that were available
throughout the network.
Software Objects
The next evolutionary step in programming language gave birth to object-oriented
languages such as C++ and Java. Procedural languages focused on functionality, where
a program was organized into functions that contained statements and data that were
necessary to execute a task. Functions were either internal software services within a
program or external software services called by RPC.
Programs written in an object-oriented language were organized into software
objectsnot by functionality. A software object resembles a real-world object in that
a software object encapsulates data and functionality in the same way data and
functionality are associated with a real-world object. A software object is a software
service that can be used by a program.
Although objects and programs could use RPC for communication, RPC was
designed around software services being functionally centric and not software-objectcentric. This meant it was unnatural for programs to call software objects using RPC.
A new protocol was needed that could naturally call software objects.
Simultaneously two protocols were developed to access software objects. These
were Common Object Request Broker Architecture (CORBA) and Distributed Common
Object Model (DCOM). CORBA was developed by a consortium that included Sun
Microsystems, Inc., IBM, and Oracle among others. Microsoft developed DCOM.
As you probably suspect, CORBA and DCOM were incompatible. This resulted in
confusion in the marketplace, which some technologists believe caused the lack of
widespread adoption of either protocol. Companies that embraced distributive object
technology had to adopt either CORBA or DCOM. Otherwise, companies had to use a
protocol converter as a gateway between environments that used CORBA and DCOM.
Web Services
The Internet indirectly shed new light on the conflict between these competing protocols.
The Internet is based on a set of open protocol standards that centered on the Hypertext
Transport Protocol (HTTP) that is used to share information between machines. HTTP
isnt a replacement for TCP/IP. Instead, HTTP is a high-level protocol that uses TCP/IP
for low-level transmission.
The Internet solidified the direction of distributive systems by proving to
corporations that they can greatly improve efficiency through better utilization of
computer networks. But there was another hurdle to overcome. Internet technology
lacked the capability to share software services that businesses needed to fully
integrate large-scale business applications.
P:\010Comp\CompRef8\472-x\ch02.vp
Thursday, August 15, 2002 2:32:15 PM
Chapter 2:
J 2 E E M u l t i - Ti e r A r c h i t e c t u r e
The Tier
A tier is an abstract concept that defines a group of technologies that provide one or
more services to its clients. A good way to understand a tier structures organization
is to draw a parallel to a typical large corporation (see Figure 2-1).
At the lowest level of a corporation are facilities services that consist of resources
necessary to maintain the office building. Facilities services encompass a wide variety
of resources that typically include electricity, ventilation, elevator services, computer
network services, and telephone services.
The next tier in the organization contains support resources such as accounting,
supplies, computer programming, and other resources that support the main activity
of the company. Above the support tier is the production tier. The production tier has
the resources necessary to produce products and services sold by the company. The
highest tier is the marketing tier, which consists of resources used to determine the
products and services to sell to customers.
Any resource is considered a client when a resource sends a request for service to
a service provider (also referred to as a service). A service is any resource that receives
and fulfills a request from a client, and that resource itself might have to make requests
to other resources to fulfill a clients request.
Lets say that a product manager working at the marketing tier decides the company
could make a profit by selling customers a widget. The product manager requests an
accountant to conduct a formal cost analysis of manufacturing a widget. The accountant
is on the support tier of the organization. The product manager is the client and the
accountant is the service.
P:\010Comp\CompRef8\472-x\ch02.vp
Thursday, August 15, 2002 2:32:15 PM
J2EE BASICS
The next evolution of software services was born and was called web services.
There is a common misnomer regarding web services. Some believe the web
component of web services comes from the relationship web services has with the
Internet. This isnt true. Web services is a web of services where services are software
building blocks that are available on a network from which programmers can
efficiently create large-scale distributive systems.
Three new standards were developed with the introduction of web services. These
are Web Services Description Language (WSDL), Universal Description, Discovery, and
Integration (UDDI), and Service Oriented Architecture Protocol (SOAP).
Programmers use WSDL to publish their web service, thereby making the web
service available to other programmers over the network. A programmer uses UDDI
to locate web services that have been published and uses SOAP to invoke a particular
web service. Youll learn more about WSDL, UDDI, and SOAP in Part V of this book.
Many large-scale distributive systems and web services have something in
common. They are written using J2EE because J2EE addresses the complex issues
that a programmer faces when developing a large-scale distributive system. There
are numerous web services used in a typical large-scale distributive system and each
service is associated with a tier in the multi-tier architecture that is used to share
resources over a corporate infrastructure.
27
28
Figure 2-1.
P:\010Comp\CompRef8\472-x\ch02.vp
Thursday, August 15, 2002 2:32:15 PM
Chapter 2:
J 2 E E M u l t i - Ti e r A r c h i t e c t u r e
Figure 2-2.
P:\010Comp\CompRef8\472-x\ch02.vp
Thursday, August 15, 2002 2:32:15 PM
J2EE BASICS
modify the business logic in the service to reflect the latest changes in the tax code
without having to modify the client program. These changes are hidden from the
client program.
29
30
Accessing Services
A client uses a client protocol to access a service that is associated with a particular
tier. A protocol is a standard method of communication that both a client and the tier/
component/resource understand. There are a number of protocols that are used
within a multi-tier infrastructure because each tier/component/resource could use
different protocols.
One of the most commonly implemented multi-tier architectures is used in webcentric applications where browsers are used to interact with corporate online
resources. A browser is a client and requests a service from a web server using HTTP.
In a typical enterprise-wide application, a browser requests services from other
components within infrastructures such as a servlet. A servlet uses a resource protocol
to access resources that are necessary for the servlet to fulfill the request. For example,
a servlet will use the JDBC protocol to retrieve data from DBMS. Youll be introduced
to specific protocols throughout this book as you learn to build components and use
resources.
P:\010Comp\CompRef8\472-x\ch02.vp
Friday, August 16, 2002 5:45:41 PM
Chapter 2:
J 2 E E M u l t i - Ti e r A r c h i t e c t u r e
31
J2EE BASICS
Figure 2-3.
Figure 2-4.
P:\010Comp\CompRef8\472-x\ch02.vp
Thursday, August 15, 2002 2:32:16 PM
32
Tier interacts with DBMS to fulfill the request. Requests are made to the Enterprise
JavaBeans by using the Java Remote Method Invocation (RMI) API. The requested data
is then returned by the Enterprise JavaBeans where the data is then forwarded to the
Web Tier and then relayed to the Client Tier where the data is presented to the user.
The Enterprise JavaBeans Tier contains the business logic for J2EE applications.
Its here where one or more Enterprise JavaBeans reside, each encoded with business
rules that are called upon indirectly by clients. The Enterprise JavaBeans Tier is the
keystone to every J2EE application because Enterprise JavaBeans working on this tier
enable multiple instances of an application to concurrently access business logic and
data so as not to impede the performance.
Enterprise JavaBeans are contained on the Enterprise JavaBeans server, which is a
distributed object server that works on the Enterprise JavaBeans Tier and manages
transactions and security, and assures that multithreading and persistence are properly
implemented whenever an Enterprise JavaBean is accessed.
Although an Enterprise JavaBean can access components on any tier, typically
an Enterprise JavaBean accesses components and resources such as DBMS on the
Enterprise Information System (EIS) Tier.
Access is made using an Access Control List (ACL) that controls communication
between tiers. The ACL is a critical design element in the J2EE multi-tier architecture
because ACL bridges tiers that are typically located on different virtual local area
networks and because ACL adds a security level to web applications. Hackers typically
focus their attack on the Web Tier to try to directly access DBMS. ACL prevents direct
access to DBMS and similar resources.
The EIS links a J2EE application to resources and legacy systems that are available
on the corporate backbone network. Its on the EIS where a J2EE application directly
or indirectly interfaces with a variety of technologies, including DBMS and mainframes
that are part of the mission-critical systems that keep the corporation operational.
Components that work on the EIS communicate to resources using CORBA or Java
connectors, referred to as J2EE Connector Extensions.
P:\010Comp\CompRef8\472-x\ch02.vp
Thursday, August 15, 2002 2:32:16 PM
Chapter 2:
J 2 E E M u l t i - Ti e r A r c h i t e c t u r e
Classification of Clients
Besides defining clients as an applet client, application client, or a rich client, clients
are also classified by the technology used to access components and resources that
are associated with each tier. There are five classifications: a web client, Enterprise
JavaBeans client, Enterprise Information System (EIS) client, web service peers, and
a multi-tier client.
A web client consists of software, usually a browser, that accesses resources located
on the Web Tier. These resources typically consist of web pages written in HTML or
XML. However, a web client can also access other kinds of information that is located
on the Web Tier. Web clients communicate with Web Tier resources using either HTTP
or the Hypertext Transmission Protocol Secured (HTTPS), which is used to transfer
encrypted information.
Enterprise JavaBeans clients are similar to web clients in that an Enterprise
JavaBeans client works on the Client Tier and interfaces the J2EE application with the
user. However, an Enterprise JavaBeans client only accesses one or more Enterprise
JavaBeans that are located on the Enterprise JavaBeans Tier rather than resources on the
Web Tier.
This access is made possible by using the RMI API. RMI handles communication
between the Enterprise JavaBeans client and the Enterprise JavaBeans Tier using either
the Java Remote Method Protocol (JRMP) or the Internet Inter-ORB Protocol (IIOP).
EIS clients are the interface between users and resources located on the EIS Tier.
These clients use Java connectors, appropriate APIs, or proprietary protocols to utilize
resources such as DBMS and legacy data sources.
A web service peer is a unique type of client because its also a service that works
on the Web Tier. Technically, a web service peer forms a peer-to-peer relationship with
other components on the Web Tier rather than a true client/server relationship.
However, a web service peer is commonly referred to as a client because it requests
service from other components on the Web Tier, although a web service peer can also
access other tiers. Typically, a web service peer makes requests over HTTP using either
electronic business XML or the Simple Object Access Protocol (SOAP).
Multi-tier clients are conceptually similar to a web service peer except a multi-tier
client accesses components located on tiers other than the tier where the multitier client resides. Multi-tier clients typically use the Java Message Service (JMS) to
communicate asynchronously with other tiers.
P:\010Comp\CompRef8\472-x\ch02.vp
Thursday, August 15, 2002 2:32:16 PM
J2EE BASICS
A rich client is a third type of client, but a rich client is not considered a component
of the Client Tier because a rich client can be written in a language other than Java
and therefore J2EE doesnt define a rich client container.
A rich client is similar to an application client in that both are applications that
contain their own user interface. And as with an application client, a rich client can
access any tier in the environment, depending on the ACLs configuration, using HTTP,
SOAP, ebXML, or an appropriate protocol.
33
34
P:\010Comp\CompRef8\472-x\ch02.vp
Friday, August 16, 2002 5:47:06 PM
Chapter 2:
J 2 E E M u l t i - Ti e r A r c h i t e c t u r e
35
Resource pooling
Distributed object protocols
Thread management
State management
Process management
Object persistence
Security
Deploy-time configuration
P:\010Comp\CompRef8\472-x\ch02.vp
Thursday, August 15, 2002 2:32:17 PM
J2EE BASICS
J2EE uses distributive object technology to enable Java developers to build portable,
scalable, and efficient applications that meet the 24-7 durability expected from an
enterprise system. The Enterprise JavaBeans Tier contains the Enterprise JavaBeans
server, which is the object server that stores and manages Enterprise JavaBeans.
The Enterprise JavaBeans Tier is a vital element in the J2EE multi-tier architecture
because this tier provides concurrency, scalability, lifecycle management, and fault
tolerance. The Enterprise JavaBeans Tier automatically handles concurrency issues that
assure multiple clients have simultaneous access to the same object. The Enterprise
JavaBeans Tier is the tier where some vendors include features that enable scalability
of an application, because the tier is designed to work in a clustered environment.
This assumes that vendor components that are used support clustering. If not, a Local
Director is typically used for horizontal load balancing.
The Enterprise JavaBeans Tier manages instances of components. This means
component containers working on the Enterprise JavaBeans Tier create and destroy
instances of components and also move components in and out of memory.
Fault-tolerance is an important consideration in mission-critical applications. The
Enterprise JavaBeans Tier is the tier where some vendors include features that provide
fault-tolerant operation by making it possible to have multiple Enterprise JavaBeans
servers available through the tier. This means backup Enterprise JavaBeans servers can
be contacted immediately upon the failure of the primary Enterprise JavaBeans server.
The Enterprise JavaBeans server has an Enterprise JavaBeans container within
which is a collection of Enterprise JavaBeans. As discussed in previous sections of this
chapter, an Enterprise Java Bean is a class that contains business logic and is callable
from a servlet or JSP.
Collectively the Enterprise JavaBeans server and Enterprise JavaBeans container are
responsible for low-level system services that are required to implement business logic
of an Enterprise Java Bean. These system services are
36
A key benefit of using the Enterprise JavaBeans server and Enterprise JavaBeans
container technology is that this technology makes proper use of a programmers
expertise. That is, a programmer who specializes in coding business logic isnt concerned
about coding system services. Likewise, a programmer whose specialty is system
services can focus on developing system services and not be concerned with coding
business logic.
Any component, regardless of the tier where the component is located, can use
Enterprise JavaBeans. This means that an Enterprise Java Bean client can reside outside
the Client Tier. The protocol used to communicate between the Enterprise JavaBeans
Tier and other tiers is dependent on the protocol used by the other tier.
Components on the Client Tier and the Web Tier communicate with the Enterprise
JavaBeans Tier using the Java RMI API and either IIOP or JRMP. Sometimes software
on other tiers, usually the middle tier, uses JMS to communicate with the Enterprise
JavaBeans Tier. This communication isnt exclusively used to send and receive messages
between machines. JMS is also used for other communication, such as decoupling tiers
using the queue mechanism.
However, the Enterprise Java Bean that is used must be a message-driven bean (MDB).
MDBs are commonly used to process messages on a queue that may or may not reside
on the local machine. Youll learn more about MDB when Enterprise JavaBeans is
discussed in detail in Chapter 12.
P:\010Comp\CompRef8\472-x\ch02.vp
Thursday, August 15, 2002 2:32:17 PM
Chapter 2:
J 2 E E M u l t i - Ti e r A r c h i t e c t u r e
37
Challenges
P:\010Comp\CompRef8\472-x\ch02.vp
Thursday, August 15, 2002 2:32:17 PM
J2EE BASICS
P:\010Comp\CompRef8\472-x\ch02.vp
Thursday, August 15, 2002 2:32:17 PM