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

Spring MVC: Designing Real-World Web Applications

Book Description

Unleash the power of Spring MVC and build enterprise-grade, lightning-fast web applications

About This Book

  • Configure Spring MVC to build logic-less controllers that transparently support the most advanced web techniques
  • Secure your developments with easy-to-write, reliable unit and end-to-end tests
  • Get this fast-paced, practical guide to produce REST resources and templates as required by the latest front-end best practices

Who This Book Is For

This Learning Path is for Java developers who want to exploit Spring MVC and its features to build web applications. It will help you step up in your career and stay up to date or learn more about Spring’s web scalability.

What You Will Learn

  • Set up and build standalone and web-based projects using Spring Framework with Maven or Gradle
  • Develop RESTful API applications for XML and JSON data transfers
  • Investigate Spring data access mechanisms with Spring Data Repositories
  • Generate templates for a responsive and powerful front end with AngularJS and Bootstrap
  • Authenticate over REST with a BASIC authentication scheme and OAuth2; handle roles and permissions
  • Communicate through WebSocket and STOMP messages
  • Design complex advanced-level forms and validate the model
  • Create maintainable unit and acceptance tests to secure the apps
  • Deploy the web application to the cloud in a snap

In Detail

Spring MVC helps you build flexible and loosely coupled web applications. The Spring MVC Framework is designed in such a way that every piece of logic and functionality is highly configurable. This Learning Path aims to make you an expert in designing web applications with Spring MVC 4.

In our first module, we’ll begin with an introduction to the Spring framework. You'll then learn aspect-oriented programming. Packed with real-world examples, you’ll get an insight into how you can use Spring Expression Language in your applications to make them easier to manage and maintain.

In the second module, you'll learn everything you need to build modern Spring-based enterprise web applications. From practical development techniques and useful tools from the wider Spring ecosystem, to the new JEE standards, the impact of JavaScript, and even the Internet of Things, you'll feel confident that you can deploy Spring for an impressive range of creative purposes.

In the final module, you'll find out how to take advantage of Spring MVC's advanced features - essential if you are to properly master the framework. To do this you'll investigate the inner mechanics of Spring MVC, and how they tie into to the broader principles that inform many modern web architectures. With further guidance on how to test, secure, and optimize your application, as well as designing RESTful services, you'll very quickly be ready to use Spring in your next web project.

This Learning Path combines some of the best that Packt has to offer in one complete, curated package. It includes content from the following Packt products:

  • Spring Essentials by Shameer Kunjumohamed, Hamidreza Sattari
  • Spring MVC Cookbook by Alex Bretet
  • Mastering Spring MVC 4 by Geoffroy Warin

Style and approach

