You are on page 1of 16

8/28/2011

Ni dung

B mn Cng ngh Phn mm


Vin CNTT & TT
Trng i hc Bch Khoa H Ni

LP TRNH WEB HNG JAVA


Bi 05: Tng quan v Java EE

Ging vin: ThS. Trnh Tun t


B mn CNPM
Email: trinhtuandat.bk@gmail.com/dattt@soict.hut.edu.vn

1. J2EE l g?
2. S pht trin ca cc Enterprise Application
Frameworks
3. Ti sao la chn J2EE?
4. J2EE APIs and Technologies
5. Standard Impl (J2EE 1.4), Compatibility Test
Suite (CTS)
6. BluePrints
7. J2EE v Web Services
8. Cc bc nghin cu J2EE

Enterprise Computing
Challenges
Portability
Diverse
Environments
Time-to-market
Core Competence
Assembly
Integration

1. J2EE l g?

Key
Technologies
J2SE
J2EE
JMS
Servlet
JSP
Connector
XML
Data Binding
XSLT

Products
App Servers
Web Servers
Components
Databases
Object to DB
tools
Legacy
Systems
Databases
TP Monitors
EIS Systems

J2EE l g?

Java Platform

L nn tng (platform) m, chun tc

pht trin (developing), trin khai (deploying) v


qun l (managing)
cc ng dng doanh nghip hng thnh phn
(component-based), ng dng Web, Server,

Java Technology
Enabled Devices

Java Technology
Enabled Desktop

Workgroup
Server

High-End
Server

8/28/2011

JavaTM Platform
2. S pht trin ca cc
Enterprise Application
Frameworks

Java 2 Platform Micro Edition


(J2METM)

Optional
Packages

Optional
Packages

Java 2
Enterprise
Edition
(J2EE)

Java 2
Standard
Edition
(J2SE)

Personal
Basis Profile

Personal
Profile

Foundation Profile
CDC

JVM

MIDP
CLDC
KVM

Java
Card
APIs
CardVM

8
* Under development in JCP

ng dng doanh nghip (Enterprise


Applications)

2. S pht trin ca cc Enterprise Application


Frameworks

1 tng (Single tier)


2 tng (Two tier)
3 tng (Three tier )

Da trn RPC
Da trn Remote object

3 tng (HTML browser v Web server)


My ch ng dng c quyn (Proprietary
application server)
My ch ng dng chun (Standard application
server)

Cc thnh phn ca 1 enterprise application

S pht trin ca 1 enterprise application


framework th hin

Single Tier (Mainframe-based)

Dumb terminals kt ni trc tip vi mainframe


Theo m hnh tp trung (ngc vi m hnh phn
tn)
Cc x l Presentation, business, v data access
c thc hin duy nht trong 1 ng dng
mainframe

Presentation logic
Business logic
Data access logic (v data model)
System services

Cch thc thay i linh ng nh th no?


Cc dch v h thng c cung cp ra sao?

Single-Tier: u nhc im

u im:

Khng cn qun l pha client


Nht qun d liu (Data consistency)

Nhc im:

Cc thao tc (presentation, data model, business


logic) c mix vo ln nhau kh bo tr & ti
s dng code.

8/28/2011

Two-Tier

Fat clients giao tip vi database pha sau

Two-Tier

Thun li:

Cons:

Gi truy vn SQL, nhn v d liu th

Presentation, Business logic v Data Model


processing logic u nm trong ng dng
client

SQL request

Database

SQL
response

Three-Tier (RPC based)

iu khin tng tranh, a lung, transaction, security,


persistence, multiplexing, performance, ...

u im:

Business logic v data access logic nm trn server trung


gian (middle tier server), client x l presentation

Middle tier server cn x l cc dch v h thng

SQL
request

SQL
response

Business logic v data model pht trin theo m


hnh T

u im:

Business logic v data model c m t tru tng


(interface language)

M hnh i tng c s dng: CORBA, RMI,


