EJB 3.1 Cookbook


EJB 3.1 Cookbook
eBook: $32.99
Formats: PDF, PacktLib, ePub and Mobi formats
$28.04
save 15%!
Print + free eBook + free PacktLib access to the book: $87.98    Print cover: $54.99
$54.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Support
Sample Chapters
  • 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

Book Details

Language : English
Paperback : 436 pages [ 235mm x 191mm ]
Release Date : June 2011
ISBN : 1849682380
ISBN 13 : 9781849682381
Author(s) : Richard M. Reese
Topics and Technologies : All Books, Enterprise Products and Platforms, Cookbooks, Enterprise, Java

Table of Contents

Preface
Chapter 1: Getting Started With EJBs
Chapter 2: Session Beans
Chapter 3: Message-Driven Beans
Chapter 4: EJB Persistence
Chapter 5: Querying Entities using JPQL and the Criteria API
Chapter 6: Transaction Processing
Chapter 7: EJB Security
Chapter 8: Interceptors
Chapter 9: Timer Services
Chapter 10: Web Services
Chapter 11: Packaging the EJB
Chapter 12: EJB Techniques
Index
  • 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 descriptors for default interceptors
                        • Using deployment descriptors for callbacks 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

                          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.
                          Sorry, we don't have any reviews for this title yet.

                          Code Downloads

                          Download the code and support files for this book.


                          Submit Errata

                          Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


                          Errata

                          - 2 submitted: last submission 18 Jun 2013

                          Error Type: Code     Page: 21

                          Resource(mappedName = "jms/SalutationQueue")

                          Should be:

                          @Resource(mappedName = "jms/SalutationQueue")

                           

                          Errata Type: Content   Page: 29

                           

                          RESTLess 
                          Should be:
                          RESTful
                          
                          
                          
                          

                           

                           

                          Errata Type: Typo    Page: 38

                          Add the following annotation after the @Stateless 

                          annotation in the Constantsbean class.

                          Should be:

                          Add the following annotation after the @Stateless 

                          annotation in the ConstantsBean class.   

                           

                           

                          Errata Type: Content  Page: 44

                          An EJB will always reside inside of an EJB

                          Should be:

                          An EJB will always run within a manage runtime environment, that is, an EJB container

                           

                          Errata Type: Content   Page: 46

                          dependency inject

                          Should be:

                          dependency injection

                           

                          Errata Type: Technical   Page: 62

                          playerState

                          Should  be:

                          state

                          
                          
                          
                          

                          Errata Type: Typo   Page: 67

                          currency

                          Should be:

                          concurrency

                           

                          Errata Type: Typo   Page: 86

                          MDB's are managed by the server EJB container

                          Should be:

                          MDB's are managed by the server's EJB container

                           

                          Errata Type: Content   Page: 95

                          comment sent 

                          Should be:

                          part sent

                           

                          Errata Type: Code   Page: 96

                          createByteMessage

                          Should be:

                          createBytesMessage

                           

                          Errata Type: Typo  Page: 117

                          SEVERE: Jonathan is available

                          Should be:

                          SEVERE: Tom is avialable

                           

                          Errata Type: Content Code   Pages: 119 and 123

                          'Public textMessage sent' should be  'Private textMessage sent'

                          and

                          'Private textMessage sent' should be 'Public textMessage sent'  respectively

                           

                           

                           

                           

                           

                          Errata Type: Typo   Pages: 64 and 270

                          EJBS

                          Should be:

                          EJBs

                           

                          Errata Type: Typo    

                           

                          Errata type: Typo   Page: 69

                           

                          The synchronized keyword was also be used on a block of code instead of a method. The 

                          following rewrite of the setState method illustrates how to synchronize a block.

                          Should be:

                           

                          The synchronized keyword can also be used on a block of code instead of a method. The 

                          following rewrite of the setState method illustrates how to synchronize a block.

                           

                           

                          Errata type: typo    Page: 118

                           

                          Create a Queue named jms/PostingsQueue and a QueueConnectionFactory named 

                          jms/PostngsQueueFactory as described in the introduction.

                          Should be:

                           

                          Create a Queue named jms/PostingsQueue and a QueueConnectionFactory named 

                          jms/PostingsQueueFactory as described in the introduction.

                           

                           

                           

                           

                          Errata Type: Typo    Page: 153

                           

                          The "??" regular expression qualifiers specify that the preceding character will 

                          appear once or not all.

                          Should be:

                           

                          The "??" regular expression qualifiers specify that the preceding character will 

                          appear once or not at all.

                           

                          Errata Type: Formatting   Page: 203

                           

                          The TransactionAttributeType 

                          element is assigned one of six possible values as detailed in the There's more section.

                          Should be:

                           

                          The TransactionAttributeType 

                          element is assigned one of six possible values as detailed in the There's more section.

                           

                           

                           

                           

                          Errata type: Code   Page: 282

                          String titles[] = {"Lead", "Programmer", "Adminsitrator"};

                          Should be:

                          String titles[] = {"Lead", "Programmer", "Administrator"};

                           

                           

                          Errata type: Typo   Page: 311

                          @Schedule(hour="1", dayOfMonth="1", timezone=" Europe/Stockholm")

                          Should be: 

                          @Schedule(hour="1", dayOfMonth="1", timezone="Europe/Stockholm")

                           

                           

                          Errata type: Typo    Page: 325

                           

                           The timer was triggered by the 

                          displayMemeoryReport method using the @Schedule annotation.

                          Should be:

                           

                           The timer was triggered by the 

                          displayMemoryReport method using the @Schedule annotation.

                           

                           

                          Errata type: Typo    Page: 327

                           

                          The second category is Representational State Transfer )  (RESTful) web services as 

                          supported by JAX-RS.

                          Should be:

                           

                          The second category is Representational State Transfer (RESTful) web services as 

                          supported by JAX-RS.

                           

                           

                           

                           

                          Errata Type: Code   Page: 330

                           public int getCustomerCountByRegion (String region) {

                          Should be:

                           public int getCustomerCountByRegion(String region) {

                           

                           

                          Errata Type: Code   Page: 378

                          log.error(e.getMessage), e);

                          Should be:

                          log.error(e.getMessage(), e);

                          On page 245 before the second to last paragraph you need to do the following:
                          Log in as the glassfish admin and turn on the default mapping by choosing Configuration | Security in the admin console. Then select Enabled next to Default Principal to Role Mapping and Save.

                          Sample chapters

                          You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

                          Frequently bought together

                          EJB 3.1 Cookbook +    Sakai Courseware Management: The Official Guide =
                          50% Off
                          the second eBook
                          Price for both: $43.50

                          Buy both these recommended eBooks together and get 50% off the cheapest eBook.

                          What you will learn from this book

                          • 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.

                          Approach

                          Each recipe comprises step-by-step instructions followed by an analysis of what was done in each task and other useful information. The book is designed so that you can read it chapter by chapter, or look at the list of recipes and refer to them in no particular order. It is packed with useful screenshots to make your learning even easier.

                          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.

                          Code Download and Errata
                          Packt Anytime, Anywhere
                          Register Books
                          Print Upgrades
                          eBook Downloads
                          Video Support
                          Contact Us
                          Awards Voting Nominations Previous Winners
                          Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
                          Resources
                          Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software