Anda di halaman 1dari 81

Application Servers

Gökçe Banu Laleci

1
aim
 for building integrated, enterprise-class
applications that share information, deliver
services, and automate collaboration among
networked companies at Internet volume and
speed
 separate of presentation, business logic, and data
 provide the underlying core functionality
necessary for the development and deployment of
business-driven application
 connect legacy systems, and Web Services
11.12.2003 CENG 520 2
Gokce Banu Laleci
Why?
 applications with complex business logic
 potentially servicing tens of thousands of
concurrent users in real-time
 require a scalability and reliability

 Distributed system
 Stock trading system
 Banking application

11.12.2003 CENG 520 3


Gokce Banu Laleci
What you need?
 RMI  Logging and auditing
 Load balancing  System management
 Transparent fail over  Threading
 Back-end integration  Message-oriented
 Transaction middleware
 Clustering  Object life cycle
 Dynamic  Resource polling
redeployement  Security
 Clean shutdown  Caching
11.12.2003 CENG 520 4
Gokce Banu Laleci
Adds..
 a new layer of
functions and
services
between Web
servers and
underlying
applications and
databases

11.12.2003 CENG 520 5


Gokce Banu Laleci
What do they provide
 speeds application development and relieves developers of the
effort and expense of creating these crucial services on their own
 Load balancing
 Fault tolerance
 Web Services
 Legacy integration
 Transaction management
 Security
 Messaging
 Multi-threading
 Persistence
 Database connectivity
 Resource pooling
 Development, testing, and packaging facilities

11.12.2003 CENG 520 6


Gokce Banu Laleci
Single server / clustered
servers

11.12.2003 CENG 520 7


Gokce Banu Laleci
J2EE based..
TM
J2EE Patterns

11.12.2003 CENG 520 8


Gokce Banu Laleci
J2EE based…
 BEA WebLogic Java Application Server
 IBM WebSphere Java Application Server

 Oracle 9i Java Application Server

 Sun ONE Java Application Server (iPlanet)

 HP Application Server (HP-AS) (Bluestone)

 JBoss Application Server

 Enhydra Application Server

11.12.2003 CENG 520 9


Gokce Banu Laleci
J2EE Components used..
 Java Servlets & Java Server Pages (JSP)
 Enterprise Java Beans (EJB)
 Java Transaction API (JTA)
 Java Transaction Service (JTS)
 Java API for XML Parsing (JAXP)
 Java Messaging Service (JMS)
 Message Driven Beans (MDB)
 Remote Method Invocation (RMI)
 Java Database Connection 2 (JDBC2)
 Java Connector Architecture (JCA)
 Java Naming and Directory Interface (JNDI)
 JavaBeans Activation Framework (JAF)
11.12.2003 CENG 520 10
Gokce Banu Laleci
Three layered architecture
 The presentation layer
 managing the user interfaces of applications,
including desktop applications, Web browsers,
and pervasive devices
 The business layer
 contains the business logic
 The back-end layer
 provides connectivity with enterprise systems
and databases
11.12.2003 CENG 520 11
Gokce Banu Laleci
Three layered architecture

Hosting Organization

Subscriber 1

Presentation

Logic

Subscriber 2

Persistence

Subscriber 3

11.12.2003 CENG 520 12


Gokce Banu Laleci
Presentation Layer
 Thin clients
 such as Web browsers that send HTTP requests
and receive HTTP responses for static HTML or
dynamic Web pages built by Java Servlets and
Java Server Pages (JSPs)
 Thick clients
 such as Java applets and applications, ActiveX
controls, or Visual Basic clients that run on a
desktop and communicate with BEA WebLogic
Server through CORBA, Java RMI,IIOP, or COM+

11.12.2003 CENG 520 13


Gokce Banu Laleci
Presentation Layer
 Pervasive devices
 including wireless phones, PDAs, smart
appliances, and other emerging remote clients
that communicate with the server via specific and
usually very compact
 can generate WML pages from Servlets and JSPs.
 Web Services
 that connect to the system using Web Services
technologies, such as SOAP,UDDI, and WSDL

11.12.2003 CENG 520 14


Gokce Banu Laleci
Presentation Layer
 Provides a Web Server
 Servlet and JSP results caching and JSP tags
caching
 provides high-reliability, scalability, monitoring,
and other features required by enterprise
applications
 plug-ins for Apache, iPlanet, and Microsoft IIS
Web servers

11.12.2003 CENG 520 15


