© copyright 2005 chris ling monash university introducing j2ee

39
© Copyright 2005 Chris Ling Monash University Introducing J2EE

Post on 22-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling

Monash University

Introducing J2EE

Page 2: © Copyright 2005 Chris Ling Monash University 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.

Page 3: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

Enterprise Example

Customer Partners

CustomerSupport

InventoryManagement Sales

Employees HR Other

Shared Resources

Data

Data

Page 4: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

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.

Page 5: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

Two-Tier ArchitectureEarly 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.

PCsDatabaseServer

Presentation Logic

Business Logic

Page 6: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

DisadvantagesEasy 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.

Page 7: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

Three-Tier ArchitectureSplit the presentation logic (client computer) from the business logic (middle-tier server).

Presentation Logic

BusinessLogic

PCMiddle-Tier

Server

DatabaseServer

Page 8: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

Another Three-tier Architecture

A standard architecture for developing and deploying enterprise Web-oriented applications and applets using Java.Example: CSE3420 Practical Assignment.

Browser ServletContainer

(PresentationAnd

Logic)

Desktop Client Web Container

Database

Page 9: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

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.

Page 10: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

Early Web-based Architecture

Web application developers used various plug-in extensions to Web serversCGI applications or cgi-bin scripts, butDo 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.

Page 11: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

Component-based SoftwareObject-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).

Page 12: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

J2EE HistoryJava (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.

Page 13: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

Container

ServiceAPI

ServiceAPI

ServiceAPI

ServiceAPI

ServiceAPI

ServiceAPI

Component

Component

Component

Component

CONTAINER

SERVER

Page 14: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

Container ConceptsContainer: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.

Page 15: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

J2EE Containers1. 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.

Page 16: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

J2EE ArchitectureA 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-bin-based approach).

Page 17: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

J2EE Architecture

J2EE Application Programming Model for Three-Tier Applications:

Application-ClientContainer

Presentation Components

EJBContainer

Enterprise Bean

Desktop Client Business Logic

Database

JDBC

Page 18: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

J2EE Architecture

J2EE Application Programming Model

AppletContainer

Applets

WebContainer

WebApplication(Servlets, JSPs …)

EJBContainer

Enterprise Beans

Browser Web Service Business Logic

Database

Internet

ApplicationClient Container

Internet

Page 19: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

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.

Page 20: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

Multitiered Applications

Page 21: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

J2EE ComponentsJ2EE Clients or Client tier. Two types:

Web client - consists of:1. Dynamic web pages consisting of various types of markup

language (HTML, XML etc)2. A Web browser

Application client 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.

Page 22: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© 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.

Page 23: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling

Monash University

J2EE Architecture and Technologies

Page 24: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

Container ServicesContainers are the interfaces between a component and the low-level platform-specific functionality.Before the web, enterprise bean or application-client 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.

Page 25: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

J2EE Server and Containers

Page 26: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

Web Services SupportWeb 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

Page 27: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

Wow!XMLAPISOAP – 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

Page 28: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

J2EE Technologies and APIsJ2EE 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

Page 29: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

JDBC APIA 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.

Page 30: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

ServletsWeb 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.

Page 31: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© 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.

Page 32: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

A Servlet Exampleimport java.io.*; // From Wigglesworth 2001import 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>" ); }}

Page 33: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© 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 HTMLGenerally good practice to keep the Java code simple. Serves the same purpose as a servlet: to produce HTML page with dynamic content.

Page 34: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

A JSP ExampleThe 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.

Page 35: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

Enterprise Java Bean (EJB)The core of J2EE platformThree types: Session beans -

for transient activities Non-persistent and encapsulate mainly business logic. Can be stateless or stateful

Entity beans - 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.

Page 36: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

Classes and InterfacesTo 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.

Page 37: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

Classes and Interfaces Local Interface (EJB 2.0)

Defines the bean’s methods used by other beans in the same EJB container.

Used together with Local Home Interface.

Local Home Interface (EJB 2.0) 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.

Page 38: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

EJB RolesRoles 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.

Page 39: © Copyright 2005 Chris Ling Monash University Introducing J2EE

© Copyright 2005 Chris Ling,

Monash University

References1. K. Boone (2003). Applied Enterprise

JavaBeans Technology. Sun Microsystems.2. V. Matena and B. Stearns (2003). Applying

Enterprise JavaBeans. Component-Based Development for the J2EE Platform. Wnd Edition. Addison-Wesley.

3. K. Z. Ahmed and C. E. Umrysh (2002). Developing Enterprise Java Applications with J2EE and UML. Addison-Wesley.

4. 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.