java 2 platform, enterprise edition (j2ee) an overview

111
1 Java 2 Platform, Enterprise Edition (J2EE) An Overview 蔡 蔡 蔡 蔡蔡蔡蔡蔡蔡蔡蔡蔡蔡 [email protected]

Upload: brenden-landry

Post on 30-Dec-2015

59 views

Category:

Documents


0 download

DESCRIPTION

Java 2 Platform, Enterprise Edition (J2EE) An Overview. 蔡 文 能 交通大學資訊工程學系 [email protected]. What Is J2EE ?. Java 2 Enterprise Edition There are 3 different specifications within the Java framework (J2SE, J2ME, J2EE) - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Java 2 Platform, Enterprise Edition (J2EE) An Overview

1

Java 2 Platform, Enterprise Edition(J2EE)

An Overview

蔡 文 能交通大學資訊工程學系

[email protected]

Page 2: Java 2 Platform, Enterprise Edition (J2EE) An Overview

2

What Is J2EE ?

• Java 2 Enterprise Edition• There are 3 different specifications within the

Java framework (J2SE, J2ME, J2EE)• Created to provide a simple, unified standard

for distributed applications through a component based application model

• Specification is managed by a consortium of industry leaders

Page 3: Java 2 Platform, Enterprise Edition (J2EE) An Overview

3

Some useful online references

• http://java.sun.com

• http://java.sun.com/j2ee

• http://java.sun.com/j2ee/tutorial/index.html

Page 4: Java 2 Platform, Enterprise Edition (J2EE) An Overview

4J2EE, J2SE, J2ME

J2EE and Other Java 2 Platform EditionsSource: Computer, August 2000

Page 5: Java 2 Platform, Enterprise Edition (J2EE) An Overview

5Source: Sun Microsystems, Inc.

J2EE and Other Java 2 Platform Editions

J2EE, J2SE, J2ME

Page 6: Java 2 Platform, Enterprise Edition (J2EE) An Overview

6Source: P.J. Perrone and V.S.R.R. Chaganti, Building Java Enterprise Systems with J2EE

Java Development and Runtime Environment

Page 7: Java 2 Platform, Enterprise Edition (J2EE) An Overview

7Source: P.J. Perrone and V.S.R.R. Chaganti, Building Java Enterprise Systems with J2EE

Java 2 Platform Runtime Architecture

Page 8: Java 2 Platform, Enterprise Edition (J2EE) An Overview

8Source: Sun Microsystems, Inc., http://java.sun.com/j2se/1.3/

Java 2 Platform, Standard Edition (J2SE 1.3)

Page 9: Java 2 Platform, Enterprise Edition (J2EE) An Overview

9Source: Sun Microsystems, Inc., http://java.sun.com/j2se/1.4/

Java 2 Platform, Standard Edition (J2SE 1.4)

Page 10: Java 2 Platform, Enterprise Edition (J2EE) An Overview

10

Why J2EE ?

• A stand alone program• Client/Server (2-Tier)

– BBS, News, FTP, Telnet, …• Traditional (non-component) N-Tier Systems

– 3-tier application: Browser – WEB Server – DBMS

• New trend:– Component N-Tier Systems

(J2EE Architecture)

See figures on next slides

Page 11: Java 2 Platform, Enterprise Edition (J2EE) An Overview

11Source: Sun Microsystems, Inc., JDBC 3.0 Specification

2-Tier Database Access

• Data Tier – Database Management Services

• Client Tier – Presentation, Business Logic

Page 12: Java 2 Platform, Enterprise Edition (J2EE) An Overview

12Source: Sun Microsystems, Inc., JDBC 3.0 Specification

Traditional(non-component) N-Tier Systems

• Client Tier – Presentation Logic

• Application Tier – Business Logic

• Data Tier – Database Management Services

Page 13: Java 2 Platform, Enterprise Edition (J2EE) An Overview

13

Component N-Tier SystemsJ2EE Architecture

EnterpriseInformation

Services

EnterpriseInformation

Services

Web ContainerWeb Container

JSP

Servlet

EJB ContainerEJB Container

EJB

AppletContainer

AppletContainer

StandaloneClient

StandaloneClient

Connector

Firew

ar

e

Database ServerMachine

J2EE ServerMachineClient

Machine

Web Tier Business Tier EIS Tier

Client Tier

Page 14: Java 2 Platform, Enterprise Edition (J2EE) An Overview

14Source: Sun Microsystems, Inc., J2EE Specification v1.3

J2EE Architecture (1/2) J2EE Component and Container

Page 15: Java 2 Platform, Enterprise Edition (J2EE) An Overview

15

J2EE Architecture (2/2)

• J2EE consists of three major parts:– Components

Hold presentation and business logic– Containers

Provide context for components– Connectors

Provide access to legacy enterprise systems

Page 16: Java 2 Platform, Enterprise Edition (J2EE) An Overview

16

J2EE Components

• Application clients

• Applets

• Web components– Servelets, Java Server Pages (JSP)

– Portlet (see JSR168)

• Business components– Enterprise Java Beans (EJB)

Page 17: Java 2 Platform, Enterprise Edition (J2EE) An Overview

17

J2EE ComponentApplet Component