DCOM

phc tp cao middle-tier server


Client v middle-tier server lin kt kh cht (So
vi m hnh three-tier object based)
Cha thc s ti s dng c Code (So vi m
hnh three-tier object based)

Three-tier (Remote Object based): u


nhc im

Three-Tier (Remote Object based)

(Nm trn middle-tier server)

Nhc im:

Database

RPC response

Business logic thay i linh ng hn so vi m


hnh 2-tier

RPC request

Presentation, data model, business logic c mix ln


nhau client kh cp nht & bo tr
Data Model nh cht vi mi client: nu CSDL thay i
tt c clients u hng
Cc cp nht phi c tin hnh trn tt c cc clients
c mng trong bo tr h thng
To DB connection cho tt c client Tn ti nguyn,
kh m rng
Trao i d liu th (Raw data) tn bng thng

Three-tier (RPC based): u nhc im

Thinner client: business & data model c tch


bit vi presentation

DB product independence

Kt ni linh ng hn m hnh RPC


Ti s dng Code tt hn

Nhc im:

Vn c phc tp server trung gian

Interface language trong CORBA l IDL


Interface language trong RMI l Java interface
Object request
Object response

SQL
request
SQL
response

Database

8/28/2011

Three-tier (Web Server based): u nhc


im

Three-Tier (Web Server)

Browser x l presentation logic


Browser giao tip vi Web server qua giao
thc HTTP
Business logic v data model c x l theo
cng ngh Sinh ni dung ng (CGI,
Servlet/JSP, ASP)
HTML request

WEB
Server

HTML response

u im:

a dng cho thit b client

Khng cn qun l client

Nhc im:

Vn cn phc tp tng trung gian

SQL
request
Database

SQL
response

Xu hng

Single-tier vs. Multi-tier

Chuyn kin trc single-tier hoc two-tier


thnh kin trc multi-tier
Chuyn t m hnh nguyn khi (monolithic
model) sang m hnh ng dng hng i
tng
Chuyn ng dng client thnh HTML-based
client

Single tier

Monolithic vs. Object-based

1 Binary file
Recompiled,
relinked,
redeployed every
time there is a
change

Object-based

Pluggable parts
Reusable
Enables better
design
Easier update
Implementation
can be separated
from interface
Only interface is
published

No separation
among presentation,
business logic,
database
Hard to maintain

Multi-tier

Separation among
presentation,
business logic,
database
More flexible to
change, i.e.
presentation can
change without
affecting other tiers

Cc vn v gi php ni bt

Monolithic

in thoi di ng h tr J2ME,

Phc tp middle tier server


Cn nhn bn cc dch v h thng, gii
quyt cc vn v

Concurrency control, Transactions


Load-balancing, Security
Resource management, Connection pooling

Gii php?

Cn c 1 container chung x l ton b dch v


h thng trn
Gii php c quyn v gii php m, chun

8/28/2011

Gii php m & chun - Open and


Standard Solution

Gii php c quyn-Proprietary Solution

S dng m hnh "component v container"

Components v container c giao kt cht


ch, r rng nhng theo cch thc ca bn
cung cp

Components m nhim cc business logic


Container cung cp mi trng thc thi km cc
dch v h thng

S dng m hnh "component v container"


trong container cung cp cc dch v h
thng theo chun.
J2EE: l 1 chun nh th, cho php linh
ng trong code

Da trn cng ngh Java v standard-based Java


programming APIs

Vn : ph thuc vo nh cung cp

V d: Tuxedo, .NET

Vi Developers

3. Ti sao la chn J2EE?

C th s dng bt k J2EE implementation no


pht trin v trin khai

C rt nhiu ti nguyn trong cng ng J2EE

Bn chun tc, cht lng, min ph


Bn nng cao, c ph, m bo scalability v faulttolerance
books, articles, tutorials, quality code, best practice
guidelines, design patterns etc.

S dng cc thnh phn c sn (off-the-shelf) ca


