EJB 3.1 Cookbook

Enterprise JavaBean 3.1 - Build real world EJB solutions with a collection of simple but incredibly effective recipes with this book and eBook

EJB 3.1 Cookbook

Cookbook
Richard M. Reese

Enterprise JavaBean 3.1 - Build real world EJB solutions with a collection of simple but incredibly effective recipes with this book and eBook
$32.99
$54.99
RRP $32.99
RRP $54.99
eBook
Print + eBook
$12.99 p/month

Get Access

Get Unlimited Access to every Packt eBook and Video course

Enjoy full and instant access to over 3000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

+ Collection
Free Sample

Book Details

ISBN 139781849682381
Paperback436 pages

About This Book

  • Build real world solutions and address many common tasks found in the development of EJB applications
  • Manage transactions and secure your EJB applications
  • Master EJB Web Services
  • Part of Packt's Cookbook series: Comprehensive step-by-step recipes illustrate the use of Java to incorporate EJB 3.1 technologies

Who This Book Is For

The book is aimed at Java EE and EJB developers and programmers. Readers should be familiar with the use of servlets in the construction of a web application. A working knowledge of XML is also desirable.

Table of Contents

Chapter 1: Getting Started With EJBs
Introduction
Creating a simple session EJB
Accessing a session bean using dependency injection
Accessing the session bean using JNDI
Creating a simple message-driven bean
Sending a message to a message-driven bean
Accessing an EJB from a web service (JAX-WS)
Accessing an EJB from a web service (JAX-RS)
Accessing an EJB from an Applet
Accessing an EJB from JSP
Calling an EJB from JSF
Accessing an EJB from a Java Application using JNDI
Accessing an EJB from a Java Application using an embeddable container
Accessing the EJB container
Chapter 2: Session Beans
Introduction
Creating a stateless session bean
Creating a stateful session bean
Creating a singleton bean
Using multiple singleton beans
Using container managed concurrency
Using bean managed concurrency
Controlling the initialization process
Using session beans with more than one business interface
Understanding parameter behavior and granularity
Using an asynchronous method to create a background process
Chapter 3: Message-Driven Beans
Introduction
Handling a string-based message
Handling a byte-based message
Handling a stream-based message
Handling a map-based message
Handling an object-based message
Using an MDB in a point-to-point application
Using MDB in a publish-and-subscribe application
Specifying which types of message to receive using the message selector
Browsing messages in a message queue
Chapter 4: EJB Persistence
Introduction
Creating an entity
Creating an entity facade
Using the EntityManager
Controlling the Object-Relationship Mapping (ORM) process
Using embeddable classes in entities
Using application-managed persistence
Validating persistent fields and properties
Validating null fields
Validating string fields
Validating temporal fields
Validating using regular expressions
Validating Boolean fields
Validating Integer fields
Using the Validator class
Chapter 5: Querying Entities using JPQL and the Criteria API
Introduction
Populating the Patient and Medication tables
Using the Select query
Using the Where clause
Controlling the number of entities returned by a Select query
Using the Delete query
Using the Update query
Using parameters in a query
Using a Named query
Using the Criteria API
Chapter 6: Transaction Processing
Introduction
Creating the Demonstration classes
Handling transactions the easy way
Using the SessionSynchronization interface with session beans
Understanding how the TransactionAttributeType affects transactions
Handling transactions manually
Rolling back a transaction
Handling errors in a transaction
Using timeouts with transactions
Chapter 7: EJB Security
Introduction
Creating the SecurityApplication
Configuring the server to handle security
Understanding and declaring roles
Controlling security using declarations
Propagating identity
Controlling security programmatically
Chapter 8: Interceptors
Introduction
Creating the Registration Application
Defining and using interceptors
Using the InvocationContext to verify parameters
Using interceptors to enforce security
Using interceptors to handle transactions
Using interceptors to handle application statistics
Using lifecycle methods in interceptors
Chapter 9: Timer Services
Introduction
Setting up the ReportsApplication
Creating and using declarative timers
Creating and using programmatic timers
Understanding calendar-based scheduling
Using the timer interface
Using persistent and non-persistent timers
Creating timers upon application deployment
Using interceptors with timers
Chapter 10: Web Services
Introduction
Creating an EJB-based web service using JAX-WS
Creating an EJB-based web service using JAX-RS
Using an MDB as part of a web service
Chapter 11: Packaging the EJB
Introduction
Understanding an application's JAR files using the jar command
Understanding class loading
Using deployment descriptors for interceptors
Using deployment descriptors for timer interceptors
Using deployment descriptor for default interceptors
Using deployment descriptors for callback interceptors
Using a deployment descriptors for transactions
Using deployment descriptors for security
Chapter 12: EJB Techniques
Introduction
Exception handling and EJBs
Using logging within an EJB
Using an interceptor for logging and exception handling
Creating your own interceptor
Using time within an EJB
How to support currency
Efficient manipulation of strings

