O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Developing Middleware in Java EE 8

Book Description

Use Java features such as JAX-RS, EJBs, and JPAs to build powerful middleware for newer architectures such as the cloud

About This Book
  • Explore EJBs to build middleware solutions for enterprise and distributed applications
  • Understand middleware designs such as event-based and message-driven web services
  • Learn to design and maintain large-scale systems and vendor disputes
Who This Book Is For

Enterprise architects, designers, developers, and programmers who are interested in learning how to build robust middleware solutions for enterprise software will find this book useful. Prior knowledge of Java EE is essential

What You Will Learn
  • Implement the latest Java EE 8 APIs and manage dependencies with CDI 2.0
  • Perform CRUD operations and access databases with JPA 2.1
  • Use bean validation API 2.0 to validate data
  • Develop business logic with EJB 3.2
  • Incorporate the REST architecture and RESTful API design patterns
  • Perform serialization and deserialization on JSON documents using JSON-B
  • Utilize JMS for messaging and queuing models and securing applications
  • Test applications using JUnit and Mockito and deploy them using Docker
In Detail

Middleware is the infrastructure in software based applications that enables businesses to solve problems, operate more efficiently, and make money. As the use of middleware extends beyond a single application, the importance of having it written by experts increases substantially. This book will help you become an expert in developing middleware for a variety of applications.

The book starts off by exploring the latest Java EE 8 APIs with newer features and managing dependencies with CDI 2.0. You will learn to implement object-to-relational mapping using JPA 2.1 and validate data using bean validation. You will also work with different types of EJB to develop business logic, and with design RESTful APIs by utilizing different HTTP methods and activating JAX-RS features in enterprise applications. You will learn to secure your middleware with Java Security 1.0 and implement various authentication techniques, such as OAuth authentication. In the concluding chapters, you will use various test technologies, such as JUnit and Mockito, to test applications, and Docker to deploy your enterprise applications.

By the end of the book, you will be proficient in developing robust, effective, and distributed middleware for your business.

Style and approach

