KEMBAR78
J2ee | PPT
JJ22EEEE –– BBuuiillddiinngg 
CCoommppoonneenntt--bbaasseedd EEnntteerrpprriissee 
WWeebb AApppplliiccaattiioonnss 
0055//0099//22000022 
Paulo Merson 
Copyright 2002 © Paulo Merson 1
Copyright 2002 © Paulo Merson 2 
Agenda 
1. Application servers 
2. What is J2EE? 
 Main component types 
 Application Scenarios 
 J2EE APIs and Services 
1. EJB – a closer look 
2. Examples
1. Application Servers 
 In the beginning, there was darkness and 
cold. Then, … 
mainframe 
Centralized, non-distributed 
terminals 
Copyright 2002 © Paulo Merson 3 
terminals
Application Servers 
 In the 90’s, systems should be client-server 
Copyright 2002 © Paulo Merson 4
Application Servers 
Today, enterprise applications use 
the multi-tier model 
Copyright 2002 © Paulo Merson 5
Application Servers 
 “Multi-tier applications” have several 
independent components 
 An application server provides the 
infrastructure and services to run such 
applications 
Copyright 2002 © Paulo Merson 6
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.) 
Copyright 2002 © Paulo Merson 7
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) 
Copyright 2002 © Paulo Merson 8
Web Server and Application Server 
Web Server 
(HTTP Server) 
App Server 1 
App Server 2 
Copyright 2002 © Paulo Merson 9 
Internet Browser 
HTTP(S)
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 
Copyright 2002 © Paulo Merson 10
J2EE Benefits 
 High availability 
 Scalability 
 Integration with existing systems 
 Freedom to choose vendors of 
application servers, tools, components 
 Multi-platform 
Copyright 2002 © Paulo Merson 11
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 
Copyright 2002 © Paulo Merson 12
J2EE Benefits 
Don’t forget to say 
that Java is cool! 
Copyright 2002 © Paulo Merson 13
Main technologies 
 JavaServer Pages (JSP) 
 Servlet 
 Enterprise JavaBeans (EJB) 
 JSPs, servlets and EJBs are application 
components 
Copyright 2002 © Paulo Merson 14
Copyright 2002 © Paulo Merson 15 
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
Copyright 2002 © Paulo Merson 16 
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
Copyright 2002 © Paulo Merson 17 
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
J2EE Multi-tier Model 
Copyright 2002 © Paulo Merson 18
J2EE Application Scenarios 
 Multi-tier typical application 
Copyright 2002 © Paulo Merson 19
J2EE Application Scenarios 
 Stand-alone client 
Copyright 2002 © Paulo Merson 20
J2EE Application Scenarios 
 Web-centric application 
Copyright 2002 © Paulo Merson 21
J2EE Application Scenarios 
 Business-to-business 
Copyright 2002 © Paulo Merson 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 
Copyright 2002 © Paulo Merson 23
Copyright 2002 © Paulo Merson 24 
JMS 
 Point-to-point 
 Destination is “queue”
Copyright 2002 © Paulo Merson 25 
JMS 
 Publish-subscribe 
 Destination is “topic”
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. 
Copyright 2002 © Paulo Merson 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 
Copyright 2002 © Paulo Merson 27
J2EE Services and APIs 
Copyright 2002 © Paulo Merson 28 
 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
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 
Copyright 2002 © Paulo Merson 29
J2EE Services and APIs 
 JDBC 
 JavaMail 
 Java API for XML Parsing (JAXP) 
 Web services APIs 
Copyright 2002 © Paulo Merson 30
3. EJB – a closer look 
Copyright 2002 © Paulo Merson 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 
Copyright 2002 © Paulo Merson 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 
Copyright 2002 © Paulo Merson 33
Copyright 2002 © Paulo Merson 34
EJB – The Big Picture 
Copyright 2002 © Paulo Merson 35
EJB at runtime 
Client can be local or remote 
Copyright 2002 © Paulo Merson 36
EJB at runtime 
Copyright 2002 © Paulo Merson 37
E n te rp ris e B e a n 
E n tity B e a n M e s s a g e D riv e n B e a n 
Copyright 2002 © Paulo Merson 38 
Types of EJB 
E J B T a x o n o m y 
S e s s io n B e a n 
S ta te fu l 
S ta te le s s 
B M P 
C M P 
New!
Copyright 2002 © Paulo Merson 39 
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
Copyright 2002 © Paulo Merson 40 
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
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 
Copyright 2002 © Paulo Merson 41
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 
Copyright 2002 © Paulo Merson 42
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 
Copyright 2002 © Paulo Merson 43
Copyright 2002 © Paulo Merson 44 
4. Examples 
 JSP example 
 Servlet example 
 EJB example
