PowerPoint 演示文稿

Download Report

Transcript PowerPoint 演示文稿

Middleware Technology (J2EE/EJB)
Stateless Session Bean
Session Beans (Stateless)
• How to develop an EJB Component
(1) Write the .java files that compose your bean
(2) Write the deployment descriptor
(3) Compile the .java files
(4) Using the jar utility to create an ejb-jar file containing the descriptor and .class
files
(5) Deploy the ejb-jar file into your container in a vendor-specific manner
(6) Configure your EJB server in a vendor-specific manner
(7) Start your EJB container
(8) Optionally, write a test client
2
Object Model of the first
Stateless Session Beans
3
Java sources
•
•
•
•
•
the Remote Interface ---- Hello (Hello.java)
the Local Interface ---- HelloLocal (HelloLocal.java)
the Home Interface ---- HelloHome (HelloHome.java)
the Local Home Interface ---- HelloLocalHome (HelloLocalHome.java)
the Bean Class (HelloBean.java)
setSessionContext()
(Demo 1: J2SDKEE developing,
StatelessSession/J2SDKEE/readme.txt)
4
5
EJB Context Object
• A bean’s status may change over the bean’s life cycle, and thus the
EJB context object can dynamically change over the time as well.
• A bean can query the container for information about its current
status or modify its current status through the EJB context object,
which can be derived from calling setSessionContext() method.
• An EJB context contains callbacks useful for session beans, entity
beans and message-driven beans. In comparison, a session context,
entity context and message-driven context are specific EJB contexts
used only for session beans, entity beans and message-driven beans.
6
Exceptions and EJB
• Every method in an EJB object and Home object must throw a
remote exception to indicate a special error condition ---- a network
failure、machine failure、or other catastrophic failure.
• EJB defines two types of exception:
 System-level Exception
not necessarily thrown back to the client, container in charge of the
system-level exception. (*)
 Application-level Exception
always thrown back to then client, including CreateException、
FindException、user-defined exceptions (such as insufficient funds in a
bank account).
7
Deployment Descriptor and Vendor-Specific Files
• A deployment descriptor is an XML document. The default file name is ejbjar.xml, which is required by the EJB specification.
• EJB specification can’t cover everything, vendors differentiate their products in
areas such as instance pooling algorithms, clustering algorithms, and so on. The
vendor-specific files are not portable and can use any file format, including
XML、flat file, or binary.
8
The Client Side
• How to call beans




Look up a Home object
Use the Home object to create an EJB object
Call business methods on the EJB object
Remove the EJB object
• Two different kinds of clients
 Java RMI-IIOP based clients
using JNDI to look up objects over network and using JTA to control
transaction
 CORBA clients
using CORBA Naming Service (COS Naming) to look up objects over
network and using CORBA Object Transaction Service (OTS) to control
transaction.
9
Deployment
• Compile source codes
• Start j2ee server
j2ee -verbose
10
Start deploytool
11
Create a new application
12
13
Create a new Enterprise Bean
1.Select an application (HelloApp) 2. File/New/Enterprise Bean
14
Configure Enterprise Bean
15
Configure JNDI name
16
Deploy application client
1. Select an application (HelloApp) 2. File/New/Application Client
17
18
Deploy Application
• Tools/deploy
• Tools/Verifier
• Tools/Update
• Tools/Update and Redeploy
19
Web Component
1. Select an application (HelloApp) 2. File/New/Web Component
20
21
22
Config the context of WebApp
23
Using Local interface in Web Component
Change client.jsp and24redeploy
Output in Server Console
• Method Invocation Sequence
– setSessionContext()
– ejbCreate()
– hello()
25