Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Copyright 2002 © Paulo Merson J2EE – Building Component-based Enterprise Web Applications 05/09/2002 Paulo Merson.

Similar presentations


Presentation on theme: "1 Copyright 2002 © Paulo Merson J2EE – Building Component-based Enterprise Web Applications 05/09/2002 Paulo Merson."— Presentation transcript:

1 1 Copyright 2002 © Paulo Merson J2EE – Building Component-based Enterprise Web Applications 05/09/2002 Paulo Merson

2 2 Copyright 2002 © Paulo Merson Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look 4. Examples

3 3 Copyright 2002 © Paulo Merson 1. Application Servers  In the beginning, there was darkness and cold. Then, … Centralized, non-distributed terminals mainframe terminals

4 4 Copyright 2002 © Paulo Merson Application Servers  In the 90’s, systems should be client- server

5 5 Copyright 2002 © Paulo Merson Application Servers  Today, enterprise applications use the multi-tier model

6 6 Copyright 2002 © Paulo Merson Application Servers  “Multi-tier applications” have several independent components  An application server provides the infrastructure and services to run such applications

7 7 Copyright 2002 © Paulo Merson 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.)

8 8 Copyright 2002 © Paulo Merson 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)

9 9 Copyright 2002 © Paulo Merson Web Server and Application Server Web Server (HTTP Server) App Server 1 App Server 2 Internet Browser HTTP(S)

10 10 Copyright 2002 © Paulo Merson 2. What is J2EE?  It is a public specification that embodies several technologies  Current version is 1.3  J2EE defines a model for developing multi-tier, web based, enterprise applications with distributed components

11 11 Copyright 2002 © Paulo Merson J2EE Benefits  High availability  Scalability  Integration with existing systems  Freedom to choose vendors of application servers, tools, components  Multi-platform

12 12 Copyright 2002 © Paulo Merson 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

13 13 Copyright 2002 © Paulo Merson J2EE Benefits Don’t forget to say that Java is cool!

14 14 Copyright 2002 © Paulo Merson Main technologies  JavaServer Pages (JSP)  Servlet  Enterprise JavaBeans (EJB)  JSPs, servlets and EJBs are application components

15 15 Copyright 2002 © Paulo Merson 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

16 16 Copyright 2002 © Paulo Merson 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

17 17 Copyright 2002 © Paulo Merson 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

18 18 Copyright 2002 © Paulo Merson J2EE Multi-tier Model

19 19 Copyright 2002 © Paulo Merson J2EE Application Scenarios  Multi-tier typical application

20 20 Copyright 2002 © Paulo Merson J2EE Application Scenarios  Stand-alone client

21 21 Copyright 2002 © Paulo Merson J2EE Application Scenarios  Web-centric application

22 22 Copyright 2002 © Paulo Merson J2EE Application Scenarios  Business-to-business

23 23 Copyright 2002 © Paulo Merson 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

24 24 Copyright 2002 © Paulo Merson JMS  Point-to-point Destination is “queue”

25 25 Copyright 2002 © Paulo Merson JMS  Publish-subscribe Destination is “topic”

26 26 Copyright 2002 © Paulo Merson 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.

27 27 Copyright 2002 © Paulo Merson 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

28 28 Copyright 2002 © Paulo Merson J2EE Services and APIs  Security Java Authentication and Authorization Service (JAAS) is the new (J2EE 1.3) 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

29 29 Copyright 2002 © Paulo Merson 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

30 30 Copyright 2002 © Paulo Merson J2EE Services and APIs  JDBC  JavaMail  Java API for XML Parsing (JAXP)  Web services APIs

31 31 Copyright 2002 © Paulo Merson 3. EJB – a closer look

32 32 Copyright 2002 © Paulo Merson 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

33 33 Copyright 2002 © Paulo Merson 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

34 34 Copyright 2002 © Paulo Merson

35 35 Copyright 2002 © Paulo Merson EJB – The Big Picture

36 36 Copyright 2002 © Paulo Merson EJB at runtime Client can be local or remote

37 37 Copyright 2002 © Paulo Merson EJB at runtime

38 38 Copyright 2002 © Paulo Merson Types of EJB New!

39 39 Copyright 2002 © Paulo Merson 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

40 40 Copyright 2002 © Paulo Merson 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

41 41 Copyright 2002 © Paulo Merson 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

42 42 Copyright 2002 © Paulo Merson 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

43 43 Copyright 2002 © Paulo Merson 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

44 44 Copyright 2002 © Paulo Merson 4. Examples  JSP example  Servlet example  EJB example

45 45 Copyright 2002 © Paulo Merson JSP example

46 46 Copyright 2002 © Paulo Merson JSP example Hello, User My name is Duke. What's yours?

47 47 Copyright 2002 © Paulo Merson JSP example <% if (request.getParameter("username") != null) { %> <% } %>

48 48 Copyright 2002 © Paulo Merson Servlet example public class HelloWorldServlet extends HttpServlet { public void service(HttpServletRequest req, HttpServletResponse res) throws IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println(" Hello World Servlet "); out.println(" Hello World! "); }

49 49 Copyright 2002 © Paulo Merson 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; }

50 50 Copyright 2002 © Paulo Merson 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; }

51 51 Copyright 2002 © Paulo Merson EJB Example // Enterprise bean class public 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(); }

52 52 Copyright 2002 © Paulo Merson 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(); }

53 53 Copyright 2002 © Paulo Merson 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; }... }

54 54 Copyright 2002 © Paulo Merson 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!"); }

55 55 Copyright 2002 © Paulo Merson Questions

56 56 Copyright 2002 © Paulo Merson 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

57 57 Copyright 2002 © Paulo Merson Sources & Resources  The J2EE Tutorial. Sun Microsystems  IBM WebSphere Application Server manuals  BEA WebLogic Server manuals  www.java.sun.com/j2ee  www.theserverside.com


Download ppt "1 Copyright 2002 © Paulo Merson J2EE – Building Component-based Enterprise Web Applications 05/09/2002 Paulo Merson."

Similar presentations


Ads by Google