55
1 Java 2 Platform, Enterprise Edition (J2EE): Enabling Technologies for EAI Tony Ng, Staff Engineer Rahul Sharma, Senior Staff Engineer Sun Microsystems Inc.

Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

Embed Size (px)

Citation preview

Page 1: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

1

Java 2 Platform,Enterprise Edition (J2EE):

Enabling Technologies for EAI

Tony Ng, Staff EngineerRahul Sharma, Senior Staff Engineer

Sun Microsystems Inc.

Page 2: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

2

J2EE Overview

Tony Ng, Staff EngineerSun Microsystems Inc.

Page 3: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

3

What is Java 2 Platform, Enterprise Edition?• Java 2 Enterprise Edition (J2EE) is a

platform that enables solutions for developing, deploying and managing n-tier server-centric enterprise applications.

• J2EE provides building blocks for EAI

Page 4: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

4

Java™ Platforms

Java Technology

Enabled Desktop

WorkgroupServer

Java TechnologyEnabled Devices

High-EndServer

Page 5: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

5

J2EE Integrated Platform

Transactions

Mail

ObjectsDirectory

Transactions

Messaging

Transactions Messaging Directory

Data Objects Mail

Page 6: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

6

J2EE Platform Deliverables

• J2EE specification– Defines the J2EE requirements

• J2EE reference implementation– Prototype of J2EE platform

• J2EE compatibility test suite– Vaidates J2EE platform compatibility

• J2EE blueprints– Best practices for J2EE solutions

Page 7: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

7

J2EE Reference Implementation

• Fully functional prototype• Allow development of compatibility tests• Help developers prototype J2EE

technology-enabled applications• Help server platform and tool vendors

build J2EE platform support in their products

• Source code available

Page 8: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

8

Compatibility Test Suite

• Allow branding of compatible servers• Ensure all J2EE implementations

branded by Sun conform to the J2EE specification

• Move us towards the goal of Write Once, Run Anywhere

Page 9: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

9

J2EE Blueprints

• Best practices for J2EE– Examples, patterns, templates

• J2EE blueprints include:– Book, Designing Enterprise Applications– Application— “Java Pet Store”

Page 10: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

10

J2EE Architecture

Page 11: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

11

J2EE Components

• Enterprise JavaBeansTM (EJB™)– Business logic

• JavaServer PagesTM (JSP)– Dynamic content

• Servlet– Portable CGI script

• Application Client– First-tier Java application

Page 12: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

12

J2EE Technologies

• J2EE Connector Architecture– Enterprise systems integration

• Java Message Service (JMS)– Asynchronous messaging

• Java API for XML Processing– XML transformation

• Java Transaction API– Data integrity

Page 13: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

13

J2EE Technologies (Cont...)

• Java Naming and Directory Interface (JNDI)– Enterprise directory

• JavaMail– Email Notification

• JDBC– Database connectivity

• JavaIDL, RMI, CORBA– Remote services

Page 14: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

14

J2EE Containers

• Container handles:– Concurrency– Transactions– Security– Scalability– Distribution

• Components provide:– Business logic– Presentation

Page 15: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

15

J2EE Components and Containers

JND

I

J2SE

JMS

RM

I/IIO

PJD

BC

DatabaseDatabase

AppAppClientClient

App Client App Client ContainerContainer

HTTP/HTTP/HTTPSHTTPS

J2SEJ2SERMIRMI

J2SEJ2SE

JND

IJN

DI

JMS

JMS

RM

I/IIO

PR

MI/I

IOP

JDB

CJD

BC

JTA

JTA JavaMailJavaMail

JAFJAF JND

IJN

DI

JMS

JMS

RM

I/IIO

PR

MI/I

IOP

JDB

CJD

BC

JTA

JTA JavaMailJavaMail

JAFJAF

HTTP/HTTP/HTTPHTTP

SS

Applet Applet ContainerContainer

AppletApplet JSPJSP ServletServlet EJBEJB

Web ContainerWeb Container EJB ContainerEJB Container

RMIRMI

J2SEJ2SE

Page 16: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

16

Benefits of Using J2EE

• Faster solution delivery time to market– Components– JavaServer Pages, EJB and other APIs

• Freedom of choice– No vendor lock– Skill reuse

• Simplified connectivity– JDBC, Connector, CORBA, JMS

Page 17: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

17

J2EE and EAI

• Components and containers:– EJB:business process– Servlet, JSP: web components

• JAXP: XML parsing and transformation