• An applet is a program written in the JavaTM programming language that can be included in an HTML page, much in the same way an image is included. When you use a Java technology-enabled browser to view a page that contains an applet, the applet's code is transferred to your system and executed by the browser's Java Virtual Machine (JVM).

• An applet is a small program that is intended not to be run on its own, but rather to be embedded inside another application.

Page 18: Java 2 Platform, Enterprise Edition (J2EE) An Overview

18

Applet pro vs. con

• Applets: Java code that runs inside browser • Advantages:

– Extends functionality on the client side – More complicated GUIs than w/ HTML or JavaScript – Computation can be off-loaded from server – Users don’t have to build, install, and configure

• Disadvantages: – Download time – “Sandbox” limits functionality (unless signed) – Window management by browser

Page 19: Java 2 Platform, Enterprise Edition (J2EE) An Overview

19

J2EE ComponentWeb Component

• Servlets – A servlet is a program that extends the functionality of a Web

server. Servlets receive a request from a client, dynamically generate the response (possibly querying databases to fulfill the request), and then send the response containing an HTML or XML document to the client

• JSP– The JavaServer Pages (JSP) technology provides an extensible

way to generate dynamic content for a Web client. A JSP page is a text-based document that describes how to process a request to create a response

Page 20: Java 2 Platform, Enterprise Edition (J2EE) An Overview

20

Java Servlet

Browser

Class Loader

Invoker

Services

WebServices

HTTP Request

HTTP Response

Servlet Class wasn’t

loaded into System

Load Servlet class

Into System

Servlet Class

was loaded

Page 21: Java 2 Platform, Enterprise Edition (J2EE) An Overview

21

Java Servlet

• Java Servlet is the bridge for user to use Java solution in Web Server.

• Java Servlet has better performance than CGI(Common Gateway Interface).

• Java Servlet can use session to replace cookie and enhance security.

• J2EE Server maintains the session for Java Servlets.

Page 22: Java 2 Platform, Enterprise Edition (J2EE) An Overview

22

JavaServer Pages (JSP)

Browser Invoker

jspServices

WebServices

HTTP Request (.jsp)

HTTP Response

JavaSourceCode

New JSP PageJSP was modified

JavaBytecode

Compiler

Class Loader

Load Servlet class

Into System

JSP isn’t loaded yet.

Page 23: Java 2 Platform, Enterprise Edition (J2EE) An Overview

23

JavaServer Pages (JSP)

• JSP has all features of Servlet.

• JSP is a HTML like document.

• JSP is designed for Web Page Developer.

• JSP will change to Java Servlet source.

• JSP is ran via Servlet mode.

Page 24: Java 2 Platform, Enterprise Edition (J2EE) An Overview

24

JavaServer PagesObjects

• JSP has 9 objects which developer can use directly without new it.

JSP Object java class scoperequest javax.servlet.ServletRequestrequestresponse javax.servlet.ServletResponse pagpageContext javax.servlet.jsp. PageContext pagesession javax.servlet.http.HttpSession

sessionapplication javax.servlet.ServletContext applicationout javax.servlet.jsp.JspWriter pageconfig javax.servlet.ServletConfig pagepage java.lang.Object pageexception java.lang.Throwable page

Page 25: Java 2 Platform, Enterprise Edition (J2EE) An Overview

25

Portlet and Portal

Portal Server

Browser

JSR168 Portlet Container

JSR168 Portlet

JSR168 Portlet

HTTP

WSRP

• JSR168– Java portlet

standard

• WSRP– Remote portlet

communication protocol

– Portals aggregate remote portlets

(Web Services for Remote Portlets )

Page 26: Java 2 Platform, Enterprise Edition (J2EE) An Overview

26

The Reason For JDBC

• Despite almost all databases supporting SQL, database vendors (Microsoft Access, Oracle etc.) provide proprietary (no standard) Application Programming Interfaces for sending SQL to the server and receiving results from it!

• Languages such as C/C++ can make use of these proprietary APIs directly– High performance– Can make use of non standard features of the database– All the database code needs to be rewritten if you change

database vendor or product• JDBC (Java DataBase Connectivity) is a vendor independent

API for accessing relational data from different database vendors in a consistent way

CCTM: Course material developed by James King ([email protected])

Page 27: Java 2 Platform, Enterprise Edition (J2EE) An Overview

27

JDBC• JDBC provides an API that hides the vendor specific APIs by

inserting a driver between the Java application and the database API• JDBC requires a vendor-specific driver• The driver converts calls from JDBC API to vendor’s API =>

performance penalty• The driver does not provide access to vendor specific functionality• The same Java application can be used with a different vendor’s

database by simply switching JDBC driver and changing one line of Java code.

• JDBC 1.0 is included inside JDK 1.1 or higher in a package java.sql • JDBC 2.0 and 3.0 require updated drivers and an additional package

javax.sql

CCTM: Course material developed by James King ([email protected])

Page 28: Java 2 Platform, Enterprise Edition (J2EE) An Overview

28

Rollback and Commit

• By default connections to the database commit each update as soon as it is completed.

• If you want to make a set of changes and only commit the aggregate result if nothing goes wrong auto commit needs to be switched off

connection.setAutoCommit(false)You can then use

