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

Architecting Modern Java EE Applications

Book Description

Find out how to craft effective, business-oriented Java EE 8 applications that target customer’s demands in the age of Cloud platforms and container technology.

About This Book

  • Understand the principles of modern Java EE and how to realize effective architectures
  • Gain knowledge of how to design enterprise software in the age of automation, Continuous Delivery and Cloud platforms
  • Learn about the reasoning and motivations behind state-of-the-art enterprise Java technology, that focuses on business

Who This Book Is For

This book is for experienced Java EE developers who are aspiring to become the architects of enterprise-grade applications, or software architects who would like to leverage Java EE to create effective blueprints of applications.

What You Will Learn

  • What enterprise software engineers should focus on
  • Implement applications, packages, and components in a modern way
  • Design and structure application architectures
  • Discover how to realize technical and cross-cutting aspects
  • Get to grips with containers and container orchestration technology
  • Realize zero-dependency, 12-factor, and Cloud-native applications
  • Implement automated, fast, reliable, and maintainable software tests
  • Discover distributed system architectures and their requirements

In Detail

Java EE 8 brings with it a load of features, mainly targeting newer architectures such as microservices, modernized security APIs, and cloud deployments. This book will teach you to design and develop modern, business-oriented applications using Java EE 8. It shows how to structure systems and applications, and how design patterns and Domain Driven Design aspects are realized in the age of Java EE 8. You will learn about the concepts and principles behind Java EE applications, and how to effect communication, persistence, technical and cross-cutting concerns, and asynchronous behavior.

This book covers Continuous Delivery, DevOps, infrastructure-as-code, containers, container orchestration technologies, such as Docker and Kubernetes, and why and especially how Java EE fits into this world. It also covers the requirements behind containerized, zero-dependency applications and how modern Java EE application servers support these approaches. You will also learn about automated, fast, and reliable software tests, in different test levels, scopes, and test technologies. This book covers the prerequisites and challenges of distributed systems that lead to microservice, shared-nothing architectures. The challenges and solutions of consistency versus scalability will further lead us to event sourcing, event-driven architectures, and the CQRS principle. This book also includes the nuts and bolts of application performance as well as how to realize resilience, logging, monitoring and tracing in a modern enterprise world. Last but not least the demands of securing enterprise systems are covered.

By the end, you will understand the ins and outs of Java EE so that you can make critical design decisions that not only live up to, but also surpass your clients' expectations.

Style and approach

This book focuses on solving business problems and meeting customer demands in the enterprise world. It covers how to create enterprise applications with reasonable technology choices, free of cargo-cult and over-engineering. The aspects shown in this book not only demonstrate how to realize a certain solution, but also explain its motivations and reasoning.

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 code file.