bn th 3

27

Vi Vendors

Vendors: cng to ra cc c t
(specifications), sau cnh tranh trong ci
t/thc thi

Vi Business Customers

Trong cc lnh vc Scalability, Performance,


Reliability, Availability, v development tools,

T do sng to trong ci t, vn m bo
tnh portability ca cc ng dng
Khng cn create/maintain cc APIs cho
ring mnh

m bo tnh portability cho ng dng


C nhiu thc thi la chn, ty
requirements

Price (freetr ph), scalability (1 CPU m


hnh clustered), reliability, performance, tools,
Lun c la chn ti u

Rt nhiu cng c pht trin

8/28/2011

J2EE 1.4 APIs and Technologies

4. J2EE APIs & Technologies

J2SE 1.4 (improved)


JAX-RPC (new)
Web Service for J2EE
J2EE Management
J2EE Deployment
JMX 1.1
JMS 1.1
JTA 1.0

Servlet 2.4
JSP 2.0
EJB 2.1
JAXR
Connector 1.5
JACC
JAXP 1.2
JavaMail 1.3
JAF 1.0

31

Java EE 5

JAX-WS 2.0 & JSR 181


Java Persistence
EJB 3.0
JAXB 2.0
JavaSever Faces 1.2 new to Platform
JSP 2.1 Unification w/ JSF 1.2
StAX Pull Parser new to Platform

Servlet l g?

Servlets l cc Java objects, m rng chc


nng ca 1 HTTP server

Cho php sinh ng ni dung (Dynamic contents


generation)

L la chn u vit hn CGI, NSAPI, ISAPI,


...

hiu qu
c lp Platform v Server
H tr qun l Session
Nn tng Java

4.1. Servlet &


JSP (JavaServer Pages)

Servlet vs. CGI


Request
Request CGI1
CGI1
Request
Request CGI2
CGI2
Request
Request CGI1
CGI1
Request
Request Servlet1
Servlet1
Request
Request Servlet2
Servlet2
Request Servlet1

Child
Child for
for CGI1
CGI1

CGI
CGI
Based
Based
Webserver
Webserver

Child
Child for
for CGI2
CGI2
Child
Child for
for CGI1
CGI1

Servlet
Servlet Based
Based Webserver
Webserver
JVM
JVM

Servlet1
Servlet1
Servlet2
Servlet2

8/28/2011

Cng ngh JSP?

Cho php tch bit business logic khi


presentation

4.2. EJB
(Enterprise Java Beans)

Presentation: dng HTML hoc XML/XSLT


Business logic: c thc hin vi Java Beans
hoc custom tags
Bo tr, ti s dng tt hn

D m rng ng dng vi custom tags


Da trn cng ngh Servlet

EJB Technology?

L cng ngh cho cc components pha


server
Cho php pht trin v trin khai cc ng
dng doanh nghip vi cc tnh nng cao
cp:

Transactional, distributed, multi-tier, portable,


scalable, secure,

Ti sao s dng EJB Technology?

Tn dng c cc li ch ca m hnh hng


thnh phn trn server
Tch bit business logic vi system code

m bo tnh portability cho cc components

Trn cc servers khc nhau


Trn mi trng tnh ton khc nhau

Cho php cu hnh ti thi im trin khai


(deployment-time configuration)

EJB Architecture

Container cung cp cc system services

Deployment descriptor (XML file)

Enterprise JavaBeans
Enterprise JavaBeans

Synchronous communication
Session Bean

Stateless

Entity Bean

Asynchronous communication
Message-Driven Bean

Stateful

Bean managed
Persistence
(BMP)

Container managed
Persistence
(CMP)

8/28/2011

Java Message Service (JMS)


4.3. JMS
(Java Message Service)

Messaging systems (MOM) cung cp

Li ch ca cc Messaging systems

Giao tip linh ng


Giao tip khng ng b (Asynchronous communication)
C vai tr nh 1 bu in tp trung
Flexible, Reliable, Scalable communication systems

