Web-Tier Components

Download Report

Transcript Web-Tier Components

J2EE Overview
Copyright © 2004, Oracle. All rights reserved.
Objectives
After completing this lesson, you should be able to do
the following:
• Describe the Java™ 2, Enterprise Edition (J2EE)
platform
• Define the various components of J2EE
• Describe the deployment options for a J2EE
application
• Describe the architecture of Oracle Application
Server 10g Containers for J2EE (OC4J)
• Describe the directory structure and the uses of
the configuration files of OC4J
2-2
Copyright © 2004, Oracle. All rights reserved.
Java 2, Enterprise Edition Platform
The Java 2, Enterprise Edition (J2EE) platform is a
standard for developing and implementing
enterprisewide applications:
• It provides multitier applications support.
• It is designed to help improve the process of
developing, deploying, and implementing
enterprisewide applications.
2-3
Copyright © 2004, Oracle. All rights reserved.
J2EE Platform
•
•
Is a multitiered, distributed application model
Supports component-based J2EE applications
Servlet
Web clients
JSP Page
Web components
Application
Enterprise
Beans
Browser
2-4
EJB clients
EJB components
Client tier
Middle tier
Copyright © 2004, Oracle. All rights reserved.
EIS tier
Benefits of the J2EE Platform
•
•
•
•
•
2-5
“Write once, run anywhere” provides simplified
component development.
Multiple server products and vendors support the
J2EE standard, thus giving more deployment
choices.
Integration with legacy systems through standard
APIs is possible.
J2EE separates client requirements from business
logic.
J2EE provides multiple development and design
scenarios.
Copyright © 2004, Oracle. All rights reserved.
Benefits of the J2EE Platform
•
•
•
•
•
2-6
J2EE separates development tasks into specific
skill areas.
Web designers can create JSP components.
Application behavior is created by Java
programmers.
Business logic and rules are created by Java
programmers and business experts.
Assembly and deployment can be assigned to
production environment teams.
Copyright © 2004, Oracle. All rights reserved.
J2EE Components
•
•
•
•
•
J2EE is a component-based architecture for the
development and deployment of enterprisewide
applications.
A component is an application-level software unit.
Components can be easily updated as business
needs change.
Components are reusable.
There are several types of components:
– Client-side components
– Web components
– Business-tier components
2-7
Copyright © 2004, Oracle. All rights reserved.
J2EE 1.3 Components
The J2EE 1.3 Specification lists the following
components:
• Java Message Service
• Servlet 2.3
1.0.2
• JavaServer Pages 1.2
• Java Transaction API 1.0
• Enterprise
• Java Authentication and
JavaBeans 2.0
Authorization Service
• JDBC 2.0
1.0
• RMI-IIOP
• J2EE Connector
• JNDI 1.2
Architecture 1.0
• Web services 1.1
• SOAP with Attachments
API for Java 1.1
2-8
Copyright © 2004, Oracle. All rights reserved.
J2EE Architecture
J2EE Server
Web Container
Browser
Application
Client
Java Servlet/JSP
EJB
EJB
Business container
APIs
Application
Client
Container
JNDI
JTA
JMS
Client Machine
RMI
JDBC
JAF
JavaMail
2-9
Copyright © 2004, Oracle. All rights reserved.
Database
Client-Tier Components
•
A Web browser:
– Is used for a Web-based J2EE application
– Downloads static or dynamic Web pages from Webtier components
– Is a thin client
•
An application client:
–
–
–
–
–
2-10
Is used for a non-browser-based J2EE application
Executes on the client machine
Can contain a graphical or command-line interface
Is a thick client
Accesses business-tier components or a servlet on
the Web tier
Copyright © 2004, Oracle. All rights reserved.
J2EE Web-Tier Components
•
A Web tier may consist of:
– Java servlets
– JSPs
•
Servlets and JSPs:
–
–
–
–
–
Work on a request-response model
Generate HTML dynamically
Access the database through JDBC
Access the business-tier components
Handle user-centric events, such as an HREF link or
form submission
– Usually generate visual interfaces such as a Web
page
2-11
Copyright © 2004, Oracle. All rights reserved.
What Is a Servlet?
Servlet
Browser
Client info (host name,
form data)
Request
Process results
(access database)
Format results and produce
HTML
Success or failure
Send page back to client
Response
2-13
Copyright © 2004, Oracle. All rights reserved.
What Is a JavaServer Page (JSP)?
A JSP:
• Is a text-based document that includes:
– HTML
– JSP tags
– Java code (including calls to JavaBeans
and servlets)
•
•
•
2-14
Cleanly separates content creation from
presentation logic
Focuses on rapid development and easy
modification of the user interface
Provides presentation-centric method of
developing servlets
Copyright © 2004, Oracle. All rights reserved.
Web-Tier Components: Summary
•
•
Web-tier components generate dynamic content.
Servlets:
– Extend Web server functionality
– Are designed more for processing than for
presentation
•
JSPs:
– Combine HTML (or other markup) and Java
– Are designed to separate content creation from
presentation logic
– Are precompiled and converted to servlets at run
time
2-15
Copyright © 2004, Oracle. All rights reserved.
Business-Tier Components
Business-tier components:
• Are EJBs
• Handle business logic
• Receive data from client programs
• Retrieve data from database storage
• Process the data and communicate with the
database and the client program
• Can be invoked by the Web-tier components
2-16
Copyright © 2004, Oracle. All rights reserved.
Enterprise JavaBeans (EJB)
Enterprise JavaBeans:
• Are server-side components written in Java
• Contain the business logic of an enterprise
application
• Are hosted in EJB containers
• Are based on Remote Method Invocation (RMI)
communication
• Are platform independent
• Provide remote services for clients
• Can be exposed as Web services
• Use JDBC to connect to a database
2-17
Copyright © 2004, Oracle. All rights reserved.
J2EE Communication APIs
•
•
J2EE provides component communication
through APIs.
The APIs include:
– RMI
– JNDI
– JDBC
•
2-18
These APIs facilitate communication between the
J2EE components.
Copyright © 2004, Oracle. All rights reserved.
J2EE Server
The J2EE server provides:
• Containers for each component type of a J2EE
application
• System-level services to components:
– Naming and directory services (JNDI)
– Security services for Web components and EJBs
(JAAS)
– Transaction architecture (JTA)
– Remote client connectivity:
Enterprise beans (RMI/IIOP, ORMI)
Servlet/JSP (HTTP, HTTPS, FTP)
2-19
Copyright © 2004, Oracle. All rights reserved.
Oracle Application Server 10g Containers
for J2EE (OC4J)
•
•
OC4J is the J2EE server implementation in Oracle
Application Server 10g
Key features:
–
–
–
–
–
–
2-21
Implements J2EE 1.3 Specification
Runs on standard JVM
Provides high performance and scalability
Is productive for developers to use
Is simple to manage and deploy
Provides clustering for high availability and failover
Copyright © 2004, Oracle. All rights reserved.
J2EE Applications
J2EE applications consist of J2EE components and
are deployed in the form of modules:
• Web modules contain the user interface: HTML,
JSP, and servlets.
• EJB modules contain reusable EJB components.
• Client modules provide access to remote
application code.
• Packaging information identifies dependencies
between modules.
2-22
Copyright © 2004, Oracle. All rights reserved.
Packaging J2EE Application Components
1. ejb.jar
Bean class, Home and Remote
interfaces, other supported files, DD
2. webtier.war
Java servlets, JSP files, HTML, GIF files,
DD (references to EJBs)
J2EEapplication.ear
3. J2EEappClient.jar
J2EE application client (Java class),
DD (references to EJBs)
4. DD for J2EE application (.xml)
DD = XML Deployment
Descriptor
2-23
5. Resource adapter (.rar)
Copyright © 2004, Oracle. All rights reserved.
JARs
•
•
•
•
2-24
Are simple Java Archive files
Are used to package application files together
(for example, classes, images, and so on)
Can be included in Web Archives (WARs) and
Enterprise Archives (EARs)
Can be included in library paths
Copyright © 2004, Oracle. All rights reserved.
WARs
•
•
•
Are specialized archives for packaging J2EEcompliant Web applications
Have a fixed directory structure
Have a deployment descriptor for the Web
application
WEB-INF
web.xml
classes
lib
index.html
Contain servlet code and
JavaBeans not in standard
JAR files
Contains required classes
that are packaged in
standard JAR files
welcome.jsp
2-25
Copyright © 2004, Oracle. All rights reserved.
EJB JARs
•
•
•
Are specialized JARs for packaging EJBs
Have a fixed directory structure
Have a deployment descriptor for the EJB
components
myEJB
META-INF
ejb-jar.xml
EJB Classes
Remote, Home and
Bean classes
2-26
Contain the class files
for the EJBs, usually
in a package directory
structure
Copyright © 2004, Oracle. All rights reserved.
EARs
The EAR files:
• Are specialized archives for packaging J2EEcompliant enterprise applications for deployment
• Have a deployment descriptor
• May have Web modules
• May have EJB modules
• May have client modules
2-27
Copyright © 2004, Oracle. All rights reserved.
EAR File Structure for a
J2EE Application: Example
<appname>
|-------META-INF
|
|-------application.xml
|-------<ejb_module>
|
|-------EJB classes
|
|-------META-INF
|
|-------ejb-jar.xml
|-------<web_module>
|
|-------index.html
|
|-------JSP pages
|
|-------WEB-INF
|
|----web.xml
|
|----classes
|
|-------Servlet classes
|-------<client_module>
|
|-------Client classes
|
|-------META-INF
|
|-------application-client.xml
2-28
Copyright © 2004, Oracle. All rights reserved.
OC4J Architecture
Oracle HTTP
Server
HTTP
JNDI
AJP
mod_oc4j
AJP13
Web
container
JMS
JDBC
JTA
Client
JAAS
ORMI
EJB
container
JCA
JavaMail
ORMI
JAF
EJB client
2-29
OC4J server process
Copyright © 2004, Oracle. All rights reserved.
OC4J Server Configuration Files
OC4J Server XML Files
Server Configuration
server.xml
jazn.xml*
jazn-data.xml*
Web site
Web
Website
site
default-website.xml
data-sources.xml
rmi.xml
jms.xml
Oracle HTTP Server
configuration files
mod_oc4j.conf
2-30
Copyright © 2004, Oracle. All rights reserved.
Relation of Configuration Files
•
When an application is deployed, an entry is made in
the \config\server.xml file:
<application name="lesson02"
path="../applications/lesson02.ear" />
•
For each Web module within the application, a context
root is defined in \config\default-web-site.xml:
<web-app application="lesson02" name="webapp1"
root="/lesson02"/>
•
The modules of the application are defined in
\applications\lesson02\METAINF\application.xml:
<web><web-uri>webapp1.war</web-uri></web>
2-31
Copyright © 2004, Oracle. All rights reserved.
Data Sources
A data source is the instantiation of an object that
implements the javax.sql.DataSource interface,
which enables you to retrieve a connection to a
database server.
• OC4J data sources are defined in datasources.xml.
•
2-32
J2EE applications use JNDI to look up these
DataSource objects.
Copyright © 2004, Oracle. All rights reserved.
Application Logging
•
Application logging in Oracle Application Server
10g is configured by specifying the location of a
log file in the application.xml file:
<log>
<file path="practice02-oc4j-app.log"/>
</log>
•
To create a log file formatted in XML, use Oracle
Diagnostic Logging (ODL):
<log>
<odl path="practice02-oc4j-app.log"/>
</log>
2-33
Copyright © 2004, Oracle. All rights reserved.
J2EE Application Deployment to
Oracle Application Server 10g
Deploying to OC4J can be done in multiple ways:
Step 1: Create WAR,
EAR file
Step 2: Deploy
Step 2: Deploy
Use a commandline tool (such as
ANT).
Use Oracle Enterprise Manager
(installed with Oracle Application
Server 10g): Access the
Enterprise Manager Web site
Use JDeveloper – specifyhttp://localhost:1810
an
Application Server and click
'Deploy'
(requires
login).
Use JDeveloper.
Use JDeveloper: Specify an
application server and click
“Deploy.”
2-34
Copyright © 2004, Oracle. All rights reserved.
Oracle Enterprise Manager
localhost
2-35
Copyright © 2004, Oracle. All rights reserved.
JDeveloper and J2EE
JDeveloper provides:
• Integrated development, deployment, and testing
support for Web-tier and business-tier
components
• A J2EE framework for rapid development
– Application Development Framework (ADF)
business components
– Data tags
•
•
•
•
2-36
Integration with Struts
UML modeling
JDeveloper
Visual editors for Web clients
Easy deployment to Oracle Application Server 10g
Copyright © 2004, Oracle. All rights reserved.
Oracle JDeveloper 10g Environment
Customizable code editor
Wizards for
JSPs,
servlets, and
EJBs
Error
checking
for HTML
and JSP
EAR, WAR
deployment
to J2EE
server
2-37
Code insight
Copyright © 2004, Oracle. All rights reserved.
Oracle JDeveloper 10g
Visual Design Tools
Drag JSP, HTML
elements
Design in visual
or code views
2-38
Modify values
in property
inspector
Copyright © 2004, Oracle. All rights reserved.
Summary
In this lesson, you should have learned that:
• J2EE is a set of Java technologies that support
end-to-end application development
• Components are the foundation of the J2EE
architecture
• Web components (servlets, JSPs) generate
dynamic content
• Business components (EJBs) are server-side
components that contain business logic
• Applications can be built by using Oracle
JDeveloper 10g and deployed to a J2EE server,
such as Oracle Application Server 10g
2-39
Copyright © 2004, Oracle. All rights reserved.
Practice 2-1: Overview
This practice covers the following topics:
• Navigating to the OC4J console by using Oracle
Enterprise Manager
• Mapping a data source in OC4J
• Restarting the OC4J server instance from Oracle
Enterprise Manager
• Deploying an EAR file by using Oracle Enterprise
Manager
2-40
Copyright © 2004, Oracle. All rights reserved.