Learn how to design and implement professional enterprise middleware solutions using the latest techniques and features provided by the Java EE 8 platform.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Developing Middleware in Java EE 8
  3. Dedication
  4. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  5. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  7. Delving into Java EE 8
    1. What is Java EE?
      1. Enterprise applications
      2. Java EE architecture
    2. Chapter roadmap
      1. Contexts and dependency injection
      2. Data persistence
      3. Data validation
      4. Enterprise JavaBeans
      5. RESTful services
      6. JSON processing
      7. Messaging
      8. Mailing
      9. WebSockets
      10. Security
    3. Required software
      1. IDE
      2. Application server
      3. Build tool
      4. Relational database system
    4. Book project
    5. Goodbye Java EE, welcome Jakarta EE!
    6. Summary
  8. Dependency Injection Using CDI 2.0
    1. What's new in CDI 2.0?
    2. Creating your first CDI bean
      1. First CDI bean
    3. Providing alternative implementations to your bean
      1. Using qualifiers
    4. Specifying a bean scope
    5. Injecting beans
      1. Direct field injection
      2. Bean constructor parameter injection
      3. Initializer method parameter injection
    6. Using producers
      1. Scope of producer methods
      2. Injection into the producer methods
    7. Using interceptors
      1. Interceptor types
    8. Using events
    9. Summary
  9. Accessing the Database with JPA 2.1
    1. What's new in JPA 2.2?
      1. Architecture
        1. Writing your first JPA application
          1. Step 1: Creating a data source
          2. Step 2: Creating a persistence unit
          3. Step 3: Creating an entity class
          4. Step 4: Creating a data access object
    2. Entities
      1. Entity mapping
        1. Primary keys
      2. Table mapping
      3. Column mapping
      4. Date and time mapping
      5. Ignoring properties
      6. Composite primary keys
      7. Embedded objects
    3. Performing CRUD operations
      1. Managed versus detached entities
      2. Inserting a new record
      3. Retrieving an existing record
      4. Updating an existing record
      5. Deleting a record
      6. Detaching an entity
    4. Mapping entity relationships
      1. Many-to-one relationships
      2. Many-to-many relationships
      3. Bidirectional relationships
      4. Cascading
    5. Map collections of primitives
    6. JPA query language
      1. Basic syntax
      2. Query parameters
        1. Named parameters
        2. Positional parameters
      3. Query examples
        1. Selecting entities
        2. Ordering entities
        3. Limiting records
        4. Selecting entities with clauses
        5. Selecting entities with projection
        6. Eliminating duplicates
        7. Entity navigation
        8. Update entities
        9. DELETE entities
    7. Using native SQL queries
    8. Named queries
    9. Criteria queries
    10. Mapping inheritance
      1. Single table strategy
      2. Joined table strategy
      3. Table per class strategy
      4. Comparing strategies
      5. Polymorphic queries
    11. Summary
  10. Validating Data with Bean Validation 2.0
    1. What's new in Bean Validation 2.0?
    2. First validation example
      1. First approach – programmatic validation
      2. Second approach – auto validation
    3. Injecting the validator object
    4. Graph validation
    5. List of available constraints
    6. Validating parameters and return values
    7. Defining a custom constraint
      1. Associating messages with attributes
      2. Adding more constraints
    8. Summary
  11. Exposing Web Services with JAX-RS 2.1
    1. What are web services?
    2. RESTful versus SOAP services
      1. SOAP services
      2. RESTful services
    3. Understanding HTTP
      1. Basics
      2. HTTP request
      3. HTTP response
    4. Writing your first REST service
      1. Writing a resource class
      2. Configuring a project for Jersey
      3. Testing your web services
      4. Postman as a test tool
    5. Handling HTTP methods
    6. Sub-resources
    7. Receiving parameters
      1. Query parameters
      2. Matrix parameters
      3. Path parameters
      4. Form parameters
      5. Header parameters
      6. Providing default values
      7. Bean parameters
      8. Using context objects
    8. Handling JSON
      1. Enabling Moxy
      2. Returning JSON
      3. Consuming JSON
    9. Custom responses
    10. Uploading files
    11. Handling exceptions
      1. Declaring custom web application exceptions
      2. Mapping existing exceptions
    12. Server-sent events
    13. Summary
  12. Manipulating JSON with JSON-B 1.0
    1. Why JSON?
    2. Mapping objects
    3. Mapping collections
    4. Formatting output
    5. Customizing property names
    6. Customizing naming strategies
    7. Customizing property ordering
    8. Ignoring properties
    9. Handling nulls
    10. Formatting dates and numbers
    11. Using binary
    12. Summary
  13. Communicating with Different Systems with JMS 2.0
    1. Message-Oriented Middleware
    2. Java Messaging System (JMS)
      1. Architecture
        1. JMS provider
        2. JMS clients
        3. Messages
        4. Administered objects
      2. Messaging styles
        1. Point-to-point style
        2. Publish-subscribe
    3. First JMS application
      1. Creating administered objects
        1. Creating a destination
        2. Creating a connection factory
      2. Creating the producer
      3. Creating the consumer
    4. Using JMS resources with annotations
      1. Creating connection factories
      2. Creating destinations
      3. Injecting connection factories
      4. Injecting destinations
      5. Putting them all together
    5. Message-Driven Beans
      1. Creating a message-driven bean
      2. Sending and receiving messages
        1. Text messages
        2. Map messages
        3. Object messages
    6. Summary
  14. Sending Mails with JavaMail 1.6
    1. Explaining mail protocols
      1. POP3 and IMAP
      2. SMTP
    2. Sending an email
    3. Sending an HTML email message
    4. Setting To, CC, and BCC fields
    5. Sending an email with attachments
    6. Summary
  15. Securing an Application with Java Security 1.0
    1. Terminology
      1. Authentication mechanism
      2. Caller
      3. Caller principal
      4. Identity store
    2. Basic login example
      1. Creating a web page to protect
      2. Mentioning who's allowed to access the web page
      3. Defining users and associated roles in a database
      4. Mapping security configuration to the user database
    3. Identity stores
      1. Database identity store
      2. LDAP identity store
      3. Custom identity store
        1. Creating a custom identity store class
        2. Creating an HTTP authentication mechanism
    4. Security context
    5. Authentication mechanisms
      1. Basic authentication
      2. Form authentication
    6. Summary
  16. Making Interactive Applications with WebSockets 1.1
    1. Understanding WebSockets 
    2. How does WebSockets work?
    3. Sending and receiving messages
      1. Creating an endpoint
      2. Creating a client web page
    4. Lifecycle events
    5. Accepting path parameters
    6. Maintaining user state
    7. Using encoders
    8. Seat-booking application
      1. Designing and implementing the backend
      2. Designing and implementing the frontend
    9. Summary
  17. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think