Title: J2EE Introduction
1J2EE Introduction
- EJB, JSP/Servlets, JMS, JDBC
2TerminologyJ2EE
- A specification
- Version 1.4 document (24 Nov 2003, 246 pgs.)
- Response to JSR-151 (not just a Sun thing)
- Umbrella which freezes other technologies
- Each has its own spec / rev reference
implementation - A Download
- Interfaces (javax. above / beyond J2SE)
- Reference implementation
- Rollup of individual technologies reference
implementations - E.g. Tomcat 4.X for Servlet 2.0
- Compatibility Test Suite
- BluePrints (best practices documents)
3(No Transcript)
4(No Transcript)
5(No Transcript)
6J2EE Goals
- High Availability
- Security
- Reliability
- Scalability
- of Enterprise Information Services (EISs),
- Usually in a multitier environment.
7(No Transcript)
8J2EE Technologies Givens
- J2SE 1.4.2_02
- JDBC 3.0 java.sql
- javax.sql
- JAXP 1.2 org.w3c.dom
- org.w3c.sax (3)
- javax.xml.parsers
- javax.xml.transform (4)
- JTA 1.0 javax.transaction.xa
- JNDI javax.naming (DNS, LDAP, COS, RMI)
- RMI-IIOP javax.rmi
- org.omg. (30)
- JavaIDL, CORBA
9J2EE Technologies Top Four
- EJB 2.1 javax.ejb
- Servlet 2.4 javax.servlet
- JSP 2.0 javax.servlet.jsp (3)
- JMS 1.1 javax.jms
10J2EE Technologies 11 More
- JavaMail 1.3 javax.mail
- JAF 1.0 javax.activation
- Connector 1.5
- Web Services 1.1 javax.xml.
- JAX-RPC 1.1
- SAAJ 1.2
- JAXR 1.0 javax.resource.
- J2EE Mgmt 1.0 javax.management.
- JMX 1.2
- J2EE Deploy 1.1 javax.enterprise.deploy.
- JACC 1.0 javax.security.jacc
11Application Component Types
- Applets (Just like conventional Applet)
- Application Clients
- Just like conventional J2SE application
- Except may require J2EE APIs
- JSP / Servlet
- Anything that talks HTTP
- Requires container Apache/Tomcat is RefImpl
- EJB
- Transactional component
- Requires container server
- Download gives you RefImpl
12(No Transcript)
13TerminologyEJB
- A specification from Sun Microsystems
- EJB 1.1 document (285 pgs.)
- javax.ejb. interfaces (12)
- NOT an implementation! NOT JavaBeans!
- Framework for enterprise components
- Alternatives DCOM, CORBA
- 50,000 ft view
- J2EE, J2SE, J2ME (EJB part of J2EE)
- Related J2EE specs JNDI, JMS, JTA, JAAS
14EJB Spec...Six Roles
- The CastIn Order of Appearance
- 1. EJB Server Provider
- 2. EJB Container Provider
- 3. EnterpriseBean Provider
- 4. Deployer
- 5. Application EJB Client Assembler
- 6. System Administrator
- EJB Spec lists roles in a different order
- EnterpriseBean-centric vice chronological
Combined for our purposes...
15EJB Server Container
- Implement majority (4/5?) of EJB spec
- Provide backbone of EJB System
- Mediator among other players
- EJB Clients
- EnterpriseBeans
- At least one backend database
- Various implementations (cross compatible)
- BEA/Weblogic, IBM/Websphere, 8 others
- EJB 2.X should clear up Container bounds
16Terminology...EnterpriseBean1
- Reusable software component
- Logic only no GUI
- Built / bought to meet a business need
- Banking BankAccountBean
- Shipbuilding ProductStructureBean
- Deployed to an EJB Server implementation
- Serves multiple users across enterprise
- HR, Finance, Design, Planning, Ops, Logistics
17Terminology...EnterpriseBean2
- Compiled Java class file
- Implements EnterpriseBean interface
- Instantiated (newd) by Container
- Satisfies client needs for objects of type X
- Maps to two java.rmi.Remote interfaces
- XHome (home, used by client to create / find)
- X (used by client to execute business methods)
- Doesnt actually implement X and XHome
- EJB Compiler (from Container) enforces mapping
18TerminologyEJB Client
- Application that uses EnterpriseBeans
- GUI or non-GUI (e.g. Servlets)
- Java or CORBA
- Remote or local (EB Intranet NNS other
EnterpriseBeans) - Client view is remote interfaces
- XHome Xbut NOT EnterpriseBean!
- Considered less trustworthy than server side
- Client flaw should not affect EJB Server
19EJB Architecture
EJB Server
Container
XHome
create() find()
EnterpriseBean
Client
X
Existing Database
(Wire)
(Wire)
Tier 1Tier 2..Tier N
20Why All the Fuss?
- The Alternative a straight RMI impl
- XImpl provides not only business logic, but also
- transactions, security, concurrency, access
control, database connectivity - EJB separates responsibilities
- Business logic goes in the EnterpriseBean
- systems stuff is provided by Server / Container
X
Client
XImpl
21Relationship to UML
- Each UML class is an X
- EB writes X, XHome remote interfaces
- Specify client-side contract
- Ensure cross-project needs are met
- CSC implements EnterpriseBean for X
- Satisfy X, Xhome
- Map to persistent store
- Arbitrate where business logic resides
- No code generation (today)
22EJBean Lifecycle
Doesnt Exist
ejbFind()
pooled
ejbPassivate()
ejbRemove()
ejbCreate()
ejbActivate()
ready
ejbLoad()
ejbStore()
businessMethod()
23Outline for Lesson 2
- Intro to javax.ejb package
- Writing Java Code
- How to write an EntityBean
- Bean-managed Persistence (BMP)
- Container-managed Persistence (CMP)
- How to write a SessionBean
- Writing a Deployment Descriptor
- Manifests, ejb-jars, and EJB Compilers
- Deploying an EnterpriseBean
24Terminology...EntityBean
- EnterpriseBean that is long lived
- Maps to backend data store
- Bean-managed persistence
- Container-managed persistence
- Has unique key (primary key or XPK)
- Implements EntityBean interface
- Examples
- EmployeeBean with SSN as PK
25TerminlogySessionBean
- EnterpriseBean that is short lived
- Duration no longer than user login
- State not stored to any database
- Examples
- ShoppingCartBean
- TableModelBean
- Implements EnterpriseBean interface
26javax.ejb Package
- 6 classes
- All are of type Exception
- Cover this in greater detail in Lesson 3
- 12 interfaces
- 6 are seen by EJB Client
- other 6 are only seen by EJB Server/Container
- Often implement java.io.Serializable or
java.io.Remote - Thats it.
27javax.ejb Interfaces (5/12)
java.rmi.Remote
java.io.Serializable
javax.ejb.EnterpriseBean
javax.ejb.EJBHome
javax.ejb.EJBObject
javax.ejb.SessionBean
javax.ejb.EntityBean
YBeanImpl
X
XHome
YHome
Y
XBeanImpl
Client Server
28Reality Check
- What does the Bean Provider provide?
- Which are concrete? Which are interfaces?
- EB Roles? CSC/AD Roles?
- Why have X, Y interfaces without impls?
- What can we say about reqd methods on
- X, Y?
- Xhome, Yhome?
- XBeanImpl?
- YBeanImpl?
29X,Y Required Methods
- Entity, Session bean remote interfaces share
EJBObject - EJBHome getEJBHome()
- Handle getHandle()
- Object getPrimaryKey()
- boolean isIdentical(EJBObject obj)
- Similar to .equals() method
- void remove()
- EJBObject extends java.rmi.Remote
30XHome,YHome Reqd Methods
- Entity / Session share EJBHome interface
- Summation of Requirements
- EJBMetaData getEJBMetaData()
- void remove(Handle handle)
- void remove(Object primaryKey)
- void create() // Session/Entity
- void findXXX() // Entity Only
- Any EJBean can be referenced either by handle or
primaryKey. EJBHome provides means for removing.
- All create()s must be named create, but may be
overloaded - All findXXX()s map to ejbFindXXX on EJBean.
31XBeanImpl Required Methods
- Entity beans are distinct from Session
- But no distinction between Bean Managed
Container Managed Persistence - Void ejbActivate()
- Invoked by container to associate with EJBObject
- void ejbLoad()
- Do a database lookup (bean-managed persistence
only) - void ejbPassivate()
- Invoked by container about to get dissociated
with EJBObject - void ejbRemove()
- void ejbStore()
- - Persist yourself to database (bean-managed
persistence only) - void setEntityContext(EntityContext ctx)
- void unsetEntityContext()
32YBeanImpl Required Methods
- SessionBeans are distinct from Entity
Void ejbActivate() void ejbPassivate() void
ejbRemove() void setSessionContext(SessionContext
)
33Division of EffortEntityBean
- Decide on UML model
- EB
- Write XHome and X interfaces
- EB
- Write XBeanImpl
- CSC
34Client Side...Handle
- EJBObject getEJBObject()
- Any handle has knowledge of home as well as key,
so it can be used to locate and return reference
to EJBObject. - All handles are Serializable
35Client Side...EJBMetaData
- EJBHome getEJBHome()
- Class getHomeInterfaceClass()
- Class getPrimaryKeyClass()
- Class getRemoteInterfaceClass()
- boolean isSession()
- Allow introspection by remote integrated
development environments.
36Server SideEnterpriseBean
- Common superclass of
- SessionBean
- EntityBean
- extends Serializable
- Thats it!
37Server SideEJBContext
- Identity getCallerIdentity()
- Identify caller on per-call basis
- EJBHome getEJBHome()
- Properties getEnvironment()
- boolean getRollbackOnly()
- dont waste time if rollback set
- UserTransaction getUserTransaction()
- boolean isCallerInRole(Identity role)
- implement role-based access
- void setRollbackOnly()
- set rollback so other trans dont waste time