connection.commit() to apply the changesconnection.rollback() to undo changes since the last commit• You can switch auto commit back on usingconnection.setAutoCommit(true)

CCTM: Course material developed by James King ([email protected])

Page 29: Java 2 Platform, Enterprise Edition (J2EE) An Overview

29

J2EE Compoent (1/2)EJB Component

• Enterprise JavaBean (EJB)– The Enterprise JavaBeans (EJB) architecture is a server-

side technology for developing and deploying components containing the business logic of an enterprise application.

– Enterprise JavaBeans components, termed enterprise beans, are scalable, transactional, and multi-user secure.

• EJB is an architecture for component-based transactional distributed computing.

Page 30: Java 2 Platform, Enterprise Edition (J2EE) An Overview

30

EJB Component (2/2)

• An enterprise bean contains business logic that operates on the enterprise’s data.

• Client access is mediated by a Container.

• There are three kinds of enterprise beans: session beans, entity beans, and message-driven beans.

Page 31: Java 2 Platform, Enterprise Edition (J2EE) An Overview

31

Enterprise Bean Objects

• Session objects: for a single client, short-lived, …Stateful, Stateless

• Entity objects: object view of data in the database, shared by multiple clients, long-lived, …

• Message-driven objects: triggered by a single client message, short-lived, stateless, …

Page 32: Java 2 Platform, Enterprise Edition (J2EE) An Overview

32

Stateful vs. Stateless Session Beans

• Stateful– Possess Internal State

– One per client

– Need to handle activation/ passivation

• Stateless– Do not possess state

– Can be pooled to handle multiple clients

– Do not need to be passivated

Page 33: Java 2 Platform, Enterprise Edition (J2EE) An Overview

33

Entity Beans: CMP vs. BMP

• Container Manager Persistence– Container responsible

for database accesses/ controls

– Developer focuses on data use

• Bean Managed Persistence– Developer must write

code to handle database accesses/ controls

– Used for more specialized data mapping strategies

Page 34: Java 2 Platform, Enterprise Edition (J2EE) An Overview

34

Entity Bean Characteristics

• Provides an object view of data in the underlying database

• Shared across multiple users

• Long-lived

• Survives container crash

Page 35: Java 2 Platform, Enterprise Edition (J2EE) An Overview

35

To Implement an Enterprise Bean (1/2)

• Any enterprise bean must define two interfaces and one or two classes– Remote interface

• defines a bean’s external interface• must extend javax.ejb.EJBObject (which in turn extends

java.rmi.Remote)

– Home interface• The home interface defines a bean’s “life cycle” methods, eg.

create bean, remove bean, find bean, etc.• must extend javax.ejb.EJBHome which also extends

java.rmi.Remote

Page 36: Java 2 Platform, Enterprise Edition (J2EE) An Overview

36

To Implement an EJB (2/2)

• Bean Class– The java class that actually implements the bean’s external

interface, e.g. the bean class provides implementations for the bean’s “business methods”

– An entity bean must implement the javax.ejb.EntityBean interface, while a session bean must implement the (you guessed it) javax.ejb.SessionBean. Both of these interfaces extend javax.ejb.EnterpriseBean

• Primary Key– The primary key is a very simple class that provides a pointer into

a database; Only entity beans need a primary key. This class must implment java.io.Serializable (so the entity bean can automatically be sent to persistent storage)

Page 37: Java 2 Platform, Enterprise Edition (J2EE) An Overview

37

EJB Container

• A container is provided by the Application Server vendor to provide basic services that are required by J2EE specification.

• An EJB programmer places their code here, and is assured a variety of basic services are available

• This means the developer doesn’t have to code these services from scratch

• Specification states which services must be supported but not how

Page 38: Java 2 Platform, Enterprise Edition (J2EE) An Overview

38

Basic Services Supplied by the EJB Container

• Security

• Transaction management

• Remote Client Connectivity

• Life Cycle Management

• Database Connection Pooling

Page 39: Java 2 Platform, Enterprise Edition (J2EE) An Overview

39

More Services provided by container

• The following basic services will be supported by all J2EE compliant products– RMI/RMI-IIOP

– Resource Pooling

– Thread Control

– Presentation Logic

– Persistence

– Messaging

– And more…IIOP: Internet Inter-ORB Protocol

ORB: Object Request Broker

Page 40: Java 2 Platform, Enterprise Edition (J2EE) An Overview

40

Can’t Do in an EJB

• Can’t use threads

• Can’t use the AWT

• Can’t act as network server

• Can’t use java.io package

• Can’t load native libray

• Can’t use this as an argument or return value

Page 41: Java 2 Platform, Enterprise Edition (J2EE) An Overview

41

EJB Benefits Summary

• Developing distributed applications in Java – Application developer is spared from following details

• Transaction management • State management • Multi-threading • Connection pooling

• Write once, run anywhere • Interoperability with other languages • Compatible with CORBA protocols

Page 42: Java 2 Platform, Enterprise Edition (J2EE) An Overview

42

J2EE Containers (1/2) Web Containers

• Web Component Containers– 1. Servlet Containers

• A servlet container provides network services (by which requests and responses are sent), decodes requests, and formats responses. All servlet containers must support HTTP as a protocol for requests and responses, but may also support additional request-response protocols