What You Will Learn

  • Create and use the different types of EJBs along with the use of the optional session bean business interface
  • Create a singleton session bean for application-wide use
  • Use declarative and programmatic techniques for security, timer services, and transaction processing
  • Use asynchronous session beans to complement message driven beans
  • Support aspect oriented features such as logging and data validation using interceptors
  • Use EJBs in support of message based applications
  • Master the use of deployment descriptors and improved packaging options
  • Use EJBs outside of the Java EE environment using the embeddable container

In Detail

Enterprise Java Beans enable rapid and simplified development of secure and portable applications based on Java technology.Creating and using EJBs can be challenging and rewarding. Among the challenges are learning the EJB technology itself, learning how to use the development environment you have chosen for EJB development, and the testing of the EJBs.

This EJB 3.1 Cookbook addresses all these challenges and covers new 3.1 features, along with explanations of useful retained features from earlier versions. It brings the reader quickly up to speed on how to use EJB 3.1 techniques through the use of step-by-step examples without the need to use multiple incompatible resources. The coverage is concise and to the point, and is organized to allow you to quickly find and learn those features of interest to you.

The book starts with coverage of EJB clients. The reader can choose the chapters and recipes which best address his or her specific needs. The newer EJB technologies presented include singleton beans which support application wide needs and interceptors to permit processing before and after a target method is invoked. Asynchronous invocation of methods and enhancements to the timer service are also covered.

The EJB 3.1 CookBook is a very straightforward and rewarding source of techniques supporting Java EE applications.

Authors

Table of Contents

Chapter 1: Getting Started With EJBs
Introduction
Creating a simple session EJB
Accessing a session bean using dependency injection
Accessing the session bean using JNDI
Creating a simple message-driven bean
Sending a message to a message-driven bean
Accessing an EJB from a web service (JAX-WS)
Accessing an EJB from a web service (JAX-RS)
Accessing an EJB from an Applet
Accessing an EJB from JSP
Calling an EJB from JSF
Accessing an EJB from a Java Application using JNDI
Accessing an EJB from a Java Application using an embeddable container
Accessing the EJB container
Chapter 2: Session Beans
Introduction
Creating a stateless session bean
Creating a stateful session bean
Creating a singleton bean
Using multiple singleton beans
Using container managed concurrency
Using bean managed concurrency
Controlling the initialization process
Using session beans with more than one business interface
Understanding parameter behavior and granularity
Using an asynchronous method to create a background process
Chapter 3: Message-Driven Beans
Introduction
Handling a string-based message
Handling a byte-based message
Handling a stream-based message
Handling a map-based message
Handling an object-based message
Using an MDB in a point-to-point application
Using MDB in a publish-and-subscribe application
Specifying which types of message to receive using the message selector
Browsing messages in a message queue
Chapter 4: EJB Persistence
Introduction
Creating an entity
Creating an entity facade
Using the EntityManager
Controlling the Object-Relationship Mapping (ORM) process
Using embeddable classes in entities
Using application-managed persistence
Validating persistent fields and properties
Validating null fields
Validating string fields
Validating temporal fields
Validating using regular expressions
Validating Boolean fields
Validating Integer fields
Using the Validator class
Chapter 5: Querying Entities using JPQL and the Criteria API
Introduction
Populating the Patient and Medication tables
Using the Select query
Using the Where clause
Controlling the number of entities returned by a Select query
Using the Delete query
Using the Update query
Using parameters in a query
Using a Named query
Using the Criteria API
Chapter 6: Transaction Processing
Introduction
Creating the Demonstration classes
Handling transactions the easy way
Using the SessionSynchronization interface with session beans
Understanding how the TransactionAttributeType affects transactions
Handling transactions manually
Rolling back a transaction
Handling errors in a transaction
Using timeouts with transactions
Chapter 7: EJB Security
Introduction
Creating the SecurityApplication
Configuring the server to handle security
Understanding and declaring roles
Controlling security using declarations
Propagating identity
Controlling security programmatically
Chapter 8: Interceptors
Introduction
Creating the Registration Application
Defining and using interceptors
Using the InvocationContext to verify parameters
Using interceptors to enforce security
Using interceptors to handle transactions
Using interceptors to handle application statistics
Using lifecycle methods in interceptors
Chapter 9: Timer Services
Introduction
Setting up the ReportsApplication
Creating and using declarative timers
Creating and using programmatic timers
Understanding calendar-based scheduling
Using the timer interface
Using persistent and non-persistent timers
Creating timers upon application deployment
Using interceptors with timers
Chapter 10: Web Services
Introduction
Creating an EJB-based web service using JAX-WS
Creating an EJB-based web service using JAX-RS
Using an MDB as part of a web service
Chapter 11: Packaging the EJB
Introduction
Understanding an application's JAR files using the jar command
Understanding class loading
Using deployment descriptors for interceptors
Using deployment descriptors for timer interceptors
Using deployment descriptor for default interceptors
Using deployment descriptors for callback interceptors
Using a deployment descriptors for transactions
Using deployment descriptors for security
Chapter 12: EJB Techniques
Introduction
Exception handling and EJBs
Using logging within an EJB
Using an interceptor for logging and exception handling
Creating your own interceptor
Using time within an EJB
How to support currency
Efficient manipulation of strings

Book Details

ISBN 139781849682381
Paperback436 pages
Read More