• Connectors: EIS integration

• JMS: Asynchronous messaging

• Future: JAXM, XML data binding

Page 18: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

18

Building EAI framework

• J2EE provides building blocks• EAI frameworks add:

– Intelligent routing– Metadata facility– Rules engine– Integration of business processes– Workflow– Tools

Page 19: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

19

Enterprise JavaBeans

Tony Ng, Staff EngineerSun Microsystems Inc.

Page 20: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

20

The Problem

• Difficult to write distributed, n-tier applications

• Focus on business logic, not plumbing• Multi-platform, heterogeneous

environment• Time to market

Page 21: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

21

What Is the Enterprise JavaBeans Architecture?• A component architecture for the

development and deployment of distributed business applications

• Goals– Simplify development and deployment of

business applications– Separate business logic from system code– Portable components (Write Once,

Run Anywhere™)– Allow multi-vendor interoperability

Page 22: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

22

EJB Features

• Flexible component model• Attribute-based application semantics• Transaction: Declarative and

programmatic• Security: ACLs on operations• Distributed access: home and remote

interfaces• Deployment: ejb-jar file

Page 23: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

23

Benefits

• Simplifies development• Write once, run anywhere• Industry support• Vendor/platform independent• Partitioning of expertise

Page 24: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

24

Types of Enterprise Beans

• Session Beans– Stateless– Stateful

• Entity Beans– Bean-managed persistence– Container-managed persistence

• Message-Driven Beans

Page 25: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

25

Session Beans

• On behalf of a single client• May keep conversation state (stateful)• Relatively short-lived: client session• Do not survive server crashes• Example: shopping cart

Page 26: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

26

Entity Beans

• Represents business entities• Shared access for multiple users• Long-lived: as long as data in database• Transactional• Survive server crashes• Container Managed Persistence:

– Relationships, EJB-QL• Example: Account, Employee

Page 27: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

27

Message-driven Beans

• New enterprise bean type– Asynchronous– Activated upon message arrival– Stateless– No home or remote interface– Configured as listener for queue/topic

Page 28: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

28

Message-driven Bean Scenario

OrderBean

InventoryManagement

Bean

Mail

MessageDrivenBean

JMS Topics

Publish/subscribe

ProcessOrder

Procure Inventory

<Entity EJB>

<Entity EJB>

Database

Page 29: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

29

Roles

• Enterprise bean provider• Application assemblers• Deployers• System administrator• EJB server/container provider

Page 30: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

30

Deployment Descriptor

• Declarative rather than programmatic• Allows easy customization• Transaction attributes• Security attributes• Access control list• Resource and EJB references• Environment properties

Page 31: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

31

Transaction

• Declarative or programmatic• Transparent support for distributed

transaction• EJB server handles

– transaction boundaries– propagation– resource enlistments

Page 32: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

32

Security

• Declarative and/or programmatic• Access control list on business

methods• RunAs mode• Security-related methods in enterprise

bean context

Page 33: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

33

Writing Enterprise beans

• Implement business methods and component contract

• Define home and remote interface• Define deployment descriptor• Deploy and Run• Tools support

Page 34: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

34

Home Interface

• Allows a client to create, locate or destroy a bean

• Example:public interface AccountHome extends EJBHome {

public Account create(String ssn, String name)throws CreateException, RemoteException;

public Account findByPrimaryKey(String ssn)

throws FinderException, RemoteException;

}

Page 35: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

35

Remote Interface

• Exposes business methods to clients• Example:public interface Account extends EJBObject {

public void debit(double amount) throws

InsufficientBalanceException, RemoteException;

public void credit(double amount) throws

RemoteException;

public double getBalance() throws

RemoteException;

}

Page 36: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

36

Business Logic

public class AccountBean implements EntityBean {

// entity state

private String name;

private double balance;

public void debit(double amount) throws

InsufficientBalanceException {

if (balance - amount < 0.0) {

throw new InsufficientBalanceException();

}

balance -= amount;

}

// more business methods and

// component contract implementation

}

Page 37: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

37

XML Support in J2EE

Tony Ng, Staff EngineerSun Microsystems Inc.

Page 38: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

38

XML in J2EE

• Java API for XML Processing• Future Technologies:

– Java API for XML Messaging (JAXM)– Java XML Data Binding

Page 39: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

39

JAXP 1.1

• Java Community Process initiative JSR-000063

• Feature list:– SAX2.0.– SAX 2 extensions.– DOM Level 2 Core interfaces.– XSLT 1.0– Improved mechanism for factory lookup.

