AJP Unit V
AJP Unit V
ENTERPRISE APPLICATIONS
Server side components need to run in a highly available (24/7), fault-tolerent transactional,
and multiuser secure environment. The application server provides this high-end server side
environment for the enterprise beans, and it provides the runtime containment necessary to
mange enterprise bean.
Perform business logic. Example include computing the taxs on the shopping cart, ensuring that
the manger has authority to approve the purchase order, or sending an order confirmation
email using the java mail AP.
Access database : Example include submitting an order for books, transferring money between
two banks etc.
EJB Architecture
• EJB server:The server contains the EJB container
• An EJB client does not communicate directly with an EJB component Remote interface
• Define the business methods that can be called by client Home interface
• Method to create and destroy the proxies for the remote interface EJB container :the EJB
specification defines a container as the environment in which one or more component execute
it.
The EJB enumeration aims to provide a standard way to implement the server-side business
software typically found in enterprise applications. Such machine code addresses the same
types of problems, and solutions to these problems are often repeatedly re-implemented by
programmers. Enterprise Java Beans is assumed to manage such common concerns as
endurance, transactional probity and security in a standard way that leaves programmers free
to focus on the particular parts of the enterprise software at hand.
To run EJB application we need an application server (EJB Container) such as Jboss, Glassfish,
Weblogic, Websphere etc. It performs:
1. Life cycle management - Bean life cycle is managed by the spring container. When we run
the program then, first of all, the spring container gets started. After that, the container creates
the instance of a bean as per the request, and then dependencies are injected. And finally, the
bean is destroyed when the spring container is closed
2. Security - Authentication − This is the process ensuring that user accessing the system or
application is verified to be authentic.
Authorization − This is the process ensuring that authentic user has right level of authority to
access system resources.
J2EE is the standard platform for developing applications in the enterprise and is designed for
enterprise applications that run on servers. J2EE provides APIs application programming
interfaces that let developers create workflows and make use of resources such as databases or
web services. The Java EE provides a platform for developers with enterprise features such as
distributed computing and web services
Client tier
In the client tier, Web components, such as Servlets and JavaServer Pages (JSPs), or
standalone Java applications provide a dynamic interface to the middle tier.
Middle tier
In the server tier, or middle tier, enterprise beans and Web Services encapsulate
reusable, distributable business logic for the application. These server-tier
components are contained on a J2EE Application Server, which provides the platform
for these components to perform actions and store data.
Enterprise data tier
In the data tier, the enterprise's data is stored and persisted, typically in a relational
database.
J2EE applications are comprised of components, containers, and services. Components are
application-level components. Web components, such as Servlets and JSPs, provide dynamic
responses to requests from a Web page. EJB components contain server-side business logic for
enterprise applications. Web and EJB component containers host services that support Web
and EJB modules.
Additional services and APIs upon which J2EE is based include:
Written in the Java programming language, an enterprise bean is a server-side component that
encapsulates the business logic of an application. The business logic is the code that fulfills the
purpose of the application. In an inventory control application, for example, the enterprise
beans might implement the business logic in methods called checkInventoryLevel and
orderProduct. By invoking these methods, remote clients can access the inventory services
provided by the application.
1. Session Bean: A session bean represents a single client inside the Application Server. To
access an application that is deployed on the server, the client invokes the session bean’s
methods. The session bean performs work for its client, shielding the client from complexity by
executing business tasks inside the server. As its name suggests, a session bean is similar to an
interactive session. Session bean contains business logic that can be invoked by local, remote or
webservice client. There are two types of session beans:
Stateful session bean performs business task with the help of a state. The state of an object
consists of the values of its instance variables. In a stateful session bean, the instance variables
represent the state of a unique client-bean session. Because the client interacts (“talks”) with
its bean, this state is often called the conversational state. The state is retained for the duration
of the client-bean session. If the client removes the bean or terminates, the session ends and
the state disappears. This transient nature of the state is not a problem, however, because
when the conversation between the client and the bean ends there is no need to retain the
state.
A stateless session bean does not maintain a conversational state for the client. When a client
invokes the method of a stateless bean, the bean’s instance variables may contain a state, but
only for the duration of the invocation. When the method is finished, the state is no longer
retained. Because stateless session beans can support multiple clients, they can offer better
scalability for applications that require large numbers of clients.
A stateless session bean can implement a web service, but other types of enterprise beans
cannot.
Stateful session beans are appropriate if any of the following conditions are true:
• The bean’s state represents the interaction between the bean and a specific
client.
• The bean needs to hold information about the client across method invocations.
• The bean mediates between the client and the other components of the
application, presenting a simplified view to the client.
2. Message Driven Bean: Like Session Bean, it contains the business logic but it is invoked by
passing message.
3. Entity Bean: An entity bean represents a business object in a persistent storage mechanism.
Some examples of business objects are customers, orders, and products. In the Application
Server, the persistent storage mechanism is a relational database. Typically, each entity bean
has an underlying table in a relational database, and each instance of the bean corresponds to a
row in that table.
Entity beans differ from session beans in several ways. Entity beans are persistent, allow shared
access, have primary keys, and can participate in relationships with other entity beans. It
summarizes the state that can be remained in the database. It is deprecated. Now, it is
replaced with JPA (Java Persistent API). There are two types of entity bean:
The term container-managed persistence means that the EJB container handles all
database access required by the entity bean. The bean’s code contains no database
access (SQL) calls. As a result, the bean’s code is not tied to a specific persistent
storage mechanism (database). Because of this flexibility, even if you redeploy the
same entity bean on different J2EE servers that use different databases, you won’t
need to modify or recompile the bean’s code.
5.5 transaction
To emulate a business transaction, a program may need to perform several steps.
A transaction can end in two ways: with a commit or with a rollback. When a transaction
commits, the data modifications made by its statements are saved. If a statement within a
transaction fails, the transaction rolls back, undoing the effects of all statements in the
transaction. In the pseudocode, for example, if a disk drive were to crash during the credit step,
the transaction would roll back and undo the data modifications made by the debit statement.
Although the transaction fails, data integrity would be intact because the accounts still balance.
A transaction is a single unit of work items, which follows the ACID properties. ACID stands for
Atomic, Consistent, Isolated, and Durable.
Atomic − If any of the work item fails, the whole unit will be considered failed. Success
meant, all items execute successfully.
Consistent − A transaction must keep the system in consistent state.
Isolated − Each transaction executes independent of any other transaction.
Durable − Transaction should survive system failure if it has been executed or
committed.
Container-Managed Transactions
In an enterprise bean with container-managed transaction demarcation, the EJB container sets
the boundaries of the transactions.
Enterprise beans that use container-managed transaction demarcation must not use any
transaction-management methods that interfere with the container’s transaction demarcation
boundaries. Examples of such methods are the commit, setAutoCommit, and rollback methods
of java.sql.Connection or the commit and rollback methods of javax.jms.Session
EJB 3.0 has specified following attributes of transactions, which EJB containers implement −