Josh Juneau Java EE 8 Recipes A Problem-Solution Approach 2nd ed. Josh Juneau Hinckley, Illinois, USA Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page, located at www.apress.com/9781484235935 . For more detailed information, please visit http://www.apress.com/source-code . ISBN 978-1-48423593-5 e-ISBN 978-1-4842-3594-2 https://doi.org/10.1007/978-1-4842-3594-2 Library of Congress Control Number: 2018946699 © Josh Juneau 2018 This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800- SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. This book is dedicated to my wife Angela, my five children: Kaitlyn, Jacob, Matthew, Zachary, and Lucas. You are my joy and inspiration. It is also dedicated to the many Java developers worldwide. I hope that these recipes can lead you to developing the sophisticated solutions of tomorrow. —Josh Juneau Introduction The Java platform is one of the most widely used platforms for application development in the world. The platform is so popular that there are several different flavors of Java that can be used for developing applications that run on different mediums. From development of desktop, mobile, or web applications and hardware operating systems, Java can be utilized for development of just about any solution. As such, Java has become a very popular platform for development of web and enterprise applications, offering web services, reliability, security, and much more. Java Enterprise Edition was originally released in 1999 as Java 2 Platform, Enterprise Edition (J2EE). Although several enterprise frameworks were available for development of reliable and secure applications on the Java platform, it made sense to standardize some solutions in order to minimize customization and help provide standards around Java Enterprise development to make it more prevalent in the industry. The platform originally included a terse number of specifications for standardization, including Java Servlet, JavaServer Pages, RMI, Java Database Connectivity (JDBC), Java Message Service API (JMS), Java Transaction API (JTA), and Enterprise JavaBeans. Early development of J2EE applications had a large learning curve, and it was cumbersome because it required lots of XML configuration. Even with these setbacks, it became popular among larger organizations and companies due to the prevalence of Java and its well-known security benefits. In 2001, J2EE 1.3 was released, adding more specifications to the platform, including the JavaServer Pages Standard Tag Library (JSTL), and Java Authentication and Authorization Service (JAAS). Other specifications, such as Java Servlet, also gained enhancements under the J2EE 1.3 release, making evolutionary enhancements to the platform. The release of J2EE 1.4 in 2003 marked a major milestone for Java Enterprise, as many new specifications were added to the platform, providing standards for even more Java technologies. The release of J2EE 1.4 marked the first iteration of Web Services for J2EE 1.1, JavaServer Faces (JSF), and Java APIs for XML solutions such as JAXP, JAXR, and more. Although the release of J2EE 1.4 included many specifications, it was still deemed as “difficult to learn,” “cumbersome,” and “not productive”. Over the next few years, J2EE was re-worked in an attempt to make it easier to learn and utilize for the construction of modern web applications. Although XML is an excellent means for configuration, it can be cumbersome and difficult to manage, so configuration was a big item that was being addressed for the next release. Technologies such as Enterprise JavaBeans (EJB) included some redundant characteristics, making EJB coding time-consuming and difficult to manage, so an overhaul of EJB was also in order. In May of 2006, Java EE 5 was released, leaving the J2EE acronym behind, and changing to simply Java EE instead. The Java EE 5 platform was significantly easier to use and maintain because features such as annotations were introduced, cutting down the amount of XML configuration significantly, as configuration could now be injected via annotations. EJBs were made easier to develop, and Java Persistence API (JPA) became a marketable technology for object-relational mapping. Java Enterprise Edition has since become a widely adopted and mature platform for enterprise development. Java EE 6 was released in 2009, making configuration and APIs even easier, and adding more specifications to the platform. Specifications such as Contexts and Dependency Injection and Bean Validation were introduced, vastly changing the landscape of the platform and streamlining development. Java EE 7 (released in 2013) continued to strengthen and modernize the platform, adding the WebSockets and JSON-P specifications. In the Java EE 7 release, specifications such as JSF and EJB were also enhanced, adding even more features to increase productivity and functionality and allowing them to work better for more modern web solutions. What occurred next in the timeline was a definitive game changer for the Java EE platform. The Java EE 8 initiative had begun in 2015 and many of the specifications that make up the platform had begun to work. The focus of Java EE 8 was to continue to work toward Java SE 8 compatibility throughout the APIs and to continue making the APIs easier to use. There was also a focus on creating new specifications around making microservices easier to develop with Java EE. In late 2015, many of the specifications stopped moving forward, and there was a halt in progress across the board. A few specifications, such as JSF, CDI, and JSON-B, continued to progress, while many of the others stalled. During this stall, the community became concerned about the future of Java EE, and there was a perception that it was going to be dropped. Oracle was silent on the progress of Java EE 8 and uncertainty was in the air. It was during this same timeframe that the Java EE Guardians group was formed, with the focus on trying to make Oracle produce a statement about the future direction of the platform, and to make open source the platform rather than dropping it. Around that same time, the Microprofile project was started as a collaborative effort by a number of the Java EE container vendors, with the focus on providing a true Microservices profile for the Java EE platform. In late 2016, Oracle changed the direction of Java EE 8 by removing some of the previously planned specification updates and adding others. There became a renewed effort to keep Java EE 8 moving forward in the hopes to produce a final release in 2017, working towards a better platform for producing microservices based applications. The Java EE 8 release was final in the fall of 2017, and it included updates to many of the specifications. However, even some of the specifications that were planned for enhancing microservices development were dropped in an effort to produce a timely release, including MVC and the Health Checking API. In early Fall 2017 just before the release of Java EE 8, Oracle announced that they were going to open source Java EE. After a short while, it was announced that Oracle was going to contribute all of the Java EE sources (for each of the underlying specifications), along with all documentation and TCKs (Technology Compatibility Kits) to the Eclipse Foundation. In late 2017, the EE4J (Eclipse Enterprise for Java) project was formed, and the transfer of each specification began. In early 2018 it was voted that the new name for the platform under the open source EE4J project would become Jakarta EE. Once all of the specification sources, documentation, and TCKs were transferred, Jakarta EE was to release a 1.0, which was in parity with Java EE 8. This book focuses on the Java EE 8 release, as well as the Jakarta EE initial release. As such, throughout this book, I will refer to the platform as Java EE 8. However, each of the recipes in this book also work with the initial release of Jakarta EE. The platform is covered as a whole, touching upon each most of the widely used specifications that make up Java EE. You will learn how to use each of the major specifications, making use of real-world examples and solutions. This book will cover APIs that have not been updated for Java EE 8, as well as those that have been enhanced, providing complete coverage for those who are newer to the platform. It also features recipes that cover the newest features of the platform, so that seasoned Java EE developers can skip those introductory concepts and delve into newer material. I work with Java EE/Jakarta EE on a daily basis, and I have a deep passion for the technologies involved in the platform. I hope that this book increases your passion and productivity using the platform in its entirety.