Page 40: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

40

JAXP: Processing APIs for Java

User Application

Reference Impl Other Impl

JAXP Interfaces

Page 41: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

41

JAXP Description

• A lightweight API for parsing XML Documents

• API for transformation, referred to as TrAX.

• Allows for pluggable parsers• Allows for pluggable XSLT enginges.• Allows processing of XML using:

– Callback Driven (SAX)– Tree Based (DOM)– XSL Transformation.

Page 42: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

42

SAX2.0 API

• Simple API for XML• Accesses Documents Serially• Fast and Lightweight• Harder to Program• Sequential Access Only• Org.xml.sax• Org.xml.sax.ext

Page 43: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

43

SAX 2.0 (Contd)

ProvidedHandler

XMLDocument Parser

EventsInput

Page 44: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

44

SAX used via JAXP

import java.xml.parsers.*import org.xml.sax.*

SAXParserFactory factory = SAXParserFactory.newInstance();factory.setValidating(true);SAXParser parser = factory.newSAXParser();parser.parse("http://server.com/foo.xml", handler);

// can also parse InputStreams, Files, and // SAX input sources.

Page 45: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

45

SAX ContentHandler

import org.xml.sax.*

public class MyHandler implements ContentHandler {public void startDocument() throws SAXException {

// start processing here. Could store it in a // stack and build your own tree representation// This is the first method invoked

}

public void endDocument() throws SAXException {// This is the last method invoked on the

// handler}

}

Page 46: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

46

DOM Level 2

• Document Object Model• Access XML document via a tree

structure• Composed of element nodes and text

nodes• Can "walk" the tree back and forth• Larger memory requirements• org.w3c.dom.*

Page 47: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

47

DOM Level 2 (Contd)

XMLDocument Parser

Input Creates Tree

Page 48: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

48

DOM used via JAXP

import java.xml.parsers.*import org.w3c.dom.*

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();factory.setValidating(true);DocumentBuilder builder = factory.newDocumentBuilder();Document doc =

builder.parse("http://server.com/foo.xml");

// can also parse InputStreams, Files, and // SAX input sources.

Page 49: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

49

XSLT 1.0

• XSL Transformations.• Syntax and semantics for transforming

xml documents into other xml documents or any other format.

• Expressed as a well-formed xml document.

• Recommended Processing Instruction to apply to an xml document– <?xml-stylesheet href="mystyle.css"

type="text/css"?>

Page 50: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

50

XSLT 1.0 (Contd)

XMLDocument

XSLT Processor

Input

XSLStylesheet

Resulting XML

Document

Result

Page 51: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

51

XSLT used via JAXP

import java.xml.transform.*;

Transformer transformer;TransformerFactory factory = TransformerFactory.newInstance();try {

// Create a transformer for a particular stylesheet.transformer = factory.newTransformer(new StreamSource(stylesheet));

// Transform the source xml to System.out.transformer.transform(new StreamSource(sourceId),new StreamSource(System.out));

} catch (Exception e) {// handle error

}

Page 52: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

52

XSLT used via JAXP (contd)The following example illustrates the serialization of a DOM node to an XML stream.

import java.xml.transform.*;

TransformerFactory tfactory = TransformerFactory.newInstance();Transformer serializer = tfactory.newTransformer();Properties oprops = new Properties();oprops.put(“method”, “html”);oprops.put(“indent-amount”, “2”);serializer.setOutputProperties(oprops);serializer.transform(new DOMSource(doc),new StreamResult(System.out));

Page 53: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

53

Plugability

• Factory lookup is accomplished by– System property

• javax.xml.parsers.SAXParserFactory• javax.xml.parsers.DocumentBuilderFactory• javax.xml.transform.TransformerFactory

– $JAVA_HOME/lib/jaxp.properties file– Jar Services API

• META-INF/services/javax.xml.parsers.XXXFactory

– Reference Default

Page 54: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

54

Reference Implementation

• Parser and XSLT Engine based on ASF Code

• Apache Crimson for XML Parsing• Apache Xalan for XSLT Processing

Page 55: Java 2 Platform, Enterprise Edition (J2EE): Enabling ... · PDF file• Java 2 Enterprise Edition (J2EE) is a ... • JavaMail – Email Notification ... XML in J2EE • Java API for

55

Current Status

• Public Review 2 of the spec and beta of the RI can be obtained by following links from – http://java.sun.com/xml

• eedback aliases

[email protected]