0%

Book Description

Update your knowledge of the Enterprise Java platform through this user-friendly tutorial that’s designed around real-life examples. The pragmatic approach means you’ll be up to speed almost effortlessly. For intermediate users upwards.

  • 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

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.

Table of Contents

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