Gokce Banu Laleci
Additional Features
 Virtual hosting
 www.company1.com and www.company2.com
 Clustering
 scalability and high-availability
 insulates clients from hardware or power failures
by eliminating single points of failure
 Load balancing
 Incoming requests can be distributed across
multiple instances of AS
11.12.2003 CENG 520 16
Gokce Banu Laleci
Additional Features
 High availability with transparent fail-over
 The data contained in Web components can be
replicated across multiple machines
 In the event of a failure, current client session
information is maintained
 disk-based persistence
 in- memory replication of a client ’s session state

11.12.2003 CENG 520 17


Gokce Banu Laleci
Business Layer
 contains the application’s business logic
independent of the user interface, including
distributed components, running in the
application server environment
 Enterprise Java Beans

11.12.2003 CENG 520 18


Gokce Banu Laleci
Enterprise Java Beans
 Reusable server components
 A manageable, discrete chunk of code
implementing a set of well defined interfaces
 it has to be compliant to a well defined
interfaces
 To be reusable
 To be able to use the AS functionalities

11.12.2003 CENG 520 19


Gokce Banu Laleci
Java Beans vs. EJB
 Generic java  Standard for building
component model distributed systems
 Can be either visible or  Non-visible remote
not objects
 Local to a single  Remotely executable
process on the client comp. deployed in the
side server
 Uses BeanInfo classes  Uses Deployment
to define themselves descriptor to describe
itself
11.12.2003 CENG 520 20
Gokce Banu Laleci
Why EJB
 Architecturalindependence from middleware
 WORA for sever side components

 Establishes roles for application development

 Take care of transaction management

 Provides distributed transaction support

 Portable

 Integrates seamlessly with CORBA

11.12.2003 CENG 520 21


Gokce Banu Laleci
The EJB architecture

11.12.2003 CENG 520 22


Gokce Banu Laleci
What do containers provide
 Remote invocation
 Pool and cache services

 Security

 Transaction

 Integration with external data sources

11.12.2003 CENG 520 23


Gokce Banu Laleci
Containers
 Interface btw EJBeans
& outside world
 EJB Clients never
access an EJB directly-
any access is done
through container-
generated methods in
turn invoke bean
methods

11.12.2003 CENG 520 24


Gokce Banu Laleci
Home interface
 Contains factory methods for locating,
creating and instances of EJBs
 The EJB developer defines the Home
Interface for his bean
 Object generated by the Container vendor

11.12.2003 CENG 520 25


Gokce Banu Laleci
An example

11.12.2003 CENG 520 26


Gokce Banu Laleci
Remote Interface & EJBObject
 Lists the business methods present in EJB
 Interface defined by the developer

 Object created by the container vendor

 Clients use this object to invoke business


methods

11.12.2003 CENG 520 27


Gokce Banu Laleci
An example

11.12.2003 CENG 520 28


Gokce Banu Laleci
EJB Client
 Finds EJB containers using JNDI
 Uses EJB container to invoke EJB methods

 Uses Home Object to locate, create or


destroy and EJB class
 Uses the EJBObject instance to invoke
methods

11.12.2003 CENG 520 29


Gokce Banu Laleci
JNDI
 Client API provides
naming & directory
services for Java Apps
 Does not replace DNS,
CORBA, RMI etc
 Allows multiple
directory services co-
exist
 Provides a federated
name server
11.12.2003 CENG 520 30
Gokce Banu Laleci
An example
// get the JNDI naming context
Context initialCtx = new InitialContext ();
// use the context to lookup the EJB Home interface
AccountHome home
=(AccountHome)initialCtx.lookup
("com/~gopalan/Account");
// use the Home Interface to create a Session bean
object
Account account = home.create (1234, "Athul",
1000671.54d);

11.12.2003 CENG 520 31


Gokce Banu Laleci
EJB Types
 EntityBeans
 Session Beans

 Message-Driven Beans

11.12.2003 CENG 520 32


Gokce Banu Laleci
Entity Beans
 Used to represent business data in an application
 Correspond with information stored in databases or other
persistent storage
 Have primary key
 Participate in transactions
 Long-lived
 Can survive EJB server clashes
 Multiple clients can access and work with the same entity bean
 When not used
 Preserved in persistent location and returned to the pool
 When used
 Can be cached

11.12.2003 CENG 520 33


Gokce Banu Laleci
Entity Bean Interface
 ejbActivate ()
 ejbLoad ()
 ejbPassivate ()

 ejbRemove ()

 ejbStore ()

11.12.2003 CENG 520 34


