48
J1-680, Hapner/Shannon 1 Java 2 Platform, Enterprise Edition (J2EE) Bruno Souza Java Technologist, Sun Microsystems, Inc.

Java 2 Platform, Enterprise Edition (J2EE) - javaman.com.brjavaman.com.br/apres/files/J2EEandAPM.pdf · Enterprise Edition (J2EE) Bruno Souza ... JavaMail JAF JNDI JMS JTA RMI/IIOP

Embed Size (px)

Citation preview

J1-680, Hapner/Shannon 1

Java™ 2 Platform,Enterprise Edition (J2EE)

Bruno SouzaJava Technologist, Sun Microsystems, Inc.

J1-677, Kassem 2

Contents

• The Java™ 2 Platform, Enterprise Edition(J2EE)

• J2EE Environment

• APM and key APM questions

• Application Scenarios and theSample Application

• Deployment and Security

• Resources

J1-680, Hapner/Shannon 3

A Short History ofJava Enterprise Technology

J1-680, Hapner/Shannon 4

Where Have We Been?Where Are We Going?

• MicroEdition

• StandardEdition

• EnterpriseEdition

• MicroEdition

• StandardEdition

• EnterpriseEdition

• JDK “AllThings to theEnterprise”

• EarlyDevelopmentof ConsumerJava

• EarlyDevelopmentof “Enterprise”APIs”

• JDK “AllThings to theEnterprise”

• EarlyDevelopmentof ConsumerJava

• EarlyDevelopmentof “Enterprise”APIs”

Year 1Year 1• JDK All

Things toEveryone

• JDK AllThings toEveryone

Year 2Year 2 Year 3Year 3

The Java ™ Platform

J1-680, Hapner/Shannon 5

Java TechnologyEnabled Desktop Workgroup

Server

Java TechnologyEnabled Devices

High-EndServer

Java 2 Platforms

J1-680, Hapner/Shannon 6

Why another Java ™ 2 Platform?

J1-680, Hapner/Shannon 7

Clients

Middle-Tiers

EIS Tier

EnterpriseEnterpriseServicesServices

DeviceDevice

DD DD DD

DBMSsDBMSs ERP SystemsERP Systems

The Global Enterprise

J1-680, Hapner/Shannon 8

Enterprise Services Require

• Concurrency(multi user)

• Consistency(Transactions)

• Security

• Availability

• Scalability

• Administration

• EIS Integration

• Distribution

J1-680, Hapner/Shannon 9

The Java ™ 2 Platform,Enterprise Edition

• Develop– With the J2EE App Model

• Deploy– With the J2EE App unit

• Run– On the J2EE Platform

J1-680, Hapner/Shannon 10

J2EE Platform

J1-680, Hapner/Shannon 11

What is the purpose of J2EEContainers?

J1-680, Hapner/Shannon 12

JND

I

J2SE

JMS

RM

I/IIO

P

JDB

C

DatabaseDatabase

AppClientApp

Client

App ClientContainerApp ClientContainer

HTTP/HTTPSHTTP/HTTPS

J2SE

RMIRMI

J2SE

JND

I

JMS

RM

I/IIO

P

JDB

C

JTA JavaMail

JAF JND

I

JMS

RM

I/IIO

P

JDB

C

JTA

JavaMail

JAF

HTTP/HTTPSHTTP/HTTPS

Applet ContainerApplet Container

AppletApplet JSPJSP ServletServlet EJBEJB

Web ContainerWeb Container EJB ContainerEJB Container

RMIRMI

J2SEJ2SE

J2EE Platform

J1-680, Hapner/Shannon 13

Containers and Components

• The container is the car

• The component is the driver

• The container is the platform

• The component is your application

J1-680, Hapner/Shannon 14

J2EE Containers

• Containers do their work invisibly– No complicated APIs– They control by interposition

• Containers implement J2EE– Look the same to components– Have great freedom to innovate

J1-680, Hapner/Shannon 15

J2EE Containers Handle

• Concurrency(multi user)

• Consistency(Transactions)

• Security

• Availability

• Scalability

• Administration

• Integration

• Distribution

J1-680, Hapner/Shannon 16

J2EE Components Handle

• Presentation

• Business logic

• Data access

J1-680, Hapner/Shannon 17

Container Perspectives

• To a J2EE vendor– It is their product

• To a component developer– It is a standard app model

• To an app assembler– It is a standard app package

• To an executing component– It is god

J1-680, Hapner/Shannon 18

Why Does J2EE Focus onDeployment?

J1-680, Hapner/Shannon 19

EJBEJB

ApplicationClient ModuleApplication

Client Module

EJBEJB

EJBEJB

WEBWEB

WEBWEB

Web Client Module

Web Client Module

EJBModule

EJBModule

Deployment Tool

Deployment Tool

APPDD

APPDDDDDD

DDDD

DDDD

DDDD

DDDD

DDDD

11

22

33

11

22

33

Application Packaging

J1-680, Hapner/Shannon 20

Creation Assembly Deployment

Created by Component Developer

