Book Details

ISBN 139781849682381

Paperback436 pages

Book Description

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.

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

Authors

Richard M. Reese

Richard M. Reese holds a Ph.D. in Computer Science from Texas A & M University and is currently an Associate Professor in the Department of Engineering and Physics at Tarleton State University in Stephenville, Texas. In addition to his experience in academia, Richard has over 17 years experience in industry including operating system development at GTE Automatic Electric Labs and at Lockheed Martin in Fort Worth, Texas, where he supervised a tool development group and oversaw various research and development projects. Prior to his industrial experience he served four years in the United States Air Force.
Richard has been involved with Java since 1996 and is a certified Java SE 7 Associate Programmer. He has worked as consultant/instructor of software languages in private and public classes providing him with a variety of insight into industry applications. He has published numerous papers and has developed courseware for a variety of topics including advanced Java technologies. He has also written the EJB 3.1 Cookbook and Java 7 New Features Cookbook for Packt Publishing.

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

Alerts & Offers

Series & Level

We understand your time is important. Uniquely amongst the major publishers, we seek to develop and publish the broadest range of learning and information products on each technology. Every Packt product delivers a specific learning pathway, broadly defined by the Series type. This structured approach enables you to select the pathway which best suits your knowledge level, learning style and task objectives.

Learning

As a new user, these step-by-step tutorial guides will give you all the practical skills necessary to become competent and efficient.

Beginner's Guide

Friendly, informal tutorials that provide a practical introduction using examples, activities, and challenges.

Essentials

Fast paced, concentrated introductions showing the quickest way to put the tool to work in the real world.

Cookbook

A collection of practical self-contained recipes that all users of the technology will find useful for building more powerful and reliable systems.

Blueprints

Guides you through the most common types of project you'll encounter, giving you end-to-end guidance on how to build your specific solution quickly and reliably.

Mastering

Take your skills to the next level with advanced tutorials that will give you confidence to master the tool's most powerful features.

Starting

Accessible to readers adopting the topic, these titles get you into the tool or technology so that you can become an effective user.

Progressing

Building on core skills you already have, these titles share solutions and expertise so you become a highly productive power user.