Session Bean Examples
Session Bean Examples
Session Bean Examples
Session beans provide a simple but powerful way to encapsulate business logic within an
application. They can be accessed from remote Java clients, web service clients, and from
components running in the same server.
In
you built a stateless session bean named
ConverterBean
. This chapter examines the source code of three more session beans:
CartBean
: a stateful session bean that is accessed by a remote client
HelloServiceBean
: a stateless session bean that implements a web service
TimerSessionBean
: a stateless session bean that sets a timer
The cart Example
The cart session bean represents a shopping cart in an online bookstore. The bean's client can
add a book to the cart, remove a book, or retrieve the cart's contents. To assemble cart, you
need the following code:
Session bean class (CartBean)
Remote business interface (Cart)
All session beans require a session bean class. All enterprise beans that permit remote access
must have a remote business interface. To meet the needs of a specific application, an enterprise
bean may also need some helper classes. The CartBean session bean uses two helper classes
(BookException and IdVerifier) which are discussed in the section
The source code for this example is in the tut-install/javaeetutorial5/examples/ejb/cart/
directory.
22
C H A P T E R
2 2
657