Created by Component Developer

Assembledand Augmentedby Application

Assembler

Assembledand Augmentedby Application

Assembler

Processed by DeployerProcessed by Deployer

Deploy

EnterpriseComponentsEnterprise

Components

J2EE ContainerJ2EE Container

J2EE APPJ2EE Modules

Application Life Cycle

J1-680, Hapner/Shannon 21

The Deplo yer

• Is an expert in the operationalenvironment– Familiar with local security practices– Familiar with local EIS configuration– Familiar with local containers and their apps

• Uses J2EE platform product tools

J1-680, Hapner/Shannon 25

Deplo yment Summar y

• Apps may be written without knowledgeof the operational environment

• Deployment Descriptor communicatesapp’s needs

• A key interface between applicationdeveloper and platform

J1-680, Hapner/Shannon 26

What Exactly Is in J2EE?

J1-680, Hapner/Shannon 27

J2EE API Summar y

• J2SE 1.2

• JDBC™ 2.0

• RMI/IIOP 1.0

• EJB 1.1

• Servlet 2.2

• JSP 1.1

• JNDI 1.2

• JTA 1.0

• JMS 1.0

• JavaMail™ 1.1

• JAF 1.0

J1-680, Hapner/Shannon 28

J2EE Standards

• TCP/IP

• HTTP 1.0

• HTML 3.2

• SSL 3.0

• IIOP 1.0

J1-680, Hapner/Shannon 29

The Java ™ 2 Platform,Enterprise Edition

• Platform Specification– Defines J2EE requirements

• Compatibility Test Suite– Validates J2EE platform compatibility

• Reference Implementation– Operational J2EE platform

• Application Programming Model– Describes how to build J2EE applications

J1-677, Kassem 3

Java™ 2 Platform, Enterprise EditionApplication Programming Model (APM)

• Organized set of design patterns,templates and architectural principles– Focus is on design of manageable, deployable

and maintainable J2EE applications– Results in faster product delivery time to market

of enterprise solutions

• Recommends how the J2EE specificationsshould be applied to application domains

J1-677, Kassem 6

Some Ke y APM Questions

• Choose Servlets or JavaServer Pages™technology (JSP)?

• Access EIS Resources via EnterpriseJavaBeans™ technology (EJB) serveror Directly from JSP?

• Session Beans or Entity Beans?

• Distributed transactions or localtransactions?

• How to exchange Data withExternal Systems?

J1-677, Kassem 7

Client

Client

Client

Client

Client

Client Tier EIS TierMiddle Tier

Enterprise Information

Systems (EIS):

Relational-Database,Legacy Applications,

ERP Systems

EnterpriseJavaBeanEnterpriseJavaBean

EnterpriseJavaBeanEnterpriseJavaBean

Other Services:JNDI, JMS,Java Mail

Other Services:JNDI, JMS,Java Mail

ApplicationServer

ApplicationServer

Web ServerJSP, Servlet, HTML, XML

Firewall

The J2EE EnvironmentEnabling End-to-end Solutions

J1-677, Kassem 8

Web Access

• Exposes application logic to web client(s)as coarse grained service(s):– Responsible for handling “user” input/application

presentation– Named via URI– Modeled as HTML (or XML)

• Comprised of dynamic and static content– Java Server Pages for dynamic content:

• Higher level of abstraction than Servlets

• Easier to generate HTML(and XML in future)

J1-677, Kassem 9

“Other” Clients

• EJB from another “application”:– RMI/IIOP now, JMS later

• Standalone “clients”:– CORBA client:

• IIOP access direct to application logic– Java technology client:

• RMI/IIOP or JMS access– Desktop productivity application:

• MS desktop integration solution viaplug-in, JRE and RMI/IIOP

J1-677, Kassem 11

Application Lo gic

• Modeled using EJBs:– SessionBean (stateless & stateful)– EntityBean (CMP or BMP)– Componentize:

• Workflow, processes, business rules and entities…

• Fine grain imperative interface contract

• External resources are logicallynamed internally– Customized via deployment descriptor– Resolved by deployer at deployment time

J1-677, Kassem 12

Enterprise InformationServices (EIS)

• Integration is achieved by either:– Directly using platform API such as:

• JDBC™

• JMS

• Java Naming and Directory Interface ™ (JNDI)– Or via Connector(s):

• Connector is:– Resource adapter, Access Bean,

integration tool(s)

• Ubiquitous Connector APIs for specificEIS products

J1-677, Kassem 13

Middle Tier

Entity EJPEntity EJPClient

Session EJPSession EJPServlet/JSPServlet/JSP

HTTP(S) ServiceHTTP(S) Service

Data AccessBean

Data AccessBean

Data AccessBean

Data AccessBean

JNDIJNDI

ConnectorConnector

ConnectorConnector

EISEIS

EISEIS

EJB ContainerEJB Container

EJB Components

J1-677, Kassem 14

Application Scenarios

EISResources

Browser

Stand-alone

Web ServerWeb Server App. ServerApp. Server

