Beginning Java™ EE 6 Platform with GlassFish™ 3

Book description

Java Enterprise Edition (Java EE) continues to be one of the leading Java technologies and platforms from Oracle (previously Sun). Beginning Java EE 6 Platform with GlassFish 3, Second Edition is this first tutorial book on the final (RTM) version of the Java EE 6 Platform.

Step by step and easy to follow, this book describes many of the Java EE 6 specifications and reference implementations, and shows them in action using practical examples. This book uses the new version of GlassFish 3 to deploy and administer the code examples.

Written by an expert member of the Java EE 6 specification request and review board in the Java Community Process (JCP), this book contains the best information possible, from an expert's perspective on enterprise Java technologies.

Table of contents

  1. Copyright
  2. Foreword
  3. About the Author
  4. About the Technical Reviewer
  5. Acknowledgments
  6. Preface
    1. How Is This Book Structured?
    2. Downloading and Running the Code
    3. Contacting the Author
  7. 1. Java EE 6 at a Glance
    1. 1.1. Understanding Java EE
      1. 1.1.1. A Bit of History
      2. 1.1.2. Standards
      3. 1.1.3. Architecture
        1. 1.1.3.1. Components
        2. 1.1.3.2. Containers
        3. 1.1.3.3. Services
        4. 1.1.3.4. Network Protocols
        5. 1.1.3.5. Packaging
        6. 1.1.3.6. Java Standard Edition
      4. 1.1.4. Java EE 6 Specifications
    2. 1.2. What's New in Java EE 6?
      1. 1.2.1. Lighter
        1. 1.2.1.1. Pruning
        2. 1.2.1.2. Profiles
      2. 1.2.2. Easier to Use
      3. 1.2.3. Richer
      4. 1.2.4. More Portable
    3. 1.3. The CD-BookStore Application
    4. 1.4. Setting Up Your Environment
      1. 1.4.1. JDK 1.6
      2. 1.4.2. Maven 2
        1. 1.4.2.1. A Bit of History
        2. 1.4.2.2. Project Descriptor
        3. 1.4.2.3. Managing Artifacts
        4. 1.4.2.4. Project Modularity
        5. 1.4.2.5. Plug-ins and Life Cycle
        6. 1.4.2.6. Installation
        7. 1.4.2.7. Usage
      3. 1.4.3. JUnit 4
        1. 1.4.3.1. A Bit of History
        2. 1.4.3.2. How Does It Work?
        3. 1.4.3.3. Test Methods
        4. 1.4.3.4. Assert Methods
        5. 1.4.3.5. Fixtures
        6. 1.4.3.6. Launching JUnit
        7. 1.4.3.7. JUnit Integration
      4. 1.4.4. Derby 10.6
        1. 1.4.4.1. Installation
        2. 1.4.4.2. Usage
      5. 1.4.5. GlassFish v3.0.1
        1. 1.4.5.1. A Bit of History
        2. 1.4.5.2. GlassFish v3 Architecture
        3. 1.4.5.3. Update Center
        4. 1.4.5.4. GlassFish Subprojects
        5. 1.4.5.5. Administration
          1. 1.4.5.5.1. Admin Console
          2. 1.4.5.5.2. The asadmin CLI
        6. 1.4.5.6. Installing GlassFish
    5. 1.5. Summary
  8. 2. Java Persistence
    1. 2.1. JPA Specification Overview
      1. 2.1.1. A Brief History of the Specification
      2. 2.1.2. What's New in JPA 2.0?
      3. 2.1.3. Reference Implementation
    2. 2.2. Understanding Entities
      1. 2.2.1. Object-Relational Mapping
      2. 2.2.2. Querying Entities
      3. 2.2.3. Callbacks and Listeners
    3. 2.3. Putting it all Together
      1. 2.3.1. Writing the Book Entity
      2. 2.3.2. Writing the Main Class
      3. 2.3.3. Persistence Unit for the Main Class
      4. 2.3.4. Compiling with Maven
      5. 2.3.5. Running the Main Class with Derby
      6. 2.3.6. Writing the BookTest Class
      7. 2.3.7. Persistence Unit for the BookTest Class
      8. 2.3.8. Running the BookTest Class with Embedded Derby
    4. 2.4. Summary
  9. 3. Object-Relational Mapping
    1. 3.1. How to Map an Entity
      1. 3.1.1. Configuration by Exception
    2. 3.2. Elementary Mapping
      1. 3.2.1. Tables
        1. 3.2.1.1. @Table
        2. 3.2.1.2. @SecondaryTable
      2. 3.2.2. Primary Keys
        1. 3.2.2.1. @Id and @GeneratedValue
        2. 3.2.2.2. Composite Primary Keys
          1. 3.2.2.2.1. @EmbeddedId
          2. 3.2.2.2.2. @IdClass
      3. 3.2.3. Attributes
        1. 3.2.3.1. @Basic
        2. 3.2.3.2. @Column
        3. 3.2.3.3. @Temporal
        4. 3.2.3.4. @Transient
        5. 3.2.3.5. @Enumerated
      4. 3.2.4. Access Type
      5. 3.2.5. Collection of Basic Types
      6. 3.2.6. Map of Basic Types
    3. 3.3. Mapping with XML
    4. 3.4. Embeddables
      1. 3.4.1. Access Type of an Embeddable Class
    5. 3.5. Relationship Mapping
      1. 3.5.1. Relationships in Relational Databases
      2. 3.5.2. Entity Relationships
        1. 3.5.2.1. Unidirectional and Bidirectional
        2. 3.5.2.2. @OneToOne Unidirectional
        3. 3.5.2.3. @OneToMany Unidirectional
        4. 3.5.2.4. @ManyToMany Bidirectional
      3. 3.5.3. Fetching Relationships
      4. 3.5.4. Ordering Relationships
        1. 3.5.4.1. @OrderBy
        2. 3.5.4.2. @OrderColumn
    6. 3.6. Inheritance Mapping
      1. 3.6.1. Inheritance Strategies
        1. 3.6.1.1. Single-Table-per-Class Hierarchy Strategy
        2. 3.6.1.2. Joined-Subclass Strategy
        3. 3.6.1.3. Table-per-Concrete-Class Strategy
          1. 3.6.1.3.1. Overriding Attributes
      2. 3.6.2. Type of Classes in the Inheritance Hierarchy
        1. 3.6.2.1. Abstract Entity
        2. 3.6.2.2. Nonentity
        3. 3.6.2.3. Mapped Superclass
    7. 3.7. Summary
  10. 4. Managing Persistent Objects
    1. 4.1. How to Query an Entity
    2. 4.2. Entity Manager
      1. 4.2.1. Obtaining an Entity Manager
      2. 4.2.2. Persistence Context
      3. 4.2.3. Manipulating Entities
        1. 4.2.3.1. Persisting an Entity
        2. 4.2.3.2. Finding by ID
        3. 4.2.3.3. Removing an Entity
        4. 4.2.3.4. Orphan Removal
        5. 4.2.3.5. Synchronizing with the Database
          1. 4.2.3.5.1. Flushing Data
          2. 4.2.3.5.2. Refreshing an Entity
        6. 4.2.3.6. Content of the Persistence Context
          1. 4.2.3.6.1. Contains
          2. 4.2.3.6.2. Clear and Detach
        7. 4.2.3.7. Merging an Entity
        8. 4.2.3.8. Updating an Entity
        9. 4.2.3.9. Cascading Events
      4. 4.2.4. Cache API
    3. 4.3. JPQL
      1. 4.3.1. Select
      2. 4.3.2. From
      3. 4.3.3. Where
        1. 4.3.3.1. Binding Parameters
        2. 4.3.3.2. Subqueries
      4. 4.3.4. Order By
      5. 4.3.5. Group By and Having
      6. 4.3.6. Bulk Delete
      7. 4.3.7. Bulk Update
    4. 4.4. Queries
      1. 4.4.1. Dynamic Queries
      2. 4.4.2. Named Queries
      3. 4.4.3. Native Queries
      4. 4.4.4. Criteria API (or Object-Oriented Queries)
        1. 4.4.4.1. Type-Safe Criteria API
    5. 4.5. Concurrency
      1. 4.5.1. Versioning
      2. 4.5.2. Optimistic Locking
      3. 4.5.3. Pessimistic Locking
    6. 4.6. Summary
  11. 5. Callbacks and Listeners
    1. 5.1. Entity Life Cycle
    2. 5.2. Callbacks
    3. 5.3. Listeners
    4. 5.4. Summary
  12. 6. Enterprise Java Beans
    1. 6.1. Understanding EJBs
      1. 6.1.1. Types of EJBs
      2. 6.1.2. Anatomy of an EJB
      3. 6.1.3. EJB Container
      4. 6.1.4. Embedded Container
      5. 6.1.5. Dependency Injection and JNDI
      6. 6.1.6. Callback Methods and Interceptors
      7. 6.1.7. Packaging
    2. 6.2. EJB Specification Overview
      1. 6.2.1. History of the Specification
      2. 6.2.2. What's New in EJB 3.1
      3. 6.2.3. EJB Lite
      4. 6.2.4. Reference Implementation
    3. 6.3. Putting It All Together
      1. 6.3.1. Writing the Book Entity
      2. 6.3.2. Writing the BookEJB Stateless Session Bean
      3. 6.3.3. Persistence Unit for the BookEJB
      4. 6.3.4. Writing the Main Class
      5. 6.3.5. Compiling and Packaging with Maven
      6. 6.3.6. Deploying on GlassFish
      7. 6.3.7. Running the Main Class with the Application Client Container
      8. 6.3.8. Writing the BookEJBTest Class
    4. 6.4. Summary
  13. 7. Session Beans and the Timer Service
    1. 7.1. Session Beans
      1. 7.1.1. Stateless Beans
      2. 7.1.2. Stateful Beans
      3. 7.1.3. Singletons
        1. 7.1.3.1. Initialization
        2. 7.1.3.2. Chaining Singletons
        3. 7.1.3.3. Concurrency
          1. 7.1.3.3.1. Container-Managed Concurrency
          2. 7.1.3.3.2. Bean-Managed Concurrency
          3. 7.1.3.3.3. Concurrent Access Timeouts and Not Allowing Concurrency
      4. 7.1.4. Session Bean Model
        1. 7.1.4.1. Interfaces and Bean Class
          1. 7.1.4.1.1. Remote, Local, and No-Interface Views
          2. 7.1.4.1.2. Web Services Interface
          3. 7.1.4.1.3. Bean Class
        2. 7.1.4.2. Client View
          1. 7.1.4.2.1. @EJB
          2. 7.1.4.2.2. Portable JNDI Name
        3. 7.1.4.3. Session Context
        4. 7.1.4.4. Deployment Descriptor
        5. 7.1.4.5. Dependency Injection
        6. 7.1.4.6. Environment Naming Context
      5. 7.1.5. Asynchronous Calls
      6. 7.1.6. Embeddable Usage
    2. 7.2. The Timer Service
      1. 7.2.1. Calendar-Based Expression
      2. 7.2.2. Automatic Timer Creation
      3. 7.2.3. Programmatic Timer Creation
    3. 7.3. Summary
  14. 8. Callbacks and Interceptors
    1. 8.1. Session Beans Life Cycle
      1. 8.1.1. Stateless and Singleton
      2. 8.1.2. Stateful
      3. 8.1.3. Callbacks
    2. 8.2. Interceptors
      1. 8.2.1. Around-Invoke Interceptors
      2. 8.2.2. Method Interceptors
      3. 8.2.3. Life-Cycle Interceptor
      4. 8.2.4. Chaining and Excluding Interceptors
    3. 8.3. Summary
  15. 9. Transactions and Security
    1. 9.1. Transactions
      1. 9.1.1. ACID
      2. 9.1.2. Local Transactions
      3. 9.1.3. Distributed Transactions and XA
    2. 9.2. Transaction Support in EJB
      1. 9.2.1. Container-Managed Transactions
        1. 9.2.1.1. Marking a CMT for Rollback
        2. 9.2.1.2. Exception Handling
      2. 9.2.2. Bean-Managed Transactions
    3. 9.3. Security
      1. 9.3.1. Principals and Roles
      2. 9.3.2. Authentication and Authorization
    4. 9.4. Security Support in EJB
      1. 9.4.1. Declarative Security
      2. 9.4.2. Programmatic Security
    5. 9.5. Summary
  16. 10. JavaServer Faces
    1. 10.1. Understanding JSF
      1. 10.1.1. FacesServlet and faces-config.xml
      2. 10.1.2. Pages and Components
      3. 10.1.3. Renderer
      4. 10.1.4. Converters and Validators
      5. 10.1.5. Managed Beans and Navigation
      6. 10.1.6. Ajax Support
    2. 10.2. Web Interface Specifications Overview
      1. 10.2.1. A Brief History of Web Interfaces
      2. 10.2.2. JSP 2.2, EL 2.2, and JSTL 1.2
      3. 10.2.3. JSF 2.0
      4. 10.2.4. What's New in JSF 2.0
      5. 10.2.5. Reference Implementation
    3. 10.3. Putting It All Together
      1. 10.3.1. Writing the Book Entity
      2. 10.3.2. Writing the BookEJB
      3. 10.3.3. Writing the BookController Managed Bean
      4. 10.3.4. Writing the newBook.xhtml Page
      5. 10.3.5. Writing the listBooks.xhtml Page
      6. 10.3.6. Configuration with web.xml
      7. 10.3.7. Compiling and Packaging with Maven
      8. 10.3.8. Deploying on GlassFish
      9. 10.3.9. Running the Example
    4. 10.4. Summary
  17. 11. Pages and Components
    1. 11.1. Web Pages
      1. 11.1.1. HTML
      2. 11.1.2. XHTML
      3. 11.1.3. CSS
      4. 11.1.4. DOM
      5. 11.1.5. JavaScript
    2. 11.2. Java Server Pages
      1. 11.2.1. Directive Elements
      2. 11.2.2. Scripting Elements
      3. 11.2.3. Action Elements
      4. 11.2.4. Putting It All Together
    3. 11.3. Expression Language
    4. 11.4. JSP Standard Tag Library
      1. 11.4.1. Core Actions
      2. 11.4.2. Formatting Actions
      3. 11.4.3. SQL Actions
      4. 11.4.4. XML Actions
      5. 11.4.5. Functions
    5. 11.5. Facelets
    6. 11.6. JavaServer Faces
      1. 11.6.1. Life Cycle
      2. 11.6.2. Standard HTML Components
        1. 11.6.2.1. Commands
        2. 11.6.2.2. Inputs
        3. 11.6.2.3. Outputs
        4. 11.6.2.4. Selections
        5. 11.6.2.5. Graphics
        6. 11.6.2.6. Grid and Tables
        7. 11.6.2.7. Error Messages
        8. 11.6.2.8. Miscellaneous
        9. 11.6.2.9. Templating
      3. 11.6.3. Resource Management
      4. 11.6.4. Composite Components
      5. 11.6.5. Implicit Objects
    7. 11.7. Summary
  18. 12. Processing and Navigation
    1. 12.1. The MVC Pattern
      1. 12.1.1. FacesServlet
      2. 12.1.2. FacesContext
      3. 12.1.3. Faces Config
    2. 12.2. Managed Beans
      1. 12.2.1. How to Write a Managed Bean
      2. 12.2.2. Managed Bean Model
        1. 12.2.2.1. @ManagedBean
        2. 12.2.2.2. Scopes
        3. 12.2.2.3. @ManagedProperty
        4. 12.2.2.4. Life Cycle and Callback Annotations
      3. 12.2.3. Navigation
      4. 12.2.4. Message Handling
    3. 12.3. Conversion and Validation
      1. 12.3.1. Converters
      2. 12.3.2. Custom Converters
      3. 12.3.3. Validators
      4. 12.3.4. Custom Validators
    4. 12.4. Ajax
      1. 12.4.1. General Concepts
      2. 12.4.2. Support in JSF
      3. 12.4.3. Putting It All Together
    5. 12.5. Summary
  19. 13. Sending Messages
    1. 13.1. Understanding Messages
      1. 13.1.1. JMS
      2. 13.1.2. MDB
    2. 13.2. Messaging Specification Overview
      1. 13.2.1. A Brief History of Messaging
      2. 13.2.2. JMS 1.1
      3. 13.2.3. EJB 3.1
      4. 13.2.4. Reference Implementation
    3. 13.3. How to Send and Receive a Message
    4. 13.4. Java Messaging Service
      1. 13.4.1. Point-to-Point
      2. 13.4.2. Publish-Subscribe
      3. 13.4.3. JMS API
        1. 13.4.3.1. Administered Objects
          1. 13.4.3.1.1. ConnectionFactory
          2. 13.4.3.1.2. Destination
          3. 13.4.3.1.3. Injection
        2. 13.4.3.2. Connection
        3. 13.4.3.3. Session
        4. 13.4.3.4. Messages
          1. 13.4.3.4.1. Header
          2. 13.4.3.4.2. Properties
          3. 13.4.3.4.3. Body
        5. 13.4.3.5. MessageProducer
        6. 13.4.3.6. MessageConsumer
          1. 13.4.3.6.1. Synchronous Delivery
          2. 13.4.3.6.2. Asynchronous Delivery
      4. 13.4.4. Selectors
      5. 13.4.5. Reliability Mechanisms
        1. 13.4.5.1. Setting Message Time-to-Live
        2. 13.4.5.2. Specifying Message Persistence
        3. 13.4.5.3. Controlling Acknowledgment
        4. 13.4.5.4. Creating Durable Subscribers
        5. 13.4.5.5. Setting Priorities
    5. 13.5. Message-Driven Beans
      1. 13.5.1. How to Write an MDB
      2. 13.5.2. MDB Model
        1. 13.5.2.1. @MessageDriven
        2. 13.5.2.2. @ActivationConfigProperty
        3. 13.5.2.3. Dependencies Injection
        4. 13.5.2.4. MDB Context
        5. 13.5.2.5. Life Cycle and Callback Annotations
      3. 13.5.3. MDB as a Consumer
      4. 13.5.4. MDB as a Producer
      5. 13.5.5. Transaction
      6. 13.5.6. Handling Exceptions
    6. 13.6. Putting It All Together
      1. 13.6.1. Writing the OrderDTO
      2. 13.6.2. Writing the OrderSender
      3. 13.6.3. Writing the OrderMDB
      4. 13.6.4. Compiling and Packaging with Maven
      5. 13.6.5. Creating the Administered Objects
      6. 13.6.6. Deploying the MDB on GlassFish
      7. 13.6.7. Running the Example
    7. 13.7. Summary
  20. 14. SOAP Web Services
    1. 14.1. Understanding SOAP Web Services
      1. 14.1.1. XML
      2. 14.1.2. WSDL
      3. 14.1.3. SOAP
      4. 14.1.4. UDDI
      5. 14.1.5. Transport Protocol
    2. 14.2. SOAP Web Services Specification Overview
      1. 14.2.1. A Brief History of SOAP Web Services
      2. 14.2.2. Java EE Specifications
        1. 14.2.2.1. JAX-WS 2.2
        2. 14.2.2.2. Web Services 1.2
        3. 14.2.2.3. JAXB 2.2
        4. 14.2.2.4. WS-Metadata 2.0
        5. 14.2.2.5. JAXR 1.0
      3. 14.2.3. Reference Implementation
    3. 14.3. How to Invoke a SOAP Web Service
    4. 14.4. Java Architecture for XML Binding
      1. 14.4.1. Binding
      2. 14.4.2. Annotations
    5. 14.5. The Invisible Part of the Iceberg
      1. 14.5.1. WSDL
      2. 14.5.2. SOAP
    6. 14.6. Java API for XML-Based Web Services
      1. 14.6.1. JAX-WS Model
        1. 14.6.1.1. Web Service Endpoints
        2. 14.6.1.2. Annotations
          1. 14.6.1.2.1. @WebService
          2. 14.6.1.2.2. @WebMethod
          3. 14.6.1.2.3. @WebResult
          4. 14.6.1.2.4. @WebParam
          5. 14.6.1.2.5. @OneWay
          6. 14.6.1.2.6. All Together
        3. 14.6.1.3. Life Cycle and Callback
        4. 14.6.1.4. Web Service Context
      2. 14.6.2. Invoking a SOAP Web Service
    7. 14.7. Putting It All Together
      1. 14.7.1. Writing the CreditCard Class
      2. 14.7.2. Writing the CardValidator SOAP Web Service
      3. 14.7.3. Compiling and Packaging with Maven
      4. 14.7.4. Deploying on GlassFish
      5. 14.7.5. Writing the Web Service Consumer
      6. 14.7.6. Generating Consumer's Artifacts and Packaging with Maven
      7. 14.7.7. Running the Main Class
    8. 14.8. Summary
  21. 15. RESTful Web Services
    1. 15.1. Understanding RESTful Web Services
      1. 15.1.1. Resources and URIs
      2. 15.1.2. Representations
      3. 15.1.3. WADL
      4. 15.1.4. HTTP
        1. 15.1.4.1. Request and Response
        2. 15.1.4.2. HTTP Methods
          1. 15.1.4.2.1. GET
          2. 15.1.4.2.2. POST
          3. 15.1.4.2.3. PUT
          4. 15.1.4.2.4. DELETE
          5. 15.1.4.2.5. Others
        3. 15.1.4.3. Content Negotiation
        4. 15.1.4.4. Content Types
        5. 15.1.4.5. Status Codes
        6. 15.1.4.6. Caching and Conditional Requests
    2. 15.2. RESTful Web Services Specification
      1. 15.2.1. A Brief History of REST
      2. 15.2.2. JAX-RS 1.1
      3. 15.2.3. What's New in JAX-RS 1.1?
      4. 15.2.4. Reference Implementation
    3. 15.3. The REST Approach
      1. 15.3.1. From the Web to Web Services
      2. 15.3.2. A Web-Browsing Experience
      3. 15.3.3. Uniform Interface
      4. 15.3.4. Addressability
      5. 15.3.5. Connectedness
      6. 15.3.6. Statelessness
    4. 15.4. Java API for RESTful Web Services
      1. 15.4.1. The JAX-RS Model
      2. 15.4.2. How to Write a REST Service
      3. 15.4.3. URI Definition
      4. 15.4.4. Extracting Parameters
      5. 15.4.5. Consuming and Producing Content Types
      6. 15.4.6. Entity Provider
      7. 15.4.7. Methods or the Uniform Interface
      8. 15.4.8. Contextual Information
        1. 15.4.8.1. Headers
        2. 15.4.8.2. Building URIs
      9. 15.4.9. Exception Handling
      10. 15.4.10. Life Cycle
    5. 15.5. Putting It All Together
      1. 15.5.1. Writing the Book Entity
      2. 15.5.2. Writing the BookResource
        1. 15.5.2.1. Header
        2. 15.5.2.2. Creating a New Book
        3. 15.5.2.3. Getting a Book by ID
        4. 15.5.2.4. Deleting a Book
      3. 15.5.3. Configuring Jersey
      4. 15.5.4. Compiling and Packaging with Maven
      5. 15.5.5. Deploying on GlassFish
      6. 15.5.6. Running the Example
    6. 15.6. Summary

Product information

  • Title: Beginning Java™ EE 6 Platform with GlassFish™ 3
  • Author(s): Antonio Goncalves
  • Release date: August 2010
  • Publisher(s): Apress
  • ISBN: 9781430228899