Gokce Banu Laleci
Persistence
Container Managed Bean Managed
 Container is responsible for  Bean is itself responsible for
saving state of bean saving its own state
 Container needs to  Bean needs to code its own
generate DB calls DB calls
 Bean persistence is  Bean persistence is hard-
independent of data source coded and is hence less
 specify container-managed adaptable
fields in Deployment
Descriptor

11.12.2003 CENG 520 35


Gokce Banu Laleci
Session Beans
 Execute on behalf of a single client
 They may or may-not be transaction-aware
 They may or may-not update data in the underlying
database
 Their lifetime is limited to that of the client and hence
they are relatively short-lived
 They do not survive server crashes
 They do not represent data in the database
 Since they only represent conversational state with
a single client, their identity is hidden

11.12.2003 CENG 520 36


Gokce Banu Laleci
Stateless/Stateful
Stateless Session Bean Stateful Session Bean
 Have no internal state  Have internal state

 need to handle
 need not be passivated Activation/Passivation
or activated  One Session Bean
object per client
 Objects can be pooled
to service multiple
clients

11.12.2003 CENG 520 37


Gokce Banu Laleci
Message-Driven Beans
 Do not have home or remote interface
 Used to integrate with JMS

 Called JMS message consumers


 Listen from a message from JMS server
 Performs a set of actions defined when message
is received

11.12.2003 CENG 520 38


Gokce Banu Laleci
Deployment Descriptors
 While deploying your EJB to container
 Provide a deployment descriptor file (xml)
 JNDI name
 Transactional rules
 Security roles and permissions of a component

11.12.2003 CENG 520 39


Gokce Banu Laleci
Additional Features
 Instance pooling
 pre-load a given number of instances and prepare
them for use, thereby saving time by not having to
create a new instance for each request
 Clustering
 EJBs can be deployed in a cluster of BEA
WebLogic Servers
 by means of distributed naming and directory
facilities

11.12.2003 CENG 520 40


Gokce Banu Laleci
Additional Features
 High availability with transparent fail-over
 replicate state that EJB hold across a cluster of
separate physical AS processes
 creating redundancy in case of
 transparently fail-over to a backup machine in the
cluster in the event of a failure
 Load balancing
 route requests from remote clients to EJB
components using a predetermined algorithm or
custom-algorithm
11.12.2003 CENG 520 41
Gokce Banu Laleci
Additional Features
 EJB Caching
 store a configurable number of EJBs in memory
to save on database access
 In case another instance of the server in the
cluster updates the same bean, all the cached
instances of the bean cached in the cluster will be
invalidated, and reloaded with the next access
 increases performance and reduces the load on
the database

11.12.2003 CENG 520 42


Gokce Banu Laleci
Back-End Layer
 provides access to other enterprise systems
 databases, ERP, CRM, mainframe or other
existing applications
 Integration layer
 messaging, e-mail, Web Services, and other
technologies to connect and communicate with
enterprise systems

11.12.2003 CENG 520 43


Gokce Banu Laleci
Databases
 JDBC
 Thin clients – servlet, JSP
 Thick clients – RMI to remote databases
 most recommended way is to use entity beans
and benefit from the underlying services
 Connection pooling

11.12.2003 CENG 520 44


Gokce Banu Laleci
Integration
 integrating new applications with any legacy
Enterprise Information System (EIS)
 J2EE Connector Architecture (J2CA)
 CORBA
 integration with legacy systems that implement the CORBA
specifications
 COM/DCOM (COM+)
 bi-directional interoperability with Microsoft ’s COM+
 can access data in Microsoft applications, communicate
with Visual Basic clients

11.12.2003 CENG 520 45


Gokce Banu Laleci
JCA
a standard architecture for connecting the
J2EE platform to heterogeneous EIS systems
 ERP, mainframe transaction processing,
database systems, and legacy applications not
written in the Java programming language
 enables the integration of EISs with application
servers and enterprise applications
 By defining a a set of scalable, secure, and
transactional mechanisms

11.12.2003 CENG 520 46


Gokce Banu Laleci
JCA
 enables an EIS vendor to provide a standard
resource adapter for its EIS
 The resource adapter plugs into an application
server, providing connectivity between the EIS, the
application server, and the enterprise application
 An EIS vendor needs to provide just one standard
resource adapter which has the capability to plug in
to any application server that supports the J2EE
Connector architecture

11.12.2003 CENG 520 47


Gokce Banu Laleci
JCA
 Multiple resource adapters are pluggable into
an application server
 enables application components deployed on
