Download Chris Ling`s J2EE Overview

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Introducing J2EE
© Copyright 2005 Chris Ling
Monash University
Enterprise Software
Enterprise - an organization of individuals
or entities, working together to achieve
some common goals.
Have common needs: info sharing and
processing, asset management, resource
planning, customer/client management etc.
Enterprise software refers to all the
software involved in supporting these
needs.
© Copyright 2005 Chris Ling,
Monash University
Enterprise Example
Customer
Customer
Support
Employees
Partners
Inventory
Management
HR
Sales
Other
Shared
Resources
© Copyright 2005 Chris Ling,
Monash University
Data
Data
Evolution of Enterprise
Software
Single-tier applications:

Dumb terminals to mainframe
Two-tier applications:

Client-server
The n-tier approach:



A better balance by separating business logic from
presentation logic.
Different tiers not necessary different pieces of
hardware.
Benefits: Faster and lower cost development, isolated
impact of changes and changes are more
manageable.
© Copyright 2005 Chris Ling,
Monash University
Two-Tier Architecture
Early 90’s, most enterprise applications
follow a two-tier architecture (client/server)
Business logic and presentation logic on the same
machine (eg. CSE5910 Assignment)
Easier to deal with because it is non-distributed.
PCs
Database
Server
Business
Logic
Presentation
Logic
© Copyright 2005 Chris Ling,
Monash University
Disadvantages
Easy to compromise database integrity.
Difficult to administer in a large enterprise.
Security violations.
Limited scalability – limited database access.
Homogeneous client architecture
Ties the application to one particular
presentation type.
Incompatible with the onset of Web.
© Copyright 2005 Chris Ling,
Monash University
Three-Tier Architecture
Split the presentation logic (client
computer) from the business logic
(middle-tier server).
Middle-Tier
Server
PC
Presentation
Logic
Business
Logic
© Copyright 2005 Chris Ling,
Monash University
Database
Server
Another Three-tier
Architecture
A standard architecture for developing and
deploying enterprise Web-oriented
applications and applets using Java.
Example: CSE3420 Practical Assignment.
Desktop Client
Browser
Web Container
Servlet
Container
(Presentation
And
Logic)
© Copyright 2005 Chris Ling,
Monash University
Database
Disadvantages
Some improvements, such as improved
scalability and security, but
Complexity – multithreading, security,
distribution, deployment and admin
support.
 Lack of application portability – different
vendor software
 Incompatibility with the web – more
suitable for intranet.

© Copyright 2005 Chris Ling,
Monash University
Early Web-based
Architecture
Web application developers used various
plug-in extensions to Web servers
CGI applications or cgi-bin scripts, but
Do not provide well-structured encapsulation
 Intertwine the implementation of the business
processes with the implementation of the
presentation logic.
 Difficult to foster the maintenance of the
integrity of the business rules - scattered
across web-servers.

© Copyright 2005 Chris Ling,
Monash University
Component-based Software
Object-oriented software development


Adopted for reusability.
Too fine-grained to achieve large-scale reusability.
Software components



Much higher level of abstractions.
More loosely coupled - using interfaces
Compatibility issues.
Distributed component models:

DCOM, Microsoft .NET and Enterprise Java
Beans (EJB) which is part of Java 2 Enterprise
Edition (J2EE).
© Copyright 2005 Chris Ling,
Monash University
J2EE History
Java (originally called Oak) evolved for client-side
developments - applets, JDBC API.
Problems with browser-based system environment - latency
over the internet before application startup.
Web-based applications through Java servlets.
However, servlets not designed to handle complex
computations.
EJB initially released separately to handle services and
functions for the enterprise.
J2EE is the result of aligning the disparate Java technologies
and APIs into a development platform for specific web-based
enterprise software.
J2EE specification - specifies how a number of Java
technologies are to interoperate.
© Copyright 2005 Chris Ling,
Monash University
Container
Service
API
Service
API
Service
API
Component
Service
API
Component
Component
Component
CONTAINER
SERVER
© Copyright 2005 Chris Ling,
Monash University
Service
API
Service
API
Container Concepts
Container:
a software entity that runs within the server.
 Provides execution environment for the
components.
 Provides independence between development
and deployment - portability.
 Manages life cycle of components.
 Enforces security, eg. Intercepting external
requests.

© Copyright 2005 Chris Ling,
Monash University
J2EE Containers
1. The EJB Container – the environment for
enterprise beans, components that implements
the business processes and entities.
2. The Web Container – the environment for
servlets and JSPs, grouped into deployable
units called Web applications (for presentation
logic of an enterprise application).
3. The Application Client Container –
environment for executing J2EE application
clients, essentailly J2SE.
4. The Applet Container – the environment for
executing applets. Environment is embedded in
a web browser.
© Copyright 2005 Chris Ling,
Monash University
J2EE Architecture
A standard architecture for developing and
deploying enterprise Web-oriented
applications and applets using Java.
Not only for intranet applications (replacing
two-tier and three-tier models), but also for
internet applications (replacing cgi-binbased approach).
© Copyright 2005 Chris Ling,
Monash University
J2EE Architecture
J2EE Application Programming Model for
Three-Tier Applications:
Desktop Client
Application-Client
Container
Presentation
Components
Business Logic
EJB
Container
Enterprise
Bean
© Copyright 2005 Chris Ling,
Monash University
Database
JDBC
J2EE Architecture
J2EE Application Programming Model
Browser
Web Service
Business Logic
Applet
Container
Web
Container
EJB
Container
Internet
Web
Application
(Servlets,
Application
Internet
JSPs …)
Client Container
Applets
Enterprise
Beans
© Copyright 2005 Chris Ling,
Monash University
Database
Why J2EE?
Separating development efforts from
interprocess communication issues: security,
database specific accesses.
Cleaner partition between development,
deployment and execution.
Support for hardware and OS independence by
providing access via Java and J2EE APIs.
Support for products by third party vendors.
Component-based: higher productivity, rapid
development, easier maintenance.
© Copyright 2005 Chris Ling,
Monash University
Multitiered Applications
© Copyright 2005 Chris Ling,
Monash University
J2EE Components
J2EE Clients or Client tier. Two types:

Web client - consists of:
1.
2.

Application client





Dynamic web pages consisting of various types of markup
language (HTML, XML etc)
A Web browser
Run on client’s machine with a richer GUI than a markup
language
GUI programs using AWT and SWING
Directly access enterprise beans running on the business
tier.
Can open an HTTP connection to communicate with
servlets.
A web page received from the Web tier can include
embedded applets and JavaBeans components.
© Copyright 2005 Chris Ling,
Monash University
J2EE Components (cont)
Web components: JSPs and servlets in
the web tier.
Business components: Enterprise
Beans running in the business tier.
EIS (Enterprise Information System) tier
handles enterprise resource planning
(ERP), mainframe transaction
processing, database systems etc.
© Copyright 2005 Chris Ling,
Monash University
J2EE Architecture and Technologies
© Copyright 2005 Chris Ling
Monash University
Container Services
Containers are the interfaces between a
component and the low-level platform-specific
functionality.
Before the web, enterprise bean or applicationclient component can be executed, it must be
assembled into a J2EE module and deployed into
its container.
Assembly/Deployment process involves specifying
container settings which customise the underlying
support, including services such as security,
transaction management, Java Naming and
Directory Interface (JNDI) lookups and remote
connectivity.
© Copyright 2005 Chris Ling,
Monash University
J2EE Server and
Containers
© Copyright 2005 Chris Ling,
Monash University
Web Services Support
Web services are Web-based enterprise
applications that use open, XML-based standards
and transport protocols to exchange data with
calling clients
J2EE provides XML APIs and tools to design,
develop, test and deploy web services and clients
that interoperate with other web services and
clients running on Java-based or non-Java-based
platforms.
XML, SOAP Transport Protocol, WSDL Standard
Format, UDDI and ebXML standard formats
© Copyright 2005 Chris Ling,
Monash University
Wow!
XML
API
SOAP – Simple Object Access Protocol
WSDL web services description language: a XML based
format for describing web services
UDDI -- Universal Description, Discovery, and
Integration, a platform-independent, XML-based registry
for businesses worldwide to list themselves on the Internet.
ebXML standard formats: electronic business
formats for specific business XML-based
interactions
© Copyright 2005 Chris Ling,
Monash University
J2EE Technologies and APIs
J2EE Technologies:
•
•
•
Servlets
JSP – Java server pages
EJB
J2EE APIs:
•
•
•
•
JDBC – Java Database connectivity
Java Naming and Directory Interface (JNDI)
JMS – Java message service
Remote Method Invocation (RMI)
Others:
J2EE Connectors, Java Transaction API (JTA),
Java IDL, RMI-IIOP, Java Transaction Service
(JTS) and JavaMail
© Copyright 2005 Chris Ling,
Monash University
JDBC API
A pure Java API for SQL access to
relational databases.
Majority of the API is in J2SE.
A vendor independent interface to
databases.
Depending on the type of EJBs you
implement, you may or may not use the
JDBC API.
Can also use JDBC from a servlet or JSP
or from normal Java application.
© Copyright 2005 Chris Ling,
Monash University
Servlets
Web components capable of generating
dynamic content.
Possible to use them (with JSPs) and
bypass the EJB Container.
Used to handle simpler tasks, such as
gathering and checking for valid input fields
on a web page.
Run inside the servlet container hosted on
the web server.
© Copyright 2005 Chris Ling,
Monash University
Servlets (cont)
A client requests a web page by issuing an
HTTP request which specifies a servlet.
A servlet runs in response to the request and
outputs an HTML page to the client.
A servlet is a Java program and is not
contained in HTML pages!
A servlet is a class that resides in a servlet
folder of the web folder and implements
certain methods.
© Copyright 2005 Chris Ling,
Monash University
A Servlet Example
import java.io.*;
// From Wigglesworth 2001
import java.util.Date;
import javax.servlet.*;
import javax.servlet.http.*;
public class TodayServlet extends HttpServlet {
public void doGet( HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType( "text/HTML" );
response.setHeader( "Pragma", "no cache" );
response.setHeader( "Cache-Control", "no cache" );
response.setHeader( "Expires", "0" );
PrintWriter out = response.getWriter();
// or ServletOutputStream out = response.getOutputStream();
out.println( "<HTML>" );
out.println( "<head>" );
out.println( "<title>Today</title>" );
out.println( "</head>" );
out.println( "<body>" );
out.println("<h1>The current date and Time is:</h1>" );
Date today = new Date();
out.println( "<p>" + today + "</p>" );
out.flush();
out.println( "</body>" );
out.println( "</HTML>" );
}
© Copyright 2005 Chris Ling,
}
Monash University
Java ServerPages (JSPs)
Another J2EE Web component which evolved
from the servlet technology.
Provide a way to write dynamic web pages as
HTML documents, rather than as output from a
servlet.
For web page presentation without being a
traditional programmer.
Permits Java code to be embedded within HTML
Generally good practice to keep the Java code
simple.
Serves the same purpose as a servlet: to
produce HTML page with dynamic content.
© Copyright 2005 Chris Ling,
Monash University
A JSP Example
The previous servlet example in JSP (today.jsp):
<html>
<head>
<META NAME=“Pragma” Content=“no-cache”>
<META NAME=“Cache-Control” CONTENT=“no-cache”>
<META NAME=“Expires” Content=“0”>
<title>Today</title>
</head>
<%@ page import=“java.util.*” %>
<body>
<H1>The current date and time is:</h1>
<p> <%= new Date( ) %> </p>
</body>
</html>
In short, JSPs let you write your HTML in HTML rather
than in Java, but you still need to know Java.
© Copyright 2005 Chris Ling,
Monash University
Enterprise Java Bean (EJB)
The core of J2EE platform
Three types:

Session beans 



Entity beans 



for transient activities
Non-persistent and encapsulate mainly business logic.
Can be stateless or stateful
encapsulate persistent data in a data store.
Assist business logic or to prepare data for web display.
Two types: CMP and BMP
Message-driven beans - for Java Messaging
Service (JMS) messages.
© Copyright 2005 Chris Ling,
Monash University
Classes and Interfaces
To implement an EJB, we need to define 2
interfaces and 1 bean class:
 Remote Interface:
presents the business methods that can be accessed
outside the EJB container
 Used together with Remote Home Interface.


Remote Home Interface:

Defines the life cycle methods of the bean: create(),
find() and remove().

Used together with Remote Interface.
© Copyright 2005 Chris Ling,
Monash University
Classes and Interfaces

Local Interface (EJB 2.0)



Local Home Interface (EJB 2.0)



Defines the bean’s methods used by other beans in the same EJB
container.
Used together with Local Home Interface.
Defines the bean’s lifecycle methods used by other beans in the
same EJB container.
Used together with Local Interface.
The Enterprise Bean class




Implements the bean’s business methods
An entity bean must implement javax.ejb.EntityBean
A session bean must implement javax.ejb.SessionBean
Both beans extend javax.ejb.EnterpriseBean.
© Copyright 2005 Chris Ling,
Monash University
EJB Roles
Roles as specified in the EJB Specification:
•
Component Provider: Software developer who
authors EJBs.
•
Application assembler: Someone who builds an
application out of existing EJBs.
•
Deployer: Someone who deploys the
application.
•
Server vendor: Supplies EJB server products.
•
Administrator: In charge of maintenance and
performance tuning of an application.
•
Tool provider: Someone who authors EJB
packaging and deployment tools.
© Copyright 2005 Chris Ling,
Monash University
References
1.
2.
3.
4.
K. Boone (2003). Applied Enterprise
JavaBeans Technology. Sun Microsystems.
V. Matena and B. Stearns (2003). Applying
Enterprise JavaBeans. Component-Based
Development for the J2EE Platform. Wnd
Edition. Addison-Wesley.
K. Z. Ahmed and C. E. Umrysh (2002).
Developing Enterprise Java Applications with
J2EE and UML. Addison-Wesley.
E. Armstrong, J. Ball, S. Bodoff, D. B. Carson,
I. Evans, D. Green, K. Haase and E. Jendrock
(2004). The J2EE 1.4 Tutorial. Sun
Microsystems.
© Copyright 2005 Chris Ling,
Monash University