Table of Contents

  1. 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
  2. Introduction
    1. New demands in enterprise systems
    2. Modern way of realizing enterprise systems
    3. Relevance of Java EE in modern systems
    4. Java EE 8 update and roadmap
    5. Java Community Process
    6. What to expect in the book
  3. Designing and Structuring Java Enterprise Applications
    1. The purpose of enterprise applications
      1. What developers should focus on
      2. Meeting customer's demands
    2. Outer enterprise project structure
      1. Business and team structures
      2. Software projects contents
        1. Application source code
        2. Software structures
        3. Version control systems
        4. Binaries
        5. Build systems
      3. Single versus multi-module projects
      4. Illusion of reusability
        1. Technical dependencies
        2. Organizational challenges
        3. Reusability considerations
      5. Project artifacts
      6. One project per artifact
      7. Build systems for Java EE
        1. Apache Maven
        2. Gradle
      8. Structuring for modern frontend technologies
        1. Enter JavaScript frameworks
        2. Organizing modern frontends
    3. Enterprise project code structure
      1. Situation in enterprise projects
      2. Horizontal versus vertical layering
      3. Business-driven structure
      4. Designing reasonable modules
      5. Realizing package structures
        1. Package contents
        2. Horizontal package layering
        3. Flat module package
        4. Entity Control Boundary
          1. Packages
          2. Package access
      6. Don't over-enforce architecture
    4. Summary
  4. Implementing Modern Java Enterprise Applications
    1. Use case boundaries
    2. Core domain components of modern Java EE
      1. EJB and CDI - differentiation and integration
      2. CDI producers
      3. Emitting domain events
      4. Scopes
    3. Patterns in Java EE
      1. Design patterns revisited
        1. Singleton
        2. Abstract factory
        3. Factory method
        4. Object pool
        5. Decorator
        6. Facade
        7. Proxy
        8. Observer
        9. Strategy
        10. Further patterns
      2. Domain-Driven Design
        1. Services
        2. Entities
        3. Value objects
        4. Aggregates
        5. Repositories
        6. Factories
        7. Domain event
    4. External and cross-cutting concerns in enterprise applications
      1. Communication with external systems
        1. How to choose communication technology
        2. Synchronous HTTP communication
          1. Representational State Transfer
          2. Java API for RESTful web services
          3. Mapping HTTP content types
          4. Validating requests
          5. Mapping errors
          6. Accessing external systems
          7. Stability when consuming HTTP
          8. Accessing Hypermedia REST services
        3. Asynchronous communication and messaging
          1. Asynchronous HTTP communication
          2. Message-oriented communication
          3. Server-sent events
          4. WebSocket
        4. Connecting enterprise technology
      2. Database systems
        1. Integrating RDBMS systems
          1. Mapping domain models
          2. Integrating database systems
          3. Transactions
        2. Relational databases versus NoSQL
      3. Cross-cutting concerns
      4. Configuring applications
      5. Caching
    5. Flow of execution
      1. Synchronous execution
      2. Asynchronous execution
        1. Asynchronous EJB methods
        2. Managed Executor Service
        3. Asynchronous CDI events
        4. Scopes in asynchronicity
        5. Timed execution
        6. Asynchronous and reactive JAX-RS
    6. Concepts and design principles of modern Java EE
    7. Preserving maintainable code with high quality
    8. Summary
  5. Lightweight Java EE
    1. Lightweight enterprise technology
    2. Why Java EE standards?
    3. Convention over configuration
    4. Dependency management of Java EE projects
    5. Lightweight way of packaging applications
    6. Java EE application servers
    7. One application per application server
    8. Summary
  6. Container and Cloud Environments with Java EE
    1. Motivations and goals
      1. Infrastructure as code
      2. Stability and production readiness
    2. Containers
    3. Java EE in the container
    4. Container orchestration frameworks
    5. Realizing container orchestration
    6. Java EE in orchestrated containers
      1. Connecting external services
      2. Configuring orchestrated applications
    7. 12-factor applications and Java EE
      1. Have one codebase tracked in revision control, many deploys
      2. Explicitly declare and isolate dependencies
      3. Store config in the environment
      4. Treat backing services as attached resources
      5. Strictly separate build and run stages
      6. Execute the app as one or more stateless processes
      7. Export services via port binding
      8. Scale out via the process model
      9. Maximize robustness with fast startup and graceful shutdown
      10. Keep development, staging, and production as similar as possible
      11. Treat logs as event streams
      12. Run admin/management tasks as one-off processes
    8. Cloud, Cloud native, and their benefits
      1. Cloud native
    9. Summary
  7. Application Development Workflows
    1. Motivation and goals of productive development workflows
    2. Realizing development workflows
      1. Version control everything
      2. Building binaries
        1. Java artifacts
        2. Artifact versions
        3. Building containers
      3. Quality assurance
      4. Deployment
        1. Configuration
        2. Credentials
      5. Data migration
        1. Adding database structures
        2. Changing database structures
        3. Removing database structures
        4. Implementing migration
      6. Testing
      7. Build metadata
      8. Going to production
      9. Branching models
      10. Technology
      11. Pipeline-as-code
    3. Workflows with Java EE
    4. Continuous Delivery culture and team habits
      1. Responsibility
      2. Check in early and often
      3. Immediately fixing issues
      4. Visibility
      5. Improve continuously
    5. Summary
  8. Testing
    1. The necessity of tests
    2. Requirements of well-crafted tests
      1. Predictability
      2. Isolation
      3. Reliability
      4. Fast execution
      5. Automation
      6. Maintainability
    3. What to test
    4. Definition of test scopes
      1. Unit tests
      2. Component tests
      3. Integration tests
      4. System tests
      5. Performance tests
      6. Stress tests
    5. Implementing tests
      1. Unit tests
        1. Implementation
        2. Technology
      2. Component tests
        1. Motivation
        2. Implementation
        3. Delegating test components
        4. Technology
      3. Integration tests
        1. Embedded containers
        2. Embedded databases
        3. Running integration tests
      4. Code level integration tests versus system tests
        1. Shortcomings of integration tests
        2. Shortcomings of system tests
        3. Conclusion
      5. System tests
        1. Managing test scenarios
        2. Simulating external concerns
        3. Designing system tests
          1. Deploying and controlling external mocks
      6. Performance tests
        1. Motivation
        2. Key performance indicators
        3. Developing performance tests
        4. Insights
    6. Running tests locally
    7. Maintaining test data and scenarios
      1. Importance of maintainable tests
      2. Signs of lack of test quality
      3. Test code quality
      4. Test technology support
    8. Summary
  9. Microservices and System Architecture
    1. Motivations behind distributed systems
    2. Challenges of distribution
      1. Communication overhead
      2. Performance overhead
      3. Organizational overhead
    3. How to design systems landscapes
      1. Context maps and bounded contexts
      2. Separation of concerns
      3. Teams
      4. Project life cycles
    4. How to design system interfaces
      1. API considerations
      2. Interface management
        1. Change-resilient APIs
        2. Breaking the business logic
        3. Hypermedia REST and versioning
      3. Documenting boundaries
      4. Consistency versus scalability
    5. Event sourcing, event-driven architectures, and CQRS
      1. Shortcomings of CRUD-based systems
        1. Scalability
        2. Competing transactions
        3. Reproducibility
      2. Event sourcing
        1. Benefits
      3. Eventually consistent real world
      4. Event-driven architectures
        1. Eventual consistency in event-driven architectures
      5. Enter CQRS
        1. Principles
        2. Design
        3. Benefits
        4. Shortcomings
    6. Communication
    7. Microservice architectures
      1. Sharing data and technology in enterprises
      2. Shared-nothing architectures
      3. Interdependent systems
      4. 12-factor and cloud native applications
      5. When to use and when not to use microservices
    8. Implementing microservices with Java EE
      1. Zero-dependency applications
      2. Application servers
      3. Implementing application boundaries
      4. Implementing CQRS
        1. System interfaces
        2. Example scenario using Apache Kafka
        3. Integrating Java EE
          1. CDI events
          2. Event handlers
          3. State representation
          4. Consuming Kafka messages
          5. Producing Kafka messages
          6. Application boundaries
        4. Integrating further CQRS concepts
      5. Java EE in the age of distribution
        1. Discovering services
        2. Communicating resiliently
          1. Validating responses
          2. Breaking timeouts and circuits
          3. Bulkheads
          4. Shaking hands and pushing back
      6. More on being resilient
    9. Summary
  10. Monitoring, Performance, and Logging
    1. Business metrics
      1. Collecting business metrics
      2. Emitting metrics
        1. Enter Prometheus
        2. Realization with Java EE
        3. Integrating the environment
    2. Meeting performance requirements in distributed systems
      1. Service level agreements
      2. Achieving SLAs in distributed systems
    3. Tackling performance issues
      1. Theory of constraints
      2. Identifying performance regression with jPDM
        1. Subsystems
          1. Actors
          2. Application
          3. JVM
          4. Operating system and hardware
        2. jPDM instances - production situations
        3. Analyzing the jPDM instances
          1. Dominating consumer - OS
          2. Dominating consumer - none
          3. Dominating consumer - JVM
          4. Dominating consumer - application
        4. Conclusion
    4. Technical metrics
      1. Types of technical metrics
      2. High frequency monitoring versus sampling
      3. Collecting technical metrics
        1. Boundary metrics
    5. Logging and tracing
      1. Shortcomings of traditional logging
        1. Performance
        2. Log levels
        3. Log format
        4. Amounts of data
        5. Obfuscation
        6. The concerns of applications
        7. Wrong choice of technology
      2. Logging in a containerized world
    6. Journaling
    7. Tracing
      1. Tracing in a modern world
    8. Typical performance issues
      1. Logging and memory consumption
      2. Premature optimization
      3. Relational databases
      4. Communication
      5. Threading and pooling
    9. Performance testing
    10. Summary
  11. Security
    1. Lessons learned from the past
    2. Security in a modern world
      1. Security principles
        1. Encrypt communication
        2. Delegate security concerns
        3. Treat user credentials properly
        4. Avoid storing credentials in version control
        5. Include tests
      2. Possibilities and solutions
        1. Encrypted communication
        2. Protocol-based authentication
        3. Decentralized security
        4. Proxies
        5. Integration in modern environments
    3. Implementing security in Java EE applications
      1. Transparent security
      2. Servlets
      3. Java principals and roles
      4. JASPIC
      5. Security API
        1. Authentication mechanisms
        2. Identity stores
        3. Custom security
        4. Accessing security information
    4. Summary
  12. Conclusion
    1. Motivations in enterprise development
    2. Cloud and Continuous Delivery
    3. Relevance of Java EE
    4. API updates introduced in Java EE 8
      1. CDI 2.0
      2. JAX-RS 2.1
      3. JSON-B 1.0
      4. JSON-P 1.1
      5. Bean Validation 2.0
      6. JPA 2.2
      7. Security 1.0
      8. Servlet 4.0
      9. JSF 2.3
    5. JCP and participation
    6. MicroProfile
    7. Eclipse Enterprise for Java
  13. Appendix: Links and further resources