View
224
Download
6
Category
Preview:
Citation preview
1
Enterprise Application Development Using J2EE / © Shmulik London 2004Interdisciplinary Center Herzeliza Israel
Enterprise Application Development using J2EE
Shmulik London
Introduction to J2EE
Enterprise Application Development Using J2EE / © Shmulik London 2004
Agenda
• What is J2EE?
• Enterprise Applications
• J2EE Concepts– J2EE Container, Container services,
Container component contract, ...
• Multi-tier Architecture
• J2EE technologies
• Sample Applications
Enterprise Application Development Using J2EE / © Shmulik London 2004
What is J2EE?
• J2EE is a framework for writing enterprise applications
• An industry standard coordinated by Sun Microsystems together with industry leaders – IBM, Oracle, BEA, SAP, Compaq, ... (JCP see JSR151)
Enterprise Application Development Using J2EE / © Shmulik London 2004
What is J2EE?
• J2EE was designed for Enterprise Applications.. not for general purpose– it is complex because EA are complex
– for many applications it is an overkill
– EA can benefit a lot from using J2EE
• In order to appreciate J2EE and use it properly it is important to understand what are EA
Enterprise Application Development Using J2EE / © Shmulik London 2004
What are Enterprise Apps?
• These are the applications that drive banks, insurance companies, online stores, market places, B2B, B2C, Supply chain, …
They’re what makes the world go round…
Enterprise Application Development Using J2EE / © Shmulik London 2004
What are Enterprise Apps?
• EA can be very different from one another, however they have common characteristics (not all exhibit all characteristics)
• Think about the EA behind
2
Enterprise Application Development Using J2EE / © Shmulik London 2004
EA characteristics
High volume, scalable,distributed
• Some EA serve thousands of users concurrently
• For new systems you would like a scalable architecture that scale with the business
Enterprise Application Development Using J2EE / © Shmulik London 2004
Scalability Exemplified
• (Data from 2002)
– 69 Million Registered users
– 380 Million dynamic hits / day!(assume 12h ⇒ >8,000 per second)
– system need to scale with business:
Registered UsersGrowth over years(Sep 04 – 95 Million)D
ata
ta
ken
fro
m J
ava
One
200
3 /
Se
ssio
n 32
64
A B
illio
n H
its a
Da
y
Enterprise Application Development Using J2EE / © Shmulik London 2004
EA characteristics
heterogeneous
• An EA is rarely a single software designed by a common team– It is a collection of interoperating
software systems designed over years by deferent teams with different technologies
– New components are added due to merger/acquisitions, business trends, introduction of new technologies...
Enterprise Application Development Using J2EE / © Shmulik London 2004
EA characteristics
Transactional
• The core of EA is processing transactions
– They must be able to process transactions consistently and efficiently
– Often distributed transactions involving different databases and other type of resources
Enterprise Application Development Using J2EE / © Shmulik London 2004
Transaction Example
• Consider a reservation of tickets for a show
• After to specify the details of the reservation, the following tasks should be performed:
– A place should be reserved for you
– You should be charged for the reservation
– A ticket (receipt) should be issued to you
• All these tasks must succeed or not occur at all
Enterprise Application Development Using J2EE / © Shmulik London 2004
Transaction Example
Checkout
Reserve chairotherwise, customerwon’t find a place
Send receiptotherwise, customerwon’t be let in
Process CCotherwise, theaterowner unhappy
3
Enterprise Application Development Using J2EE / © Shmulik London 2004
EA characteristics
Robust, non-stop, fault-tolerant, secure
• Often should be available 24/7
• Automatic recovery from crashes –fast, no data loss or integrity loss
• Manage sensitive data, different levels of access, adhere to federal regulations
Enterprise Application Development Using J2EE / © Shmulik London 2004
Direct Downtime Costs (hour)
Sour
ces:
Inte
rnet
Wee
k4
/3/2
000+
Fib
reC
hann
el:
A C
ompr
ehen
sive
Int
rodu
ctio
n, R
. K
emb
el2
00
0, p
.8.
”...b
ased
on
a su
rvey
don
e b
y C
ontin
gen
cy P
lann
ing
Res
earc
h."
$14,000ATM service fees
$25,000On-line network fees
$41,000Cellular service activation
$89,000Airline reservation center
$90,000Catalog sales center
$113,000Home shopping channel
$150,000Package shipping services
$180,000Amazon.com
$225,000Ebay
$2,600,000Credit card authorization
$6,450,000Brokerage operations
22 hour outage, June 1999 ⇒
estimated loss several million $
Enterprise Application Development Using J2EE / © Shmulik London 2004
Enterprise App Challenges
Robust
Non-Stop24/7
Scaleable
Secure Transactional
FaultTolerant
Heterogeneous
Distributed
Complex
Web Front
Multi Faces
Localized
ConfigurableTraceable
How do you developsomething that addressesall these challenges??
This picture is taken from www.compugeeks.us/
Enterprise Application Development Using J2EE / © Shmulik London 2004
J2EE Container
• In order to attack these challenges J2EE introduces the concept of a J2EE Container
• The ‘application’ consist of a set of components that live inside a container
• The container itself is distributed and can span several machines
Enterprise Application Development Using J2EE / © Shmulik London 2004
Separation of concerns
• The container allows for separation of concerns:– the container provide a set of services
such as transaction management, distributed communication, etc.
– the components use these services in a manner that allows them to concentrate on the business logic they perform
Enterprise Application Development Using J2EE / © Shmulik London 2004
Example – online catalog
• Suppose your application is an online store and you want to implement a product catalog
• Many users access your catalog concurrently each issuing a query
• Consider the implementation of such a catalog... 1
1) To simplify matters we assume that the data in thecatalog doesn’t change
4
Enterprise Application Development Using J2EE / © Shmulik London 2004
Example – online catalog
• For good response you must process multiple request concurrently– this requires multithreading
– each request processing requires resources (socket, db connection), you need to limit the number of concurrent request processing to avoid server crash
– you want to cache results for similar requests
Enterprise Application Development Using J2EE / © Shmulik London 2004
Example – online catalog
• You want to achieve scale with several machines
– you need to balance the load between the machines
– if a machine fails (crash, network..) you would like to rerun the requests it was handling on a different machine
Enterprise Application Development Using J2EE / © Shmulik London 2004
Example – online catalog
• With J2EE you write a component with a single method that process a single request. The Container will:
– manage several copies of your component on each machine
– load balance request processing
– rerun requests in case a machine fails*
– pool database connections and bound number of threads/sockets...
Enterprise Application Development Using J2EE / © Shmulik London 2004
Container Services
• Concurrency, load balancing, failover, resource pooling
• Transactions
• Persistence
• Distributed Objects
• Messaging
• Naming
• Security
Enterprise Application Development Using J2EE / © Shmulik London 2004
Container – component contract
• In the previous example we used the load-balancing service of the container implicitly – there was no need for a load-balancing API
• However, we do need to denote to the container that the request processing should be subject to load-balancing, failover, etc.
Enterprise Application Development Using J2EE / © Shmulik London 2004
Container component contract
• We denote our use of a service in several ways
– Extending certain class/interface
– Use annotations
– Follow naming conventions
– Use descriptors files
– in some cases programmatically
5
Enterprise Application Development Using J2EE / © Shmulik London 2004
Annotations@Entity
@Table(name="USERS")
public class User implements Serializable {
private Long id;
private String username;
private String password;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
. . .
Enterprise Application Development Using J2EE / © Shmulik London 2004
Annotations@Retention(RetentionPolicy.RUNTIME)
public @interface Monitored {
String description();
double lowerLimit() default 0;
double upperLimit() default 0;
}
public class MachineA {
...
@Monitored(description=“productionRate”,lowerLimit= 20,…)
public double getProductionRate() {
return currentRate;
}
Enterprise Application Development Using J2EE / © Shmulik London 2004
Container component contract
• The rules that summarize the interaction between the component and the container (around the use of the container services) is referred to as the container component contract.
Enterprise Application Development Using J2EE / © Shmulik London 2004
Application Servers
• In the same way the JVM provide an abstraction for Java that allows it to be implemented on different platforms, the J2EE Container provide an abstraction that allows different application servers to host J2EE applications
Enterprise Application Development Using J2EE / © Shmulik London 2004
Application Servers
• Each application server vendor has its own implementation of the container
• In the past it was thought that the container would be separated from the application server
Enterprise Application Development Using J2EE / © Shmulik London 2004
Common Application Servers
Oracle
Sun Microsystems SunOne
JBoss
IBM WebSphere
BEA WebLogic
6
Enterprise Application Development Using J2EE / © Shmulik London 2004
J2EE Specification
• J2EE is a standard defined by Sun Microsystems jointly with industry leaders
• The J2EE Specifications specify– container services
– component types
– included APIs
– naming conventions
– ...
Enterprise Application Development Using J2EE / © Shmulik London 2004
Multi-tier architecture
• J2EE applications has a multi-tier architecture
• The system is divided into 3 or more layers
– presentation layer
– business logic layer(s)
– enterprise information systems layer
Enterprise Application Development Using J2EE / © Shmulik London 2004
Mainframe
Mainframe
Enterprise Application Development Using J2EE / © Shmulik London 2004
Client-Server Applications
Client Server
Enterprise Application Development Using J2EE / © Shmulik London 2004
Multi-tiered Application
RDBMS
EnterpriseInformationSystems
Data LayerBusiness Logic LayerPresentation Layer
LegacySystem
ERP
CRM
GUIClient
WEBClient
Business components
MobileDevice
WEBService
Enterprise Application Development Using J2EE / © Shmulik London 2004
.. in J2EE terminology
RDBMS
EnterpriseInformationSystems
Data LayerBusiness Logic LayerPresentation Layer
LegacySystem
ERP
CRM
Swing App. /Applet
Browser
Enterprise beans
MobileDevice
JSP /Servlet
JSP /Servlet
7
Enterprise Application Development Using J2EE / © Shmulik London 2004
J2EE technologies
• J2EE include the following elements
– Web technologies – Servlets, JSP, web-services
– EJB (Enterprise Java Beans)
– Additional APIs
Enterprise Application Development Using J2EE / © Shmulik London 2004
Servlets & JSP
• Most EA have a Web-interface
• In J2EE Servlets & JSP are used for implementing Web-interfaces
• There are other technologies some build top of JSP and/or Servlets
– Struts, Velocity, Tapestry, ...
Enterprise Application Development Using J2EE / © Shmulik London 2004
Web Services
• Some EA expose some of their functionality to be accessed in an automated way to allow B2B or custom clients
• This can be done via web-services
– e.g. Amazon, eBay, Google, ...
• An evolving technology, expected to play central role in the future
Enterprise Application Development Using J2EE / © Shmulik London 2004
Enterprise Java Beans
• EJB is a server-side component architecture targeted at business logic and persistence
• It defines components called Enterprise Beans
• There are several types of Enterprise Beans – Session Beans (stateless/stateful), Entity Beans, Message Driven Beans
Enterprise Application Development Using J2EE / © Shmulik London 2004
J2EE APIs
• EJB
• JDBC
• Servlets & JSP
• JMS
• JNDI
• JTA
• Java IDL
• JavaMail & JAF
• JAXP
• JCA
• JAAS
• JAX-RPC, JAXM
Enterprise Application Development Using J2EE / © Shmulik London 2004
Sample applications
• We present two examples of J2EE applications to make the previous concepts more concrete
• Please bear in mind that these are sterile ‘classroom’ examples that cannot manifest the complex nature of most enterprise applications
8
Enterprise Application Development Using J2EE / © Shmulik London 2004
Java Pet Store
Enterprise Application Development Using J2EE / © Shmulik London 2004
Pet Store Design
Designing Enterprise Applications with the JavaTM 2 Platform, Enterprise Edition /Nicholas Kassem and the Enterprise Team, pp. 250
Enterprise Application Development Using J2EE / © Shmulik London 2004
Course Project
Internet
J2EE Server
J2ME ClientJ2ME Client
Enterprise Application Development Using J2EE / © Shmulik London 2004
Course Project Design
RDBMS
Data LayerBusiness Logic LayerPresentation Layer
Entity Beans
JSP
JSPSession
Façade
Controller
Servlet
Recommended