the application server to access the
underlying EIS systems

11.12.2003 CENG 520 48


Gokce Banu Laleci
JCA

11.12.2003 CENG 520 49


Gokce Banu Laleci
Resource Adapter
 To achieve a standard system-level
pluggability between application servers and
EISs, the J2EE Connector architecture
defines a standard set of system-level
contracts between an application server and
EIS
 The resource adapter implements the EIS-
side of these system-level contracts

11.12.2003 CENG 520 50


Gokce Banu Laleci
Resource Adapter
 system-level software driver used by an
application server or an application client to
connect to an EIS
 By plugging into an application server, the
resource adapter collaborates with the server
to provide the underlying mechanisms, the
transactions, security, and connection pooling
mechanisms
 A resource adapter is used within the
address space of the application server
11.12.2003 CENG 520 51
Gokce Banu Laleci
Application Contract
 An application server and an EIS collaborate to
keep all system-level mechanisms, such as
transactions, security, and connection management,
transparent from the application components
 A Connection Management contract
 A Transaction Management contract
 Security contract
 A Message Inflow contract
 A Lifecycle Management contract
 A Work Management contract

11.12.2003 CENG 520 52


Gokce Banu Laleci
Web Service Support
 Automatically wraps the business components in to Web
services
 Support for WSDL and UDDI
 Publish, search, host
 Support for Web Services Security standard
 Reliable SOAP implementation
 based on a sequence of asynchronous SOAP communications,
receipts, and notifications
 guaranteed delivery, “exactly-once ” delivery, ordered
conversation
 A set of convenient graphical tools for development, search, and
composing of the Web Services
 BEA WebLogic Workshop

11.12.2003 CENG 520 53


Gokce Banu Laleci
Messaging
 Asynchronous method invocations
 Why?
 Performance
 Reliability
 Support for multiple senders and receivers

Message
Application Application
Oriented
Middleware

11.12.2003 CENG 520 54


Gokce Banu Laleci
MOM
 Provides
 Guaranteed message delivery
 Fault tolerance
 Load balancing of destinations
 Subscription mech.
 Proprietary solutions
 Tibco Rendezvous
 IBM MQSeries
 BEA Tuxedo/Q
 Microsoft MSMQ

11.12.2003 CENG 520 55


Gokce Banu Laleci
Java Message Service
 API
 Write code to send and receive msg
 Service Provider Interface (SPI)
 Plug in JMS drivers
 to allow existing companies to JMS-enable their
applications without impacting client-side development
 Supports
 Publish/subscribe
 Point-to-point
11.12.2003 CENG 520 56
Gokce Banu Laleci
JMS System
 ConnectionFactory

 Connection

 Session

 Destination

 MessageProducer

 MessageConsumer

 Message

11.12.2003 CENG 520 57


Gokce Banu Laleci
2:Create JMS Connection
Connection Factory

3:Create
Session
JMS Connection
Serialized
Message
5:Create JMS Session
Client Producer or
Connection

Consumer
JMS Producer
1:RetrieveJ 6:Send or
MS Driver Receive Or
Connection Message
JMS Consumer
Factory
4:Lookuo JMS
Destination JMS Driver Client Runtime

JNDI

Naming
Service

11.12.2003 CENG 520 58


