Enterprise Applications Architecture
Download
Report
Transcript Enterprise Applications Architecture
Enterprise Applications
Architecture
Prof. Dr. R. Todtenhoefer
University of Applied Sciences
Fulda
Overview
• N-Tier Architectures
–
–
–
–
Configuration
Presentation Tier
Business Tier
Resource Management Tier
• PHP
• Electronic Business Application Scenarios
– Sun Microsystems view of N-Tier Architectures
– Web Application Architectures
– Component Technologies
Objectives
• Students acquire an understanding of:
–
–
–
–
modern software architectures
Knowledge of multi-tier application
Hands-on experience in writing PHP and Java EE programs
Basic knowledge of
• Java Servlets
• Enterprise Java Beans
• Session Beans
Application Scenarios
• In web applications we need a flexible programming
model and support for variety of software architectures
Copyright Sun Microsystems
N-Tier Architectures
• Distributed Web-Applications are today implemented as
Multi-Tier Applications
• Each tier (= layer) has it‘s own functionality
• Advantages
–
–
–
–
–
Separate components are less complex
Distribution of implementation tasks
Flexibility
Scalability
Security
N-Tier Architectures
• Separation of functionality into three conceptual layers
• Presentation Tier
– interacts with user, presents information and accepts requests
– has usually a graphical user interface
• Business Tier
– implements application logic
– often divided into
• Web Tier
• Application Server
• Resource Management Tier
– manages the data sources of the information system (DBMS, file
system, ERP-system)
Presentation Layer
• User Interface
• Nowadays is usually realized as thin client, implemented
with a Web-Browser
• Functionallity
– accept user requests
– Present results of server side computations
• Common technologies
– HTML (forms)
– JSP
– …
Business Layer
• This layer is where most of the appliction logic is
implemented, e.g.
– shopping cart (in an e-business application)
– price computation, tax calculation
• This layer is for scalibility and safety reasons often
further divided into
– Web-Server
– Application Server
• Common technologies
– Servlets, JSP, ASP, .NET, Corba, EJB
Resource Management Layer
• Often referred to as Data Layer
• Function is to manage the business data of an
application
– customer information
– product data
– orders
• Common technologies
– Data Base Systems like DB2, Oracle, MySql, …
– Enterprise Resource Planning Systems like SAP
1-Tier Architecture
• All conceptual layers are combined in a single tier
• Very popular on mainframe computer architectures =>
Monolithic systems
–
–
–
–
Clients are usually dumb terminals
No other entry points from outside
Focus on efficient usage of hardware resources
Prototyp of a legacy system
• Advantages
– Optimizes performance, no communication overhead required
• Disadvantages
– Maintanance is difficult, qualified Cobol programmers necessary
2-Tier Architecture
• Most popular approach: Client / Server System
• Parts of the presentation layer (and application logic) is
transferred on a PC or workstation
• Clients correspond to presentation layer, servers
correspond to application logic and data layer or
• Clients include presentation and application layer,
servers are used as database-servers
– thin client / fat server versus fat client and thin server
3-Tier Architecture
• Based on a clear separation of three layers
– Client tier with presentation layer
– Middle tier implements application logic
– Resource management layer is composed of one (or many)
database-servers
• Scalable, application layer can be distributed on different
computers in a cluster
• Supports integration of multiple resource managers
(ERP-Systems, DBMSs etc.) but
• increased communication between layers
N-Tier Architectures
• Further generalizes 3-Tier architecture
– Resource layer consists of different tier, focus on intergration of
different systems
– Presentation layer is realised in 2 separate tiers
• Clients are using browsers for HTML
• Web-Servers generate dynamic HTML-pages
• Usually results in 4-Tier architecture (see J2EE part of lecture)
• N => N+1
– adds flexibility and distribution options, but
– introduces performance, complexity and management issues
eBusiness Application Architecture
• Sun‘s view of a N-Tier Architecture
Copyright Sun Microsystems
J2EE Components & Services
Copyright Sun Microsystems
Components
• Application Clients / Browser
• Web Components
– PHP
– Java Server Pages
– Web Container / Servlet Engine (Apache, Tomcat)
• Enterprise Java Beans (EJB) Components
–
–
–
–
Session Beans
Entity Beans
Message Driven Beans
Beans Container (Glassfish , JBoss)
J2EE Services & APIs
• Services
–
–
–
–
Name Service
Deployment Service
Transaction Service
Security Services
• APIs
–
–
–
–
Java Database Connector (JDBC)
Java Transaction API and Service (JTA / JTS)
Java Naming and Directory Interface (JNDI)
Connector Architecture
J2EE - Containers
• Containers are run-time enviroments that support the
functionality of the components
Copyright Sun Microsystems
J2EE Application Scenarios
• J2EE provides a flexible programming model and
supports a variety of software architectures:
Copyright Sun Microsystems
J2EE Application Scenarios
• A typical 4 – Tier architecture of an J2EE-application with a thin
client, web server, application server and database:
Copyright Sun Microsystems
J2EE Application Scenarios
• Web - centric 3 – Tier architecture
• Web-Container implements presentation- and application logic
Copyright Sun Microsystems
J2EE Application Scenarios
• J2EE guidelines even allow classical C/S architectures
• 2-Tier applications with stand-alone clients
Copyright Sun Microsystems
J2EE at work
• Putting all pieces together:
Copyright Sun Microsystems
Client - Technologies
• Where we are
Copyright Sun Microsystems
Web - Clients
• Run on a browser (e.g. Firefox, …)
• User Interface (content) is generated dynamicaly on the
server-side
• Generated documents are presented by the browser
• Communication protocoll is HTTP (or HTTPS)
• Documents are written in HTML
• „runs everywhere“
Web – Client (Example 1)
• Read Mailing List Items
Web – Client (Example 2)
• Calculate your Body-Mass-Index
Web – Client (Code)
• HTML - Code
<html>
<head>
<title>RSS and PHP</title>
</head>
<link type="text/css" rel="stylesheet" href="./BMI.css">
<body>
<h1>RSS Form (PHP Version)</h1>
<form name="RSSForm" action="MyRSS.php" method="post">
RSS Feed: <input type="text" name="RSSURL" size=100 /><br /><br />
<input type="reset" value="Reset" />
<input type="submit" value="Read" />
</form>
</body>
</html>
Web – Client (Example)
• Functionality of the presentation tier
– Presentation of results of server side computations
– Accept user inputs
• What we need:
– HTML – elements for user input (HTML – forms)
– Transport mechanism for data from client to server (HTTP GET
and HTTP POST methods)
• We can use URLs to submit data as parameters
– Format: http://host:port/path/program?p1=v1&p2=v2
– http://sfoproject.informatik.fhfulda.de/CareeOnline/BMI/height=1.73&weight=73.0
Web - Tier
• Where we are
Copyright Sun Microsystems
Web - Tier
• The purpose of the Web-Tier
–
–
–
–
The server in the Web-Tier processes HTTP requests
Manages interaction between web client and application logic
Generates HTML (or XML) content
Business logic may be implemented entirely within the Web-Tier
(3-Tier architecture) but is often implemented in another tier
using EJB-technologies
– For greater detail see
• Designing Enterprise Applications with the J2EE ™ Platform, Second
Edition, by Inderjeet Singh, Beth Stearns,Mark Johnson, and the Enterprise
Team [1]
Web - Tier
• Web-enables business logic —The Web tier manages interaction
between Web clients and application business logic.
• Generates dynamic content —Web-tier components generate
content dynamically,in entirely arbitrary data formats, including
HTML
• Presents data and collects input —Web-tier components translate
HTTP PUTand GET actions into a form that the business logic
understands and present results as Web content.
• Maintains state —The Web tier has a simple, flexible mechanism
for accumulating data for transactions and for interaction context
over the lifetime of a user session.
• May implement business logic —While many enterprise
applications implement b usiness logic in enterprise beans, Webonly, low- to medium-volumeapplications with simple transactional
behavior can implement business logic entirely within the Web tier.
Source: [1], see page 75-76
Web - Container
Web-Container
Tools
Web-Server
Servlet-Engine
Web - Container
<?php
//Read Channel-Info
$channel=$rss->getChanne
// Print Channel Title
echo "<h2>"
$items= $rss->getItems();
echo "<ul>";
DB
foreach ($items as $item )
{
echo "<li><a href='".u'>";
echo utf8_decode($item/li>";
echo utf8_decode($itemuthor']);
echo "<br /><br />";
}
echo "</ul>";
?>
Web-Server
<html>
<head>
<title>RSS and PHP</title>
</head>
<link type="text/css"
<body>
<h1>RSS Form (PHP )</h1>
<form name="RSSForm"
RSS Feed: ><br />
<input type="reset" />
<input type="submit"/>
</form>
</body>
</html>
PHP
Processor
PHP – Simple example
<?php
require_once("XML/RSS.php");
$rssurl = $_POST['RSSURL'];
$rss =new XML_RSS($rssurl);
//Parse Data
$res=$rss->parse();
if (true===PEAR::isError($res))
{
die ($res->getMessage());
}
//Read Channel-Info
$channel=$rss->getChannelInfo();
// Print Channel Title
echo "<h2>".utf8_decode($channel['title'])."</h2>";
PHP – Simple Example (cont.)
// Create Link
$url=utf8_decode($channel['link']);
echo "<a href='$url'>$url</a><br /><br />";
// Print Channel Description
echo "<b>".utf8_decode($channel[description])."</b>";
// Loop thru items
$items= $rss->getItems();
echo "<ul>";
foreach ($items as $item )
{
echo "<li><a href='".utf8_decode($item['link'])."'>";
echo utf8_decode($item['title'])."</a></li>";
echo utf8_decode($item['author']);
echo "<br /><br />";
}
echo "</ul>";
?>
Servlets
• Are based on the Java Servlet Specification
– CGI
– Applets
• Are implemented in Java, use Java Servlet API
• Must be deployed in a Servlet container (= runtime
enviroment)
• Are object-oriented
• Often used together with other web technologies (Java
Server Pages, static HTML pages)
• Typical functions: generate dynamic HTML-code,
database queries, simple business processes
Servlet Life Cycle
The life cycle of a servlet is controlled by the container in which the servlet has
been deployed. When a request is mapped to a servlet, the container performs
the following steps.
1. If an instance of the servlet does not exist, the web container
a. Loads the servlet class.
b. Creates an instance of the servlet class.
c. Initializes the servlet instance by calling the init method.
2. Invokes the service method, passing request and response objects.
If the container needs to remove the servlet, it finalizes the servlet by calling the
servlet’s destroy method.
From: Sun J2EE –Tutorial, p.447
Servlet Libraries
• See packages
– javax.servlet.* and
– javax.servlet.http.*
• Most important: Servlet
• Generic objects and interfaces
– GenericServlet
– ServletRequest
– ServletResponse
• Web objects and interfaces
– HttpServlet
– HttpServletRequest
– HttpServletResponse
Writing your own Servlets
• Three ways to program a Servlet
– Implement the Servlet interface
– Extend the class GenericServlet
– Extend the class HttpServlet
• Im most cases you will extend HttpServlet
• Each Servlet has to implement the Servlet interface (this
can also be done implicitly by extending
GenericServlet or HttpServlet)
• Servlet Container relies on methods in this interface
Servlets – Very simple example
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
public class HelloServlet extends HttpServlet {
public void doGet (HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
PrintWriter out = res.getWriter();
out.println("HelloWorld");
out.close();
}
}
HttpServletRequest / Response
• See online API documentation:
http://java.sun.com/j2ee/1.4/docs/api/javax
/servlet/http/HttpServletRequest.html
Servlet – Simple Example
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
// Im Browser: http://localhost:8080/BMI/beispiel
public class BMIServlet extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String
String
String
String
name = req.getParameter("name");
vorname = req.getParameter("firstname");
groesse = req.getParameter("groesse");
gewicht = req.getParameter("gewicht");
Double heigth = new Double(groesse);
Double weight = new Double(gewicht);
double h = heigth.doubleValue();
double g = weight.doubleValue();
double bmi = g / (h * h);
Double BMI = new Double(bmi);
Servlet – Simple Example (cont.)
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<title>Ergebniss dieser BMI –
Berechnung</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello " + vorname + " " + name + "</h1>");
out.println("<h1>Ihr BMI ist " + BMI + "</h1>");
out.println("</body>");
out.println("</head>");
out.close();
}
}
Enterprise Java Beans (EJB)
• Where we are
Copyright Sun Microsystems
Enterprise Beans - Overview
• In multi-tier applications an enterpise bean is a serverside component
• Implements (and encapsulates) business logic of an
application
• provides system-level services such as transaction
management, concurrency control, and security
• EJB technology provides a distributed component model
that enables developers to focus on solving business
problems
• J2EE platform helps to handle complex systemlevel
issues.
4-Tier Architecture with EJBs
EJB - Container
• EJBs are created and managed at runtime by a
container
• Features of an EJB container
–
–
–
–
–
–
–
Lifecycle management of bean instances
Ressource management
Remote access to instances
Transaction management
Security
Persistence
Deployment Tools
EJB - Components
• Each EJB consists of several components
EJB – Naming Conventions
Home - Interface
• Manages the lifecycle of EJB instances
• Method types
– Create – methods, find – methods, remove methods
• Example
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface BMIHome extends EJBHome {
BMI create() throws RemoteException, CreateException;
}
Remote - Interface
• Definition of all business methods (only method
signatures, not implementation)
• Example
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface BMI extends EJBObject {
public double calculateBMI(double weight, double height)
throws RemoteException;
}
Enterprise Bean Class
• Implements the methods in the Home – Interface
– For each create-method in home interface we need a
corresponding ejbCreate-method
• Implements each (business-) method defined in the
Remote – Interface
• Implements several administrative callback-methods
(EJB-Container needs these methods, ejbActivate())
• All these methods are never called by clients directly, but
allways via the home- or remote-interface (delegation)
EJB - Example
import
import
import
import
java.rmi.RemoteException;
javax.ejb.EJBException;
javax.ejb.SessionBean;
javax.ejb.SessionContext;
public class BMIBean implements SessionBean {
private static final long serialVersionUID = 1L;
public double calculateBMI(double groesse, double gewicht) {
return (gewicht / (groesse * groesse));
}
public BMIBean() {
}
public
public
public
public
public
}
void ejbCreate() {}
void ejbActivate() throws EJBException, RemoteException {}
void ejbPassivate() throws EJBException, RemoteException {}
void ejbRemove() throws EJBException, RemoteException {}
void setSessionContext(SessionContext arg0) throws EJBException,
RemoteException {}
Types of Enterprise Beans
• Three different types of Enterprise Beans
• Session Beans
– Performs a task (e.g. computations) for a client, often used to
model processes
• Entity Beans
– Represents a business object (e.g. customer) that exists in a
persistent storage
• Message Driven Beans
– Processes messages asynchronously
– Acts as a listener for the Java Message Service API
Entity Beans
• An entity bean is a persistent object that represents data
maintained in a data store;its focus is data-centric.
• An entity bean is identified by a primary key.
• An entity bean can manage its own persistence or it can
delegate this function to its container.
• An entity bean can live as long as the data it represents.
Persistence is handled in one of two ways:
– Bean-managed persistence—The developer handles
persistence as part of the entity bean’s source code
– Container-managed persistence—The developer specifies the
bean fields that need to be persistent and lets the EJB container
manage persistence.
From: [ 1 ], page 29
Message Driven Bean
• A message-driven bean enables asynchronous clients to
access the business logic inthe EJB tier.
• Message-driven beans are activated only by
asynchronous messages received from a JMS queue to
which they listen.
• A client does not directly access a message-driven bean;
instead, a client asynchronously sends a message to a
JMS queue or topic.
• Because message-driven beans have no need to expose
their methods to clients, they do not implement
component or home interfaces.
• They also do not maintain state on behalf of a client.
From: [ 1 ], page 30
Session Beans
• A session bean is created to provide some service on
behalf of a client and usually exists only for the duration
of a single client-server session.
• A session bean performs operations such as calculations
or accessing a database for the client.
• Session beans can be stateless or can maintain
conversational state across methods and transactions.
• If they do maintain state, the EJB container manages this
state if the object must be removed from memory.
• However, the session bean object itself must manage its
own persistent data.
From: [ 1 ], page 29
Session Bean - Example
Deployment Descriptor
• A Deployment Descriptor (DD) is a XML-file
• It describes the contents of deployment units (e.g. EJBs)
and configure components to their environment.
• Avoids hard-coding of some properties of enterprise
beans (e.g. mapping of instance variables to database
fields)
• DD are used for
– Persistance management
– Transaction management
– Security
• DD are usually generated by tools (e.g. SUN Deploy
Tool)
Application clients
• Coding the (web-) client
– Locating the home interface of an EJB
– Creating an enterprise bean instance
– Invoking a business method
• Compiling the client (automatically done by you favorite
IDE)
• Packaging the web client
• Specify and ap the client‘s EJB reference
• Deploy everthing
• Run the application
Application Client (Example)
import …
public class BMIEJBServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String
String
String
String
String
name = req.getParameter("name");
vorname = req.getParameter("firstname");
groesse = req.getParameter("groesse");
gewicht = req.getParameter("gewicht");
fehler = "Fehlermeldung:";
Double dgroesse = new Double(groesse);
Double dgewicht = new Double(gewicht);
double diegroesse = dgroesse.doubleValue();
double dasgewicht = dgewicht.doubleValue();
double bmi = 0.0;
// Ausgelagert in die Bean
try {
Context initial = new InitialContext();
Context myEnv = (Context)initial.lookup("java:comp/env");
Object objref = myEnv.lookup("ejb/BMIBean");
fehler = objref.toString();
BMIHome home =
(BMIHome) PortableRemoteObject.narrow(objref,
BMIHome.class);
fehler = fehler + home.toString();
BMI myBMI = home.create();
fehler = fehler + myBMI.toString();
bmi = myBMI.calculateBMI(diegroesse, dasgewicht);
}
catch(NamingException e) {fehler = fehler + "NamingException";}
catch(CreateException e) {fehler = fehler + "NamingException";}
/* Ausgabe in HTML Seite */
Double bmiValue = new Double(bmi);
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<title>Ergebniss dieser BMI - Berechnung</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello " +fehler + "..."+ vorname + " " + name +
" " + dgroesse +" " + dgewicht +"</h1>");
out.println("<h1>Ihr BMI ist " + bmiValue + "</h1>");
out.println("</body>");
out.println("</head>");
out.close();
}
Summary
• Objectoriented Analysis and Design of an application
• Implementaion of the components (make or buy) by
using J2EE technologies
• Testing (components)
• Packging
• Deployment
• „Einsatz“
• Maintenance