such as HTTPS.

– 2. JSP Containers• A JSP container provides the same services as a servlet container and

an engine that interprets and processes a JSP page into a servlet.

– 3. Web Containers• A Web container provides the same services as a JSP container and

access to the J2EE service and communication APIs.

Page 43: Java 2 Platform, Enterprise Edition (J2EE) An Overview

43

J2EE Containers (2/2) EJB Containers

• EJB Container– Enterprise beans are hosted by an EJB

container. In addition to standard container services, an EJB container provides a range of transaction and persistence services and access to the J2EE service and communication APIs.

Page 44: Java 2 Platform, Enterprise Edition (J2EE) An Overview

44

Tomcat

• Tomcat: Java-based web server + servlet container w/ JSP environment

• Execution modes: – Standalone: default mode for Tomcat – Out-of-process add-on: web server plugin

opens JVM outside web server; plugin and JVM communicate using IPC mechanism (TCP/IP sockets and special protocol)

Page 45: Java 2 Platform, Enterprise Edition (J2EE) An Overview

45

Tomcat and Apache 

• Communication mechanism between Tomcat and Apache: web server adapter” or named as “connector”

• Implemented as shared library (e.g., mod_jserv.so, mod_jk.so)

• Uses/manages TCP connections • Uses the AJPV12/AJPV13 communication

protocol

Page 46: Java 2 Platform, Enterprise Edition (J2EE) An Overview

46

J2EE Connectors

• Contract between container and Enterprise Information Systems (EIS)

• Proprietary and under the hood

• Implementation is available with J2EE specification version 1.3 / 1.4

Page 47: Java 2 Platform, Enterprise Edition (J2EE) An Overview

47

J2EE Standard Services

• HTTP/HTTPS

• Java Transaction API (JTA)

• Java Database Connection (JDBC)• Java Message Service (JMS)

• Java Authentication and Authorization Service (JAAS)

• J2EE Connector Architecture (JCA)

• Others: RMI-IIOP, JavaIDL, JavaMail, JavaBeans Activation Framework (JAF), Java API for XML Parsing (JAXP)

IIOP: Internet Inter-ORB Protocol

Page 48: Java 2 Platform, Enterprise Edition (J2EE) An Overview

48

The Solution: J2EE Application Model

• J2EE application model partitions the work needed to implement a multi-tier service into two parts– the business and presentation logic (implemented by

the application developer)

– the standard system services provided by the J2EE platform.

• The developer can rely on the platform to provide the solutions for the hard systems level problems of developing a middle-tier service.

Page 49: Java 2 Platform, Enterprise Edition (J2EE) An Overview

49Source: Sun Microsystems, Inc., http://java.sun.com/j2ee/overview2.html

J2EE Application Model

Page 50: Java 2 Platform, Enterprise Edition (J2EE) An Overview

50

Benefits of J2EE Application Model

• The J2EE application model provides the benefits of Write Once, Run Anywhere™ portability and scalability for multi-tier applications.

• This standard model minimizes the cost of developer training while providing the enterprise with a broad choice of J2EE servers and development tools.

Page 51: Java 2 Platform, Enterprise Edition (J2EE) An Overview

51

J2EE Platform Roles

• J2EE Product Provider

• Application Component Provider

• Application Assembler

• Deployer

• System Administrator

• Tool Provider

Page 52: Java 2 Platform, Enterprise Edition (J2EE) An Overview

52

The Connector Architecture

• Integration of J2EE servers with Enterprise Information Systems (EIS)

• EIS vendor-provided resource adaptors

• Resource adaptor-permitting application servers

Page 53: Java 2 Platform, Enterprise Edition (J2EE) An Overview

53

J2EE Connector

• J2EE Connector– The J2EE Connector architecture defines a standard

architecture for connecting the J2EE platform to heterogeneous EISs. Examples of EISs include ERP, mainframe transaction processing, database systems, and legacy applications not written in the Java programming language. By defining a a set of scalable, secure, and transactional mechanisms, the J2EE Connector architecture enables the integration of EISs with application servers and enterprise applications.

Page 54: Java 2 Platform, Enterprise Edition (J2EE) An Overview

54Source: Sun Microsystems, Inc., J2EE Connector Architecture Specification

System Level Pluggability

Page 55: Java 2 Platform, Enterprise Edition (J2EE) An Overview

55Source: Sun Microsystems, Inc., J2EE Connector Architecture Specification

Connector Architecture Overview

Page 56: Java 2 Platform, Enterprise Edition (J2EE) An Overview

56

Source: Sun Microsystems, Inc., J2EE Connector Architecture Specification

Connector Architecture Overview (cont.)

Page 57: Java 2 Platform, Enterprise Edition (J2EE) An Overview

57Source: Sun Microsystems, Inc., J2EE Connector Architecture Specification

Connector Architecture in B2B Scenario

Page 58: Java 2 Platform, Enterprise Edition (J2EE) An Overview

58

Client View of an Enterprise Bean

• Home Interface: methods for creating, removing, and finding bean instances

• Remote Interface: methods callable by the client

• Object Identity• Metadata Interface: mainly for dynamic

invocation• Handle

