Enterprise Java Overview
JUG Leader & Java Champion
Java Enterprise Edition
Introduction to JEE
JEE Application Servers
The next step
Large scale and complex systems
n number or tiers
Thousands of users
Thousands or millions of requests per hour
Support for fail
Support for transactions
Support for security
Developer had to do everything
Care about multithreading
Care about transactions
Care about fail
Care about security
... on top of that care about the business logic
Application Server/Container takes care of
Developer takes care of business logic
JEE architecture layers
(image taken from http://www.itindepth.com/)
Java objects that extend the functionality of a
Run on the server
Require a servlet container to run in
Platform and server independent
They access all the Java APIs
Having HTML/XML/WML code within a Java
class is ugly, error
prone and hard to maintain
A simple and easy way to create dynamic web
HTML/XML/WML/etc with Java code (scriplets)
embedded into it
Runs on the server
Platform and server independent
Needs to be pre
compiled into a servlet
Servlets & JSP
They work together
JSP used for presentation
Servlets are used as controllers/implement
By separating logic from presentation
(design) it is easier to maintain, scale and
build web applications
The cornerstone of a JEE application
Server side components
They enable fast and simplified
development of distributed, transactional,
secure and portable enterprise applications
They are deployed into a container
Three types of EJB (Session, Entity,
The container is responsible for
Loading and initialising
Persistence (activation/passivation and db
communication with clients via remote
JNDI for finding EJB instances
Perform actions on behalf of a particular
Maintains conversational state with the client
Does not maintain state between client calls.
The container can substitute beans as
necessary between method calls.
Map data to a database row
Provide abstraction layer so when working
with an entity the storage mechanism is not
The container persists the data to the db
Developer writes code that persists data to the
db and container calls these methods
Message Driven Beans
Receive asynchronous notifications from a
for example send a purchase order to a JMS
Client does not interact with them directly
but only through message queues
Java Messaging Service
Software that provides service for
Can be stand
alone or consolidated within
an application server
Messages are sent into a queue and read from
the queue. One consumer only
Publish/subscribe mode. Messages are
broadcast to all the consumers
Java Naming and Directory Interface
It is used to store and retrieve objects by
Object have to register with a naming service
Can interact with existing naming services
The Java Transaction API allows
application servers to handle transactions
Developer declares the transaction
The application server takes care of the
The Java Mail API provides classes that
model a mail system
Supports many common protocols
Java Authentication and Autorisation Service
Authenticates users, makes sure users can log
into the system and execute Java code
Authorises users, makes sure users have the
right permissions to perform the actions required
Authentication modules include
Java Database Connectivity
Lets developers access database from
Also provides access to other form of data
such as excel files
There are drivers for all the known
Connectors provide a way to connect J
applications to heterogenous systems not
written in Java (Siebel, SAP, etc)
System vendor provides the right connector
Take care of application
Provide sophisticated means to handle
Handle the life
cycle of the installed
Usually cost thousands of pounds per CPU
All of application servers provide their own
services (JMS, JNDI, servlet containers,
Some application servers
JBoss (free and open source, but you pay for
You deploy the application onto the
application server in a form of EAR
(Enterprise ARchive) file
EAR is nothing more than a zipped file that
contains all relevant files needed.
It is expanded on deployment
Application servers usually provide a
console where the administrator or
developer can manage the application
Define JDBC resource
Define users and roles
Services residing somewhere on the web
Web services enable application to
application interaction via the web
Built on existing standards (SOAP over
Web services are focused on messages not
APIs (we don't care what created the
Web Services (continued)
Interoperability between disparate systems
You can access a .NET web service from a
Java client (the opposite is also true), etc
Enable Service Oriented Architecture
Traditional approach is based on objects, we
discover and use objects
With SOA we discover and use services
Web Services protocol
Simple Object Access Protocol (SOAP)
Transmission over existing HTTP protocol
In essence we send HTTP requests with the
whole SOAP message in the body of the
Web Services Description Language
Describes a web service
Describes methods and parameter types
Describes return types
How to access it (what port it's running on,
where it's running on)
Complicated, use tools to generate the
Universal Description, Discovery and
It's a registry of services
Publishes information about a web service
(similar to yellow pages)
Publishes the access point of a web service
Aims behind Spring
Enterprise Java should be easier.
Interfaces are better than classes.
JavaBeans better than EJBs.
Testability is important and should be easier.
Small size (around
One core jar file (and a few more
Spring manages life
cycle and configuration
of application objects.
Objects are given their dependencies instead
of creating/looking for them.
Spring gives dependencies upon instatiation.
Application data are configured through an
XML configuration file.
Can be complicated and hard to maintain if
there are too many beans configured.
Like JEE, developer is only concerned
about business logic, Spring takes care of
application related functionality.
Spring contains several modules, each one
can be used on its own.
Core and Context modules, the heart of the
Spring framework. Provide fundamental
ORM Module (hooks for other ORM
Spring Core Modules
Initialise all the application objects
(JavaBeans) by reading the XML
Supply enterprise services such as JNDI,
multithreading, remote calls etc.
Provide support with integration with other
frameworks (FreeMarker, iBatis etc).
Spring & AOP
a general feature we want to
apply globally to our application (e.g.
logging or exception handling).
Aspects are declared through the XML
Container executes the aspect after, before
or around a method call.
Around can change the method behaviour.
Spring & JDBC
Provides functionality for JDBC.
Database information (url, port etc) is
configured via the XML configuration file.
Handles the creation of connections, result
sets, statements, pools etc.
Closes the connection and returns it to the
pool of available connections.
Spring & Transactions
Declare transactions in the configuration
file/class meta data by using annotations.
Can declare roll back behaviour per method
or exception type.
You can't do that with EJBs, only
No native support for distributed
transactions. Only through JTA.
EJBs support distributed transactions by
Spring & Persistence
Doesn't support out of the box ORM
We need to integrate with existing
technologies (Hibernate, TopLink etc). Spring
provides the right plumbing to do so.
Alternatively use plain JDBC.
Spring & Web applications
Provides its own web framework (Spring
Typical MVC pattern with a central servlet
acting as controller.
Spring supports several web
(multipart file uploading, session handling
Can be integrated with other web
frameworks like Struts, Tapestry, JSF.
Spring & Distributed
Remote calls to Spring ca be done via
RMI (same as EJBs)
JAX/RPC (for Web Services)
Spring & Security
Spring Security (formerly Acegi security)
Supports declarative security via XML
configuration or class meta data annotations
for security (EJBs also support declarative
security via roles and users).
Spring & Deployment
A Spring application should run the same
on any other machine that supports Spring.
Migration should be easy (just copy & paste
the application data & the XML
Same with EJBs, although a bit tricky.
JEE compatible servers