Copyright 2002 © Paulo Merson 45 
JSP example
Copyright 2002 © Paulo Merson 46 
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>
Copyright 2002 © Paulo Merson 47 
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>
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("<html><head><title>Hello 
World Servlet</title></head>"); 
out.println("<body><h1>Hello 
World!</h1></body></html>"); 
Copyright 2002 © Paulo Merson 48 
} 
}
Copyright 2002 © Paulo Merson 49 
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; 
}
Copyright 2002 © Paulo Merson 50 
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; 
}
Copyright 2002 © Paulo Merson 51 
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(); 
}
Copyright 2002 © Paulo Merson 52 
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(); 
}
Copyright 2002 © Paulo Merson 53 
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; 
} 
. . . 
}
Copyright 2002 © Paulo Merson 54 
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!"); 
} 
} 
}
Copyright 2002 © Paulo Merson 55 
Questions
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 
Copyright 2002 © Paulo Merson 56
Sources & Resources 
 The J2EE Tutorial. Sun Microsystems 
 IBM WebSphere Application Server 
manuals 
 BEA WebLogic Server manuals 
 www.java.sun.com/j2ee 
 www.theserverside.com 
Copyright 2002 © Paulo Merson 57

J2ee

  • 1.
    JJ22EEEE –– BBuuiillddiinngg CCoommppoonneenntt--bbaasseedd EEnntteerrpprriissee WWeebb AApppplliiccaattiioonnss 0055//0099//22000022 Paulo Merson Copyright 2002 © Paulo Merson 1
  • 2.
    Copyright 2002 ©Paulo Merson 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 1. EJB – a closer look 2. Examples
  • 3.
    1. Application Servers  In the beginning, there was darkness and cold. Then, … mainframe Centralized, non-distributed terminals Copyright 2002 © Paulo Merson 3 terminals
  • 4.
    Application Servers In the 90’s, systems should be client-server Copyright 2002 © Paulo Merson 4
  • 5.
    Application Servers Today,enterprise applications use the multi-tier model Copyright 2002 © Paulo Merson 5
  • 6.
    Application Servers “Multi-tier applications” have several independent components  An application server provides the infrastructure and services to run such applications Copyright 2002 © Paulo Merson 6
  • 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.) Copyright 2002 © Paulo Merson 7
  • 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) Copyright 2002 © Paulo Merson 8
  • 9.
    Web Server andApplication Server Web Server (HTTP Server) App Server 1 App Server 2 Copyright 2002 © Paulo Merson 9 Internet Browser HTTP(S)
  • 10.
    2. What isJ2EE?  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 Copyright 2002 © Paulo Merson 10
  • 11.
    J2EE Benefits High availability  Scalability  Integration with existing systems  Freedom to choose vendors of application servers, tools, components  Multi-platform Copyright 2002 © Paulo Merson 11
  • 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 Copyright 2002 © Paulo Merson 12
  • 13.
    J2EE Benefits Don’tforget to say that Java is cool! Copyright 2002 © Paulo Merson 13
  • 14.
    Main technologies JavaServer Pages (JSP)  Servlet  Enterprise JavaBeans (EJB)  JSPs, servlets and EJBs are application components Copyright 2002 © Paulo Merson 14
  • 15.
    Copyright 2002 ©Paulo Merson 15 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.
    Copyright 2002 ©Paulo Merson 16 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.
    Copyright 2002 ©Paulo Merson 17 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.
    J2EE Multi-tier Model Copyright 2002 © Paulo Merson 18
  • 19.
    J2EE Application Scenarios  Multi-tier typical application Copyright 2002 © Paulo Merson 19
  • 20.
    J2EE Application Scenarios  Stand-alone client Copyright 2002 © Paulo Merson 20
  • 21.
    J2EE Application Scenarios  Web-centric application Copyright 2002 © Paulo Merson 21
  • 22.
    J2EE Application Scenarios  Business-to-business Copyright 2002 © Paulo Merson 22
  • 23.
    J2EE Services andAPIs  Java Message Service (JMS)  Implicit invocation  Communication is loosely coupled, reliable and asynchronous  Supports 2 models:  point-to-point  publish/subscribe Copyright 2002 © Paulo Merson 23
  • 24.
    Copyright 2002 ©Paulo Merson 24 JMS  Point-to-point  Destination is “queue”
  • 25.
    Copyright 2002 ©Paulo Merson 25 JMS  Publish-subscribe  Destination is “topic”
  • 26.
    J2EE Services andAPIs  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. Copyright 2002 © Paulo Merson 26
  • 27.
    J2EE Services andAPIs  Transaction service:  Controls transactions automatically  You can demarcate transactions explicitly  Or you can specify relationships between methods that make up a single transaction Copyright 2002 © Paulo Merson 27
  • 28.
    J2EE Services andAPIs Copyright 2002 © Paulo Merson 28  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.
    J2EE Services andAPIs  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 Copyright 2002 © Paulo Merson 29
  • 30.
    J2EE Services andAPIs  JDBC  JavaMail  Java API for XML Parsing (JAXP)  Web services APIs Copyright 2002 © Paulo Merson 30
  • 31.
    3. EJB –a closer look Copyright 2002 © Paulo Merson 31
  • 32.
    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 Copyright 2002 © Paulo Merson 32
  • 33.
    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 Copyright 2002 © Paulo Merson 33
  • 34.
    Copyright 2002 ©Paulo Merson 34
  • 35.
    EJB – TheBig Picture Copyright 2002 © Paulo Merson 35
  • 36.
    EJB at runtime Client can be local or remote Copyright 2002 © Paulo Merson 36
  • 37.
    EJB at runtime Copyright 2002 © Paulo Merson 37
  • 38.
    E n terp ris e B e a n E n tity B e a n M e s s a g e D riv e n B e a n Copyright 2002 © Paulo Merson 38 Types of EJB E J B T a x o n o m y S e s s io n B e a n S ta te fu l S ta te le s s B M P C M P New!
  • 39.
    Copyright 2002 ©Paulo Merson 39 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.
    Copyright 2002 ©Paulo Merson 40 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.
    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 Copyright 2002 © Paulo Merson 41
  • 42.
    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 Copyright 2002 © Paulo Merson 42
  • 43.
    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 Copyright 2002 © Paulo Merson 43
  • 44.
    Copyright 2002 ©Paulo Merson 44 4. Examples  JSP example  Servlet example  EJB example
  • 45.
    Copyright 2002 ©Paulo Merson 45 JSP example
  • 46.
    Copyright 2002 ©Paulo Merson 46 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>
  • 47.
    Copyright 2002 ©Paulo Merson 47 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>
  • 48.
    Servlet example publicclass 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>"); Copyright 2002 © Paulo Merson 48 } }
  • 49.
    Copyright 2002 ©Paulo Merson 49 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.
    Copyright 2002 ©Paulo Merson 50 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.
    Copyright 2002 ©Paulo Merson 51 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.
    Copyright 2002 ©Paulo Merson 52 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.
    Copyright 2002 ©Paulo Merson 53 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.
    Copyright 2002 ©Paulo Merson 54 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.
    Copyright 2002 ©Paulo Merson 55 Questions
  • 56.
    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 Copyright 2002 © Paulo Merson 56
  • 57.
    Sources & Resources  The J2EE Tutorial. Sun Microsystems  IBM WebSphere Application Server manuals  BEA WebLogic Server manuals  www.java.sun.com/j2ee  www.theserverside.com Copyright 2002 © Paulo Merson 57