Page 59: Java 2 Platform, Enterprise Edition (J2EE) An Overview

59Source: Sun Microsystems, Inc., Enterprise JavaBeans 2.0

Client View of Session Beans

Page 60: Java 2 Platform, Enterprise Edition (J2EE) An Overview

60Source: Sun Microsystems, Inc., J2EE Specification, v1.3

Accessing Enterprise Beans from Servlets/JavaServer Pages

Page 61: Java 2 Platform, Enterprise Edition (J2EE) An Overview

61

Source: Sun Microsystems, Inc., J2EE Specification, v1.3

J2EE Deployment

Page 62: Java 2 Platform, Enterprise Edition (J2EE) An Overview

62Source: Sun Microsystems, Inc., J2EE Connector Architecture Specification

J2EE Application Life Cycle

Page 63: Java 2 Platform, Enterprise Edition (J2EE) An Overview

63Source: P.J. Perrone and V.S.R.R. Chaganti, Building Java Enterprise Systems with J2EE

Overview of Enterprise Applications Integration (EAI)

Page 64: Java 2 Platform, Enterprise Edition (J2EE) An Overview

64Source: P.J. Perrone and V.S.R.R. Chaganti, Building Java Enterprise Systems with J2EE

Overview of Enterprise Applications Integration (EAI)

Page 65: Java 2 Platform, Enterprise Edition (J2EE) An Overview

65Source: P.J. Perrone and V.S.R.R. Chaganti, Building Java Enterprise Systems with J2EE

EAI with XML

Page 66: Java 2 Platform, Enterprise Edition (J2EE) An Overview

66Source: Sun Microsystems, Inc., The J2EE Tutorial

Enterprise Beans of the Example Design

Page 67: Java 2 Platform, Enterprise Edition (J2EE) An Overview

67

J2EE Platform Technologies 1/3

• Servlets and JSP– Java technology servlets and JavaServer Pages are server components that

run in a web server that supports dynamic HTML generation and session management for browser clients.

• EJB– Enterprise JavaBeans is a server component model that provides

protability across application servers and implements automatic services on behalf of the application components.

• JTA– Java Transaction API provides a transaction demarcation API.

• JTS– Java transaction Service defines a distributed transaction management

service based on the CORBA Object Transaction Service.

Page 68: Java 2 Platform, Enterprise Edition (J2EE) An Overview

68

J2EE Platform Technologies 2/3

• JNDI– Java Naming and Directory Interface provides access to naming and

directory services, such as DNS, LDAP, NDS, and CORBA Naming.

• RMI-IIOP– Remote Method Invocation(RMI) creates remote interfaces for Java-to-

Java communication. This extension uses the CORBA standard IIOP communication protocol.

• Java IDL– Java Interface Definition Language creates remote interfaces to support

java-to-CORBA communications.

Page 69: Java 2 Platform, Enterprise Edition (J2EE) An Overview

69

J2EE Platform Technologies 3/3

• JDBC– JDBC database access API provides uniform access to relational databases.

• JMS– Java Messaging Service supports asynchronous communication using either a

reliable queuing or publish/subscribe model.

• JavaMail– JavaMail provides a protocol-independent framework to build mail and

messaging applications.

• JAF– JavaBeans Activation Framework provides standard services to determine the

type of an arbitrary piece of data and activate an appropriate JavaBeans component to manipulate the data.

Page 70: Java 2 Platform, Enterprise Edition (J2EE) An Overview

70

History of J2EE Technologies

• Distributed Objects– CORBA, DCOM, etc.– Three-tier scenario: presentation, business logic, and

backend databases• Hard to “get right” without the proper infrastructure

• Server-Side Components– Focuses on encapsulating “business rules” into objects

in the middle tier

• Component Transaction Monitors– Descendant of CORBA’s Object Request Broker

• provides discovery, persistence, event notification, transactions, etc. for three-tier or n-tier applications

Page 71: Java 2 Platform, Enterprise Edition (J2EE) An Overview

72

J2EE Platform Services

• Naming Services– Provide application clients, EJB and Web components with access to a

JNDI naming environment.

• Deployment Services– Allow components and applications to be customized at the time they are

packaged and deployed.

• Transaction Services– Devide an application into a series of indivisible or atomic units of work.

• Security Services– Designed to ensure that resources are accessed only by users authorized to

use them.

Page 72: Java 2 Platform, Enterprise Edition (J2EE) An Overview

73

J2EE Platform Benefits

• Simplified architecture and development• Scalability to meet demand variations• Integration with existing information systems• Choices of servers, tools, components• Flexible security model• The J2EE reduces the cost and complexity of developing

these multi-tier services, resulting in services that can be rapidly deployed and easily enhanced as the enterprise responds to competitive pressures.

Page 73: Java 2 Platform, Enterprise Edition (J2EE) An Overview

74

J2EE Platform• The J2EE platform is the standard environment for running J2EE

applications. The J2EE platform is composed of the following elements:– J2EE deployment specification - a standard that defines a

common way of packaging applications for deployment on any J2EE compatible platform.

– Java technology standards for the J2EE platform - a set of standards that all J2EE platform products must support (JMS , JNDI etc)

– IETF standards for the J2EE platform - a set of standards defined by the Internet Engineering Task Force that all J2EE platform products must support.(eg XML, HTTP, HTML)

