55
1 J2EE J2EE

1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE? Main component types Application Scenarios J2EE APIs and Services 3. EJB – a closer look

Embed Size (px)

Citation preview

Page 1: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

1

J2EE J2EE

Page 2: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

2

Agenda1. Application servers2. What is J2EE?

Main component types Application Scenarios J2EE APIs and Services

3. EJB – a closer look4. Examples

Page 3: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

3

1. Application Servers In the beginning, there was darkness and

cold. Then, …

Centralized, non-distributed

terminals

mainframe

terminals

Page 4: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

4

Application Servers In the 90’s, systems should be client-

server

Page 5: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

5

Application Servers

Today, enterprise applications use the multi-tier model

Page 6: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

6

Application Servers

“Multi-tier applications” have several independent components

An application server provides the infrastructure and services to run such applications

Page 7: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

7

Application Servers

Application server products can be separated into 3 categories: J2EE-based solutions Non-J2EE solutions (PHP, ColdFusion, Perl,

etc.) And the Microsoft solution (ASP/COM and

now .NET with ASP.NET, VB.NET, C#, etc.)

Page 8: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

8

J2EE Application Servers

Major J2EE products: BEA WebLogic IBM WebSphere Sun iPlanet Application Server Oracle 9iAS HP/Bluestone Total-e-Server Borland AppServer Jboss (free open source)

Page 9: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

9

Web Server and Application Server

Web Server

(HTTP Server)

App Server 1

App Server 2

Internet Browser

HTTP(S)

Page 10: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

10

2. What is J2EE?

It is a public specification that embodies several technologies

Current version is 1.6 J2EE defines a model for developing

multi-tier, web based, enterprise applications with distributed components

Page 11: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

11

J2EE Benefits

High availability Scalability Integration with existing systems Freedom to choose vendors of

application servers, tools, components Multi-platform

Page 12: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

12

J2EE Benefits

Flexibility of scenarios and support to several types of clients

Programming productivity: Services allow developer to focus on business Component development facilitates maintenance

and reuse Enables deploy-time behaviors Supports division of labor

Page 13: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

13

Main technologies

JavaServer Pages (JSP) Servlet Enterprise JavaBeans (EJB)

JSPs, servlets and EJBs are application components

Page 14: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

14

JSP Used for web pages with dynamic content Processes HTTP requests (non-blocking

call-and-return) Accepts HTML tags, special JSP tags, and

scriptlets of Java code Separates static content from presentation

logic Can be created by web designer using

HTML tools

Page 15: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

15

Servlet Used for web pages with dynamic content Processes HTTP requests (non-blocking call-

and-return) Written in Java; uses print statements to

render HTML Loaded into memory once and then called

many times Provides APIs for session management

Page 16: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

16

EJB EJBs are distributed components used to

implement business logic (no UI) Developer concentrates on business logic Availability, scalability, security,

interoperability and integrability handled by the J2EE server

Client of EJBs can be JSPs, servlets, other EJBs and external aplications

Clients see interfaces

Page 17: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

17

J2EE Multi-tier Model

Page 18: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

18

J2EE Application Scenarios

Multi-tier typical application

Page 19: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

19

J2EE Application Scenarios

Stand-alone client

Page 20: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

20

J2EE Application Scenarios

Web-centric application

Page 21: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

21

J2EE Application Scenarios

Business-to-business

Page 22: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

22

J2EE Services and APIs

Java Message Service (JMS) Implicit invocation Communication is loosely coupled,

reliable and asynchronous Supports 2 models:

point-to-point publish/subscribe

Page 23: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

23

JMS Point-to-point

Destination is “queue”

Page 24: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

24

JMS Publish-subscribe

Destination is “topic”

Page 25: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

25

J2EE Services and APIs

JNDI - Naming and directory services Applications use JNDI to locate objects,

such as environment entries, EJBs, datasources, message queues

JNDI is implementation independent Underlying implementation varies: LDAP,

DNS, DBMS, etc.

Page 26: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

26

J2EE Services and APIs

Transaction service: Controls transactions automatically You can demarcate transactions explicitly Or you can specify relationships between

methods that make up a single transaction

Page 27: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

27

J2EE Services and APIs

Security Java Authentication and Authorization Service

(JAAS) is the standard for J2EE security Authentication via userid/password or digital

certificates Role-based authorization limits access of users to

resources (URLs, EJB methods) Embedded security realm

Page 28: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

28

J2EE Services and APIs

J2EE Connector Architecture Integration to non-J2EE systems, such as

mainframes and ERPs. Standard API to access different EIS Vendors implement EIS-specific resource

adapters Support to Corba clients

Page 29: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

29

J2EE Services and APIs

JDBC JavaMail Java API for XML Parsing (JAXP) Web services APIs

Page 30: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

30

3. EJB – a closer look

Page 31: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

31

Home Interface

Methods to create, remove or locate EJB objects

The home interface implementation is the home object (generated)

The home object is a factory

Page 32: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

32

Remote Interface

Business methods available to clients The remote interface implementation

is the EJB object (generated) The EJB object acts as a proxy to the

EJB instance

Page 33: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

33

EJB – The Big Picture

Page 34: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

34

EJB at runtime

Client can be local or remote

Page 35: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

35

EJB at runtime

Page 36: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

36

Types of EJB

EJB Taxonomy

Sta te ful

Sta te le ss

SessionBea n

BMP

C MP

EntityBea n M essa geDrivenBea n

Ente rp riseBea n

New!

Page 37: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

37

Session Bean

Stateful session bean: Retains conversational state (data) on

behalf of an individual client If state changed during this invocation, the

same state will be available upon the following invocation

Example: shopping cart

Page 38: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

38

Session Bean

Stateless session bean: Contains no user-specific data Business process that provides a generic

service Container can pool stateless beans Example: shopping catalog

Page 39: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

39

Entity Bean Represents business data stored in a

database persistent object Underlying data is normally one row of a

table A primary key uniquely identifies each bean

instance Allows shared access from multiple clients Can live past the duration of client’s session Example: shopping order

Page 40: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

40

Entity Bean

Bean-managed persistence (BMP): bean developer writes JDBC code to access the database; allows better control for the developer

Container-managed persistence (CMP): container generates all JDBC code to access the database; developer has less code to write, but also less control

Page 41: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

41

Message-Driven Bean

Message consumer for a JMS queue or topic

Benefits from EJB container services that are not available to standard JMS consumers

Has no home or remote interface Example: order processing – stock info

Page 42: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

42

4. Examples

JSP example Servlet example EJB example

Page 43: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

43

JSP example

Page 44: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

44

JSP example<%@ page import="hello.Greeting" %><jsp:useBean id="mybean" scope="page"

class="hello.Greeting"/><jsp:setProperty name="mybean" property="*" /><html><head><title>Hello, User</title></head><body bgcolor="#ffffff" background="background.gif"><%@ include file="dukebanner.html" %><table border="0" width="700"><tr><td width="150"> &nbsp; </td><td width="550"> <h1>My name is Duke. What's yours?</h1></td></tr>

Page 45: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

45

JSP example<tr> <td width="150" &nbsp; </td> <td width="550"><form method="get"><input type="text" name="username" size="25"> <br><input type="submit" value="Submit"><input type="reset" value="Reset"></td> </tr></form> </table><% if (request.getParameter("username") != null) {%><%@ include file="response.jsp" %><% }%></body></html>

Page 46: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

46

Servlet examplepublic class HelloWorldServlet extends HttpServlet {

public void service(HttpServletRequest req,

HttpServletResponse res) throws IOException {

res.setContentType("text/html");

PrintWriter out = res.getWriter();

out.println("<html><head><title>Hello

World Servlet</title></head>");

out.println("<body><h1>Hello

World!</h1></body></html>");

}

}

Page 47: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

47

EJB Example// Shopping Cart example

// Home interface

public interface CartHome extends EJBHome {

Cart create(String person)

throws RemoteException, CreateException;

Cart create(String person, String id)

throws RemoteException, CreateException;

}

Page 48: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

48

EJB Example// Remote interface

public interface Cart extends EJBObject {

public void addBook(String title)

throws RemoteException;

public void removeBook(String title)

throws BookException, RemoteException;

public Vector getContents()

throws RemoteException;

}

Page 49: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

49

EJB Example// Enterprise bean classpublic class CartEJB implements SessionBean { String customerName, customerId; Vector contents; private SessionContext sc;

public void ejbCreate(String person) throws CreateException { if (person == null) { throw new CreateException("Null person not allowed."); } else { customerName = person; } customerId = "0"; contents = new Vector(); }

Page 50: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

50

EJB Example public void ejbCreate(String person, String id) throws CreateException { if (person == null) { throw new CreateException("Null person not allowed."); } else { customerName = person; } IdVerifier idChecker = new IdVerifier(); if (idChecker.validate(id)) { customerId = id; } else { throw new CreateException("Invalid id: " + id); } contents = new Vector(); }

Page 51: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

51

EJB Example public void addBook(String title) { contents. addElement(title); }

public void removeBook(String title) throws BookException { boolean result = contents.removeElement(title); if (result == false) { throw new BookException(title + " not in cart."); } }

public Vector getContents() { return contents; }

. . .}

Page 52: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

52

EJB Example// EJB client (stand-alone application)public class CartClient { public static void main(String[] args) { try { CartHome home = (CartHome)initial.lookup("MyCart"); Cart shoppingCart = home.create("Duke DeEarl", "123"); shoppingCart.addBook("The Martian Chronicles"); shoppingCart.addBook("2001 A Space Odyssey"); shoppingCart.remove(); } catch (BookException ex) { System.err.println("Caught a BookException: " + ex.getMessage()); } catch (Exception ex) { System.err.println("Caught an unexpected exception!"); } }}

Page 53: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

53

Questions

Page 54: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

54

Sources & Resources Java 2 Platform Enterprise Edition

Specification, v1.3 Designing Enterprise Applications with the

Java 2, Enterprise Edition. Nicholas Kassen and the Enterprise Team

Does the App Server Maket Still Exist? Jean-Christophe Cimetiere

The State of The J2EE Application Server Market. Floyd Marinescu

Page 55: 1 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look

55

Sources & Resources

The J2EE Tutorial. Sun Microsystems IBM WebSphere Application Server

manuals BEA WebLogic Server manuals www.java.sun.com/j2ee www.theserverside.com