This is a hands-on, practical guide based on logical modules of the whole Spring framework family, employing a combination of theory and examples with pro-level practices, techniques, and solutions.

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. Spring MVC: Designing Real-World Web Applications
    1. Table of Contents
    2. Spring MVC: Designing Real-World Web Applications
    3. Spring MVC: Designing Real-World Web Applications
    4. Credits
    5. Preface
      1. What this learning path covers
      2. What you need for this learning path
      3. Who this learning path is for
      4. Reader feedback
      5. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    6. I. Module 1
      1. 1. Getting Started with Spring Core
        1. The Spring landscape
          1. The Spring Framework modules
          2. Spring Tool Suite (STS)
          3. Spring subprojects
        2. Design concepts behind Spring Framework
        3. Setting up the development environment
        4. Your first Spring application
          1. Inversion of Control explained
        5. Dependency Injection
          1. The Spring IoC container
          2. Configuration metadata
            1. XML-based configuration metadata
            2. Annotation-based configuration metadata
            3. XML-based versus annotation-based configuration
            4. Component stereotype annotations
            5. Java-based configuration metadata
            6. JSR 330 standard annotations
        6. Beans in detail
          1. Bean definition
          2. Instantiating beans
            1. With constructors
            2. With a static factory-method
            3. With an instance factory-method
          3. Injecting bean dependencies
            1. Constructor-based Dependency Injection
            2. Setter-based Dependency Injection
          4. Constructor-based or setter-based DI – which is better?
          5. Cleaner bean definitions with namespace shortcuts
          6. Wiring a List as a dependency
          7. Wiring a Map as a dependency
          8. Autowiring dependencies
          9. Bean scoping
          10. Dependency Injection with scoped beans
          11. Creating a custom scope
        7. Hooking to bean life cycles
          1. Implementing InitializingBean and DisposableBean
          2. Annotating @PostConstruct and @PreDestroy on @Components
          3. The init-method and destroy-method attributes of <bean/>
        8. Container-level default-init-method and default-destroy-method
        9. Working with bean definition profiles
        10. Injecting properties into the Spring environment
        11. Externalizing properties with PropertyPlaceholderConfigurer
        12. Handling resources
        13. Spring Expression Language
          1. SpEL features
          2. SpEL annotation support
          3. The SpEL API
        14. Aspect Oriented Programming
          1. Static and dynamic AOP
          2. AOP concepts and terminology
          3. Spring AOP – definition and configuration styles
          4. XML schema-based AOP
          5. @AspectJ annotation-based AOP
          6. Declaring an @Aspect annotation
            1. Pointcuts
              1. Pointcut designators
              2. Pointcut examples
            2. Advices
              1. The @Around Advice
              2. Accessing Advice parameters
        15. Testing with Spring
          1. Mock objects
          2. Unit and integration testing utilities
        16. Summary
      2. 2. Building the Web Layer with Spring Web MVC
        1. Features of Spring MVC
        2. The Model-View-Controller pattern
        3. Your first Spring MVC application
        4. Setting up a Spring MVC application
          1. The project structure of a Spring MVC application
          2. The web.xml file – Springifying the web app
          3. ApplicationContext files in a Spring MVC application
          4. HomeController – @Controller for the home screen
          5. The home.jsp file – the landing screen
          6. Handling incoming requests
        5. The architecture and components of Spring MVC
        6. DispatcherServlet explained
          1. WebApplicationContext – ApplicationContext for the Web
          2. Beans supporting DispatcherServlet and their roles
        7. Controllers in detail
          1. Mapping request URLs with @RequestMapping
          2. URI template patterns with the @PathVariable annotation
          3. Binding parameters with the @RequestParam annotation
          4. Request handler method arguments
          5. Request handler method return types
          6. Setting Model attributes
          7. Building RESTful services for JSON and XML media
          8. Building a RESTful service with RestController
        8. Asynchronous request processing in Spring MVC
        9. Working with views
          1. Resolving views
          2. Resolving JSP views
          3. Binding Model attributes in JSP pages using JSTL
        10. Spring and Spring form tag libraries
        11. Composing a form in JSP
        12. Validating forms
        13. Handling file uploads
        14. Resolving Thymeleaf views
        15. More view technologies
        16. Summary
      3. 3. Accessing Data with Spring
        1. Configuring DataSource
        2. Using embedded databases
        3. Handling exceptions in the Spring Data layer
        4. DAO support and @Repository annotation
        5. Spring JDBC abstraction
          1. JdbcTemplate
            1. NamedParameterJdbcTemplate
          2. SimpleJdbc classes
          3. JDBC operations with Sql* classes
        6. Spring Data
          1. Spring Data Commons
          2. Spring Data repository specification
            1. Spring Data JPA
            2. Enabling Spring Data JPA
            3. JpaRepository
          3. Spring Data MongoDB
            1. Enabling Spring Data MongoDB
            2. MongoRepository
          4. Domain objects and entities
            1. Query resolution methods
            2. Using the @Query annotation
            3. Spring Data web support extensions
            4. Auditing with Spring Data
        7. Spring Transaction support
        8. Relevance of Spring Transaction
          1. Spring Transaction fundamentals
          2. Declarative transaction management
            1. Transactional modes – proxy and AspectJ
            2. Defining transactional behavior
            3. Setting rollback rules
          3. Using the @Transactional annotation
            1. Enabling transaction management for @Transactional
          4. Programmatic transaction management
        9. Summary
      4. 4. Understanding WebSocket
        1. Creating a simple WebSocket application
        2. STOMP over WebSocket and the fallback option in Spring 4
        3. Broadcasting a message to a single user in a WebSocket application
        4. Summary
      5. 5. Securing Your Applications
        1. Authentication
        2. Authorization
          1. The OAuth2 Authorization Framework
        3. Summary
      6. 6. Building a Single-Page Spring Application
        1. The motivations behind SPAs
        2. SPAs explained
          1. The architectural benefits of SPAs
          2. SPA frameworks
        3. Introducing Ember.js
        4. The anatomy of an Ember application
          1. Routers
          2. Routes or route handlers
          3. Templates
          4. Components
          5. Models
          6. Controllers
          7. Input helpers
          8. Custom helpers
          9. Initializers
          10. Services
        5. Working with Ember CLI
          1. Setting up Ember CLI
          2. Getting started with Ember CLI commands
          3. The Ember project structure
          4. Working with the POD structure
        6. Understanding the Ember object model
          1. Declaring types (classes) and instances
          2. Accessing and mutating properties
          3. Computed properties
          4. Property observers
        7. Working with collections
        8. Building UI templates using Handlebars
          1. Handlebars helpers
          2. Data binding with input helpers
          3. Using control flow helpers in Handlebars
          4. Using event helpers
        9. Handling routes
        10. Handling UI behavior using components
          1. Building a ToggleButton component step by step
        11. Persisting data with Ember Data
          1. Ember Data architecture
          2. Defining models
          3. Defining model relationships
        12. Building a Taskify application
        13. Building the API server app
          1. Setting up and configuring the project
          2. Defining the model definitions – User and Task
          3. Building API endpoints for the Taskify app
            1. UserController.java
            2. TaskController.java
        14. Building the Taskify Ember app
          1. Setting up Taskify as an Ember CLI project
          2. Setting up Ember Data
          3. Configuring application routes
          4. Building the home screen
          5. Building the user screen
          6. Building a custom helper
          7. Adding action handlers
          8. Building a custom component – modal window
            1. Building userEditModal using {{modal-window}}
          9. Building the task screen
        15. Summary
      7. 7. Integrating with Other Web Frameworks
        1. Spring's JSF integration
        2. Spring's Struts integration
        3. Summary
    7. II. Module 2
      1. 1. Setup Routine for an Enterprise Spring Application
        1. Introduction
          1. Why such a routine?
          2. Why making use of the Eclipse IDE?
          3. Why making use of Maven?
          4. What does the Spring Framework bring?
        2. Installing Eclipse for JEE Developers and Java SE 8
          1. Getting ready
          2. How to do it...
          3. How it works…
            1. Eclipse for Java EE developers
            2. Choosing a JVM
            3. Java SE 8
        3. Configuring Eclipse for Java 8, Maven 3, and Tomcat 8
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. The eclipse.ini file
            2. Setting the –vm option
            3. Customizing JVM arguments
            4. Changing the JDK compliance level
            5. Configuring Maven
            6. A repository manager
            7. Tomcat 8 inside Eclipse
          4. There's more...
        4. Defining the project structure with Maven
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. New Maven project, new Maven module
            2. The standard project hierarchy
            3. The project's structure in the IDE
            4. Maven's build life cycles
              1. The clean life cycle
              2. The default life cycle
              3. Plugin goals
              4. Built-in life cycle bindings
              5. About Maven commands
          4. There's more...
            1. How did we choose the jar module's name?
            2. How did we choose the names for deployable modules?
            3. Why did we create core modules?
          5. See also...
        5. Installing Spring, Spring MVC, and a web structure
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Inheritance of Maven dependencies
              1. Basic inheritance
              2. Managed inheritance
            2. Including third-party dependencies
              1. The Spring Framework dependency model
              2. The Spring MVC dependency
              3. Using Maven properties
            3. The web resources
              1. The target runtime environment
              2. The Spring web application context
              3. Plugins
                1. The Maven compiler plugin
                2. The Maven surefire plugin
                3. The Maven enforcer plugin
                4. The Maven war plugin
          4. There's more...
          5. See also
            1. The Maven checkstyle plugin
      2. 2. Designing a Microservice Architecture with Spring MVC
        1. Introduction
          1. The User eXperience paradigm
          2. Microservice architectures
        2. Configuring a controller with simple URL mapping
          1. Getting ready
          2. How to do it...
            1. Downloading and installing GIT
            2. Configuring GIT in Eclipse
          3. How it works...
            1. Spring MVC overview
              1. Front controller
              2. MVC design pattern
              3. Spring MVC flow
            2. DispatcherServlet – the Spring MVC entrypoint
            3. Annotation-defined controllers
              1. @Controller
              2. @RequestMapping
            4. Controller method-handler signatures
              1. Supported method arguments types
              2. Supported annotations for method arguments
              3. Supported return Types
          4. There's more...
        3. Configuring a fallback controller using ViewResolver
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. URI template patterns
              1. Ant-style path patterns
              2. Path pattern comparison
              3. ViewResolvers
          4. There's more...
            1. @PathVariable to read variables in URI template patterns
        4. Setting up and customizing a responsive single page webdesign with Bootstrap
          1. Getting ready
          2. How to do it...
            1. Installing a Bootstrap theme
            2. Customising a Bootstrap theme
            3. Creating responsive content
          3. How it works...
            1. The theme installation
            2. Bootstrap highlights
              1. Bootstrap scaffolding
                1. Grid system and responsive design
                2. Defining columns
                3. Offsetting and nesting
                4. Fluid gridding
              2. Bootstrap CSS utilities
                1. Uniform Buttons
                2. Icons
                3. Tables
              3. Bootstrap components
                1. Navbars
                2. Hero units
                3. Alerts
                4. Badges and labels
          4. There's more...
          5. See also
        5. Displaying a model in the View, using the JSTL
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. The approach to handle our data
              1. Injection of services via interfaces
              2. How does Spring choose the dummy implementations?
              3. DTOs to be used in View layer
              4. Dummy service implementations
            2. Populating the Model in the controller
            3. Rendering variables with the JSP EL
              1. Implicit objects
            4. Rendering variables with the JSTL
              1. Taglib directives in JSPs
          4. There's more...
            1. More about JSP EL
            2. More about the JavaBeans standard
            3. More about the JSTL
        6. Defining a common WebContentInterceptor
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Common behaviors for Controllers
            2. Global session control
              1. Requiring sessions
              2. Synchronizing sessions
            3. Cache-header management
            4. HTTP method support
            5. A high-level interceptor
            6. Request lifecycle
          4. There is more...
            1. More features offered by WebContentGenerator
          5. See also...
            1. Web caching
            2. New support classes for @RequestMapping since Spring MVC 3.1
        7. Designing a client-side MVC pattern with AngularJS
          1. Getting ready
          2. How to do it...
            1. Setting up the DOM and creating modules
            2. Defining the module's components
          3. How it works...
            1. One app per HTML document
              1. Module autobootstrap
              2. Manual module bootstrap
            2. AngularJS Controllers
              1. Bidirectional DOM-scope binding
            3. AngularJS directives
              1. ng-repeat
              2. ng-if
            4. AngularJS factories
              1. Dependency injection
          4. There's more...
      3. 3. Working with Java Persistence and Entities
        1. Introduction
          1. The Entities' benefits
          2. The Entity manager and its persistence context
        2. Configuring the Java Persistence API in Spring
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. The Spring-managed DataSource bean
            2. The EntityManagerFactory bean and its persistence unit
            3. The Spring Data JPA configuration
          4. See also
        3. Defining useful EJB3 entities and relationships
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Entity requirements
            2. Mapping the schema
              1. Mapping tables
              2. Mapping columns
              3. Annotating fields or getters
              4. Mapping primary keys
              5. Identifier generation
            3. Defining inheritance
              1. The single-table strategy
              2. The table-per-class strategy
            4. Defining relationships
              1. How relationships between entities have been chosen
          4. There's more...
            1. The FetchType attribute
            2. The Cascade attribute
          5. See also
        4. Making use of the JPA and Spring Data JPA
          1. How to do it...
          2. How it works...
            1. Injecting an EntityManager instance
            2. Using JPQL
            3. Reducing boilerplate code with Spring Data JPA
              1. Query creation
              2. Persisting Entities
          3. There's more...
            1. Using native SQL queries
            2. Transactions
          4. See also
      4. 4. Building a REST API for a Stateless Architecture
        1. Introduction
          1. A definition of REST
          2. RESTful CloudStreetMarket
        2. Binding requests and marshalling responses
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. A super RequestMappingHandlerAdapter bean
              1. Broad support for @RequestMapping annotations
                1. setMessageConverters
                2. setCustomArgumentResolvers
                3. setWebBindingInitializer
              2. The ConversionService API
              3. Choosing between PropertyEditors or converters
          4. There's more...
            1. Built-in PropertyEditor implementations
            2. The Spring IO reference document
        3. Configuring content-negotiation (JSON, XML, and so on)
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Support for XML marshalling
              1. The XStream marshaller
            2. Negotiation strategies with ContentNegotiationManager
              1. The Accept header
              2. The file extension suffix in the URL path
              3. The request parameter
              4. Java Activation Framework
            3. @RequestMapping annotations as ultimate filters
          4. There's more...
            1. Using a JAXB2 implementation as an XML parser
            2. The ContentNegotiationManagerFactoryBean JavaDoc
        4. Adding pagination, filters, and sorting capabilities
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Spring Data pagination support (you will love it!)
              1. Pagination and sorting in repositories
              2. PagingAndSortingRepository<T,ID>
              3. The web part – PageableHandlerMethodArgumentResolver
            2. A useful specification argument resolver
              1. The JPA2 criteria API and Spring Data JPA specifications
              2. SpecificationArgumentResolver
          4. There's more...
            1. Spring Data
            2. Angular routes
          5. See also
            1. Bootstrap pagination with the Angular UI
        5. Handling exceptions globally
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Global exception handling with @ControllerAdvice
              1. The support ResponseEntityExceptionHandler class
              2. A uniform error response object
          4. There's more...
            1. HTTP Status Codes
            2. The official article about exception handling in Spring MVC
            3. JavaDocs
          5. See also
        6. Documenting and exposing an API with Swagger
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. An exposed metadata
            2. The Swagger UI
          4. There's more...
            1. The Swagger.io
            2. The swagger-springmvc documentation
          5. See also
            1. Different tools, different standards
      5. 5. Authenticating with Spring MVC
        1. Introduction
        2. Configuring Apache HTTP to proxy your Tomcat(s)
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. DNS configuration or host aliasing
            2. In production – editing DNS records
            3. An alias for the host
              1. Alias definition for OAuth developments
            4. Apache HTTP configuration
              1. Virtual-hosting
              2. The mod_proxy module
              3. ProxyPassReverse
                1. Workers
              4. The mod_alias module
            5. Tomcat connectors
              1. HTTP connectors
              2. AJP connectors
          4. There is more…
          5. See also
            1. Alternatives to Apache HTTP
        3. Adapting users and roles to Spring Security
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Introduction to Spring Security
            2. ThreadLocal context holders
            3. Noticeable Spring Security interfaces
            4. The Authentication interface
            5. The UserDetails interface
              1. Authentication providers
                1. The UserDetailsManager interface
              2. The GrantedAuthority interface
          4. There is more…
            1. Spring Security reference
              1. Technical overview
              2. Sample applications
              3. Core services
        4. Authenticating over a BASIC scheme
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. The Spring Security namespace
              1. The <http> component
              2. The Spring Security filter-chain
                1. Our <http> configuration
            2. The AuthenticationManager interface
            3. Basic authentication
              1. BasicAuthenticationFilter
                1. With an authenticationEntryPoint
                2. Without an authenticationEntryPoint
          4. There is more…
            1. In the Spring Security reference
            2. The remember-me cookie/feature
        5. Authenticating with a third-party OAuth2 scheme
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. From the application point of view
            2. From the Yahoo! point of view
              1. OAuth2 explicit grant flow
              2. Refresh-token and access-token
            3. Spring social – role and key features
            4. Social connection persistence
            5. Provider-specific configuration
              1. One entry-point – connectionFactoryLocator
              2. Provider-specific ConnectionFactories
              3. Signing in with provider accounts
          4. There is more…
            1. Performing authenticated API calls
            2. The Spring social ConnectController
          5. See also
            1. SocialAuthenticationFilter
            2. The list of Spring social connectors
            3. Implementing an OAuth2 authentication server
            4. The harmonic development blog
        6. Storing credentials in a REST environment
          1. Getting ready
          2. How to do it...
            1. Client side (AngularJS)
            2. Server side
          3. How it works...
            1. Authenticating for Microservices
            2. Using the BASIC authentication
              1. Using OAuth2
            3. HTML5 SessionStorage
            4. SSL/TLS
            5. BCryptPasswordEncoder
          4. There is more…
            1. Setting HTTP headers with AngularJS
            2. Browser support for localStorage
            3. About SSL and TLS
        7. Authorizing on services and controllers
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Spring Security authorities
            2. Configuration attributes
            3. Pre-invocation handling
              1. AccessDecisionManager
            4. After invocation handling
            5. Expression-based access control
              1. Web Security expressions
              2. Method security expressions
                1. Access control using @PreAuthorize and @PostAuthorize
                2. Filtering collections using @PreFilter and @PostFilter
            6. JSR-250 and legacy method security
          4. There is more…
            1. Domain Object Security (ACLs)
            2. Spring EL
            3. The Spring Security reference
          5. See also
      6. 6. Implementing HATEOAS
        1. Introduction
          1. The Richardson Maturity Model
        2. Turning DTOs into Spring HATEOAS resources
          1. How to do it…
          2. How it works...
            1. Spring HATEOAS resources
              1. The ResourceSupport class
              2. The Resource class
            2. The Identifiable interface
            3. Abstracting the Entities' @Id
          3. There's more…
          4. See also
        3. Building links for a hypermedia-driven API
          1. How to do it…
          2. How it works...
            1. Resource assemblers
            2. PagedResourcesAssembler
            3. Building links
              1. EntityLinks
              2. ControllerLinkBuilder
          3. There's more…
            1. The use of regular expressions in @RequestMapping
          4. See also
        4. Choosing a strategy to expose JPA Entities
          1. How to do it…
          2. How it works...
            1. The REST CRUD principle
            2. Exposing the minimum
              1. If the Entity doesn't own the relationship
              2. If the Entity owns the relationship
            3. Separation of resources
          3. There's more…
            1. Jackson custom serializers
            2. XStream converters
        5. Retrieving data from a third-party API with OAuth
          1. How to do it…
          2. How it works...
            1. Introduction to the financial data of Yahoo!
              1. Graph generation/display
            2. How is the financial data pulled/refreshed?
            3. Calling third-party services
          3. There's more…
            1. Spring Social — existing API providers
          4. See also
      7. 7. Developing CRUD Operations and Validations
        1. Introduction
        2. Extending REST handlers to all HTTP methods
          1. Getting ready
          2. How to do it…
          3. How it works...
            1. HTTP/1.1 specifications – RFC 7231 semantics and content
              1. Basic requirements
              2. Safe and Idempotent methods
              3. Other method-specific constraints
            2. Mapping request payloads with @RequestBody
            3. HttpMessageConverters
              1. Provided HttpMessageConverters
              2. Using MappingJackson2HttpMessageConverter
            4. Using @RequestPart to upload an image
            5. Transaction management
              1. The simplistic approach
          4. There's more…
            1. Transaction management
              1. ACID properties
              2. Global versus local transactions
          5. See also
        3. Validating resources using bean validation support
          1. Getting ready
          2. How to do it…
          3. How it works...
            1. Using Spring validator
              1. ValidationUtils
              2. I18n validation errors
            2. Using JSR-303/JSR-349 Bean Validation
              1. On-field constraint annotations
                1. Implementation-specific constraints
              2. LocalValidator (reusable)
          4. There's more…
            1. ValidationUtils
            2. Grouping constraints
            3. Creating a custom validator
            4. The Spring reference on validation
          5. See also
        4. Internationalizing messages and contents for REST
          1. How to do it…
            1. Backend
            2. Frontend
          2. How it works...
            1. MessageSource beans
              1. ResourceBundleMessageSource
              2. ReloadableResourceBundleMessageSource
              3. StaticMessageSource
            2. Our MessageSource bean definition
            3. Using a LocaleResolver
              1. AcceptHeaderLocaleResolver
              2. FixedLocaleResolver
              3. SessionLocaleResolver
              4. CookieLocaleResolver
          3. There's more…
            1. Translating client-side with angular-translate.js
        5. Validating client-side forms with HTML5 AngularJS
          1. How to do it…
          2. How it works...
            1. Validation-constraints
              1. Required
              2. Minimum/maximum length
              3. Regex pattern
              4. Number/e-mail/URL
            2. Control variables in forms
              1. Modified/Unmodified state
              2. Valid/Invalid state
              3. Errors
            3. Form state transclusions and style
          3. See also
      8. 8. Communicating Through WebSockets and STOMP
        1. Introduction
        2. Streaming social events with STOMP over SockJS
          1. Getting ready
          2. How to do it…
            1. Apache HTTP Proxy configuration
            2. Frontend
            3. Backend
          3. How it works...
            1. An introduction to WebSockets
              1. WebSocket Lifecycle
              2. Two dedicated URI schemes
            2. The STOMP protocol
            3. SockJS
            4. Spring WebSocket support
              1. All-in-one configuration
              2. Defining message handlers via @MessageMapping
            5. Sending a message to dispatch
              1. SimpMessagingTemplate
              2. The @SendTo annotation
          4. There's more…
          5. See also
        3. Using RabbitMQ as a multiprotocol message broker
          1. Getting ready
          2. How to do it…
          3. How it works...
            1. Using a full-featured message broker
              1. Clusterability – RabbitMQ
              2. More STOMP message types
            2. StompMessageBrokerRelay
          4. See also
        4. Stacking and consuming tasks with RabbitMQ and AMQP
          1. Getting ready
          2. How to do it…
            1. Sender side
            2. Consumer side
            3. Client-side
          3. How it works...
            1. Messaging architecture overview
              1. A scalable model
            2. AMQP or JMS?
          4. There's more…
            1. A great introduction to AMQP by pivotal
            2. A better way to publish application events
          5. See also
        5. Securing messages with Spring Session and Redis
          1. Getting ready
          2. How to do it…
            1. Apache HTTP proxy configuration
            2. Redis server installation
            3. MySQL server installation
            4. Application-level changes
            5. RabbitMQ configuration
            6. The results
          3. How it works...
            1. The Redis server
            2. Spring session
              1. SessionRepositoryFilter
                1. RedisConnectionFactory
              2. CookieHttpSessionStrategy
              3. Spring Data Redis and Spring Session Data Redis
            3. The Redis Session manager for Tomcat
            4. Viewing/flushing sessions in Redis
            5. securityContextPersistenceFilter
            6. AbstractSessionWebSocketMessageBrokerConfigurer
            7. AbstractSecurityWebSocketMessageBrokerConfigurer
          4. There's more…
            1. Spring Session
            2. Apache HTTP proxy extra configuration
            3. Spring Data Redis
          5. See also
      9. 9. Testing and Troubleshooting
        1. Introduction
        2. Automating Database Migrations with FlyWay
          1. Getting ready
          2. How to do it…
          3. How it works...
            1. A limited number of commands
              1. Migrate
              2. Clean
              3. Info
              4. Validate
              5. Baseline
              6. Repair
            2. About Flyway Maven plugin
          4. There is more…
            1. The official documentation
          5. See also
        3. Unit testing with Mockito and Maven Surefire
          1. How to do it…
          2. How it works...
            1. @Test annotation
              1. The expected and timeout arguments
            2. The @RunWith annotation
            3. @Before and @After annotations
            4. @BeforeClass and @AfterClass annotations
            5. Using Mockito
              1. MockitoJUnitRunner
              2. The transferCriticalData example
              3. The registerUser example
          3. There is more…
            1. About Mockito
            2. JUnit Rules
          4. See also
        4. Integration testing with Cargo, Rest-assured, and Maven failsafe
          1. Getting ready
          2. How to do it…
          3. How it works...
            1. Maven Failsafe versus Maven Surefire
            2. Code Cargo
              1. Cargo Maven Plugin
                1. Binding to Maven phases
                2. Using an existing Tomcat instance
            3. Rest assured
              1. Static imports
              2. A Given, When, Then approach
          4. There is more…
            1. About Cargo
            2. More REST-assured examples
        5. Injecting Spring Beans into integration tests
          1. Getting ready
          2. How to do it…
          3. How it works...
            1. SpringJUnit4ClassRunner
            2. The @ContextConfiguration annotation
          4. There is more…
            1. JdbcTemplate
            2. Abstraction of boilerplate logic
              1. Extraction of auto-generated IDs
        6. Modern application Logging with Log4j2
          1. Getting ready
          2. How to do it…
          3. How it works...
            1. Apache Log4j2 among other logging frameworks
              1. The case of SLF4j
            2. Migrating to log4j 2
              1. Log4j 2 API and Core
              2. Log4j 2 Adapters
                1. Log4j 1.x API Bridge
                2. Apache Commons Logging Bridge
                3. SLF4J Bridge
                4. Java Util Logging Adapters
                5. Web Servlet Support
            3. Configuration files
          4. There is more…
            1. Automatic configuration
            2. Official documentation
            3. Interesting Redis Appender implementation
    8. III. Module 3
      1. 1. Mastering the MVC Architecture
        1. The MVC architecture
        2. MVC critics and best practices
          1. Anemic Domain Model
          2. Learning from the sources
        3. Spring MVC 1-0-1
        4. Using Thymeleaf
          1. Our first page
        5. Spring MVC architecture
          1. DispatcherServlet
          2. Passing data to the view
        6. Spring Expression Language
          1. Getting data with a request parameter
        7. Enough Hello Worlds, let's fetch tweets!
          1. Registering your application
          2. Setting up Spring Social Twitter
          3. Accessing Twitter
        8. Java 8 streams and lambdas
        9. Material design with WebJars
          1. Using layouts
          2. Navigation
        10. The check point
        11. Summary
      2. 2. Handling Forms and Complex URL Mapping
        1. The profile page – a form
        2. Validation
          1. Customize validation messages
          2. Custom annotation for validation
        3. Internationalization
          1. Changing the locale
          2. Translating the application text
          3. A list in a form
        4. Client validation
        5. The check point
        6. Summary
      3. 3. File Upload and Error Handling
        1. Uploading a file
          1. Writing an image to the response
          2. Managing upload properties
          3. Displaying the uploaded picture
          4. Handling file upload errors
        2. Translating the error messages
        3. Placing the profile in a session
        4. Custom error pages
        5. URL mapping with matrix variables
        6. Putting it together
        7. The check point
        8. Summary
      4. 4. Crafting a RESTful Application
        1. What is REST?
        2. Richardson's maturity model
          1. Level 0 – HTTP
          2. Level 1 – Resources
          3. Level 2 – HTTP verbs
          4. Level 3 – Hypermedia controls
        3. API versioning
        4. Useful HTTP codes
        5. Client is the king
        6. Debugging a RESTful API
          1. A JSON formatting extension
          2. A RESTful client in your browser
          3. httpie
        7. Customizing the JSON output
        8. A user management API
        9. Status codes and exception handling
          1. Status code with ResponseEntity
          2. Status codes with exceptions
        10. Documentation with Swagger
        11. Generating XML
        12. The check point
        13. Summary
      5. 5. Securing Your Application
        1. Basic authentication
          1. Authorized users
          2. Authorized URLs
          3. Thymeleaf security tags
        2. The login form
        3. Twitter authentication
          1. Setting up social authentication
          2. Explanation
        4. Distributed sessions
        5. SSL
          1. Generating a self-signed certificate
          2. The easy way
          3. The dual way
          4. Behind a secured server
        6. The check point
        7. Summary
      6. 6. Leaving Nothing to Luck – Unit Tests and Acceptance Tests
        1. Why should I test my code?
        2. How should I test my code?
        3. Test-driven development
        4. The unit tests
          1. The right tools for the job
        5. The acceptance tests
        6. Our first unit test
        7. Mocks and stubs
          1. Mocking with Mockito
          2. Stubbing our beans while testing
          3. Should I use mocks or stubs?
        8. Unit testing REST controllers
        9. Testing the authentication
        10. Writing acceptance tests
          1. The Gradle configuration
          2. Our first FluentLenium test
          3. Page Objects with FluentLenium
          4. Making our tests more Groovy
          5. Unit tests with Spock
          6. Integration tests with Geb
          7. Page Objects with Geb
        11. The check point
        12. Summary
      7. 7. Optimizing Your Requests
        1. A production profile
        2. Gzipping
        3. Cache control
        4. Application cache
          1. Cache invalidation
          2. Distributed cache
        5. Async methods
        6. ETags
        7. WebSockets
        8. The check point
        9. Summary
      8. 8. Deploying Your Web Application to the Cloud
        1. Choosing your host
          1. Cloud Foundry
          2. OpenShift
          3. Heroku
        2. Deploying your web application to Pivotal Web Services
          1. Installing the Cloud Foundry CLI tools
          2. Assembling the application
          3. Activating Redis
        3. Deploying your web application on Heroku
          1. Installing the tools
          2. Setting up the application
            1. Gradle
            2. Procfile
          3. A Heroku profile
          4. Running your application
          5. Activating Redis
        4. Improving your application
        5. Summary
      9. 9. Beyond Spring Web
        1. The Spring ecosystem
          1. Core
          2. Execution
          3. Data
          4. Other noteworthy projects
        2. The deployment
          1. Docker
        3. Single Page Applications
          1. The players
          2. The future
          3. Going stateless
        4. Summary
    9. A. Bibliography
    10. Index