Web ServerWeb Server App. ServerApp. Server

2

3 4

5

1

76

J1-677, Kassem 15

1

3

5

7

SampleApp.

Core Application Scenarios

• n-tier Web Access– HTML, XML, HTTP client– JSP/Servlets, RMI/IIOP– EJBs, JDBC (Connectors)

• n-tier Intranet Access– EJB Client, EJB Sever

• 2-tier Java Client– JSP/Servlets and JDBC

• B2B Enterprise Transactions– EJBs, JMS and XML

J1-677, Kassem 16

Sample ApplicationHigh Level Requirements

• Must offer Web Presence

• Must be Robust and Scalable

• Must leverage existing EIS resources

• Must utilize core competencies of diversedevelopment teams

• Must facilitate B2B transactions

• Get it done yesterday!

J1-677, Kassem 17

Sample ApplicationHigh Level Technical Decisions

• Client tier– Chose HTML Clients for End-User Web Access– Chose XML for selective Data externalization

• Web Server tier– Chose JSP/Servlets to be WS neutral

• App Server tier– Chose EJB’s to be AS neutral– JDBC Data Access Beans to encapsulate

EIS access– Chose to optionally support distributed

transactions

J1-677, Kassem 19

SA—Scenario

• Web-based browsing of a product catalog

• Creation and maintenance of ashopping cart

• User account creation

• Placing orders

• Secure order processing– B2B transactions– Externalization of order data

(expressed in XML)– Order confirmation using e-mail

J1-677, Kassem 20

View CatalogView Catalog

Add to CartAdd to Cart

Select AccountSelect AccountProcess OrderProcess Order

Pull StockPull Stock

Ship OrderShip Order

Receive OrderReceive Order Bill CustomerBill Customer

Pay BillPay BillClose OrderClose Order

Customer Sales Warehouse

SA—Activit y Diagram

J1-677, Kassem 21

table supplier (

suppid...)

table account (

userid...)

table orders (

orderid userid...)

table product (

productid category...)

table category (

catid ...)

table orderstatus (

orderid linenum...)

table lineitem (

orderid linenum itemid...)

table inventoryitem (

itemid productid supplier...)

table attrdesc (

attrcode...)

SA—DB Schema

J1-677, Kassem 22

SA—Architecture

Tables Physical DBs

Access BeansSession Beans Entity Beans

AccountAccount

OrdersOrders

OrderStatusOrderStatus

Line itemLine item

CategoryCategory

ProductProduct

InventoryInventory

AccountDAB

OrderDAB

CatalogDAB

InventoryDAB

AccountEJB

OrderEJB

UserValidatorEJB

MailerEJB

ShoppingCartEJB

EStoreKeeperEJB

CatalogEJB

InventoryEJB

db1

db2

J1-677, Kassem 23

SA—JSP Usa ge

<html>

<jsp:request include="/banner.html"/>

<form action=" validatenewuseraccount.jsp " name="login">

<table border ="0">

<tr><td>User ID:</td>

<td align="left"><input type="text" size="15" name="user_name"></td>

</tr>

<tr><td>Password:</td>

<td align="left"><input type="password" size="15" name ="password"></td>

</tr>

…..

</table>

</html>

J1-677, Kassem 24

<html>

<% if (formValid){ %>

<jsp:useBean id="useraccount"class="com.sunw.estore.account.jspbeans. UserAccountJSPBean "scope="session" />

<jsp:setProperty name="useraccount" property="init" value="<%= session %>"/>

<jsp:setProperty name="useraccount" property="billingLastName"param="last_name" />

...

<% } else { %>

...

<% } %>

</html>

SA—JSP Usa ge

J1-677, Kassem 25

public interface EStorekeeper extends EJBObject { public Catalog getCatalog() throws RemoteException; public ShoppingCart getShoppingCart() throws RemoteException; public Credential getCredential() throws RemoteException; public Account getAccount() throws RemoteException; public Enumeration getOrders() throws RemoteException,

FinderException; public void handleEvent(EStoreEvent se) throws RemoteException;}

SA—Controller Interface

J1-677, Kassem 26

public class EStorekeeperEJB implements SessionBean { public void ejbCreate() throws RemoteException { sm = new StateMachine(this); } public Catalog getCatalog() throws RemoteException { if (catalog == null) { try { Context initial = new InitialContext(); Object objref = initial.lookup (EJBUtil.jndiNameOfCatalogHome); CatalogHome catalogHome = (CatalogHome) PortableRemoteObject.narrow(objref, CatalogHome.class); catalog = catalogHome.create(); } catch (NamingException ne) { ... } return catalog; }

Locate Catalog EJB’s H/I using JNDI

SA—Controller Implementation

J1-677, Kassem 31

Application Model

• Makes Recommendations across all tiers– Client– Middle-tier (includes Web server and EJB)– Data access– Messaging– External application integration– Communication protocols– Deployment file formats

• Results in Faster product delivery

J1-677, Kassem 32

J2EE Resources

• White paper:– http://java.sun.com/j2ee