View
215
Download
2
Category
Preview:
Citation preview
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 1
Developing Enterprise Applications Using Java
School of Technology of Setubal
Setubal, PortugalApril 8, 2002
Qusay H. MahmoudSchool of Computing Science
Simon Fraser University, Vancouver, B.C., Canada
qmahmoud@cs.sfu.ca
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 2
Objectives
Understand the architecture of the J2EEUnderstand the technologies involved
in J2EEKnow how to build web-based
enterprise applicationsKnow what effort is involved in
development
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 3
Agenda
The J2EE Platform and SDKThe J2EE APIsWeb Components (Servlets, JSPs)Enterprise JavaBeans Technology (EJBs)Duke’s Bank ApplicationSecurity issuesWeb ServicesOnline Resources
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 4
Enterprise Applications
Enterprise is a synonym for distributedDistributed computation done by programs
interacting over the networkEnterprise is a hot buzzwordReputation for complexityEnterprise computing takes place in a
heterogeneous networkInvolve the use of many different network
protocols
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 5
Buzzword: N-tier apps
Used to describe applications that reside on client and several servers
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 6
Why Java?
It helps alleviate intimidating aspects of enterprise computing Java is portable (Write Once, Run
Everywhere) Enterprise APIs form a single standard
layer on top of various proprietary or vendor-enhanced APIs
The elegance of Java and OO power make the APIs simpler, easier to understand, and easier to use
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 7
Java Platforms
[Source: Sun Microsystems Website]
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 8
J2EE Platform
Brings the benefits of component-based development to enterprise applications
Components are Simpler to develop Portable Reusable
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 9
J2EE Components
Server-side components Enterprise JavaBeans (EJBs) Java Servlets JavaServer Pages (JSPs)
Client-side components Application client
Configured via deployment descriptorsDeployed into containers
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 10
J2EE Components packed into Modules
Enterprise Beans (JAR file) Classes Deployment descriptor
Web Components (WAR file) Servlet classes, JSPs, HTML, images Web application deployment descriptor
Application Clients Classes Application client deployment descriptor
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 11
J2EE Applications
Packed into Enterprise ARchives (EAR file)Configured via application deployment
descriptors<application> <display-name>BankApp</display-name> <module> <ejb>account-ejb.jar</ejb> </module> … <module> <web> <web-uri>bank.war</web-uri> <context-root>bank</context-root> </web> </module></application>
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 12
J2EE Standard APIs
JDBCJava Naming and Directory Interface (JNDI)Java Message Service (JMS)Remote Method Invocation (RMI)Enterprise JavaBeans (EJBs)Technologies
Servlets JavaServer Pages (JSPs)
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 13
Other J2EE APIs
J2EE ConnectorsJava Transaction API (JTA)JavaIDLRMI-IIOPJava Transaction Service (JTS)JavaMail
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 14
Multi-tiered Architecture
Advantages: Decouples accessing of data from end-user
applications Encourages component-based code reusability
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 15
J2EE SDK
J2EE ServerCloudscape databaseApplication deployment tool
Create and edit deployment descriptors Package components and J2EE applications Verify and deploy J2EE applications
Download: http://java.sun.com/j2ee/download.html
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 16
J2EE SDK Tools
j2eeadmin: add/remove resourcescleanup: remove deployed apps from servercloudscape: start/stop/query database serverdeploytool: deploy/undeploy applications j2ee: start/stop J2EE serverkeytool: create keys and generate certificatespackager: package J2EE componentsrealmtool: add/remove J2EE users and import
certificatesverifier: validate J2EE archive files
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 17
J2EE Server
Standard containers (EJBs and Web) Life cycle management Concurrent execution
Standard platform services Security Transactions Resource connections
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 18
J2EE Containers
A container is the interface between a component and the low-level platform specific functionality
J2EE server provides services in the form of a container for every component type
You don’t have to develop these services yourself; you concentrate on solving the business problem
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 19
J2EE Containers
Before a component can be executed, it must be assembled into a J2EE application and deployed into its container
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 20
Web Components
Used to generate dynamic Web contentRun on the server-sidePortableReusableThey can be:
Based on the Java Servlet API Based on the JavaServer Pages (JSPs)
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 21
HTTP Overview
An application-level protocolSupports several request methods
( such as GET and POST) GET http://www.yahoo.com HTTP/1.0
Request
Reply
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 22
Servlets
A servlet is a Java classFunctions:
Process requests Create replies
Deployed into a Web container, which Manages servlet life cycle Maps URLs to servlets Converts HTTP requests and responses to objects
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 23
Servlet Example
A simple servletpublic class HelloServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{ response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println(“<html><head><title>hello</title></head>
"); out.println(<body><h1>Hello</h1></body></html>);}
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 24
Servlet as a Mediator
Devices that have no support for socket or datagram connections, access ‘net services through a mediator
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 25
JavaServer Pages (JSPs)
JSP is a document that contains two types of text Template data (HTML, XML, WML) that
generates static content JSP elements that generate dynamic content
Delegates dynamic processing to EJBs, JavaBeans components, custom tags
Translates into and executes as a servlet
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 26
JSP Elements
Directive controls translation into servlet class <%@ page import=“java.io.*” %>
Declaration creates object or method <%! int i %>
Scriptlet for dynamic processing <% ArrayList accts =
beanManager.getAcountController().getAccountsOfCustomer(request.getRemoteUser()); %>
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 27
JSP: JavaBeans Components
Create components and access their properties <jsp:useBean id=“accountHistBean” class=“AccountHistorybean”
scope=“request”/> scope: page, request, session, or application <jsp:setProperty name=“accountHistbean”
property=“beanManager” value=“<%= beanManager %>” />value can be a String or a JSP expression
<jsp:getProperty name=“accountHistBean” property=“credits” />
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 28
JSP: Custom Tags
Extensions to JSP that encapsulate dynamic processing
Tag libraries Standard Tag Library (JSR 052) Struts: http://jakarta.apache.org/struts Jakarta Taglibs: http://jakarta.apache.org/taglibs
Examples (we will see them in action) Effort involved in developing custom tags
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 29
Enterprise JavaBeans
What is an Enterprise Bean?
Component for EJB technology Runs on the server Encapsulates business logic Portable Reusable Transactional
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 30
How do Enterprise beans simplify development
Enterprise bean developer Focuses on solving business problems
EJB container Provides system-level services
Client developer Focuses on presentation and usability
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 31
Type of Enterprise Beans
Session beans
Entity beans
Message-driven beans
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 32
What is a Session Bean?
Represents a single client in the serverA logical extension of the clientTransient state – not persistent
Examples Sample session beans in action
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 33
What is an Entity Bean?
Represents a business object in a persistent storage (e.g. a database)
Often provides an object view of a database table
Examples Sample entity beans in action
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 34
What is a Message-Driven Bean?
Based on Java Message Service (JMS) technology)
Message listenerConsumes messages from a queueThe onMessage() method is invoked
upon message arrival
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 35
Structure of an EJB
Enterprise Bean Class Implementation
Home Interface Life cycle methods
Remote Interface Business methods
Deployment Descriptor XML file
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 36
Duke’s Bank Application
Online access to bank accountsCustomers – web clients
Withdraw and deposit funds Account history Transfer funds
Administrators (J2EE application client) Manage customers Manage accounts
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 37
Duke’s Bank Application
High-level architecture
[source: Sun Microsystems Website]
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 38
Duke’s Bank Client’s View
Defining client’s view with interfaces
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 39
Duke’s Bank Application
Enterprise Beans
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 40
Duke’s Client Application
Client: locate, create, deposit
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 41
Duke’s Bank Application
TxControllerEJB: Deposit
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 42
Duke’s Bank Application
TxEJB: Create
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 43
Duke’s Bank Application
Web Component Integration
[source: Sun]
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 44
Duke’s Bank Application
Security
Secure each container to secure entire application
Use authentication to prove identity Use authorization to restrict access
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 45
Application Client Security
Admin uses the application client to create customers and accounts
Must authenticate to access any management functions by the application client Login screen pops up when the application
client is accessed
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 46
Duke’s Bank Application
Creating a customer account Admin creates the customer record
Customer ID is embedded in the customer record
Admin uses realmtool to add customer ID, password, group to default realmRealm –add 200 j2ee customer
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 47
Duke’s Bank Application
Creating an account Admin accesses the application client and
creates an account for the customer Create methods in the enterprise bean can
only be accessed by users in the admin role
The customer ID, found in the customer record, binds the account to the customer
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 48
Duke’s Bank Application
Securing the Web Components Web components are protected when the
application is deployed Customer must authenticate to access web
componentsA form-based login pops up when the customer tries to
access web component
Web component retrieves the customer ID by calling getUserPrincipal()
<% ArrayList accts = beanManager.getAccountController().getAccountsOfCustomer(request.getUserPrincipal().getName()); %>
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 49
Duke’s Bank Application
Securing the Enterprise Beans Enterprise beans provide methods for creating
customer and accounts Method permissions on the home interface restrict
account and customer creation to admin role Roles and mapping between users and roles is
specified at application deployment time Enterprise beans provide methods for crediting,
debiting, transferring funds Methods permission on the remote interface
restricts these operations to customer role
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 50
Transaction Management
Indivisible unit of workAtomic (all or nothing)
Committed or rolled backBean-managed
Your code sets transaction boundariesContainer-managed
EJB container sets boundaries
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 51
Resources Connections
Types: Database connections Java Message Service API-based objects Mail sessions URLs Resource adapters
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 52
Resource Connections
Exampleprivate String dbName =
“java:comp/env/jdbc/BankDB”;
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup(dbName);
Connection con = ds.getConnection();
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 53
Connector Architecture
Enables J2EE components such as EJB to interact with enterprise information systems
A resource adapter is a J2EE component that implements the J2EE connector architecture for a specific enterprise information system
A resource adapter is analogous to a JDBC driver For JDBC: the outside resource is DBMS For resource adapter: the outside resource is
enterprise information system
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 54
Web Services
Services offered through the web and can be accessed from any web-services enabled machine with Internet access
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 55
Online Resources
J2EE: http://java.sun.com/j2ee
J2EE Tutorial: http://java.sun.com/j2ee/tutorial
J2EE white papers:http://java.sun.com/j2ee/white
J2EE BluePrints:http://java.sun.com/blueprints
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 56
Online Resources
JSP Taglibs: http://java.sun.com/products/jsp/taglibraries.html
Tomcathttp://jakarta.apache.org/tomcat
Web Serviceshttp://java.sun.com/webservices
Deploying Web Services on J2EE:http://developer.java.sun.com/developer/technicalArticles/WebServices/wsj2ee
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 57
Thank you
Q & A
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 58
Copyright Info
Java™ and J2EE ™ are registered trademarks of Sun Microsystems, Inc.
Part of the slides have been adapted from J2EE Tutorial and JavaOne Sessions 2001.
All trademarked product and company names are the property of their respective trademark holders.
http://www.javacourses.com Copyright © 2002 Qusay H. Mahmoud 59
Speaker Bio
Qusay H. Mahmoud is a faculty member in the School of Computing Science at Simon Fraser University, Canada. He is widely published on the Java programming language, including the MIDP and Palm programming articles for Sun Microsystems Java Developer Connection. Qusay is the author of Distributed Programming with Java (Manning Publications, 1999) and Learning Wireless Java (O’Reilly & Associates, 2002)
http://www.cs.sfu.ca/~qmahmoud
Recommended