Java EE 7 Developer Handbook


Java EE 7 Developer Handbook
eBook: $35.99
Formats: PDF, PacktLib, ePub and Mobi formats
$30.59
save 15%!
Print + free eBook + free PacktLib access to the book: $95.98    Print cover: $59.99
$59.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Reviews
Support
Sample Chapters
  • Learn about local and remote service endpoints, containers, architecture, synchronous and asynchronous invocations, and remote communications in a concise reference
  • Understand the architecture of the Java EE platform and then apply the new Java EE 7 enhancements to benefit your own business-critical applications
  • Learn about integration test development on Java EE with Arquillian Framework and the Gradle build system
  • Learn about containerless builds featuring the GlassFish 4.0 embedded application server
  • Master Java EE 7 with this example-based, up-to-date guide with descriptions and explanations

Book Details

Language : English
Paperback : 634 pages [ 235mm x 191mm ]
Release Date : September 2013
ISBN : 1849687943
ISBN 13 : 9781849687942
Author(s) : Peter A. Pilgrim
Topics and Technologies : All Books, Application Development, Enterprise, Java

Table of Contents

Preface
Chapter 1: Java EE 7 HTML5 Productivity
Chapter 2: Context and Dependency Injection
Chapter 3: Enterprise Java Beans
Chapter 4: Essential Java Persistence API 3.2
Chapter 5: Object-Relational Mapping with JPA
Chapter 6: Java Servlets and Asynchronous Request-Response
Chapter 7: Java API for HTML5WebSocket
Chapter 8: RESTful Services JAX-RS 2.0
Chapter 9: Java Message Service 2.0
Chapter 10: Bean Validation
Chapter 11: Advanced Topics in Persistence
Appendix A: Java EE 7 Platform
Appendix B: Java EE 7 Persistence
Appendix C: Java EE 7 Transactions
Appendix D: Java EE 7 Assorted Topics
Index
  • Chapter 1: Java EE 7 HTML5 Productivity
    • Java EE 7
    • Enhanced HTML5 support
    • Java EE 7 architecture
      • Standard platform components and APIs
      • New productivity themes
      • Refinements
    • Java EE Platform
      • Java EE Profiles
        • Web Profile
        • Enterprise Profile
    • A working example
      • Entities
      • Business logic
      • The service endpoints
        • A WebSocket endpoint
        • A RESTful endpoint
        • The Entity Control Boundary pattern
    • Summary
    • Chapter 2: Context and Dependency Injection
      • Software engineering definitions
      • The Context and Dependency Injection service
        • Beans and bean types
        • Basic injection
          • Field injection
          • Setter injection
          • Constructor injection
        • Qualifiers
          • Built-in qualifiers
        • The CDI classpath scanning
        • Factory production
        • Generating new instances every time
        • Bean names and presentation views
        • Bean scopes
        • CDI initialization and destruction
          • The @PostConstruct annotation
          • The @PreDestroy annotation
        • Programmatic Lookup of the CDI Beans
        • Configuring a CDI application
      • Standalone CDI application
      • Building the standalone project with Gradle
      • Using the DeltaSpike CDI container tests
      • Injecting arbitrary objects using Producers
      • Advanced CDI
        • The lifecycle component example
        • Alternatives
      • The Arquillian test framework
        • A new kind of Java EE testing framework
        • Setting up of Arquillian
        • The disposable methods
      • CDI and crosscutting concerns
        • Interceptors
        • Decorators
        • Observers and events
        • Stereotypes
      • Summary
      • Chapter 3: Enterprise Java Beans
        • EJB protocols
          • Criticism of EJB
          • Simplification of EJB
        • Features of EJB components
        • Session beans
          • Stateless session beans
            • Concurrency and stateless session EJBs
          • Stateful session beans
          • Singleton session beans
        • The lifecycle of session EJBs
          • Lifecycle of stateless EJBs
          • Lifecycle of stateful session beans
          • Lifecycle of singleton session beans
        • Business interfaces
          • Local access
          • Remote access
          • Access summary
            • No interface views
        • EJB references
        • Asynchronous invocations
        • The relationship between EJB and CDI containers
        • Lightweight scope of EJBs
        • Summary
        • Chapter 4: Essential Java Persistence API 3.2
          • Entities
            • Defining Entity bean
            • An entity bean example
              • A Plain Old Java Object
              • A simple entity bean
              • Expanded entity bean definition
            • Annotating entity beans
              • Annotating entities with the instance variables
              • Annotating entities with property accessors
              • Comparing annotating styles
          • Running a simple entity bean test
            • The Gradle build file for the entity bean test
            • A stateful session bean
            • An entity bean integration test
            • A persistence context XML configuration
            • Arquillian configuration for the embedded GlassFish server
            • Running an integration test
          • The lifecycle of an entity bean
            • The new entity state
            • The managed entity state
            • The detached entity state
            • The removed entity state
          • EntityManager
            • Persistence context
              • The EntityManager methods
            • Transactional support
              • Application managed transactions
            • Retrieving an EntityManager by injection
            • Retrieving an EntityManager by factory
            • Retrieving an EntityManager by the JNDI lookup
          • Moving further along with entity beans
            • Controlling the mapping of entities to the database table
            • Expanding the @Table annotation
              • Mapping the primary keys
            • The single primary key
            • Composite primary keys
              • Using the @IdClass annotation
              • Using the @Embeddable annotation
              • Using the @EmbeddedId annotation
          • JPQL
            • The dynamic queries
            • The named queries
            • The query parameters
              • The positional query arguments
          • The entity bean relationships
            • Mapping with the @OneToOne annotation
            • Mapping with the @OneToMany annotation
            • Mapping with the @ManyToOne annotation
            • Mapping with the @ManyToMany annotation
          • Configuration of persistence and the entity beans
            • The structure of the persistence unit configuration
            • The object-relational mapping files
            • Standard property configurations for the persistence units
          • Summary
          • Chapter 5: Object-Relational Mapping with JPA
            • Adding finesse to entity beans
              • Field binding
                • Binding eagerly
                • Binding lazily
                • The trade-off between eager and lazy
              • Cascades onto dependent entities
                • Cascade operations
                • Removal of orphans in relationships
              • Generated values and primary keys
                • Table auto increment
                • Sequence auto increment
                • Identity auto increment
            • Entity relationships revisited
              • One-to-one mapping
                • Persisting one-to-one unidirectional entities
                • Bidirectional one-to-one-entities
                • Persisting one-to-one bidirectional entities
                • Composite foreign keys in a one-to-one relationship
              • One-to-many mapping
                • One-to-many relationship with a join column
                • Bidirectional one-to-many relationship
                • One-to-many using an explicit join table
              • Many-to-one mapping
                • Many-to-one relationship with a join column
                • Bidirectional many-to-one relationship
              • Many-to-many mapping
                • Bidirectional many-to-many relationship
                • Unidirectional many-to-many relationship
            • Mapping entity inheritance hierarchy
              • Hierarchy in a single database table
                • An example user story
                • Benefits and drawbacks of the single table strategy
              • Common base table hierarchy
                • An example user story
                • Benefits and drawbacks of joined Inheritance
              • Table-per-class hierarchy
                • An example user story
                • Benefits and drawbacks of table-per-class hierarchy
            • Extended entities
              • Mapped super-classes
            • Troubleshooting entity persistence
              • Fetch performance
                • Prefer lazily binding for maximum performance
              • Entity Relationship
                • Prefer orphan removal
                • Excessive queries
              • Object corruption
            • Summary
            • Chapter 6: Java Servlets and Asynchronous Request-Response
              • What are Java Servlets?
                • Web containers
                • The lifecycle of Java Servlets
                  • Loading Servlets
                  • The Java Servlet initialization
                  • The Java Servlet destruction
                • The Servlet request and response
                • HTTP Servlets
                • The deployment model
              • Getting started with Java Servlets
                • A simple Servlet
                  • The URL path mapping
                • The Gradle build project
                • The containerless Java web application
              • Request and response
                • The request parameters
                • Headers
                • The request attributes
                • The session attributes
                • The Servlet context attributes
                • Redirecting the response
              • The web deployment descriptor
                • Mapping Java Servlets
                • Configuring a session timeout
                • Configuring MIME types
                • Configuring the welcome page
                • Configuring the error-handler pages
                • Annotations and the web deployment descriptor
              • The Servlet filters
                • The Servlet filter annotation attributes
                • The Servlet filter XML configuration
              • The Servlet context listener
              • Pluggable Servlet fragments
                • Ordering multiple web fragments
              • Asynchronous Java Servlets
                • The asynchronous input and output
                  • A synchronous reader example
                  • An asynchronous reader example
                  • An asynchronous writer
              • Alignment to the containers
                • Aligning Servlets to the CDI container
              • Miscellaneous features
                • Mapping the URL patterns
                • Rules for the URL path mapping
                • Single thread model
              • Summary
              • Chapter 7: Java API for HTML5WebSocket
                • The rise of WebSockets
                  • Early web technology
                  • Enter HTML5 and WebSockets
                  • WebSocket Java definitions
                  • The WebSocket protocol
                • Server-side Java WebSockets
                  • @ServerEndpoint
                  • @OnMessage
                • Invoking Java WebSocket
                • Running WebSocket examples
              • Java WebSocket API
                • Native formats communication
                • Annotated WebSockets on the server side
                  • Lifecycle WebSocket endpoint annotations
                • WebSocket sessions
              • A Java WebSocket chat server
                • The server side
                • The web client
                • Asynchronous operations
              • Client-side Java WebSockets
                • @ClientEndpoint
                • Annotated client example
                • Remote endpoints
              • Programmatic Java WebSocket
              • Encoders and decoders
              • Summary
                • Chapter 8: RESTful Services JAX-RS 2.0
                  • Representational State Transfer
                    • JAX-RS 2.0 features
                  • Architectural style
                    • REST style for collections of entities
                    • REST style for single entities
                  • Servlet mapping
                    • Mapping JAX-RS resources
                    • Test-Driven Development with JAX-RS
                  • JAX-RS server-side endpoints
                    • Defining JAX-RS resources
                    • Testing JAX-RS resources
                    • Path URI variables
                    • JAX-RS annotations for extracting field and bean properties
                      • Extracting query parameters
                      • Extracting matrix parameters
                      • Using default values
                      • Extracting form parameters
                    • Field and bean properties
                  • JAX-RS subresources
                    • Resolution by a subresource location
                    • Resolution by a subresource method
                  • Generating a JAX-RS generic response
                    • Response builder
                    • Response status
                    • Generic entities
                    • Return types
                    • Hypermedia linking
                  • JAX-RS client API
                    • Synchronous invocation
                    • Asynchronous invocation
                  • Asynchronous JAX-RS server side endpoints
                  • JAX-RS providers
                  • Filters
                    • JAX-RS filters
                      • Server-side filters
                      • Client-side filters
                    • JAX-RS interceptors
                    • Binding filter and interceptors
                      • Dynamic binding
                  • Summary
                  • Chapter 9: Java Message Service 2.0
                    • What is JMS?
                      • Messaging systems
                        • Point-to-point messaging
                        • Publish-subscribe messaging
                    • JMS definitions
                      • JMS classic API
                      • JMS simplified API
                      • JMS message types
                    • A quick JMS 2.0 example
                    • Establishing a JMS connection
                      • Connecting to a JMS provider
                      • Connection factories
                        • Default connection factory
                      • Message destinations
                      • JMSContext
                        • Retrieving a JMSContext
                    • Sending JMS messages
                      • Upgrading message producers from JMS 1.1
                      • Sending messages synchronously
                      • Sending messages asynchronously
                      • JMS message headers
                        • Setting message properties
                        • Setting a message delivery delay
                    • Receiving JMS messages
                      • Upgrade from JMS 1.1
                      • Receiving messages synchronously
                      • Receiving messages asynchronously
                        • Non-shared subscriptions
                        • Shared subscriptions
                        • Durable topic consumers
                      • Starting and stopping connections
                      • Redelivery of messages
                        • Other JMS-defined properties
                    • Message-driven Beans (MDBs)
                      • Activation configuration property
                      • Message selectors
                    • JMS exception handling
                    • Upgrading JMS 1.1 code
                      • Establish a JMS 1.1 connection
                    • JMS and dependency injection
                      • Injecting CDI beans
                      • Injection of JMSContext resources
                      • Injecting EJB beans
                      • Definition of JMS resources in Java EE
                    • Summary
                    • Chapter 10: Bean Validation
                      • Introduction to Bean Validation
                        • New features in 1.1
                        • A quick example
                      • Constraint declarations
                        • Elements of a constraint
                        • List of built-in constraints
                        • Hibernate Validator built-in constraints
                        • Constraint violations
                      • Applying constraint definitions
                        • Custom validators
                        • Groups of constraints
                          • Class-level constraints
                          • Partial validation
                      • Constraint inheritance
                      • Ordering groups of constraints
                      • Method-level constraints
                        • Method validation rules
                      • Integration with Java EE
                        • Default access to validator and validator factory
                        • JAX-RS 2.0 integration
                      • Summary
                      • Chapter 11: Advanced Topics in Persistence
                        • Persistence of map collections
                          • The MapKey relationship
                          • The MapKey join column relationship
                        • Calling stored procedures
                          • Stored procedure query
                          • MySQL remote server example
                          • Dynamic result set retrieval
                          • Retrieving outbound parameter values
                          • Stored procedure query annotations
                        • Understanding the criteria API
                          • Criteria queries
                          • CriteriaUpdate
                          • CriteriaDelete
                        • Entity graphs
                          • Worked example of a fetch plan
                        • Miscellaneous features
                          • Custom JPQL functions
                          • Down-casting entities
                          • Synchronization of persistence contexts
                          • Entity listeners with CDI
                          • Native query constructor mapping
                        • Summary
                        • Appendix A: Java EE 7 Platform
                          • Platform containers
                            • Global JNDI naming
                            • Packaging
                            • Bean XML configuration location
                            • Persistence XML configuration location
                          • Upgrading to Java EE 7 from J2EE versions
                            • Legacy application programming interfaces
                          • GlassFish 4 reference implementation
                            • Installing basic GlassFish
                            • Configuring MySQL database access
                            • Configuring command line
                            • Default resources
                          • Appendix B: Java EE 7 Persistence
                            • Persistence unit
                              • XML schema documents for Java EE 7
                              • Properties
                              • XML representation of object-relational mapping
                            • JPA miscellaneous features
                              • Converters
                              • Native constructor results
                            • Transactions and concurrency
                              • Entity managers
                              • Transactions, entity managers, and session EJBs
                                • Stateful session beans
                              • Concurrency access locks
                                • Optimistic locking
                                • Pessimistic locking
                            • Appendix C: Java EE 7 Transactions
                              • Transactions
                                • Java Transaction API
                                • Two-phase commit transactions
                                  • Heuristic failures
                                • Local transactions
                                • Distributed transactions
                              • Transaction services
                                • Container-Managed Transactions (CMT)
                                • Bean-Managed Transactions (BMT)
                                • Isolation levels
                                • JNDI lookup
                              • Appendix D: Java EE 7 Assorted Topics
                                • Concurrency utilities
                                  • Environment reference
                                  • Application container context
                                  • Contextual tasks
                                • JSON-P
                                  • Streaming
                                    • Parsing JSON with Streaming API
                                    • Generating JSON with Streaming API
                                  • Object model
                                    • Parsing JSON with the object model
                                    • Generating JSON with the object model
                                • Recommended reading

                                Peter A. Pilgrim

                                Peter A. Pilgrim is the 91st Oracle Java Champion, an independent contractor, a professional software developer and designer. Peter is an honors degree graduate of London South Bank University in 1990. He had already secured a Master's degree course for September 1991, but then instead elected to live and work in Germany for a few years in order to beat off the then, economic recession. He spent productive years at a joint-venture company developing spectroscopic scientific software in Fortran 77, C, Solaris, and X Windows. After four years abroad Peter returned to London and continued his career in the industry with more C, C++, and UNIX development. He then leapt at a chance to get into investment banking with Deutsche Bank in 1998. It was at Deutsche Bank a week after joining them that Peter discovered Java was the next best thing since sliced bread, when a colleague dropped out of a programming Java training course. As the substitute person, Peter realized this peculiar Java language and platform was the future and the answer. Peter applied his studies to his day job and learnt Java applets, then Java Swing and switched over to the server side with Java Servlets with web applications involving the Struts framework. In 2004, Peter created the JAVAWUG user group in London for the burgeoning development community who were interested in web development on the Java EE. What started as the Struts Networking Users Group in London quickly expanded to lot of other areas. The JAVAWUG ran for six years until 2010. He built a reputation for travelling to Java technology conferences in the US and Europe and being heavily involved in the wider community. He spoke at several developer conferences including QCon London, ACCU, Devoxx, Devoxx UK, and JavaOne. In 2007, Peter was elected to the Sun Microsystems' Java Champions program. Today, Peter A. Pilgrim is a well-known specialist in Java Enterprise Edition (Java EE) technology, focused on the server-side and the implementation of electronic commerce. Peter has built professional Java EE applications for Blue-chip companies and top-tier investment and retail banks including Lloyds Banking Group, Barclays, UBS, Credit Suisse, Royal Bank of Scotland, and LBi. He is also a fan of Agile practices and Test Driven Development. Peter, currently, lives in South London with his long-term partner Terry, who is a Scottish Diva, business communication coach, and a singer—her voice is phenomenal. Peter writes a blog at http://www.xenonique.co.uk/blog/ and is on Twitter as peter_pilgrim.

                                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

                                - 6 submitted: last submission 13 Mar 2014

                                The latest update on the code in this book can be found in the author's GitHub page at
                                https://github.com/peterpilgrim/javaee7-developer-handbook
                                

                                Page : 45 | Errata type: Technical

                                The following line in the last paragraph of the Basic injection section:
                                For now, we will assume that the lifetime of the bean typed live for the duration of the application.

                                should be
                                For now, we will assume that these bean types exist for the lifetime of the application's deployment.

                                 

                                Page : 29 and 31 | Errata type: Technical

                                ProjectTasksService should be ProjectTaskService

                                 

                                Page : 50 | Errata type: Grammar

                                The last sentence of the page:
                                With CDI, we use special custom annotation for this.

                                should be
                                With CDI, we use a special custom annotation for this.

                                Page : 151  |  Errata type: Technical

                                The line above the second code snippet is
                                The file, which is specific only to the GlassFish application server, and is
                                named src/test/resources-glassfish-embedded/glassfish-resources.xml is
                                as follows:

                                It should be
                                The file, which is specific only to the GlassFish application server, and is 
                                named src/test/resources-glassfish-embedded/logging.properties is
                                as follows:

                                Page : 19  |  Errata type: Technical

                                The third point of the page is
                                JSON-P 1.0: This is a brand new framework for the Java application 
                                read-and-write JavaScript Schema Object Notation (JSON) documents

                                 

                                It should be
                                JSON-P 1.0: This is a brand new framework for the Java application
                                read-and-write JavaScript Object Notation (JSON) documents 

                                Chapter number 4 is titled as Essential Java Persistence API 3.2
                                It should be Essential Java Persistence
                                 

                                Page : 129  |  Errata type: Technical

                                The third paragraph of the page starts with
                                The Java Persistence API (JPA), JSR 338, Version 3.2 is the specification that mandates how persistence can be applied...

                                It should be
                                The Java Persistence API (JPA), JSR 338, Version 2.1 is the specification that mandates how persistence can be applied...

                                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

                                Java EE 7 Developer Handbook +    Business Process Execution Language for Web Services 2nd Edition =
                                50% Off
                                the second eBook
                                Price for both: €31.00

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

                                What you will learn from this book

                                • Understand the JSR and the API that are assembled together for Java EE 7
                                • Write server side and client side WebSocket connection in Java
                                • Understand the essential differences and similarities between the EJB and CDI containers, as well as dependency injection
                                • Learn about Gradle builds, embedded containers, and the Arquillian Framework
                                • Build server side endpoints with EJB in stateless, stateful, and singleton modes
                                • Write REST server side endpoints on the client and server side
                                • Write asynchronous Servlet input and output and also annotated Servlet, Context Listeners
                                • Map entities in Java Persistence with the essential cardinalities including the Java side of many-to-many relationships
                                • Learn about mapping entities to stored procedures and entity graphs
                                • Fully understand how to verify your POJO before they hit the database with Bean Validation API
                                • Be prepared for the Java EE 8 journey and beyond, which may include deployment to the cloud

                                In Detail

                                The seventh edition of the Enterprise Java platform is aimed at helping Java engineers take advantage of the advancements in HTML5 and web standards. Web Sockets, asynchronous input and output with Servlets, and strong type safety through the CDI containers will ensure that Java EE 7 remains popular for server-side applications.
                                If you are a user aiming to get acquainted with the Java EE 7 platform, this book is for you.

                                "Java EE 7 Developer Handbook" provides a solid foundation of knowledge for developers to build business applications. Following the lead of Agile practices, there is a focus on writing tests to demonstrate test-driven development principles, using the embedded GlassFish 4.0 container examples and the Gradle build system. You will learn about CDI, EJB, JPA, JMS, MDB, Servlets, WebSocket, JAX-RS, Bean Validation, and so much more.

                                "Java EE 7 Developer Handbook" is designed as a companion to the professional software developer who quickly needs to lookup some working code, understand the basics of the framework, and then go out and fulfill the business contract with the customer. Typically, engineers are under pressure to develop professional code that is of high quality and contains a low number of bugs. Java EE 7 Developer Handbook relies heavily on the Arquillian framework to illustrate how much easier it is to write Java EE tests, and together with the modern practice of writing containerless applications that actually embed an application container, developing agile Java EE suddenly becomes reasonable, smart, pragmatic, and achievable.

                                You will start off with an overview of the Java EE platform: the containers, the design, and architecture. From there, you can follow the path of the CDI, the true gem of the framework, and then the server side end point, EJB. It is completely up to you when and if you want to learn about Java persistence. However, don’t miss out on the highlights of Java EE 7 such as WebSocket, Bean Validation, and asynchronous Servlet API.

                                "Java EE 7 Developer Handbook" is a vertical slice through standard Java enterprise architecture. If you have been wondering why developers have invested so much time and effort into learning topics such as Enterprise Java Beans, you will quickly understand why when you find out the difference between stateful and stateless Beans. Best of all, this book covers the topic from the perspective of new API and new modern practices. For instance, you, the developer and designer, are expected to write applications with annotations in comparison with J2EE. Java EE 7 Developer Handbook incorporates helpful hints and tips to get the developer up to speed in a short amount of time on EJB, CDI, Persistence, Servlet, JMS, WebSocket, JAX-RS and Bean Validation, and much more.

                                "Java EE 7 Developer Handbook" is the reference guide you need beside you at your desk.

                                Approach

                                "Java EE 7 Developer Handbook" is an example based tutorial with descriptions and explanations.

                                Who this book is for

                                "Java EE 7 Developer Handbook" is for the developer, designer, and architect aiming to get acquainted with the Java EE platform in its newest edition. This guide will enhance your knowledge about the Java EE 7 platform. Whether you are a long-term Java EE (J2EE) developer or an intermediate level engineer on the JVM with just Java SE behind you, this handbook is for you, the new contemporary Java EE 7 developer!

                                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