Gokce Banu Laleci
Example
try {
queueConnectionFactory =(QueueConnectionFactory)
jndiContext.lookup("QueueConnectionFactory");
queue =(Queue)jndiContext.lookup(queueName);
}…
try {
queueConnection =
queueConnectionFactory.createQueueConnection();
queueSession = queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
queueSender =queueSession.createSender(queue);
message =queueSession.createTextMessage();
for (int i =0;i <NUM_MSGS;i++){
message.setText("This is message "+(i +1));
System.out.println("Sending message:"+ message.getText());
queueSender.send(message);
}
11.12.2003 CENG 520 59
Gokce Banu Laleci
EJB JMS Integration
 Message Driven Beans
 Do not have home/remote interface
 Just to consume messages
 Not a component interface
 onMessage method
 Why not use existing beans
 Threading
 Life cycle management

11.12.2003 CENG 520 60


Gokce Banu Laleci
Security
 Java Authentication and Authorization Server (JAAS)
 Encryption
 Auditing
 HTTPS,
 basic HTTP authentication with Base64 encoding for services
protected by firewalls
 Role based security
 User and group definition
 Built-in security data store retains the role,profile,and entitlement
data,and is built on a highly optimized LDAP directory
 Single Sign-On
 WS-Security

11.12.2003 CENG 520 61


Gokce Banu Laleci
Adding security to EJB
 JAAS
 Portable interface
 Java applications to remain independent from
underlying authentication technologies
 Authentication
 Basic
 Digest
 Certificate

11.12.2003 CENG 520 62


Gokce Banu Laleci
Authorization
 Programmatic
 Hard code security checks in to your bean code
 Declarative
 Through deployment descriptor
 Container handles the rest

11.12.2003 CENG 520 63


Gokce Banu Laleci
Role based
 Each user must be uniquely identified
 User should be assigned one or more
security roles
 Each security role is assigned a set of
method permissions

11.12.2003 CENG 520 64


Gokce Banu Laleci
Example role definition

11.12.2003 CENG 520 65


Gokce Banu Laleci
Example method permission

11.12.2003 CENG 520 66


Gokce Banu Laleci
Transaction
A series of operations that appear to execute
as one large atomic operation
 All-or-nothing
 Allow multiple users to share the same data
 ACID
 Atomicity
 Many operations are bundled together and appear as
one atomic unit

11.12.2003 CENG 520 67


Gokce Banu Laleci
ACID
 Consistency
 A transaction leaves the system in a consistent
state
 Isolation
 Protects concurrently executing transactions from
seeing each other’s incomplete results
 Durability
 Guarantees that updates to managed resources,
such as database records, survive failures
11.12.2003 CENG 520 68
Gokce Banu Laleci
Transaction
 Type
 Flat
 Nested
 Rollback is not an undo logic
 Resource managers are transaction aware
 They do no not make the changes persistent until
a commit statement issued

11.12.2003 CENG 520 69


Gokce Banu Laleci
EJB and transactions
 EJB never interact with a transaction
manager or a resource manager
 The container handles all the low-level things

 Demarcating transactional boundries


 Programmatically
 Declaratively
 Client-initiated

11.12.2003 CENG 520 70


Gokce Banu Laleci
Programmatic Transactions
 Putthe transaction logic in to your application
code
 The programmer is responsible for issuing
 begin, commit and abort

Client Code EJB Container

1:call 2:delegate
method EJB object
3:call begin
Transaction
EJB Service
4:perform 5:call commit
business or abort
operations
11.12.2003 CENG 520 71
Gokce Banu Laleci
Declarative Transactions
 EJB container handles
 Declare in deployment descriptor

11.12.2003 CENG 520 72


Gokce Banu Laleci
Declarative Transactions

Client Code EJB Container

3:call begin
1:call Transaction
method EJB object 5:call commit Service
or abort

2:delegate

EJB

4:perform
business
operations

11.12.2003 CENG 520 73


Gokce Banu Laleci
Client Initiated Transactions

EJB Container

3:call begin
Client Code Transaction
5:call commit Service
or abort
1:call
method EJB object

2:delegate

EJB

4:perform
business
operations

11.12.2003 CENG 520 74


Gokce Banu Laleci
Container-Managed
Transactions
 Bean deployer has to provide instructions to
the container
 Deployment descriptor
 Transaction Attributes
 Entire bean
 Individual methods

11.12.2003 CENG 520 75


Gokce Banu Laleci
Transaction Attribute Values

11.12.2003 CENG 520 76


Gokce Banu Laleci
Transaction Attribute Values
Transaction Attribute Client’s transaction Bean’s transaction

none T2
Required
T1 T1
none T2
RequiresNew
T1 T2
none None
Supports
T1 T1
none Error
Mandatory
T1 T1
none None
NotSupported
T1 None
none None
Never
T1 error
11.12.2003 CENG 520 77
Gokce Banu Laleci
Programmatic Transactions
 CORBA’s Object Transaction Service (OTS)
 Multiple parties participating in a transaction
 Basic interfaces that transactional object,
resources, resource managers, and transaction
managers use to interoperate

11.12.2003 CENG 520 78


Gokce Banu Laleci
Java Transaction Service
 Corba OTS
 Java Transaction Service
 Java Transaction API
 JTAJTS OTS
 To have various vendors to interoperate
 Used by AS
 JTA
 Application developers
 Programmaticaly control transaction boundaries

11.12.2003 CENG 520 79


Gokce Banu Laleci
Java Transaction API
 begin()
 Commit()
 getStatus()
 rollBack()
 setRollbackOnly()
 setTransactionTimeout()

11.12.2003 CENG 520 80


Gokce Banu Laleci
Example

11.12.2003 CENG 520 81


Gokce Banu Laleci

Anda mungkin juga menyukai