H tr m hnh: Point-to-Point, Publish & Subscribe


JMS nh ngha cc chun Java APIs cho cc
messaging systems

Connector Architecture

4.4. Connector Architecture

nh ngha cc API chun tc tch hp cng


ngh J2EE vi cc h thng EIS

CICS, SAP, PeopleSoft, etc.

Nu khng c Connector architecture, mi App


server phi cung cp 1 adaptor ring cho tng h
thng EIS
m (# of App servers) x n (# of EIS's) Adaptors

Vi Connector architecture, cng 1 adaptor lm vic


c vi tt c App server tun theo kin trc J2EE
Connector

1 (common to all App servers) x n (# of EIS's) Adaptors

Bi ton m x n nu khng c Connector


Architecture
m

App
Server1

SAP

App
Server2

4.5. JAAS (1 thnh phn ca J2SE 1.4)


(Java Authentication &
Authorization Service)

EIS
2

App
Server3

EIS3

App
Server

EIS4

8/28/2011

JAAS: Authentication

D dng chuyn i cc k thut xc thc sau:

JAAS Pluggable Authentication

Userid/password
Smartcard
Kerberos
Biometric (Sinh trc hc)

Cho php ng dng l portable, khng quan tm s


dng k thut xc thc no

JAAS cung cp cc API c lp vi k thut s dng

Cho cc ng dng Java

C file cu hnh (login configuration file) cha thng tin


v k thut p dng cho 1 mi trng c th

JAAS: Authorization

Khng c JAAS, Java platform security da


trn:

JAAS API h tr thm:

H tr User-based authorization

4.6. Cc J2EE APIs &


Technologies khc

Where the code originated


Who signed the code
Whos running the code

JNDI

Java Naming and Directory Interface


c s dng bi cc ng dng J2EE
nh v ti nguyn & i tng (resources &
objects)

ng dng: thng qua nh danh tham chiu


ti i tng
nh danh phi c cu hnh ch ti i tng
v hoc ti nguyn no bi qun tr h thng khi
trin khai ng dng

JDBC

Cung cp Java API chun tc giao tip vi


CSDL quan h

S dng SQL

Cc nh cung cp (Vendors) a ra cc JDBC


driver tng ng Java API gi n

8/28/2011

J2EE Platform Architecture

4.7. J2EE l 1 kin trc Endto-End

B2B
Applications
Existing
Applications

B2C
Applications

Web
Services

Application Server
Enterprise
Information
Systems

Wireless
Applications

N-tier J2EE Architecture

J2EE l gii php End-to-End


Firewall
Client

J2EE
Application
Server

Enterprise
JavaBeans

Client

Enterprise
Information
Systems (EIS):
Relational
Database,

Client

Web
Server
JSP,
Servlets

Client
Client

Enterprise
JavaBeans

Legacy
Applications,
ERP Systems

HTML/XML

Client
Tier

Middle
Tier

Other Services:
JNDI, JMS,
JavaMail

Enterprise
Information
Tier

WJeBb TT ie
E
ierr

J2EE Containers & Components

JAF

JDBC

JavaMail

RMI/IIOP

JTA

JMS

JAF

JNDI

JavaMail

EJB

RMI

JDBC

JTA

JMS

JNDI

App Client
Container
App
HTTP/
Client
HTTPS

EJB Container

Servlet

JSP

J2SE

J2SE

J2SE

JDBC

JMS

RMI/IIOP

RMI

JNDI

4.8. J2EE Component &


Container Architecture

Web Container

HTTP/
HTTPS

Applet

RMI/IIOP

Applet Container

J2SE

Database

10

8/28/2011

Containers v Components
Containers
Handle

Components
Handle

Concurrency
Security
Availability
Scalability
Persistence
Transaction
Life-cycle
management
Management

Containers & Components

Presentation
Business Logic

Containers thc hin cc cng vic 1 cch


thm lng (invisibly)

Khng c cc APIs phc tp

em n tnh simplicity v flexibility cho J2EE

Containers thc thi J2EE

Gn ging vi cc components
Cc nh sn xut (Vendors) cc containers t do
sng to

Vng i pht trin ng dng J2EE

4.9. Vng i pht trin v


trin khai cc ng dng J2EE

Vit v bin dch cc thnh phn code

Assembly

Created by J2EE Modules


Component
Developer

Assembled
J2EE APP
and Augmented
by Application
Assembler

T Java EE 5, c th thay bng annotation

Tp hp cc components trong cc ready-todeployable package


Trin khai package trn server

Cc Roles trong qu trnh pht trin ng


dng J2EE

Minh ha cho vng i


Creation

Servlet, JSP, EJB

Vit deployment descriptors cho cc


components

Deployment

Deploy

J2EE Container

Component provider

Processed
by Deployer

Enterprise
Components

Cn c gi l Bean provider

Application assembler
Deployer
Platform provider
Cn c gi l Container provider

Tools provider
System administrator

11

8/28/2011

Deployment Descriptor

Ch dn cho container cch qun l v iu


khin hot ng ca cc J2EE components

Cho php declarative customization (ngc


vi programming customization)

4.10. Cc thnh phn trong


ng dng J2EE Application

Transaction
Security
Persistence

XML file

m bo tnh portability cho m ngun

Cc thnh phn c th c trong ng dng


J2EE

Web Server

Web Server

Cc ng dng J2EE 4 tng:

Cc ng dng J2EE 3 tng:

Cc ng dng J2EE 3 tng:

EJB Server

DB & EIS
Resources

Browser

Cc thnh phn trong ng dng J2EE

EJB Server

Stand-alone

HTML client, JSP/Servlets, EJB, JDBC/Connector


HTML client, JSP/Servlets, JDBC
EJB standalone applications, EJB,
JDBC/Connector

Cc ng dng B2B Enterprise

T J2EE platform n J2EE platform thng qua


trao i cc JMS hoc cc thng ip XML

Chn loi no?

Ph thuc vo 1 s yu t

Requirements ca ng dng
Tng EJB c sn c khng
Cc ti nguyn cho developer c sn c khng

5. J2EE 1.4
Standard Implementation,
Compatibility Suite, Brand

12

8/28/2011

5.1. Standard Implementation

Ci t cho J2EE 1.4: Sun Java Application


Server Platform Edition 8

5.2. Compatibility Test Suite (CTS)

Ci t theo ng chun ra
Min ph pht trin v trin khai
c cp nht lin tc

Nhim v ln nht ca cng ngh Java


technology:

Write Once, Run Anywhere


ng dng Java chy trn bt k my o java no
ng dng J2EE chy c trn J2EE platform bt
k

J2EE Application Verification Kit (J2EE


AVK)

Cch thc test tnh portability ca ng dng


J2EE?

5.3. Cc sn phm cho J2EE Platform


(Brand)

Cch thc test:

S dng J2EE RI 1.3.1 v J2EE Application


Verification Kit (J2EE AVK)
Static verification
Dynamic verification

Ly v cc kt qu test, kim tra tha


mn tt c cc yu ch cha.

Tools

IDEs: Borland JBuilder Enterprise, WebGain


Visual Cafe, IBM Visual Age for Java, Forte
for Java, Oracle JDeveloper, Macromedia Kawa
Modeling, Performance, Testing, etc.

Enterprise Integration: Connectors,


Java Message Service (JMS) API, XML
Components
Frameworks
Applications

ATG
Bea Systems
Borland
Computer
Associates
Fujitsu
Hitachi
HP
IBM
IONA

iPlanet
Macromedia
NEC
Oracle
Pramati
SilverStream
Sybase
Talarian
Trifork

u t m bo tnh compatibility ca
J2EE

Cc sn phm cho J2EE Platform

Cn c test

Sun u t xy dng cc b compatibility


test kit
Kim tra trnh k s hng nm m
bo c sn phm cht lng
u t vo Testing lun cao hn u t vo
c t (specification), thc thi
(implementation), thng mi (business)
> 10 million $ c u t trong J2EE
platform compatibility

13

8/28/2011

6. J2EE Blueprint

6. J2EE Blueprint

Cc hng dn thc hnh, mu thit k, cc


nguyn l thit k

MVC pattern

Blueprint bao trm tt c cc tng


Client tier
Web tier
Business logic (EJB) tier
Database access tier

C code mu/v d i km vi J2EE 1.4 SDK

Java Pet Store, Adventure builder

Ti sao la chn J2EE cho Web Services?

7. J2EE v Web Services?

Web services n thun l 1 trong nhiu


knh dch v ca J2EE ( khai thc tng
business logic)

Rt nhiu ch li ca J2EE c gi li trong


Web services

M hnh Web services trn J2EE


Rich Clients

XMLP/SOAP

JSP
MIDP
Devices

DBMS

XMLP/SOAP
XHTML/WML
JMS
Connectors

EJB

HTML/XML

Existing
Apps

Browsers

Java APIs cho Web Services ang pht trin rt


nhanh

JDBC

XMLP/SOAP

Portability, Scalability, Reliability


Khng ph thuc vo vendor ring l no

H tr hin ti ca J2EE cho Web services

J2EE Server JSP/ JavaServlet API / EJB

Khng cn thay i kin trc


D dng chuyn i cc J2EE components c
thnh Web services

Web services da trn WUST (WSDL, UDDI, SOAP) c


h tr rt tt
Cc tng Web services tip theo ang c pht trin

cung cp cc Tools trin khai cc J2EE


components thnh Web services
J2EE nh ngha framework y cho Web
Services (J2EE 1.4, Web services for J2EE)

Services

14

8/28/2011

Cc mc tiu thit k ca J2EE 1.4 Web


Services Framework

m bo tnh Portability cho cc Web


services component

Trn cc vendor platform khc nhau


Trn cc operational environment khc nhau

S dng cc m hnh lp trnh J2EE c


thc thi/ci t cc service
D pht trin v trin khai (deploy)

J2EE 1.4 Web Services Framework

J2EE 1.4 (JSR 151)


Web services for J2EE (JSR 109)
JAX-RPC (JSR 101)
JAXR (Java API for XML Registries)
SAAJ (SOAP with Attachments API for Java)
EJB 2.1

Java APIs mc cao


S dng m hnh trin khai c

Bc 1: Cho Beginners & Intermediate


J2EE Programmers

8. Cc bc nghin cu J2EE?

Tham gia kha hc y


S dng J2EE IDE, ty la chn
Th cc IDE m ngun m

NetBeans IDE (netbeans.org)

H tr J2EE rt tt
C rt nhiu tutorials

Eclipse

Bc 2: Cho Advanced J2EE Programmers

Tm hiu cc gii php m ngun m

Spring framework (for light-weight framework)


Hibernate (for O/R mapping)
JDO (for transparent persistence)
Struts, WebWork, Tapestry (for Web-tier
frameworks)
JUnit (for unit testing)
Log4j (for logging)
...

Tng kt

15

8/28/2011

Tng kt

J2EE l nn tng pht trin v trin khai


cc ng dng doanh nghip hng thnh
phn, n-tier, web-based, transactional
J2EE l kin trc xy dng theo chun
(standard-based architecture)
J2EE tt c v cng ng
J2EE pht trin theo yu cu ca thc t

Resources

J2EE Home page

J2EE 1.4 SDK

J2EE 1.4 Tutorial

J2EE Blueprints

NetBeans IDE Homesite

java.sun.com/j2ee
java.sun.com/j2ee/1.4/download.html#appserv
java.sun.com/j2ee/1.4/download.html#appserv
java.sun.com/blueprints/enterprise/index.html
http://www.netbeans.org

16

You might also like