– CORBA standards for the J2EE platform - a set of CORBA standards upon which the J2EE platform bases its middle-tier interoperability.

Page 74: Java 2 Platform, Enterprise Edition (J2EE) An Overview

75

J2EE Application Assembly

• A J2EE application is packaged into one or more standard units for deployment to any J2EE platform-compliant system.

• Each unit contains a functional component or components (enterprise bean, JSP page, servlet, applet, etc.), a standard deployment descriptor that describes its content, and the J2EE declarations which have been specified by the application developer and assembler.

• Once deployed, theses components can then be run.

Page 75: Java 2 Platform, Enterprise Edition (J2EE) An Overview

76

J2EE Reference Implementation

• Its primary role is as an operational definition of the J2EE platform.

• Most importantly, it is used as the standard platform for running the J2EE Compatibility Test Suite.

• A secondary role for the reference implementation is as a freely available platform for popularizing Java 2 platform, Enterprise Edition.

Page 76: Java 2 Platform, Enterprise Edition (J2EE) An Overview

77

J2EE Reference Implementation• Latest version available for download

– JavaTM 2 SDK, Enterprise Edition Version 1.3

– Downloadable at

http://java.sun.com/j2ee/

• NOTE : – This version will require Java 2 SDK, Standard Edition

(J2SE) Version 1.3.1 or higher.

Page 77: Java 2 Platform, Enterprise Edition (J2EE) An Overview

78

Application Servers

• Consists of – EJB server – Web server (HTTP) – Secured web server (HTTPS) …

• J2EE Compliance Test – Brings vendor neutrality to your applications – Consists of more than 5000 tests – Currently 9 application servers have been certified

• BEA WebLogic (BEA)• iPlanet (Sun + Netscape)• Websphere (IBM)

• (check out www.javasoft.com/j2ee for latest update)

Page 78: Java 2 Platform, Enterprise Edition (J2EE) An Overview

79

The BEA WebLogic Server

• All Java, clean-room implementation of the J2EE• Shipping basic APIs since 1997• One of the most widely-used Application Servers

on the market– Over 12,000 customers

• Associated BEA product: TUXEDO – Distributed TP Monitor– Originally developed at Bell Labs in 1984– Influenced the design of WebLogic

Page 79: Java 2 Platform, Enterprise Edition (J2EE) An Overview

80

Sun ONE Application Server 7

• Provides a comprehensive overview of the Sun ONE Application Server. Please note - the tour may take up to 1 minute to complete testing your system before starting to load.

• Sun is the first software vendor to deliver a fully J2EE[tm] platform-certified, commercial application server, free of charge, on all leading OS platforms.

• The new Sun ONE Application Server 7 includes the world's fastest, secure http server, and new "Always On" technology.

Sun ONE Application Server 7

Page 80: Java 2 Platform, Enterprise Edition (J2EE) An Overview

81

J2SE Component Links – Assistive Technologies– Drag and Drop– Java Access Bridge– JavaBeansTM Technology– Javadoc Tool– Java Foundation Classes (JFC)/Swing– Java HotSpotTM Virtual Machine– Java Platform Debugger Architecture (JPDA)– Java Plug-in for Windows XP– Java 2DTM API product page– Java Web Start– JDBCTM Technology– Pluggable Look and Feel– Remote Method Invocation (RMI)– Security

Page 81: Java 2 Platform, Enterprise Edition (J2EE) An Overview

82

List of J2ME Technologies– Personal Profile– Personal Basis Profile– Java CardTM Technology– Java Embedded ServerTM Technology– JavaPhoneTM API– Java Telematics Technology (JTT)– Java TVTM API– J2ME Wireless Toolkit– PersonalJavaTM Technology– Wireless Developer web site– Connected Limited Device Configuration (CLDC)– Mobile Information Device Profile (MIDP)– Connected Device Configuration (CDC)– Foundation Profile

Page 82: Java 2 Platform, Enterprise Edition (J2EE) An Overview

83

JBoss Application Server

• JBoss is a simply powerful J2EE application server.– JBoss Application Server is the #1 most widely used Java application

server on the market. A J2EE certified platform for developing and deploying enterprise Java applications, Web applications, and Portals, JBoss Application Server provides the full range of J2EE 1.4 features as well as extended enterprise services including clustering, caching, and persistence.

• EJB3.0– JBoss Application Server includes support for Enterprise Java Beans

(EJB) 3.0 which is designed to dramatically simplify the enterprise Java programming model.

• Service Oriented Architecture – JBoss AS is founded on a service oriented microkernel architecture with

an extremely small in footprint that ensures all services are accessed, managed, and integrated in a unified and consistent manner.

Page 83: Java 2 Platform, Enterprise Edition (J2EE) An Overview

84

Introduction to Apache Ant

• What is Ant?– Java-based build tool

• Why use Ant?– Cross-platform– Java domain smart– Fast, extensible, integrated– Alternatives?

• Analogy– Factory automation

Page 84: Java 2 Platform, Enterprise Edition (J2EE) An Overview

85

Typical Things to Build

Page 85: Java 2 Platform, Enterprise Edition (J2EE) An Overview

86

