j2ee building components
TRANSCRIPT
![Page 1: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/1.jpg)
1Copyright 2015 © Adeppa
J2EE – Building J2EE – Building Component-based EnterpriseComponent-based Enterprise
Web ApplicationsWeb Applications
09/29/201509/29/2015
![Page 2: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/2.jpg)
2Copyright 2015 © Adeppa
Agenda1. Application servers2. What is J2EE?
Main component types Application Scenarios J2EE APIs and Services
3. EJB – a closer look4. Examples
![Page 3: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/3.jpg)
3Copyright 2015 © Adeppa
1. Application Servers In the beginning, there was darkness and
cold. Then, …
Centralized, non-distributed
terminalsmainframe
terminals
![Page 4: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/4.jpg)
4Copyright 2015 © Adeppa
Application Servers In the 90’s, systems should be client-
server
![Page 5: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/5.jpg)
5Copyright 2015 © Adeppa
Application Servers Today, enterprise applications use
the multi-tier model
![Page 6: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/6.jpg)
6Copyright 2015 © Adeppa
Application Servers “Multi-tier applications” have several
independent components An application server provides the
infrastructure and services to run such applications
![Page 7: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/7.jpg)
7Copyright 2015 © Adeppa
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: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/8.jpg)
8Copyright 2015 © Adeppa
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: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/9.jpg)
9Copyright 2015 © Adeppa
Web Server and Application Server
Web Server
(HTTP Server)
App Server 1
App Server 2
Internet Browser
HTTP(S)
![Page 10: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/10.jpg)
10Copyright 2015 © Adeppa
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
![Page 11: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/11.jpg)
11Copyright 2015 © Adeppa
J2EE Benefits High availability Scalability Integration with existing systems Freedom to choose vendors of
application servers, tools, components Multi-platform
![Page 12: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/12.jpg)
12Copyright 2015 © Adeppa
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: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/13.jpg)
13Copyright 2015 © Adeppa
J2EE Benefits
Don’t forget to say
that Java is cool!
![Page 14: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/14.jpg)
14Copyright 2015 © Adeppa
Main technologies JavaServer Pages (JSP) Servlet Enterprise JavaBeans (EJB)
JSPs, servlets and EJBs are application components
![Page 15: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/15.jpg)
15Copyright 2015 © Adeppa
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 16: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/16.jpg)
16Copyright 2015 © Adeppa
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 17: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/17.jpg)
17Copyright 2015 © Adeppa
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 18: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/18.jpg)
18Copyright 2015 © Adeppa
J2EE Multi-tier Model
![Page 19: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/19.jpg)
19Copyright 2015 © Adeppa
J2EE Application Scenarios Multi-tier typical application
![Page 20: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/20.jpg)
20Copyright 2015 © Adeppa
J2EE Application Scenarios Stand-alone client
![Page 21: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/21.jpg)
21Copyright 2015 © Adeppa
J2EE Application Scenarios Web-centric application
![Page 22: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/22.jpg)
22Copyright 2015 © Adeppa
J2EE Application Scenarios Business-to-business
![Page 23: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/23.jpg)
23Copyright 2015 © Adeppa
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 24: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/24.jpg)
24Copyright 2015 © Adeppa
JMS Point-to-point
Destination is “queue”
![Page 25: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/25.jpg)
25Copyright 2015 © Adeppa
JMS Publish-subscribe
Destination is “topic”
![Page 26: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/26.jpg)
26Copyright 2015 © Adeppa
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 27: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/27.jpg)
27Copyright 2015 © Adeppa
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 28: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/28.jpg)
28Copyright 2015 © Adeppa
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
![Page 29: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/29.jpg)
29Copyright 2015 © Adeppa
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 30: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/30.jpg)
30Copyright 2015 © Adeppa
J2EE Services and APIs JDBC JavaMail Java API for XML Parsing (JAXP) Web services APIs
![Page 31: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/31.jpg)
31Copyright 2015 © Adeppa
3. EJB – a closer look
![Page 32: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/32.jpg)
32Copyright 2015 © Adeppa
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 33: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/33.jpg)
33Copyright 2015 © Adeppa
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 34: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/34.jpg)
34Copyright 2015 © Adeppa
![Page 35: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/35.jpg)
35Copyright 2015 © Adeppa
EJB – The Big Picture
![Page 36: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/36.jpg)
36Copyright 2015 © Adeppa
EJB at runtime
Client can be local or remote
![Page 37: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/37.jpg)
37Copyright 2015 © Adeppa
EJB at runtime
![Page 38: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/38.jpg)
38Copyright 2015 © Adeppa
Types of EJBEJB Taxonomy
Sta te fulSta te le ss
Se ssionBea n
BMPC MP
EntityBea n M essa geDrivenBea n
Ente rp riseBea n
New!
![Page 39: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/39.jpg)
39Copyright 2015 © Adeppa
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 40: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/40.jpg)
40Copyright 2015 © Adeppa
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 41: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/41.jpg)
41Copyright 2015 © Adeppa
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 42: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/42.jpg)
42Copyright 2015 © Adeppa
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 43: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/43.jpg)
43Copyright 2015 © Adeppa
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 44: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/44.jpg)
44Copyright 2015 © Adeppa
4. Examples JSP example Servlet example EJB example
![Page 45: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/45.jpg)
45Copyright 2015 © Adeppa
JSP example
![Page 46: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/46.jpg)
46Copyright 2015 © Adeppa
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"> </td><td width="550"> <h1>My name is Duke. What's yours?</h1></td></tr>
![Page 47: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/47.jpg)
47Copyright 2015 © Adeppa
JSP example<tr> <td width="150" </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 48: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/48.jpg)
48Copyright 2015 © Adeppa
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 49: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/49.jpg)
49Copyright 2015 © Adeppa
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 50: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/50.jpg)
50Copyright 2015 © Adeppa
EJB Example// Remote interfacepublic 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 51: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/51.jpg)
51Copyright 2015 © Adeppa
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 52: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/52.jpg)
52Copyright 2015 © Adeppa
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 53: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/53.jpg)
53Copyright 2015 © Adeppa
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 54: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/54.jpg)
54Copyright 2015 © Adeppa
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 55: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/55.jpg)
55Copyright 2015 © Adeppa
Questions
![Page 56: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/56.jpg)
56Copyright 2015 © Adeppa
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 57: j2ee Building components](https://reader036.vdocument.in/reader036/viewer/2022062523/58ed5ec21a28aba1478b46ad/html5/thumbnails/57.jpg)
57Copyright 2015 © Adeppa
Sources & Resources The J2EE Tutorial. Sun Microsystems IBM WebSphere Application Server
manuals BEA WebLogic Server manuals www.java.sun.com/j2ee www.theserverside.com