You are on page 1of 15

Implementing SOA with EJB 3.

Ingmar Rtzler

HPI, Seminar System Modeling SS2006 Implementing SOA with EJB 3.0 / 1

Outline

Introduction
Implementing services
Communication
Synchronous with session beans
Web services
Asynchronous communication

Loose Coupling
Persistence
Conclusion
Sources

HPI, Seminar System Modeling SS2006 Implementing SOA with EJB 3.0 / 2

EJB Technology

Java EE 5 technology for developing business components


Provide logic and represent data specific to a business area
e.g. perform banking account operations
Services provided by the EJB runtime environment:
Persistence
Transactions
Security
Scalability

HPI, Seminar System Modeling SS2006 Implementing SOA with EJB 3.0 / 3

Enterprise JavaBeans

Standardized components
Portable
Deployed in any compliant J2EE application server
Flexibility in distributing the components of an application

Reusable
May be used in multiple business applications

Managed
EJB container provides system-level services, e.g. transactions, security
Developer free to concentrate on application logic and data aspects

HPI, Seminar System Modeling SS2006 Implementing SOA with EJB 3.0 / 4

Rope Shop: Services

Required services:
Order Processing System
Customer Relationship Management
Billing System

Implemented as stateless session beans


Represents single unique session between client and bean instance
Exposes methods to execute business tasks
Does not maintain conversational state with client
Better scalability for applications that require large numbers of clients

Stateful session bean possible to retain client-bean session state

HPI, Seminar System Modeling SS2006 Implementing SOA with EJB 3.0 / 5

Rope Shop: Architecture

HPI, Seminar System Modeling SS2006 Implementing SOA with EJB 3.0 / 6

Client access to session beans

Business interface defines client's view of a session bean


Remote interface exposes business methods
Client may be web component, application client, or another enterprise bean
May be on different machine and JVM

Local interface mostly for tightly coupled components


Client may be web component or another enterprise bean
Must be in the same JVM

Use of interfaces allows easy change of bean implementation


All communication is synchronous

HPI, Seminar System Modeling SS2006 Implementing SOA with EJB 3.0 / 7

Rope Shop: Order Process

HPI, Seminar System Modeling SS2006 Implementing SOA with EJB 3.0 / 8

Web Service Support

Any web service client can access a stateless session bean


Automatic generation of web service endpoint

Invocation of business methods annotated with @WebMethod


Enterprise beans can also be clients of web services
Great flexibility in integrating Java EE applications with web services

HPI, Seminar System Modeling SS2006 Implementing SOA with EJB 3.0 / 9

Asynchronous communication

Message-driven beans process asynchronous messages


Typically receives messages from Java Message Service (JMS)
Messages can be sent by any Java EE component

Execute upon receipt of a single client message


Stateless (no conversational state)
May access and update shared data
Useful in many business-to-business communication scenarios

HPI, Seminar System Modeling SS2006 Implementing SOA with EJB 3.0 / 10

Loose coupling and configuration

EJB container supports Dependency Injection


Automatic supply of object's dependencies
No explicit request for resource required
Applicable to all resources of a component
Usable throughout Java 5 technology

Effectively hiding creation and lookup of resources from code


Allows dynamic configuration of resources
Container provides dependencies at run-time

HPI, Seminar System Modeling SS2006 Implementing SOA with EJB 3.0 / 11

Rope Shop: ER-Diagram

HPI, Seminar System Modeling SS2006 Implementing SOA with EJB 3.0 / 12

Rope Shop: Entities

Required entities: Customer, Supplier, Order, ...


Implemented as entity beans
Represent data in a storage medium
Hibernate-inspired O/R mapping
Relationships with other entity beans, e.g. one-to-many

Can be shared (transaction management important)


Persistent (because of underlying database)
Detached entity beans possible (e.g. serializable)
But still major problem to return persistent objects to clients

HPI, Seminar System Modeling SS2006 Implementing SOA with EJB 3.0 / 13

Conclusion

Many SOA concepts applicable


Statelessness (stateless session beans)
Composition (reuse of existing beans)
Loose coupling (dependency injection)
Configuration through container
Customization (use of interfaces)
Open standards (web services)

Drawbacks
No metadata description of services (only business interface)
No central service repository (no automatic discovery)
Dependency on heavyweight EJB container

HPI, Seminar System Modeling SS2006 Implementing SOA with EJB 3.0 / 14

Sources
Sun Microsystems. EJB 3.0 Specification Final Release
http://java.sun.com/products/ejb/docs.html

Sun Microsystems. The Java EE 5 Tutorial, 2006


http://java.sun.com/javaee/5/docs/tutorial/doc/index.html

John Stearns, Roberto Chinnici, and Sahoo. Update: An Introduction to the


Java EE 5 Platform, 2006
http://java.sun.com/developer/technicalArticles/J2EE/intro_ee5/

Ed Ort. Ease of Development in Enterprise JavaBeans Technology, 2004


http://java.sun.com/developer/technicalArticles/ebeans/ejbease/index.html

Anil Sharma. EJB 3.0 in a nutshell, 2004


http://www.javaworld.com/javaworld/jw-08-2004/jw-0809-ejb.html

JBoss. JBoss EJB3, 2006 http://labs.jboss.com/portal/jbossejb3/index.html


Chris Richardson. POJOs in Action. Manning, 2006

HPI, Seminar System Modeling SS2006 Implementing SOA with EJB 3.0 / 15