Designing a Build

• What are you building?

• What does it take to build it?

• How are the steps related?

Page 86: Java 2 Platform, Enterprise Edition (J2EE) An Overview

87

High-level Model

HTML /Textfiles

IndexApplication

(EAR)

Source Code

Page 87: Java 2 Platform, Enterprise Edition (J2EE) An Overview

88

Examples of Commercially Used AOP Tools

• AspectWerkz – Supported by BEA

• Spring AOP framework

• JBoss AOP

• CME (Concern Manipulation Environment)– Supported by IBM

Page 88: Java 2 Platform, Enterprise Edition (J2EE) An Overview

89

Technical Architecture

SearchSessionBean

SearchUtil API

Lucene API

EJB Container

Struts - SearchAction

View - JSPStruts - SearchFormCommons Validator

Web Tier

index

Ant build<index>

task

content

Page 89: Java 2 Platform, Enterprise Edition (J2EE) An Overview

90

AOP – Aspect Oriented Programming• Which tools are suitable for commercial

dev?– Over a dozen tools are listed on aosd.net– Early adopters harden new technologies– How active are the user communities of each? project posts list (november’04 posts) url

AspectJ

150..210each

aspectj-users at eclipse.org eclipse.org/aspectj

AspectWerkz

user at aspectwerkz.codehaus.org

aspectwerkz.codehaus.org

JBoss AOP aspects/jboss forum jboss.org/products/aop

Spring AOP springframework-user www.springframework.org

abc

1..30

abc-users at comlab.ox.ac.uk abc.comlab.ox.ac.uk

aspect# aspectsharp-users aspectsharp.sourceforge.net

AspectC++ aspectc-user at aspect.org aspectc.org

JAC jac-users at objectweb.org jac.objectweb.org

Page 90: Java 2 Platform, Enterprise Edition (J2EE) An Overview

91

IDE support, libs, and docside editor views debugger other libs docs

AspectJ

eclipse, jdeveloper,jbuilder, netbeans

highlighting, content assist, advice links

outline, visualizer,cross references

plain Java

ajdoc, ajbrowser

-+++

+

AspectWerkz

eclipse

advice links

- - - ++

JBoss AOP

advice links, UI for pointcut creation

aspect manager,advised members

dynamic deployment UI, jboss framework integration

++++

++

Spring AOP -

spring framework integration

+++ +

Page 91: Java 2 Platform, Enterprise Edition (J2EE) An Overview

92

Building AOP programs• What’s it like to adopt AOP on an existing

project?source compiler checking weaving deployment run

AspectJ

extended

.java, or .aj

incremental aspectj compile

full static checking

compile and load-time, produce bytecode

static deployment plain

Java program

AspectWerkz

plain .java, .xml

java compile, post processing

minor static checking, none of pointcuts

hot deployable

JBoss AOP runtime

interception and proxies

framework invoked & managed

Spring AOP

java compile -

Page 92: Java 2 Platform, Enterprise Edition (J2EE) An Overview

93

AOP features

• AspectJ and AspectWerkz– AspectJ 5 will feature support for generics in pointcuts. The

@AspectJ syntax will support the AspectWerkz annotation style

• JBoss AOP– Static typing for parameters, performance improvements,

libraries, and more IDE support features

• Spring AOP– Performance improvements, interoperability with AspectJ's

pointcuts, and packaging of some Spring AOP services as AspectJ aspects

Page 93: Java 2 Platform, Enterprise Edition (J2EE) An Overview

94

JBoss AOP (1/2)

- Lack of static checking for pointcuts

- Advanced IDE features not yet supported

+Rich set of enterprise aspects libraries are available and integrated with JBoss and JEMS

+IDE support lowers adoption and reduces need to hand-code XML

+Support for dynamic deployment of aspects

http://jboss.org/products/aop

Page 94: Java 2 Platform, Enterprise Edition (J2EE) An Overview

95

JBoss AOP (2/2)

Page 95: Java 2 Platform, Enterprise Edition (J2EE) An Overview

96

Web services in JBoss Overview: JBoss.net• Specifies how JBoss server components are exposed as Web

service– Stateless Session Beans– Web components– POJO as servlet

Page 96: Java 2 Platform, Enterprise Edition (J2EE) An Overview

97

JBoss Hibernate

Hibernate IS EJB 3.0 CMPCMP is an API and XML mappings

Hibernate is the actual persistence engine

Hibernate caches are being integrated with JBossCache

Full distributed data with OR backend on one node

Page 97: Java 2 Platform, Enterprise Edition (J2EE) An Overview

98

HibernatePart of JBoss full-time

Gavin King and Christian Bauer on board

Persistence for POJOs (JavaBeans)

• Flexible and intuitive mapping

• Support for fine-grained object models

• Powerful, high performance queries

• Dual-Layer Caching Architecture (HDLCA)

• Support for detached objects (no DTOs)

• Transparent Persistence

• Automatic dirty checking

• Transitive Persistence

• Smart fetching and caching

• Smooth migration to EJB3.0

• Consulting and support available as part of JBoss inc

Page 98: Java 2 Platform, Enterprise Edition (J2EE) An Overview

99

Tomcat 5.0.x improvements