Editor's Notes

  • #10 The Web Server (also called HTTP Server) serves only static content, typically HTML pages. The Application server serves dynamic content and contains and environment to execute Java components. Usually there is a plug-in that must be installed in the web server in order to communicate with the AppServer. Typically, if the web server is IIS, the communication with the app server is via ISAPI, if it is Apache the communication is via NSAPI, and so on.
  • #17 Actually, an HTTP servlet processes HTTP requests. APIs for maintaining session data throughout a web application and interacting with the user request  overcomes the limitation of the stateless nature of HTTP.
  • #28 J2EE servers are not obliged to implement JTS. The transaction manager must support distributed transaction, what is typically done with XA.
  • #31 JAXP was added to J2EE v1.3 J2EE v1.3 determines that J2EE products must be capable of exporting enterprise beans using the IIOP protocol. This is required to enable interoperability and to make EJB appear as Corba objects.
  • #40 The type of the session bean (stateless or stateful) is declared in the DD.
  • #41 stateless session beans can have non-client specific state, for example, an open database connection.
  • #49 Other servlet examples implement the doPost() and/or doGet() methods. These methods reply only to POST or GET requests; if you want to handle all request types from a single method, your servlet can simply implement the service() method. (However, if you choose to implement the service() method, you will not be able to implement the doPost() or doGet() methods, unless you call super.service() at the beginning of the service() method.)
  • #50 Many details are omitted in the source code examples.