• Tomcat’s Remy Maucherat is on JBoss inc staff

• Performance optimizations and reduced garbage collection

• Optional standalone deployer (validation and precompilation of webapps)

• Scalability and reliability enhancements

• Complete server monitoring using JMX

• Improved Taglibs handling, including advanced pooling and tag plugins

• Embedding of Tomcat using JMX

• Enhanced Security Manager support (now allows very restrictive policies)

• Expanded documentation

• Consulting and support available as part of JBoss inc

Page 99: Java 2 Platform, Enterprise Edition (J2EE) An Overview

100

Tomcat standalone or Tomcat inside JBoss ?

• Better JBoss deployer– Hot deployment– Deployment of nested archives (EARs, SARs)– Redeployment– Automatic undeployment

• Advanced clustering• Integrated J2EE stack within one VM

– Deployment descriptor– Optimized local calls– Integrated security

• AOP in JBoss 4.0 available in Tomcat components and webapps

• Easy to use classloader

• Nukes

Page 100: Java 2 Platform, Enterprise Edition (J2EE) An Overview

101

JBoss IDE

• JBoss IDE is based on Eclipse.

– Series of plugins for Eclipse

• The debugging and monitoring of JBoss servers and the control of their life cycle (start/stop).

• A very comfortable and sophisticated support for XDoclet – Support completion and generation

– Support for AOP (completion and generation).

• An easy way to configure and deploy the packaging layout of archives (packed or exploded)

Page 101: Java 2 Platform, Enterprise Edition (J2EE) An Overview

102

What Is JBossCache?• What is JBossCache?

– A transactional replicated cache for JBoss with and without AOP (aspect-oriented programming)

• A cache for frequently accessed elements– Stateful Session Beans, HTTPSession– Caches are used in a number of places in JBoss

• This one provides a central cache service (MBean interface)

• All access goes through the cache– Write-through (lazy or eager)– Reads only access the cache (very fast on cache hits)– Items not in the cache are loaded (e.g. from database)– Bounded size; old items are removed by eviction policy

• Local (=non-replicated) and replicated caches– Replicated caches are the interesting part

Page 102: Java 2 Platform, Enterprise Edition (J2EE) An Overview

103

Feature• Transactions

– All modifications done within TX, replication at TX commit. No replication on rollback

• Locking– Access to nodes serialized by locks– Lock acquisition timeouts used for deadlock prevention

• Replication– local: in-VM, no replication– repl-async: replication done on separate thread– repl-sync: replication done on user's thread, wait for all acks

• All combinations supported– From local/no-tx/no-locking to repl/tx/locking– Ex: repl-async/no-locking/TX

Page 103: Java 2 Platform, Enterprise Edition (J2EE) An Overview

104

Nukes on JBoss ™

• Nukes on JBoss is a port of PHP postnukes– Scalability problems with Zend engine

– Full port to EJB/J2EE.

– Leverage the vast library of nukes modules

• Most of PN modules are ported• Core : offers the core functionalities to other modules

– Security, lifecycle management, parameterization

• User : enables user management

• Html : stores files, filesystem is abstracted, stored in DB

• Sections : edit/publish articles

• FORUMS!!!!

Page 104: Java 2 Platform, Enterprise Edition (J2EE) An Overview

105

CMS: ease of update for non-techies

Page 105: Java 2 Platform, Enterprise Edition (J2EE) An Overview

106

Nukes components

Page 106: Java 2 Platform, Enterprise Edition (J2EE) An Overview

107

How to Deploy on JBoss (1/3)

1. Write your beans and package them in an ejb-jar file.

2. Write your servlets/JSPs and package them in a war file.

3. Add a Class-Path attribute to your war files MANIFEST.MF file to reference your beans package. for detailed information on that see J2EE Deployment specification.

http://www.jboss.org http://www.jboss.com

Page 107: Java 2 Platform, Enterprise Edition (J2EE) An Overview

108

How to Deploy in JBoss (2/3)

4. Package your application in an ear file.An ear file is a jar archive which contains:

• Your jar files • Your war files • A deployment descriptor for your

application.

This file must be named "application.xml", and must belocated in the META-INF directory in the ear archive. Thisfile tells JBoss which modules are EJBs, which ones areweb modules, and the context paths for the web-modules.

Page 108: Java 2 Platform, Enterprise Edition (J2EE) An Overview

109

Sample Application.xml file

<?xml version="1.0" encoding="ISO-8859-1"?>

<application> <display-name>My application</display-name>

<module>

<web>

<web-uri>webmodule.war</web-uri> <context

root>/servlets</context-root>

</web>

</module>

<module>

<ejb>beans.jar</ejb>

</module>

</application>

Page 109: Java 2 Platform, Enterprise Edition (J2EE) An Overview

110

How to Deploy in JBoss (3/3)

5. Deploy your ear file.

Option 1: Copy your ear file to JBOSS_HOME/deploy (wow!)

Write once Deploy AnyWhere!!

Page 110: Java 2 Platform, Enterprise Edition (J2EE) An Overview

111

Thank you!

謝謝捧場http://www.csie.nctu.edu.tw/~tsaiwn/java/

蔡文能

Page 111: Java 2 Platform, Enterprise Edition (J2EE) An Overview

112